Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Paypal Sandox代码400返回空值_Php_Paypal - Fatal编程技术网

Php Paypal Sandox代码400返回空值

Php Paypal Sandox代码400返回空值,php,paypal,Php,Paypal,所以我在摆弄paypal沙盒,但出于某种原因,它不想为购买返回数组。相反,它只返回null。我可以使用curl通过api检索令牌,但是处理测试卡仍然返回null。以前有人有这个问题吗 <?php use PayPal\Api\Payer; use PayPal\Api\Details; use PayPal\Api\Amount; use PayPal\Api\Transaction; use PayPal\Api\Payment; use

所以我在摆弄paypal沙盒,但出于某种原因,它不想为购买返回数组。相反,它只返回null。我可以使用curl通过api检索令牌,但是处理测试卡仍然返回null。以前有人有这个问题吗

<?php
    use PayPal\Api\Payer;
    use PayPal\Api\Details;
    use PayPal\Api\Amount;
    use PayPal\Api\Transaction;
    use PayPal\Api\Payment;
    use PayPal\Api\RedirectUrls;

    require 'src/start.php';

    $payer = new Payer();
    $details = new Details();
    $amount = new Amount();
    $transaction = new Transaction();
    $payment = new Payment();
    $redirectUrls = new RedirectUrls();

    //PAYER
    $payer->setPaymentMethod('paypal');

    //Details
    //acutal prices(20 dollars is a test)

    //Amount

    $amount->setCurrency('GBP')
      ->setTotal('22.00')
      ->setDetails($details);

    $details->setShipping('2.00')
    ->setTax('0.00')
    ->setSubtotal('20.00');
    //Transaction
    $transaction->setAmount($amount);
      // ->setDescription('Membership');

    //Payment
    $payment->setIntent('sale')
      ->setPayer($payer)
      ->setTransactions([$transaction]);

    //RedirectUrls
    $redirectUrls->setReturnUrl('http://localhost:8000/paypaletc/pay.php?approved=true');
      // ->setCancelUrl('http://localhost:8000/paypal/pay.php?approved=false');

    $payment->setRedirectUrls($RedirectUrls);


    try{

        $payment->create($api);


    } catch(PayPal\Exception\PayPalConnectionException $e){
      echo $e->getMessage();

      // header('Location: paypaletc/error.php');
    }
    var_dump($payment->getLinks());

罪魁祸首是$URL。在setRedirectUrls($RedirectUrls)中,查看$RedirectUrls中的大写字母R,这就是导致异常的原因

        $redirectUrls->setReturnUrl('http://localhost:8000/paypaletc/pay.php?approved=true')
     ->setCancelUrl('http://localhost:8000/paypal/pay.php?approved=false');

        $payment->setRedirectUrls($redirectUrls);
这将修复您的代码。另外,不打印
$e->getMessage()
,尝试使用
$e->getData()

以下是最终代码的外观:

<?php
use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;

require 'src/start.php';

$payer = new Payer();
$details = new Details();
$amount = new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls = new RedirectUrls();

//PAYER
$payer->setPaymentMethod('paypal');

//Details
//acutal prices(20 dollars is a test)

//Amount

$amount->setCurrency('GBP')
    ->setTotal('22.00')
    ->setDetails($details);

$details->setShipping('2.00')
    ->setTax('0.00')
    ->setSubtotal('20.00');
//Transaction
$transaction->setAmount($amount);
// ->setDescription('Membership');

//Payment
$payment->setIntent('sale')
    ->setPayer($payer)
    ->setTransactions([$transaction]);

//RedirectUrls
$redirectUrls->setReturnUrl('http://localhost:8000/paypaletc/pay.php?approved=true')
    ->setCancelUrl('http://localhost:8000/paypal/pay.php?approved=false');

$payment->setRedirectUrls($redirectUrls);


try{

    $payment->create($api);


} catch(PayPal\Exception\PayPalConnectionException $e){
    echo $e->getData();

    // header('Location: paypaletc/error.php');
}
var_dump($payment->getLinks());

<?php
use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;

require 'src/start.php';

$payer = new Payer();
$details = new Details();
$amount = new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls = new RedirectUrls();

//PAYER
$payer->setPaymentMethod('paypal');

//Details
//acutal prices(20 dollars is a test)

//Amount

$amount->setCurrency('GBP')
    ->setTotal('22.00')
    ->setDetails($details);

$details->setShipping('2.00')
    ->setTax('0.00')
    ->setSubtotal('20.00');
//Transaction
$transaction->setAmount($amount);
// ->setDescription('Membership');

//Payment
$payment->setIntent('sale')
    ->setPayer($payer)
    ->setTransactions([$transaction]);

//RedirectUrls
$redirectUrls->setReturnUrl('http://localhost:8000/paypaletc/pay.php?approved=true')
    ->setCancelUrl('http://localhost:8000/paypal/pay.php?approved=false');

$payment->setRedirectUrls($redirectUrls);


try{

    $payment->create($api);


} catch(PayPal\Exception\PayPalConnectionException $e){
    echo $e->getData();

    // header('Location: paypaletc/error.php');
}
var_dump($payment->getLinks());