dongshui2254 2016-10-30 14:50
浏览 26

Paypal new Item - > setQuantity Error

i got a problem with the Paypal-PHP-SDK.

I have this code:

<?php

use PayPal\Api\Payer;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Payment;
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
// Used for composer based installation
require __DIR__  . '/app/first.php';
require __DIR__  . '/../ajaxscript.php';
// Use below for direct download installation
// require __DIR__  . '/PayPal-PHP-SDK/autoload.php';

$payer = new Payer();
$payer ->setPaymentMethod('paypal');

$Bestellungsanzahl = 1;
$product = "Mousepad";
$price = 20;
$total = $price;


$item = new Item();
$item ->setName($product)
    ->setCurrency('EUR')
    ->setQuantity("4")
    ->setPrice($price);

$itemList = new ItemList();
$itemList ->setItems([$item]);

$details = new Details();
$details->setSubtotal($total);

$amount = new Amount();
$amount->setCurrency('EUR')
      ->setTotal($total)
       ->setDetails($details);

$transaction = new Transaction();
$transaction->setAmount($amount)
      ->setItemList($itemList)
      ->setDescription('KSTM Mousepads')
      ->setInvoiceNumber(uniqid());

$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl('http://localhost' . '/pay.php?success=true')
      ->setCancelUrl('http://localhost' . '/pay.php?success=false');

$payment = new Payment();
$payment->setIntent('sale')
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions([$transaction]);

try {
    $payment->create($paypal);
}
catch (Exception $e) {
    die($e);
}

$approvalUrl = $payment->getApprovalLink();

header("Location: {$approvalUrl}");

The problem is if i set quantity on 1 it works. So if ->setQuantity(1) or ->setQuantity("1") it works.

But if the quantity is more than 1 (->setQuantity("4") or ->setQuantity(4)) this error appears :

exception 'PayPal\Exception\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in C:\xampp\htdocs\paypal\vendor\paypalest-api-sdk-php\lib\PayPal\Core\PayPalHttpConnection.php:183 Stack trace: #0 C:\xampp\htdocs\paypal\vendor\paypalest-api-sdk-php\lib\PayPal\Transport\PayPalRestCall.php(73): PayPal\Core\PayPalHttpConnection->execute('{"intent":"sale...') #1 C:\xampp\htdocs\paypal\vendor\paypalest-api-sdk-php\lib\PayPal\Common\PayPalResourceModel.php(102): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL) #2 C:\xampp\htdocs\paypal\vendor\paypalest-api-sdk-php\lib\PayPal\Api\Payment.php(579): PayPal\Common\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL, Object(PayPal\Rest\ApiContext), NULL) #3 C:\xampp\htdocs\paypal\checkout.php(61): PayPal\Api\Payment->create(Object(PayPal\Rest\ApiContext)) #4 {main}

Do anyone have an idea? Thanks

  • 写回答

1条回答 默认 最新

  • douwu7168 2017-02-28 21:38
    关注
    2017 :c, total = quantity *price
    
    评论

报告相同问题?

悬赏问题

  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?