PayPal PHP SDK错误-帐单地址

时间:2018-08-06 15:43:33

标签: php paypal-rest-sdk

我很难为PayPal交易定义帐单邮寄地址,以便能够使用信用卡保险柜。

我尝试了几种不同的方法,但是无法在此处获得帐单地址。

这是错误:

  

{“名称”:“ VALIDATION_ERROR”,“详细信息”:[{“字段”:“帐单地址”,“问题”:“必填字段缺失”}

require('lib/PayPal-SDK/vendor/autoload.php');

use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\ApiContext;
use PayPal\Api\CreditCard;
use PayPal\Api\CreditCardToken;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Payer;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\ItemList;
use PayPal\Api\Item;
use PayPal\Api\Address;
use PayPal\Api\ShippingAddress;
$clientId = $paypal_client_id;

$secretId = $paypal_secret;
$sdkConfig = array( "mode" => "live" );

$amount2 =  $_POST['amount'];

$cred = new OAuthTokenCredential($clientId, $secretId, $sdkConfig);
$apiContext = new ApiContext($cred, 'Request' . time());
$apiContext->setConfig($sdkConfig);
$creditCardToken = new CreditCardToken();
$creditCardToken->setCreditCardId($creditcardtoken);

$fundingInstrument = new FundingInstrument();
$fundingInstrument->setCreditCardToken($creditCardToken);

$payerInfo = new \PayPal\Api\PayerInfo();
$payerInfo ->setEmail("test@gmail.com");

$shipping_address = new ShippingAddress();
$shipping_address->setCity('City');
$shipping_address->setCountryCode('CA');
$shipping_address->setPostalCode('H0H0H0');
$shipping_address->setLine1('711 Fake St.');
$shipping_address->setState('AB');
$payerInfo -> setBillingAddress($shipping_address);


$payer = new Payer();
//$payer->setPaymentMethod("credit_card");
$payer->setPaymentMethod("paypal");
$payer ->setPayerInfo($payerInfo);
$payer->setFundingInstruments(array($fundingInstrument));
$currency = $company_currency;
$amount = new Amount();
$amount->setCurrency("$currency");
$amount->setTotal("$amount2");


$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription("creating a payment with saved credit card");

$payment = new Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
try {
$finalPayment = $payment->create($apiContext);
} catch  (PayPal\Exception\PayPalConnectionException $ex) {
    echo $ex->getCode(); // Prints the Error Code
    echo $ex->getData(); // Prints the detailed error message
    die($ex);
} catch (Exception $ex) {
    die($ex);
}

print_r(json_decode($finalPayment));

0 个答案:

没有答案