PAYPAL PHP SDK OrdersCaptureRequest error with statusCode 42



我使用最新的paypal php sdk sandbox和样本与laravel框架,创建订单总是成功,但当捕获订单时它总是失败

并返回这个错误:

"{"name":"UNPROCESSABLE_ENTITY",
"details":[
{"issue":"COMPLIANCE_VIOLATION",
"description":"Transaction cannot be processed due to a possible compliance violation. To get more information about the transaction, call Customer Support."}],
"message":"The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id":"d701744348160",
"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-COMPLIANCE_VIOLATION","rel":"information_link","method":"GET"}]}
我web.php文件:

Route::get('capture_order', 'PayController@capture_order')->name('capture_order');
Route::get('create_order', 'PayController@create_order')->name('create_order');
Route::get('cancel', 'PayController@cancel')->name('payment.cancel');
Route::get('return', 'PayController@return')->name('payment.return');
Route::get('success', 'PayController@success')->name('payment.success');

,PayController:

<?php 
namespace AppHttpControllers;

use IlluminateHttpRequest;
use PayPalCheckoutSdkCorePayPalHttpClient;
use PayPalCheckoutSdkCoreSandboxEnvironment;
use PayPalCheckoutSdkOrdersOrdersCreateRequest;
use PayPalCheckoutSdkOrdersOrdersCaptureRequest;
class PayController extends Controller
{
public $clientId;
public $clientSecret;
public $client;
public $cancel_url = 'http://localhost:8000/cancel';
public $return_url = 'http://localhost:8000/return';
public function __construct()
{
$mode = config('paypal.mode', 'sandbox');
if ($mode == "live")  {
$this->clientId     = config('paypal.live.client_id');
$this->clientSecret = config('paypal.live.client_secret');
} else {
$this->clientId     = config('paypal.sandbox.client_id');
$this->clientSecret = config('paypal.sandbox.client_secret');
}
$environment = new SandboxEnvironment($this->clientId, $this->clientSecret);
$this->client = new PayPalHttpClient($environment);
}

private function buildRequestBody()
{
return [
'intent' => 'CAPTURE',
'application_context' =>[ "cancel_url" => $this->cancel_url,
"return_url" => $this->return_url],

'purchase_units' =>
[
0 => [
'amount' =>
[
'currency_code' => 'USD',
'value' => '20'
]
]
]
];
}

public function create_order()
{
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = $this->buildRequestBody();
try {
$response = $this->client->execute($request);
foreach ($response->result->links as $key => $value) {
if ($value->rel == "approve") 
{
return redirect($value->href);
}
}
}catch (Exception $ex) {
echo $ex->statusCode;
print_r($ex->getMessage());
}
}
public function capture_order(Request $request)
{
// if ($request->token) {
$request = new OrdersCaptureRequest($request->token);
$request->prefer('return=representation');
try {
$response = $this->client->execute($request);
}catch (Exception $ex) {
echo $ex->statusCode;
dd($ex->getMessage());
}
// }

}


/**
* Responds with a welcome message with instructions
*
* @return IlluminateHttpResponse
*/
public function cancel(Request $request)
{
dump($request->all());
dd('Your payment is canceled. You can create cancel page here.');
}


/**
* Responds with a welcome message with instructions
*
* @return IlluminateHttpResponse
*/
public function return(Request $request)
{
if ($request->token) {
return redirect()->route('capture_order', [
'token' => $request->token,
'PayerID' => $request->PayerID
]);
}

dd($request->all());
}
}

我使用paypal php sdk与沙箱帐户。

我可以使用旧的paypal版本还是它已经完全废弃了?

等待您的帮助:)

COMPLIANCE_VIOLATION

这个问题很可能与接收沙箱业务账户所在国家有关。为不同的国家(如美国)创建一个新帐户,然后创建一个使用该沙盒帐户的新REST应用程序,并在沙盒模式下测试其沙盒clientid/secret。

为了以后在实时模式中使用,请确保如果实时业务帐户来自需要它的国家之一,则实时帐户具有有效的自动扫描提款方法,例如美国银行或本地visa卡。如果您需要帮助配置实时模式的自动扫描,请联系PayPal的业务支持

我所说的支持和回应是:

进入埃及账户的资金需要自动提取到附加的资金来源,如银行。你可以通过命令来设置它设置部分的账户,然后是">钱,银行和卡";部分,在该页的底部你会发现&;自动取款";您可以指定用于自动取款的金融工具——https://www.sandbox.paypal.com/businessmanage/account/money

thanks for you all:)

最新更新