Я пытаюсь, чтобы PayPal REST api создавал платеж с помощью кредитной карты, хранящейся в хранилище. Но, когда я пытаюсь сделать платеж с помощью карты в хранилище, API PayPal будет висеть около полуминутки, а затем дать мне следующую ошибку 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"}
Это код, который я использую (извиняюсь, если здесь слишком много информации, я не знал, какая информация уместна для моей проблемы)
<?php 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); }
в<?php 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); }
выплачивается<?php 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); }
выплачивается<?php 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); }
выплачивается<?php 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
то платеж будет сделан, и транзакция появится в изолированной программной $useVault
разработчика. Я использовал это руководство на dev-tools.paypal.com, и, похоже, у меня такая же проблема, как и я (я перехожу к шагу 3 из 4, и он печатает, что произошла внутренняя ошибка службы
Paypal иногда выдает ошибку 500 при использовании часто используемого теста CC, как тот, который вы используете, поэтому попробуйте еще один или просто попробуйте с реальным номером CC, если вы находитесь в режиме песочницы, он не будет взимать плату с вас или что-то в этом роде.