贝宝中的NOT_AUTHORIZED PAYE_NOT_CONSENTED



我是PayPal的新手,我正在尝试创建一个像Fiverr和Upwork这样的应用程序,用户可以在其中销售服务并获得报酬,但在他们开始销售服务之前,他们需要连接他们的PayPal账户,这样当他们销售服务时,他们就会获得报酬,我们会收取5%的金额,而获得报酬的过程是自动的,所以钱会直接进入他们的PayPal账户

这是我的代码,我可以成功地将用户连接到我的应用程序,我会得到商家id和所有东西,但当我试图向他们转账时,我会收到错误的

我正在使用带有srmklive/贝宝软件包的laravel 9

我的按钮代码

<a href="{{ route('paypal.connect')}}">
<x-jet-secondary-button>Connect Your Paypal</x-jet-secondary-button>
</a>
<a href="{{ route('paypal.process' , ['order_no' => 'Ord62399de81ab99']) }}">
<x-jet-secondary-button>Pay with your Paypal</x-jet-secondary-button>
</a>

我的路线

Route::get('/process/{order_no}', [PaypalController::class, 'processPaypal'])->name('process');
Route::get('/success', [PaypalController::class, 'processSuccess'])->name('success');
Route::get('/cancel', [PaypalController::class, 'processCancel'])->name('cancel');
Route::get('/connect', [PaypalController::class, 'connect'])->name('connect');
Route::get('/connect/success', [PaypalController::class, 'connectSuccess'])->name('connect.success');

我的控制器代码现在要测试的是,我有一个买家和一个卖家,所以当我付款时,现在只有这个卖家会得到付款,所以为什么我静态地通过了marchent_id,一旦我成功实现了这一点,我会将其添加到用户表中的数据库中,这样每个用户都会有他们的商家id<?php

namespace AppHttpControllers;

use AppModelsOrder;
use AppModelsUser;
use IlluminateHttpRequest;
use IlluminateSupportStr;
use SrmklivePayPalServicesPayPal as PayPalClient;

class PaypalController extends Controller
{
public $provider;

public function __construct()
{
$this->provider = new PayPalClient;
$this->provider->setApiCredentials(config('paypal'));
$this->provider->setRequestHeader('PayPal-Partner-Attribution-Id', '&lt;BN_CODE&gt;');
//        $this->provider->setReturnAndCancelUrl(route('dashboard'), route('dashboard'));
$paypalToken = $this->provider->getAccessToken();
}

public function connect()
{
$provider = new PayPalClient;
$provider->setApiCredentials(config('paypal'));
$paypalToken = $provider->getAccessToken();
$provider->setAccessToken($paypalToken);
$res = $provider->createPartnerReferral([
"tracking_id" => uniqid(Str::random(40), true),
"partner_config_override" => [
"return_url" => route('paypal.connect.success')
],
"operations" => [
[
"operation" => "API_INTEGRATION",
"api_integration_preference" => [
"rest_api_integration" => [
"integration_method" => "PAYPAL",
"integration_type" => "FIRST_PARTY",
"first_party_details" => [
"features" => [
"PAYMENT",
"REFUND"
],
]
]
]
]
],
"products" => [
"EXPRESS_CHECKOUT"
],
"legal_consents" => [
[
"type" => "SHARE_DATA_CONSENT",
"granted" => true
]
]
]);

//action_url
if (isset($res['links'])) {
foreach ($res['links'] as $link) {
if ($link['rel'] == 'action_url') {
return redirect()->away($link['href']);
}
}
return redirect()->route('dashboard')->with('something went wrong');
}
}

public function connectSuccess(Request $request)
{
if (isset($request['merchantId']) &&
$request['merchantId'] != null &&
$request['permissionsGranted'] === true &&
$request['isEmailConfirmed'] === true) {
redirect()->to(env('APP_URL') . "/dashboard?merchantId=" . $request['merchantId'] . "&merchantIdInPayPal=" . $request['merchantIdInPayPal'] . "&permissionsGranted=true&accountStatus=BUSINESS_ACCOUNT&consentStatus=true&productIntentId=addipmt&isEmailConfirmed=true&returnMessage=To%20start%20accepting%20payments,%20please%20log%20in%20to%20PayPal%20and%20finish%20signing%20up")
->with('success', 'your account is Linked Successfully');
} else {
redirect()->route('dashboard')->with('error', $request['massage']);
}
}

public function processPaypal(Request $request)
{
//      $response = $this->provider->createOrder([
//        "intent" => "CAPTURE",
//        "application_context" => [
//          "return_url" => route('paypal.success'),
//          "cancel_url" => route('paypal.cancel'),
//        ],
//        "purchase_units" => [
//          0 => [
//            "amount" => [
//              "currency_code" => "USD",
//              "value" => "1.00"
//            ]
//          ]
//        ]
//      ]);
$order = Order::with('freelancer')->where('order_no', $request->order_no)->first();


$response = $this->provider->createOrder([
"headers" => "PayPal-Partner-Attribution-Id: &lt;FLAVORsb-u4l7k14614776_MP&gt;",
"intent" => "CAPTURE",
"application_context" => [
"return_url" => route('paypal.success'),
"cancel_url" => route('paypal.cancel'),
],
"purchase_units" => [
0 => [
"amount" => [
"currency_code" => "USD",
"value" => "5.00"
],
"payee" => [
"merchant_id" => "7PYAZ7V939UJW"
],
"payment_instruction" => [
"disbursement_mode" => "INSTANT",
"platform_fees" => [
0 => [
"amount" => [
"currency_code" => "USD",
"value" => "1.00"
],
"payee" => [
"merchant_id" =>     env("MY_PAYPAL_MARCHENT_ID")
]
]
]
]
],
]
]);
if (isset($response['id']) && $response['id'] != null) {
// redirect to approve href
foreach ($response['links'] as $links) {
if ($links['rel'] == 'approve') {
return redirect()->away($links['href']);
}
}
return redirect()
->route('orders.index')
->with('error', 'Something went wrong.');
} else {
return redirect()
->route('orders.index')
->with('error', $response['message'] ?? 'Something went wrong.');
}
}


public function processSuccess(Request $request)
{
$response = $this->provider->capturePaymentOrder($request['token']);

if (isset($response['status']) && $response['status'] == 'COMPLETED') {

return redirect()
->route('dashboard')
->with('success', 'Transaction complete.');

} else {

return redirect()
->route('dashboard')
->with('error', $response['message'] ?? 'Something went wrong.');

}


}


public
function processCancel(Request $request)

{

return redirect()
->route('orders.index')
->with('error', $response['message'] ?? 'You have canceled the transaction.');
}


}

这是我在尝试转账时遇到的错误

{} {"name":"NOT_AUTHORIZED","details":[{"issue":"PAYEE_NOT_CONSENTED","description":"Payee does not have appropriate consent to allow the API caller to process this type of transaction on their behalf. Your current setup requires the 'payee' to provide a consent before this transaction can be processed successfully."}],"message":"Authorization failed due to insufficient permissions.","debug_id":"3f2c4f80f412c","links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-PAYEE_NOT_CONSENTED","rel":"information_link","method":"GET"}]}

关于错误,这意味着您没有代表收款人7PYAZ7V939UJW创建订单的权限

我看到你在使用静态

"payee" => [
"merchant_id" => "7PYAZ7V939UJW"
]`;

这意味着所有订单的收款人都将是上述id,但你需要使这个动态,

你需要更新你的代码逻辑,在connectSuccess方法中,需要保留连接的帐户数据merchant_id,并将它们附加到数据库中的卖家数据,以便在创建与连接的卖家相关的订单时使用它们。

此外,最好将平台收款人merchant_id移动改为以静态方式编写。

最新更新