Paypal item description with other sdk api

I am using https://github.com/paypal/rest-api-sdk-php

And I want to view an overview of the item description, here is the code:

$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.'); $RedirectUrls = new RedirectUrls(); $RedirectUrls ->setReturnUrl('http://localhost/mrSurvey/public/#/pricing'); $RedirectUrls ->setCancelUrl('http://localhost/mrSurvey/public/#/pricing'); $payment = new Payment(); $payment->setIntent('sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $payment->setRedirectUrls($RedirectUrls); 

All I see is a description, but I want to see the item number and subtotal, what am I missing?

Update: So I read that I need to add a few things: so I did something like this:

  $item = new Item(); $item->setQuantity('1'); $item->setName('benny'); $item->setPrice('7.41'); $item->setCurrency('USD'); $item->setSku('blah'); $items = new ItemList(); $items->addItem(array($item)); 

...

 $transaction->setItemList($items); 

...

 $payment = new Payment(); $payment->setIntent('sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $payment->setRedirectUrls($RedirectUrls); $response = $payment->create($apiContext)->toarray(); return Response::json($response); 

Now the code above gives me 400 errors ... due to the added material of the element, any hints?

+7
php paypal
source share
3 answers

It seems that you are on the right track from the update you received. But it looks like you also have a few problems, and then only the stated problem.

try adding your code to the catch and echo out message from PayPal

 try{ //your code here } catch(PayPal\Exception\PayPalConnectionException $e) { //This will show error from paypal $e->getData() } 

I think I had a similar error: you are not doing the right thing to add your goods (tax, delivery, subtotal, etc.), etc. Try this sample @ https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payments/ExecutePayment.php and run it first to work, then change the code from the sample to sort your needs.

Below is the code of my modified code, and it works for me.

Please note that you have received the product description and transaction description

  //run x through loop with ++ $x = 0; //for item $items[$x] = new Item(); $items->setName($item_name) ->setDescription($item_description) ->setCurrency($currency) ->setQuantity($item_quantity) ->setTax($item_tax) ->setPrice($item_price) ->setSku($item_sku); $itemList = new ItemList(); $itemList->setItems($items); //for transaction $transaction = new Transaction(); $transaction ->setAmount($amount) ->setItemList($itemList) ->setDescription($payment_description) ->setInvoiceNumber($invoice_number); function getTotals($quantity, $tax, $price){ $tax = $tax * $quantity; $subtotal = $price * $quantity; $total = $tax + $subtotal; } total = getTotal($item_quantity, $item_tax, $item_price); 
+2
source share

I found the answer, we need more details to create the transaction, and you must set the correct number for subTotal (), total (), etc.

 Each price item * Quantity = Subtotal Subtotal +- Tax, Shipping etc... = total 

This is what I have:

  $sdkConfig = array( "mode" => "sandbox" ); $cred = new OAuthTokenCredential($client_id, $secret, $sdkConfig); $apiContext = new ApiContext($cred, 'Request' . time()); $apiContext->setConfig($sdkConfig); $payer = new Payer(); $payer->setPaymentMethod("paypal"); foreach ($cartHasItems as $key => $order) { $item[$key] = new PayPalItem(); $item[$key]->setName($order->getItem()->getName()) ->setCurrency('EUR') ->setQuantity($order->getQuantity()) ->setPrice($order->getItem()->getPrice()); } if($cart->getPromoCode()){ $item[1] = new PayPalItem(); $item[1]->setName('Promo code '.$cart->getPromoCode()->getCode()) ->setCurrency('EUR') ->setQuantity(1) ->setPrice(-$this->getDoctrine()->getRepository('AppBundle:CartHasItems')->countTotalForCart($cart, 'Promo')); } $itemList = new ItemList(); $itemList->setItems($item); $details = new Details(); $details->setTax($this->getDoctrine()->getRepository('AppBundle:CartHasItems')->countTotalForCart($cart, 'HT')*20/100) ->setSubtotal($this->getDoctrine()->getRepository('AppBundle:CartHasItems')->countTotalForCart($cart, 'HT')); $amount = new Amount(); $amount->setCurrency("EUR") ->setTotal($this->getDoctrine()->getRepository('AppBundle:CartHasItems')->countTotalForCart($cart, 'All')) ->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount) ->setItemList($itemList) ->setDescription("Payment description") ->setInvoiceNumber(uniqid()); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($this->generateUrl('paypal_success', array(), UrlGeneratorInterface::ABSOLUTE_URL)); $redirectUrls->setCancelUrl($this->generateUrl('order_validation', array('type' => 'paypal'), UrlGeneratorInterface::ABSOLUTE_URL)); $payment = new Payment(); $payment->setIntent("sale") ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions(array($transaction)); $payment->create($apiContext); 
+1
source share

Add this ...

 $transaction->setDescription("Payment description") 

...

0
source share

All Articles