/** * @param string $currency * @param int $total * @param Details $details * * @return Amount */ public static function createAmount(Details $details, $total, $currency) { $amount = new Amount(); $amount->setCurrency($currency); $amount->setTotal($total); $amount->setDetails($details); return $amount; }
/** * Creates an amount definition for given order * * @param OrderInterface $order * * @return Amount */ protected function createAmount(OrderInterface $order) : Amount { $details = $this->createDetails($order); $amount = new Amount(); $amount->setCurrency($order->getCurrency()); $amount->setTotal($order->getOrderTotal()->getGrossAmount()); $amount->setDetails($details); return $amount; }
public function createAmount($total, $currency, Details $details = null) { // Specify the payment amount. $amount = new Amount(); $amount->setCurrency($currency)->setTotal($total); if (isset($details)) { $amount->setDetails($details); } return $amount; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('ATGFkB2ea6f0pM92jwBqkZ17kxsiftDvUhLHyXson-10AUs7n5TocpEc0sis7Cl_fMIxS8uQO04kPP8Q', 'ENP_JPkc3e4Yl6VeHZ_0vgvEh0SYdtzkMvw_VGBrr2nJ67sg9RuKB_YF7y_k4bj-4t2U-_23MaAGV3vD')); $status = ''; if (isset($_GET['success']) && $_GET['success'] == 'true') { $transaction = new Transaction(); $amount = new Amount(); $paymentId = $_GET['paymentId']; $payment = Payment::get($paymentId, $apiContext); $amount->setCurrency($payment->transactions[0]->amount->getCurrency()); $amount->setTotal($payment->transactions[0]->amount->getTotal()); $amount->setDetails($payment->transactions[0]->amount->getDetails()); $transaction->setAmount($amount); $execution = new PaymentExecution(); $execution->setPayerId($_GET['PayerID']); $execution->addTransaction($transaction); $rifas = $payment->transactions[0]->description; $rifas = explode(',', $rifas); $aux = 0; try { foreach ($rifas as $rifa) { $aux = Rifa::find($rifa); if ($aux->user_id == NULL) { $aux->user_id = Auth::user()->id; $aux->save(); } else { $status = 'Numeros de rifas ja foram escolhidos por outra pessoa, por favor escolha novamente.'; return view('confirmacao')->with('status', $status); } } $result = $payment->execute($execution, $apiContext); try { $payment = Payment::get($paymentId, $apiContext); } catch (Exception $ex) { $status = 'Pagamento ainda sem confirmacao'; } } catch (Exception $ex) { $status = 'Compra nao foi executada'; } if ($result->state == "approved") { $status = 'Compra feita com sucesso!'; $aux = 1; } return view('confirmacao')->with('status', $status)->with('aux', $aux); } else { $status = 'Compra cancelada pelo usuario'; return view('confirmacao')->with('status', $status); } }
function get_approvalurl() { try { // try a payment request $PaymentData = AngellEYE_Gateway_Paypal::calculate(null, $this->send_items); $OrderItems = array(); if ($this->send_items) { foreach ($PaymentData['order_items'] as $item) { $_item = new Item(); $_item->setName($item['name'])->setCurrency(get_woocommerce_currency())->setQuantity($item['qty'])->setPrice($item['amt']); array_push($OrderItems, $_item); } } $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl(add_query_arg(array('pp_action' => 'executepay'), home_url())); $redirectUrls->setCancelUrl($this->cancel_url); $payer = new Payer(); $payer->setPaymentMethod("paypal"); $details = new Details(); if (isset($PaymentData['shippingamt'])) { $details->setShipping($PaymentData['shippingamt']); } if (isset($PaymentData['taxamt'])) { $details->setTax($PaymentData['taxamt']); } $details->setSubtotal($PaymentData['itemamt']); $amount = new Amount(); $amount->setCurrency(PP_CURRENCY); $amount->setTotal(WC()->cart->total); $amount->setDetails($details); $items = new ItemList(); $items->setItems($OrderItems); $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setDescription(''); $transaction->setItemList($items); //$transaction->setInvoiceNumber($this->invoice_prefix.$order_id); $payment = new Payment(); $payment->setRedirectUrls($redirectUrls); $payment->setIntent("sale"); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $payment->create($this->getAuth()); $this->add_log(print_r($payment, true)); //if payment method was PayPal, we need to redirect user to PayPal approval URL if ($payment->state == "created" && $payment->payer->payment_method == "paypal") { WC()->session->paymentId = $payment->id; //set payment id for later use, we need this to execute payment return $payment->links[1]->href; } } catch (PayPal\Exception\PayPalConnectionException $ex) { wc_add_notice(__("Error processing checkout. Please try again. ", 'woocommerce'), 'error'); $this->add_log($ex->getData()); } catch (Exception $ex) { wc_add_notice(__('Error processing checkout. Please try again. ', 'woocommerce'), 'error'); $this->add_log($ex->getMessage()); } }
public function payDemo() { $this->authorize(); $addr = new Address(); $addr->setLine1('52 N Main ST'); $addr->setCity('Johnstown'); $addr->setCountryCode('US'); $addr->setPostalCode('43210'); $addr->setState('OH'); $card = new CreditCard(); $card->setNumber('4417119669820331'); $card->setType('visa'); $card->setExpireMonth('11'); $card->setExpireYear('2018'); $card->setCvv2('874'); $card->setFirstName('Joe'); $card->setLastName('Shopper'); $card->setBillingAddress($addr); $fi = new FundingInstrument(); $fi->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod('credit_card'); $payer->setFundingInstruments(array($fi)); $amountDetails = new \PayPal\Api\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.'); $payment = new Payment(); $payment->setIntent('sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $payment->create($this->_apiContext); }
// to execute a PayPal account payment. // The payer_id is added to the request query parameters // when the user is redirected from paypal back to your site $execution = new PaymentExecution(); $execution->setPayerId($_GET['PayerID']); // ### Optional Changes to Amount // If you wish to update the amount that you wish to charge the customer, // based on the shipping address or any other reason, you could // do that by passing the transaction object with just `amount` field in it. // Here is the example on how we changed the shipping to $1 more than before. $transaction = new Transaction(); $amount = new Amount(); $details = new Details(); $amount->setCurrency('USD'); $amount->setTotal($payment->getTransactions()[0]->amount->total); $amount->setDetails($details); $transaction->setAmount($amount); // Add the above transaction object inside our Execution object. $execution->addTransaction($transaction); try { // Execute the payment // (See bootstrap.php for more on `ApiContext`) $result = $payment->execute($execution, $apiContext); // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY // ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result); try { $payment = Payment::get($paymentId, $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY // ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); exit(1);
public function teszt($amount, $description) { $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AfikH2WfU1x0YF1ThuSkBaMKqDh-rxE5NEBpLWOF3UVmii-P97WdgJCUhoH1ff5pMHToHnB-sXoejgGv', 'EM7ObD_onQ1EqaeiVBFvSId9AIQevTlsYcLPi-3SeVivyQ9A361Ov5jx4KlFkamOsh_c6I25VM1Ck4ZX')); //SAMPLE 1 // $card = new CreditCard(); // $card->setType("visa") // ->setNumber("4148529247832259") // ->setExpireMonth("11") // ->setExpireYear("2019") // ->setCvv2("012") // ->setFirstName("Joe") // ->setLastName("Shopper"); // // ### FundingInstrument // // A resource representing a Payer's funding instrument. // // For direct credit card payments, set the CreditCard // // field on this object. // $fi = new FundingInstrument(); // $fi->setCreditCard($card); // // ### Payer // // A resource representing a Payer that funds a payment // // For direct credit card payments, set payment method // // to 'credit_card' and add an array of funding instruments. // $payer = new Payer(); // $payer->setPaymentMethod("credit_card") // ->setFundingInstruments(array($fi)); // // ### Itemized information // // (Optional) Lets you specify item wise // // information // $item1 = new Item(); // $item1->setName('Ground Coffee 40 oz') // ->setDescription('Ground Coffee 40 oz') // ->setCurrency('USD') // ->setQuantity(1) // ->setTax(0.3) // ->setPrice(7.50); // $item2 = new Item(); // $item2->setName('Granola bars') // ->setDescription('Granola Bars with Peanuts') // ->setCurrency('USD') // ->setQuantity(5) // ->setTax(0.2) // ->setPrice(2); // $itemList = new ItemList(); // $itemList->setItems(array($item1, $item2)); // // ### Additional payment details // // Use this optional field to set additional // // payment information such as tax, shipping // // charges etc. // $details = new Details(); // $details->setShipping(1.2) // ->setTax(1.3) // ->setSubtotal(17.5); // // ### Amount // // Lets you specify a payment amount. // // You can also specify additional details // // such as shipping, tax. // $amount = new Amount(); // $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 = new Transaction(); // $transaction->setAmount($amount) // ->setItemList($itemList) // ->setDescription("Payment description") // ->setInvoiceNumber(uniqid()); // // ### Payment // // A Payment Resource; create one using // // the above types and intent set to sale 'sale' // $payment = new Payment(); // $payment->setIntent("sale") // ->setPayer($payer) // ->setTransactions(array($transaction)); // // For Sample Purposes Only. // $request = clone $payment; // // ### Create Payment // // Create a payment by calling the payment->create() method // // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) // // The return object contains the state. // try { // $payment->create($apiContext); // } catch (Exception $ex) { // // ResultPrinter::printError('Create Payment Using Credit Card. If 500 Exception, try creating a new Credit Card using <a href="https://ppmts.custhelp.com/app/answers/detail/a_id/750">Step 4, on this link</a>, and using it.', 'Payment', null, $request, $ex); // exit(1); // } //ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment); //return $payment; //END SAMPLE 1 //SAMPLE 2 // $creditCard = new \PayPal\Api\CreditCard(); // $creditCard->setType("visa") // ->setNumber("4417119669820331") // ->setExpireMonth("11") // ->setExpireYear("2019") // ->setCvv2("012") // ->setFirstName("Joe") // ->setLastName("Shopper"); // try { // $creditCard->create($apiContext); // echo '<pre>'; // print_r($creditCard); // } // catch (\PayPal\Exception\PayPalConnectionException $ex) { // echo $ex; // } //END SAMPLE 2 //SAMPLE 3 $payer = new Payer(); $payer->setPaymentMethod("paypal"); // ### Itemized information // (Optional) Lets you specify item wise // information $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)); // ### Additional payment details // Use this optional field to set additional // payment information such as tax, shipping // charges etc. /* $details = new Details(); $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 = new Amount(); $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 = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description"); // ->setInvoiceNumber('134'); //>setInvoiceNumber(uniqid()); // ### Redirect urls // Set the urls that the buyer must be redirected to after // payment approval/ cancellation. //$baseUrl = getBaseUrl(); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl("http://localhost/yii-application/frontend/web/index.php?r=/cart/default/ordered")->setCancelUrl("http://localhost/yii-application/frontend/web/index.php?r=/cart/default/index"); // ### Payment // A Payment Resource; create one using // the above types and intent set to 'sale' /* $payment = new Payment(); $payment->setIntent("sale") ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions(array($transaction)); */ $addr = new Address(); $addr->setLine1('52 N Main ST'); $addr->setCity('Johnstown'); $addr->setCountryCode('US'); $addr->setPostalCode('43210'); $addr->setState('OH'); $card = new CreditCard(); $card->setNumber('5110929378020149'); $card->setType('MASTERCARD'); $card->setExpireMonth('08'); $card->setExpireYear('2020'); $card->setCvv2('874'); $card->setFirstName('Nishanth'); $card->setLastName('Pininti'); $card->setBillingAddress($addr); $fi = new FundingInstrument(); $fi->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod('credit_card'); $payer->setFundingInstruments(array($fi)); $amountDetails = new \PayPal\Api\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.'); $payment = new Payment(); $payment->setIntent('sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); // For Sample Purposes Only. $request = clone $payment; // ### Create Payment // Create a payment by calling the 'create' method // passing it a valid apiContext. // (See bootstrap.php for more on `ApiContext`) // The return object contains the state and the // url to which the buyer must be redirected to // for payment approval 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); } // ### Get redirect url // The API response provides the url that you must redirect // the buyer to. Retrieve the url from the $payment->getApprovalLink() // method //$approvalUrl = $payment->getRedirectUrls(); // ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment); var_dump($payment); return $payment; //END SAMPLE 3 }
public function createPayment($addressee, $order) { // Order Totals $subTotal = $order->total; $shippingCharges = $order->shipping; $tax = $order->tax; $grandTotal = $order->grandTotal; // Get Context $context = $this->getApiContext(); // Payer $payer = new Payer(); $payer->setPaymentMethod('paypal'); // Cart Items $itemList = $this->generateItemsList($order); // Shipping Address if ($this->properties->isSendAddress()) { $shippingAddress = $this->generateShippingAddress($addressee, $cart); $itemList->setShippingAddress($shippingAddress); } // Details $details = new Details(); $details->setSubtotal($subTotal); $details->setShipping($shippingCharges); $details->setTax($tax); // Amount $amount = new Amount(); $amount->setCurrency($this->properties->getCurrency()); $amount->setTotal($grandTotal); $amount->setDetails($details); // Transaction $transaction = new Transaction(); $transaction->setAmount($amount); if (isset($order->description)) { $transaction->setDescription($order->description); } $transaction->setItemList($itemList); // Status URLs $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($this->successUrl); $redirectUrls->setCancelUrl($this->failureUrl); // Payment $payment = new Payment(); $payment->setRedirectUrls($redirectUrls); $payment->setIntent("sale"); $payment->setPayer($payer); $payment->setTransactions([$transaction]); $payment->create($context); return $payment; }
public function setPaypalAmount($currency, $total, $details) { $amount = new Amount(); $amount->setCurrency($currency); $amount->setTotal(number_format($total, 2)); if ($details) { $amount->setDetails($details); } return $amount; }