将信用卡保存到Paypal中

时间:2017-11-22 13:51:57

标签: php rest api paypal

我正在尝试使用贝尔代码使用paypal php sdk将信用卡保存到paypal中。

<?php
require 'PayPal-PHP-SDK-master/vendor/autoload.php';

$clientId = 'XXXXXXXXXX';
$clientSecret = 'XXXXXXXXX';

use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\CreditCard;
use PayPal\Rest\ApiContext;

$sdkConfig = array(
    "mode" => "sandbox"
);

$apiContext =  $apiContext = new ApiContext(new OAuthTokenCredential(
    $clientId,
    $clientSecret
));


$creditcard = new CreditCard();

$creditcard->setId(101);
$creditcard->setNumber('4111111111111111');
$creditcard->setType('visa');
$creditcard->setExpireMonth(12);
$creditcard->setExpireYear(2020);
$creditcard->setCvv2(123);

$request = clone $creditcard;
try {
    $output = $creditcard->create($apiContext);
    echo "success";
} catch (Exception $ex) {
    echo $ex;
    exit(1);

}

但它没有用,我得到了像贝洛一样的例外

  

例外&#39; PayPal \ Exception \ PayPalConnectionException&#39;与消息   &#39;访问时获得Http响应代码400   https://api.sandbox.paypal.com/v1/vault/credit-cards&#39。在   /var/www/html/test/paypalcard/PayPal-PHP-SDK-master/lib/PayPal/Core/PayPalHttpConnection.php:202   堆栈跟踪:#0   /var/www/html/test/paypalcard/PayPal-PHP-SDK-master/lib/PayPal/Transport/PayPalRestCall.php(78):   PayPal \ Core \ PayPalHttpConnection-&gt;执行(&#39; {&#34; id&#34;:101,&#34; numb ...&#39;)#1   /var/www/html/test/paypalcard/PayPal-PHP-SDK-master/lib/PayPal/Common/PayPalResourceModel.php(104):   PayPal \ Transport \ PayPalRestCall-&gt;执行(数组,&#39; / v1 / vault / credi ...&#39;,   &#39; POST&#39;,&#39; {&#34; id&#34;:101,&#34; numb ...&#39;,NULL)#2   /var/www/html/test/paypalcard/PayPal-PHP-SDK-master/lib/PayPal/Api/CreditCard.php(443):   贝宝\ COMMON \ PayPalResourceModel :: executeCall(&#39; / V1 /金库/克雷迪...&#39 ;,   &#39; POST&#39;,&#39; {&#34; id&#34;:101,&#34; numb ...&#39;,NULL,Object(PayPal \ Rest \ ApiContext),   NULL)#3 /var/www/html/test/paypalcard/cardtest.php(32):   PayPal \ Api \ CreditCard-&gt;创建(对象(PayPal \ Rest \ ApiContext))#4   {主要}

我的代码有什么问题,需要为此添加哪些更改?

0 个答案:

没有答案