PAYPAL PHP REST SDK-结帐时无显示-没有付款值-没有项目价格-没有数量

时间:2018-08-02 19:51:02

标签: php paypal paypal-sandbox paypal-rest-sdk

Here You can see there is no payment showing in my window

此代码完全卡住...如果可能,请帮助我。.

require "vendor/autoload.php";

// After Step 1
$apiContext = new \PayPal\Rest\ApiContext(
    new \PayPal\Auth\OAuthTokenCredential(
        '**********************************',     // ClientID
        '**********************************'      // ClientSecret
    )
);

// After Step 2
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');

$item1 = new \PayPal\Api\Item();
$item1->setName('Ground Coffee 40 oz')
     ->setCurrency('USD')
     ->setQuantity(1)
     ->setPrice(7.5);

$item2 = new \PayPal\Api\Item();
$item2->setName('Granola bars')
      ->setCurrency('USD')
      ->setQuantity(5)
      ->setPrice(2);

$itemList = new \PayPal\Api\ItemList();
$itemList->setItems(array($item1, $item2));

$details = new \PayPal\Api\Details();
$details->setShipping(1.2)
      ->setTax(1.3)
      ->setSubtotal(17.50);

$amount = new \PayPal\Api\Amount();
$amount->setCurrency("USD")
      ->setTotal(20)
      ->setDetails($details);

$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);

$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/ecom/public_html/login.php")
        ->setCancelUrl("http://localhost/ecom/public_html/checkout.php");

$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
      ->setPayer($payer)
      ->setTransactions(array($transaction))
      ->setRedirectUrls($redirectUrls);


// After Step 3
try {
  $payment->create($apiContext);
  $approveUrl = $payment->getApprovalLink();    
  header("Location: {$approveUrl}");
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
  echo $ex->getData();
}

我不知道为什么即使我在代码中添加了项目,结帐时为什么也没有显示付款金额,有人对我的脚本发生了什么一无所知。

0 个答案:

没有答案