我已经使用 Composer 设置了 Paypal Payout SDK。
Paypal 向我保证,我的账户启用了支付功能。我创建了一个新的 Live Rest-App 并在 PayPalClient 类中使用了 Client-ID 和 Client-Secret:
<?php
namespace PaypalPayoutsSDK\Payouts;
use PaypalPayoutsSDK\Core\PayPalHttpClient;
use PaypalPayoutsSDK\Core\ProductionEnvironment;
class PayPalClient {
public static function client() {
return new PayPalHttpClient(self::environment());
}
public static function environment() {
$clientId = getenv("CLIENT_ID") ?: "my-client-id";
$clientSecret = getenv("CLIENT_SECRET") ?: "my-client-secret";
return new ProductionEnvironment($clientId, $clientSecret);
}
}
?>
现在我想做一个简单的交易。我使用了 PayPal Payout SDK 中包含的示例,并使用上面提到的 PayPalClient 创建了一个付款:
<?php
require __DIR__ . '/vendor/autoload.php';
use PaypalPayoutsSDK\Payouts\PayPalClient;
use PaypalPayoutsSDK\Payouts\PayoutsPostRequest;
$request = new PayoutsPostRequest();
$body= json_decode(
'{
"sender_batch_header":
{
"email_subject": "SDK payouts test txn"
},
"items": [
{
"recipient_type": "EMAIL",
"receiver": "myname@gmail.com",
"note": "Your 4$ payout",
"sender_item_id": "Test_txn_12",
"amount":
{
"currency": "USD",
"value": "4.00"
}
}]
}',
true);
$request->body = $body;
$client = PayPalClient::client();
$response = $client->execute($request);
?>
但是,当我执行该文件时,出现以下错误:
Fatal error: Uncaught PayPalHttp\HttpException: {"name":"AUTHORIZATION_ERROR","message":"Authorization error occurred.","debug_id":"d3c2fe720217b","information_link":"https://developer.paypal.com/docs/api/payments.payouts-batch/#errors","links":[]} in /hermes/bosnaweb27a/b1507/dom.mydomain/mydomain/payment/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php:215 Stack trace: #0 /hermes/bosnaweb27a/b1507/dom.mydomain/mydomain/payment/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php(100): PayPalHttp\HttpClient->parseResponse(Object(PayPalHttp\Curl)) #1 /hermes/bosnaweb27a/b1507/dom.mydomain/mydomain/payment/payuser.php(37): PayPalHttp\HttpClient->execute(Object(PaypalPayoutsSDK\Payouts\PayoutsPostRequest)) #2 {main} thrown in /hermes/bosnaweb27a/b1507/dom.mydomain/mydomain/payment/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php on line 215
HTTPClient 似乎发生了该错误。我已经向 Paypal 的技术助理提供了相同的信息,但他似乎什么都不知道。
这里可能是什么问题。我确定 Client-ID 和 Client-Secret 是正确的,我已经尝试使用新的 REST-APP 来做到这一点。也许我的代码有问题?还是我只是错过了什么?