php 信用卡通道api,php – PayPal REST API为信用卡令牌返回500 Server错误

我正在尝试让PayPal REST API使用存储在保险库中的信用卡创建付款.但是,每当我尝试使用保险箱中的卡付款时,PayPal的API将挂起大约半分钟,然后给我以下500错误:

Exception: Got Http response code 500 when accessing https://api.sandbox.paypal.com/v1/payments/payment.

{"name":"INTERNAL_SERVICE_ERROR","message":"An internal service error has occurred","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR","debug_id":"e3c779ea99f73"}

这是我正在使用的代码(如果这里有太多信息,我很抱歉,我不知道哪些信息与我的问题有关)

include("bootstrap.php"); //Sample bootstrap file configured with my clientId and Secret, creates $apiContext

use PayPal\Api\CreditCard;

use PayPal\Api\Payer;

use PayPal\Api\FundingInstrument;

use PayPal\Api\Details;

use PayPal\Api\Amount;

use PayPal\Api\Transaction;

use PayPal\Api\Payment;

use PayPal\Api\Address;

use PayPal\Api\CreditCardToken;

$useVault = true;

$addr = new Address();

$addr->setLine1('52 N Main ST');

$addr->setCity('Johnstown');

$addr->setCountry_code('US');

$addr->setPostal_code('43210');

$addr->setState('OH');

$card = new CreditCard();

//Also used PayPal Sandbox account number here

$card->setNumber('4111111111111111');

$card->setExpire_month('03');

$card->setExpire_year('2019');

$card->setCvv2('123');

$card->setFirst_name('Joe');

$card->setLast_name('Shopper');

$card->setType('visa');

$card->setBilling_address($addr);

$fi = new FundingInstrument();

//Setting $useVault to false here

// will attempt to make the payment without storing the CC in the vault

// Which works. having it use the vault will return a 500 error

if($useVault){

//use Store the CC in the vault

$response = $card->create($apiContext);

$ccToken = new CreditCartToken();

$ccToken->setCredit_card_id($response->id);

$fi->setCredit_card_token($creditCardToken);

}else{

$fi->setCredit_card($card);

}

$payer = new Payer();

$payer->setPayment_method('credit_card');

$payer->setFunding_instruments(array($fi));

$amountDetails = new Details();

$amountDetails->setSubtotal('7.41');

$amountDetails->setTax('0.03');

$amountDetails->setShipping('0.03');

$amount = new Amount();

$amount->setCurrency('USD');

$amount->setTotal('7.47');

$amount->setDetails($amountDetails);

$transaction = new Transaction();

$transaction->setAmount($amount);

$transaction->setDescription('This is the payment transaction description.');

$payment = new Payment();

$payment->setIntent('sale');

$payment->setPayer($payer);

$payment->setTransactions(array($transaction));

try {

var_dump($payment->create($apiContext));

} catch (PayPal\Exception\PPConnectionException $ex) {

echo "Exception: " . $ex->getMessage() . PHP_EOL;

var_dump($ex->getData());

exit(1);

}

如果我将$useVault更改为false,那么将进行付款并且交易将显示在开发人员沙箱中.

我使用了this guide at dev-tools.paypal.com,它似乎和我有同样的问题(我到了第4步,它打印出内部服务错误已经发生

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要通过PayPal获得销售ID和退款,您需要使用PayPalAPI来实现。以下是使用PayPalAPI进行退款的步骤: 1. 通过PayPalAPI创建退款请求。 2. 在创建退款请求时,您需要提供订单ID或交易ID,以便PayPal能够找到要退款的交易。您可以从PayPal的网站或使用PayPalAPI检索这些ID。 3. 创建退款请求后,您将获得一个退款ID。 4. 使用PayPalAPI获取销售ID,这可以通过订单ID或交易ID完成。 5. 将退款ID和销售ID存储在您的数据库中,以便您可以随时检索它们。 以下是使用PHP实现退款的示例代码: ``` <?php require_once('paypal_config.php'); $transaction_id = 'TX-1234567890'; // Replace with your transaction ID // Create PayPal API request for refund $data = array( 'TRANSACTIONID' => $transaction_id, 'REFUNDTYPE' => 'Full', 'CURRENCYCODE' => 'USD' ); $request = array( 'METHOD' => 'RefundTransaction', 'VERSION' => $paypal_api_version, 'USER' => $paypal_api_username, 'PWD' => $paypal_api_password, 'SIGNATURE' => $paypal_api_signature, 'NVP' => http_build_query($data) ); // Send request to PayPal $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $paypal_api_endpoint); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($request)); $response = curl_exec($curl); // Parse response from PayPal parse_str($response, $response_array); if ($response_array['ACK'] == 'Success') { // Refund was successful $refund_id = $response_array['REFUNDTRANSACTIONID']; // Use PayPal API to get sale ID $data = array( 'TRANSACTIONID' => $transaction_id ); $request = array( 'METHOD' => 'GetTransactionDetails', 'VERSION' => $paypal_api_version, 'USER' => $paypal_api_username, 'PWD' => $paypal_api_password, 'SIGNATURE' => $paypal_api_signature, 'NVP' => http_build_query($data) ); // Send request to PayPal curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($request)); $response = curl_exec($curl); // Parse response from PayPal parse_str($response, $response_array); if ($response_array['ACK'] == 'Success') { $sale_id = $response_array['SALEID']; // Store refund ID and sale ID in database // ... } } curl_close($curl); ?> ``` 请注意,此示例代码仅用于演示目的,您需要根据您的具体情况进行修改。另外,您需要将paypal_config.php文件中的变量设置为您的PayPal API凭据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值