贝宝 PHP SDK OrdersCaptureRequest 错误,statusCode 422
PAYPAL PHP SDK OrdersCaptureRequest error with statusCode 422
我使用最新的 v2 paypal php sdk 沙箱和带有 laravel 框架的示例,创建订单总是成功但是当捕获订单时它总是失败
和return这个错误:
"{"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 App\Http\Controllers;
use Illuminate\Http\Request;
use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\SandboxEnvironment;
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
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 \Illuminate\Http\Response
*/
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 \Illuminate\Http\Response
*/
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
此问题很可能与接收沙盒企业帐户所在的国家/地区有关。 Create a new account for a different country such as US, then create a new REST app 使用该沙箱帐户,并改为在沙箱模式下测试其沙箱 clientid/secret。
为了以后在实时模式下使用,请确保如果实时企业帐户来自 countries that require it 之一,则该实时帐户具有有效的自动扫描提款方法并在该帐户上启用,例如美国银行卡或本地 visa 卡。如果您在为实时模式配置自动扫描方面需要帮助,请联系 PayPal 的业务支持
我打电话给支持,回复是:
埃及账户收到的资金需要自动提取到附加的资金来源,例如银行。您可以通过 going 进入账户的 settings 部分,然后是“money, banks and cards”部分,在该页面的底部,您会找到“自动取款”,您可以在其中指定用于自动取款的金融工具 -- https://www.sandbox.paypal.com/businessmanage/account/money
谢谢大家:)
我使用最新的 v2 paypal php sdk 沙箱和带有 laravel 框架的示例,创建订单总是成功但是当捕获订单时它总是失败
和return这个错误:
"{"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 App\Http\Controllers;
use Illuminate\Http\Request;
use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\SandboxEnvironment;
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
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 \Illuminate\Http\Response
*/
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 \Illuminate\Http\Response
*/
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
此问题很可能与接收沙盒企业帐户所在的国家/地区有关。 Create a new account for a different country such as US, then create a new REST app 使用该沙箱帐户,并改为在沙箱模式下测试其沙箱 clientid/secret。
为了以后在实时模式下使用,请确保如果实时企业帐户来自 countries that require it 之一,则该实时帐户具有有效的自动扫描提款方法并在该帐户上启用,例如美国银行卡或本地 visa 卡。如果您在为实时模式配置自动扫描方面需要帮助,请联系 PayPal 的业务支持
我打电话给支持,回复是:
埃及账户收到的资金需要自动提取到附加的资金来源,例如银行。您可以通过 going 进入账户的 settings 部分,然后是“money, banks and cards”部分,在该页面的底部,您会找到“自动取款”,您可以在其中指定用于自动取款的金融工具 -- https://www.sandbox.paypal.com/businessmanage/account/money
谢谢大家:)