我尝试使用Paypal-Php-Sdk创建发票,一切都没问题,但是当我尝试设置结算信息时出现问题,我收到此错误:
{"name":"VALIDATION_ERROR","message":"Invalid request - see details.","debug_id":"2d34973f0cfef","details":[{"field":"billing_info","issue":"Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at line:1, column:2"}]}exception 'PayPal\Exception\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/invoicing/invoices.' in /var/www/admin/data/www/****/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php:176
Stack trace:
#0 /var/www/admin/data/www/****/vendor/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php(74): PayPal\Core\PayPalHttpConnection->execute('{"billing_info"...')
#1 /var/www/admin/data/www/****/vendor/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalResourceModel.php(103): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/invoicing/i...', 'POST', '{"billing_info"...', NULL)
#2 /var/www/admin/data/www/****/vendor/paypal/rest-api-sdk-php/lib/PayPal/Api/Invoice.php(736): PayPal\Common\PayPalResourceModel::executeCall('/v1/invoicing/i...', 'POST', '{"billing_info"...', NULL, Object(PayPal\Rest\ApiContext), NULL)
#3 var/www/admin/data/www/****/application/controllers/store.php(487): PayPal\Api\Invoice->create(Object(PayPal\Rest\ApiContext))
#4 [internal function]: Store->payment()
#5 /var/www/admin/data/www/****/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array)
#6 /var/www/admin/data/www/****/index.php(202): require_once('/var/www/admin/...')
#7 {main}
这是我使用的代码:
$client_id = "****";
$secret = "****";
$apiContext = new ApiContext(new OAuthTokenCredential(
$client_id, $secret));
$merchantInfo = new PayPal\Api\MerchantInfo();
$merchantInfo->setEmail("****");
$merchantInfo->setWebsite("****");
$billingInfo = new PayPal\Api\BillingInfo();
$billingInfo->setEmail("****");
$invoice = new PayPal\Api\Invoice();
$invoice->setMerchantInfo($merchantInfo);
$invoice->setBillingInfo($billingInfo);
try
{
$invoice->create($apiContext);
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getData();
die($ex);
} catch (Exception $ex) {
die($ex);
}
答案 0 :(得分:0)
以下是我从Paypal支持中收到的内容:
将这两行更改为:
$invoice->setMerchantInfo(array($merchantInfo));
$invoice->setBillingInfo(array($billingInfo));
结算信息和商家信息都包含对象数组,而不是对象。
这很奇怪,但是当我仅针对结算信息进行更改时它才开始工作,所以对我来说正确的代码是:
$invoice->setMerchantInfo($merchantInfo);
$invoice->setBillingInfo(array($billingInfo));