/** * @param float $shippingPrice * @param float $taxPrice * @param float $subtotal * * @return Details */ public static function createDetails($shippingPrice, $taxPrice, $subtotal) { $details = new Details(); $details->setShipping($shippingPrice); $details->setTax($taxPrice); $details->setSubtotal($subtotal); return $details; }
public static function createAmountDetails() { $amountDetails = new Details(); $amountDetails->setSubtotal(self::$subtotal); $amountDetails->setTax(self::$tax); $amountDetails->setShipping(self::$shipping); $amountDetails->setFee(self::$fee); return $amountDetails; }
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()); } }
/** * Creates PayPal payment details from given order * * @param OrderInterface $order * * @return Details */ protected function createDetails(OrderInterface $order) : Details { $details = new Details(); $details->setShipping($order->getShippingTotal()->getNetAmount()); $details->setTax($order->getOrderTotal()->getTaxAmount()); $details->setSubtotal($order->getProductTotal()->getNetAmount()); return $details; }
public function CreatePayment($items = false, $data = false) { $apiContext = $this->getApiContext(); #die(print_r($data)); // ### Payer // A resource representing a Payer that funds a payment // For paypal account payments, set payment method // to 'paypal'. $payer = new Payer(); $payer->setPaymentMethod("paypal"); // ### Itemized information // (Optional) Lets you specify item wise // information $cart = array(); $total = 0; /*foreach($items as $item) { $itemC = new Item(); $itemC->setName($item->name) ->setCurrency('EUR') ->setQuantity($item->items) ->setSku($item->code ? $item->code : $item->id) ->setPrice(round($item->cost,2)); $cart[] = $itemC; $total += $item->items * $item->cost; } $itemList = new ItemList(); $itemList->setItems($cart);*/ // ### Additional payment details // Use this optional field to set additional // payment information such as tax, shipping // charges etc. $details = new Details(); $details->setTax(round($data->tax, 2))->setSubtotal(round($data->subtotal, 2)); // ### Amount // Lets you specify a payment amount. // You can also specify additional details // such as shipping, tax. $amount = new Amount(); $amount->setCurrency("EUR")->setTotal(round($data->total, 2))->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)->setDescription("Compra actual - " . round($data->total, 2) . " EUR")->setInvoiceNumber(uniqid()); // ### Redirect urls // Set the urls that the buyer must be redirected to after // payment approval/ cancellation. $baseUrl = base_url(); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl("{$baseUrl}cart/paypal?success=true")->setCancelUrl("{$baseUrl}cart/paypal-ko"); // ### 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)); // ### 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) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY die(print_r($ex->getData())); 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->getApprovalLink(); // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY redirect($approvalUrl); return $payment; }
public function success() { $paymentId = request('paymentId'); $payment = Payment::get($paymentId, $this->paypal); $execution = new PaymentExecution(); $execution->setPayerId(request('PayerID')); $transaction = new Transaction(); $amount = new Amount(); $details = new Details(); $productsSum = 0.0; foreach ($this->order->getProducts() as $product) { $productsSum += $product->getTotal(); } $details->setSubtotal($productsSum); $total = $productsSum; if ($delivery = $this->order->getDelivery()) { $details->setShipping($delivery); $total += $delivery; } if ($vat = $this->order->getVat()) { $details->setTax($vat); $total += $vat; } $amount->setCurrency($this->order->getCurrency())->setTotal($total)->setDetails($details); $transaction->setAmount($amount); $execution->addTransaction($transaction); try { $payment->execute($execution, $this->paypal); } catch (\Exception $e) { $this->log($e); throw $e; } finally { Payment::get($paymentId, $this->paypal); } }
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 payDemo() { $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 Details(); $amountDetails->setSubtotal('15.99'); $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)); return $payment->create($this->_apiContext); }
/** * Create a payment using the buyer's paypal * account as the funding instrument. Your app * will have to redirect the buyer to the paypal * website, obtain their consent to the payment * and subsequently execute the payment using * the execute API call. * * @param string $total payment amount in DDD.DD format * @param string $currency 3 letter ISO currency code such as 'USD' * @param string $paymentDesc A description about the payment * @param string $returnUrl The url to which the buyer must be redirected * to on successful completion of payment * @param string $cancelUrl The url to which the buyer must be redirected * to if the payment is cancelled * @return \PayPal\Api\Payment */ function makePaymentUsingPayPal($sku, $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); */ $payer = new Payer(); $payer->setPaymentMethod("paypal"); // ### Itemized information // (Optional) Lets you specify item wise // information $item1 = new Item(); $item1->setName($GLOBALS['PAY_NAME'])->setCurrency(PAYPAL_CURRENCY_EUR)->setQuantity(1)->setPrice($GLOBALS['PAY_PRICE'])->setSku(llenaEspaciosPaypal($sku, 11, '0')); $itemList = new ItemList(); $itemList->setItems(array($item1)); // ### Additional payment details // Use this optional field to set additional // payment information such as tax, shipping // charges etc. $details = new Details(); $details->setTax($GLOBALS['PAY_TAX'])->setSubtotal($GLOBALS['PAY_TOTAL_AMOUNT']); // ### Amount // Lets you specify a payment amount. // You can also specify additional details // such as shipping, tax. $amount = new Amount(); $amount->setCurrency(PAYPAL_CURRENCY_EUR)->setTotal($GLOBALS['PAY_PRICE'])->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($GLOBALS['PAY_DESCRIPTION']); $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; }
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; }
private function createDetails(OrderInterface $order) : Details { $shippingCosts = $order->getModifier('shipping_cost'); $details = new Details(); $details->setShipping($shippingCosts->getNetAmount()); $details->setTax($order->getSummary()->getTaxAmount()); $details->setSubtotal($order->getProductTotal()->getNetPrice()); return $details; }
public function setPaypalDetails($shipping, $tax, $subtotal) { $subtotal = number_format($subtotal, 2); $shipping = number_format($shipping, 2); $tax = number_format($tax, 2); $details = new Details(); $details->setSubtotal($subtotal); $details->setShipping($shipping); $details->setTax($tax); return $details; }