paypal响应:访问https://api.sandbox.paypal.com/v1/payments/payment时的Http响应代码400

时间:2017-05-25 07:38:52

标签: php paypal

当我做单品这个代码工作正常。但是当我添加多元产品并增加其数量然后他将产生400错误我不知道发生什么事情。我可以解决这个问题吗?我正在tri很多但是我正在战斗我我不明白这个错误。

    $card = new PaymentCard();
    $card->setType("visa")
            ->setNumber("4012000077777777")
            ->setExpireMonth("12")
            ->setExpireYear("2019")
            ->setCvv2("012")
            ->setFirstName("Joe")
            ->setBillingCountry("USA")
            ->setLastName("Shopper");
    $fi = new FundingInstrument();
    $fi->setPaymentCard($card);
    $payer = new Payer();
    $payer->setPaymentMethod("credit_card")
            ->setFundingInstruments(array($fi));

    $cart = \Yii::$app->cart;
    $items = $cart->getItems();


    $subtotal = null;
   foreach($items as $item){
        $subtotal +=$item['productprice'] * $item['qty'];
   } 

    $item1 = [];
    $i = 0;
    foreach ($items as $value){
    $item1[$i] = new Item();
    $item1[$i]->setName($value['productname'])
            ->setDescription('Ground Coffee 40 oz')
            ->setCurrency('USD')
            ->setQuantity($value['qty'])
            ->setTax(0)
            ->setPrice($value['productprice']*$value['qty']);
    $i++;
    }
    $itemList = new ItemList();
    $itemList->setItems($item1);
    $details = new Details();
    $details->setShipping(1.2)
            ->setTax(1.3)
            ->setSubtotal($subtotal);

    $total1 = 1.2+1.3+$subtotal;
    $amount = new Amount();
    $amount->setCurrency('USD')
            ->setTotal($total1)
            ->setDetails($details);
    $transaction = new Transaction();
    $transaction->setAmount($amount)
            ->setItemList($itemList)
            ->setDescription("Payment description")
            ->setInvoiceNumber(uniqid());
    $payment = new Payment();
    $payment->setIntent("sale")
            ->setPayer($payer)
            ->setTransactions(array($transaction));
    $request = clone $payment;  
    $resyul = $payment->create($apiContext);
                    var_dump($resyul);exit;
                   try {
                    $resyul = $payment->create($apiContext);
                    var_dump($resyul);exit;
                    if($resyul == TRUE){
                        return $this->render('Success');

                    }
                    else{

                        return $this->render('cancel');
                    }

                }
         catch (PayPal\Exception\PayPalConnectionException $ex) {
             var_dump($ex);exit;
         } 


}

0 个答案:

没有答案