// In a call to the /payment resource, provide the payment details. In the intent field, specify order, and set the payment_method to paypal. Creating an order is similar to creating a payment.
// API used: /v1/payments/payment
require__DIR__.'/../bootstrap.php';
usePayPal\Api\Amount;
usePayPal\Api\Details;
usePayPal\Api\Item;
usePayPal\Api\ItemList;
usePayPal\Api\Payer;
usePayPal\Api\Payment;
usePayPal\Api\RedirectUrls;
usePayPal\Api\Transaction;
// ### Payer
// A resource representing a Payer that funds a payment
// For paypal account payments, set payment method
// to 'paypal'.
$payer=newPayer();
$payer->setPaymentMethod("paypal");
// ### Itemized information
// (Optional) Lets you specify item wise
// information
$item1=newItem();
$item1->setName('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setPrice(7.5);
$item2=newItem();
$item2->setName('Granola bars')
->setCurrency('USD')
->setQuantity(5)
->setPrice(2);
$itemList=newItemList();
$itemList->setItems(array($item1,$item2));
// ### Additional payment details
// Use this optional field to set additional
// payment information such as tax, shipping
// charges etc.
$details=newDetails();
$details->setShipping(1.2)
->setTax(1.3)
->setSubtotal(17.50);
// ### Amount
// Lets you specify a payment amount.
// You can also specify additional details
// such as shipping, tax.
$amount=newAmount();
$amount->setCurrency("USD")
->setTotal(20)
->setDetails($details);
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it.
$transaction=newTransaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
// ### Redirect urls
// Set the urls that the buyer must be redirected to after
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Created Payment Order Using PayPal. Please visit the URL to Approve.","Payment","<a href='$approvalUrl' >$approvalUrl</a>",$request,$payment);