function test() { global $apiContext; // IncludeConfig('paypal/bootstrap.php'); $payer = new Payer(); $payer->setPaymentMethod("paypal"); $item1 = new Item(); $item1->setName('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setPrice(7.5); $item2 = new Item(); $item2->setName('Granola bars')->setCurrency('USD')->setQuantity(5)->setPrice(2); $itemList = new ItemList(); $itemList->setItems(array($item1, $item2)); $details = new Details(); $details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5); $amount = new Amount(); $amount->setCurrency("USD")->setTotal(20)->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid()); $baseUrl = getBaseUrl(); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl("{$baseUrl}/donate.php/execute_payment_test?success=true")->setCancelUrl("{$baseUrl}/donate.php/execute_payment_test?success=false"); $payment = new Payment(); $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction)); $request = clone $payment; try { $payment->create($apiContext); } catch (Exception $ex) { ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); exit(1); } $approvalUrl = $payment->getApprovalLink(); ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='{$approvalUrl}' >{$approvalUrl}</a>", $request, $payment); return $payment; }
public function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl) { $payer = new Payer(); $payer->setPaymentMethod("paypal"); // Specify the payment amount. $amount = new Amount(); $amount->setCurrency($currency); $amount->setTotal($total); // ###Transaction // A transaction defines the contract of a // payment - what is the payment for and who // is fulfilling it. Transaction is created with // a 'Payee' and 'Amount' types $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setDescription($paymentDesc); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($returnUrl); $redirectUrls->setCancelUrl($cancelUrl); $payment = new Payment(); $payment->setRedirectUrls($redirectUrls); $payment->setIntent("sale"); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $payment->create(getApiContext()); return $payment; }