public function testStartMinumumOk() { \Paynl\Config::setApiToken('123456789012345678901234567890'); \Paynl\Config::setServiceId('SL-1234-5678'); $this->setDummyData('startOk'); $result = \Paynl\Transaction::start(array('amount' => 10, 'returnUrl' => '/return.php', 'ipaddress' => '127.0.0.1')); $this->validateStartResult($result); }
<?php /* * Copyright (C) 2015 Andy Pieters <*****@*****.**> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ require_once '../../vendor/autoload.php'; require_once '../config.php'; try { $result = \Paynl\Transaction::start(array('amount' => 12.5, 'returnUrl' => dirname(Paynl\Helper::getBaseUrl()) . '/return.php', 'exchangeUrl' => dirname(Paynl\Helper::getBaseUrl()) . '/exchange.php', 'paymentMethod' => 10, 'currency' => 'EUR', 'expireDate' => new DateTime('2016-04-01'), 'description' => '123456', 'testmode' => 0, 'extra1' => 'ext1', 'extra2' => 'ext2', 'extra3' => 'ext3', 'ipaddress' => '10.0.0.1', 'invoiceDate' => new DateTime('now'), 'deliveryDate' => new DateTime('2016-06-06'), 'products' => array(array('id' => 1, 'name' => 'een product', 'price' => 5, 'vatPercentage' => 21, 'qty' => 1, 'type' => \Paynl\Transaction::PRODUCT_TYPE_ARTICLE), array('id' => 2, 'name' => 'ander product 15 %', 'price' => 5, 'vatPercentage' => 15, 'qty' => 1, 'type' => \Paynl\Transaction::PRODUCT_TYPE_ARTICLE), array('id' => 'shipping', 'name' => 'verzendkosten', 'price' => 5, 'vatPercentage' => 21, 'qty' => 1, 'type' => \Paynl\Transaction::PRODUCT_TYPE_SHIPPING), array('id' => 'fee', 'name' => 'Handling fee', 'price' => 1, 'vatPercentage' => 21, 'qty' => 1, 'type' => \Paynl\Transaction::PRODUCT_TYPE_HANDLING), array('id' => '5543', 'name' => 'Coupon 3,50 korting', 'price' => -3.5, 'vatPercentage' => 21, 'qty' => 1, 'type' => \Paynl\Transaction::PRODUCT_TYPE_DISCOUNT)), 'language' => 'EN', 'enduser' => array('initials' => 'T', 'lastName' => 'Test', 'gender' => 'M', 'birthDate' => '14-05-1999', 'phoneNumber' => '0612345678', 'emailAddress' => '*****@*****.**', 'customerReference' => '456789', 'customerTrust' => 0), 'address' => array('streetName' => 'Test', 'houseNumber' => '10', 'houseNumberExtension' => 'A', 'zipCode' => '1234AB', 'city' => 'Test', 'country' => 'NL'), 'invoiceAddress' => array('initials' => 'IT', 'lastName' => 'ITEST', 'streetName' => 'Istreet', 'houseNumber' => '70', 'houseNumberExtension' => 'A', 'zipCode' => '5678CD', 'city' => 'ITest', 'country' => 'NL'))); // Save this transactionid and link it to your order $transactionId = $result->getTransactionId(); echo '<a href="' . $result->getRedirectUrl() . '">' . $result->getRedirectUrl() . '</a>'; echo "<br />" . $transactionId; } catch (\Paynl\Error\Error $e) { echo "Fout: " . $e->getMessage(); }
<?php /* * Copyright (C) 2015 Andy Pieters <*****@*****.**> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ require_once '../../vendor/autoload.php'; \Paynl\Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab'); \Paynl\Config::setServiceId('SL-3490-4320'); $result = \Paynl\Transaction::start(array('amount' => 10, 'returnUrl' => dirname(Paynl\Helper::getBaseUrl()) . '/return.php', 'exchangeUrl' => dirname(Paynl\Helper::getBaseUrl()) . '/exchange.php', 'paymentMethod' => 10, 'currency' => 'USD', 'bank' => 1, 'description' => 'demo betaling', 'testmode' => 1, 'extra1' => 'ext1', 'extra2' => 'ext2', 'extra3' => 'ext3', 'products' => array(array('id' => 1, 'name' => 'een product', 'price' => 5, 'tax' => 0.87, 'qty' => 1), array('id' => 2, 'name' => 'ander product', 'price' => 5, 'tax' => 0.87, 'qty' => 1)), 'language' => 'EN', 'enduser' => array('initials' => 'T', 'lastName' => 'Test', 'gender' => 'M', 'dob' => '14-05-1999', 'phoneNumber' => '0612345678', 'emailAddress' => '*****@*****.**'), 'address' => array('streetName' => 'Test', 'houseNumber' => '10', 'zipCode' => '1234AB', 'city' => 'Test', 'country' => 'NL'), 'invoiceAddress' => array('initials' => 'IT', 'lastName' => 'ITEST', 'streetName' => 'Istreet', 'houseNumber' => '70', 'zipCode' => '5678CD', 'city' => 'ITest', 'country' => 'NL'))); // Save this transactionid and link it to your order $transactionId = $result->getTransactionId(); echo '<a href="' . $result->getRedirectUrl() . '">' . $result->getRedirectUrl() . '</a>';
public function startTransaction(Order $order, UrlInterface $url) { $config = new Config($this->_scopeConfig); $config->configureSDK(); $additionalData = $order->getPayment()->getAdditionalInformation(); $bankId = null; if (isset($additionalData['bank_id'])) { $bankId = $additionalData['bank_id']; } $total = $order->getGrandTotal(); $items = $order->getAllVisibleItems(); $orderId = $order->getIncrementId(); $quoteId = $order->getQuoteId(); $currency = $order->getOrderCurrencyCode(); $returnUrl = $url->getUrl('paynl/checkout/finish/'); $exchangeUrl = $url->getUrl('paynl/checkout/exchange/'); $paymentOptionId = $this->getPaymentOptionId(); $arrBillingAddress = $order->getBillingAddress(); if ($arrBillingAddress) { $arrBillingAddress = $arrBillingAddress->toArray(); $enduser = array('initials' => substr($arrBillingAddress['firstname'], 0, 1), 'lastName' => $arrBillingAddress['lastname'], 'phoneNumber' => $arrBillingAddress['telephone'], 'emailAddress' => $arrBillingAddress['email']); $invoiceAddress = array('initials' => substr($arrBillingAddress['firstname'], 0, 1), 'lastName' => $arrBillingAddress['lastname']); $arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']); $invoiceAddress['streetName'] = $arrAddress[0]; $invoiceAddress['houseNumber'] = $arrAddress[1]; $invoiceAddress['zipCode'] = $arrBillingAddress['postcode']; $invoiceAddress['city'] = $arrBillingAddress['city']; $invoiceAddress['country'] = $arrBillingAddress['country_id']; } $arrShippingAddress = $order->getShippingAddress(); if ($arrShippingAddress) { $arrShippingAddress = $arrShippingAddress->toArray(); $shippingAddress = array('initials' => substr($arrShippingAddress['firstname'], 0, 1), 'lastName' => $arrShippingAddress['lastname']); $arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']); $shippingAddress['streetName'] = $arrAddress2[0]; $shippingAddress['houseNumber'] = $arrAddress2[1]; $shippingAddress['zipCode'] = $arrShippingAddress['postcode']; $shippingAddress['city'] = $arrShippingAddress['city']; $shippingAddress['country'] = $arrShippingAddress['country_id']; } $data = array('amount' => $total, 'returnUrl' => $returnUrl, 'paymentMethod' => $paymentOptionId, 'bank' => $bankId, 'description' => $orderId, 'extra1' => $orderId, 'extra2' => $quoteId, 'exchangeUrl' => $exchangeUrl, 'currency' => $currency); if (isset($shippingAddress)) { $data['address'] = $shippingAddress; } if (isset($invoiceAddress)) { $data['invoiceAddress'] = $invoiceAddress; } if (isset($enduser)) { $data['enduser'] = $enduser; } $arrProducts = array(); foreach ($items as $item) { $arrItem = $item->toArray(); if ($arrItem['price_incl_tax'] != null) { // taxamount is not valid, because on discount it returns the taxamount after discount $taxAmount = $arrItem['price_incl_tax'] - $arrItem['price']; $product = array('id' => $arrItem['product_id'], 'name' => $arrItem['name'], 'price' => $arrItem['price_incl_tax'], 'qty' => $arrItem['qty_ordered'], 'tax' => $taxAmount); } $arrProducts[] = $product; } //shipping $shippingCost = $order->getShippingInclTax(); $shippingTax = $order->getShippingTaxAmount(); $shippingDescription = $order->getShippingDescription(); $arrProducts[] = array('id' => 'shipping', 'name' => $shippingDescription, 'price' => $shippingCost, 'qty' => 1, 'tax' => $shippingTax); // kortingen $discount = $order->getDiscountAmount(); $discountDescription = $order->getDiscountDescription(); if ($discount != 0) { $arrProducts[] = array('id' => 'discount', 'name' => $discountDescription, 'price' => $discount, 'qty' => 1, 'tax' => $order->getDiscountTaxCompensationAmount() * -1); } $data['products'] = $arrProducts; if ($config->isTestMode()) { $data['testmode'] = 1; } $data['ipaddress'] = $order->getRemoteIp(); $transaction = \Paynl\Transaction::start($data); return $transaction->getRedirectUrl(); }
public function execute() { try { /** @var \Magento\Checkout\Model\Type\Onepage $onepage */ $onepage = $this->_objectManager->get('Magento\\Checkout\\Model\\Type\\Onepage'); /** @var \Magento\Quote\Model\Quote $quote */ $quote = $onepage->getQuote(); $quote->collectTotals(); $quote->reserveOrderId(); $orderId = $quote->getReservedOrderId(); $payment = $quote->getPayment()->getMethodInstance(); $total = $quote->getGrandTotal(); $items = $quote->getAllVisibleItems(); $currency = $quote->getQuoteCurrencyCode(); $returnUrl = $this->_url->getUrl('paynl/finish/'); $exchangeUrl = $this->_url->getUrl('paynl/exchange/'); $paymentOptionId = $payment->getPaymentOptionId(); $arrBillingAddress = $quote->getBillingAddress()->toArray(); $arrShippingAddress = $quote->getShippingAddress()->toArray(); $enduser = array('initials' => substr($arrBillingAddress['firstname'], 0, 1), 'lastName' => $arrBillingAddress['lastname'], 'phoneNumber' => $arrBillingAddress['telephone'], 'emailAddress' => $arrBillingAddress['email']); $address = array(); $arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']); $address['streetName'] = $arrAddress[0]; $address['houseNumber'] = $arrAddress[1]; $address['zipCode'] = $arrBillingAddress['postcode']; $address['city'] = $arrBillingAddress['city']; $address['country'] = $arrBillingAddress['country_id']; $shippingAddress = array(); $arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']); $shippingAddress['streetName'] = $arrAddress2[0]; $shippingAddress['houseNumber'] = $arrAddress2[1]; $shippingAddress['zipCode'] = $arrShippingAddress['postcode']; $shippingAddress['city'] = $arrShippingAddress['city']; $shippingAddress['country'] = $arrShippingAddress['country_id']; $data = array('amount' => $total, 'returnUrl' => $returnUrl, 'paymentMethod' => $paymentOptionId, 'description' => $orderId, 'extra1' => $orderId, 'extra1' => $quote->getId(), 'exchangeUrl' => $exchangeUrl, 'currency' => $currency); $data['address'] = $address; $data['shippingAddress'] = $shippingAddress; $data['enduser'] = $enduser; $arrProducts = array(); foreach ($items as $item) { $arrItem = $item->toArray(); if ($arrItem['price_incl_tax'] != null) { $product = array('id' => $arrItem['product_id'], 'name' => $arrItem['name'], 'price' => $arrItem['price_incl_tax'], 'qty' => $arrItem['qty'], 'tax' => $arrItem['tax_amount']); } $arrProducts[] = $product; } //shipping $shippingCost = $quote->getShippingAddress()->getShippingInclTax(); $shippingTax = $quote->getShippingAddress()->getShippingTaxAmount(); $shippingDescription = $quote->getShippingAddress()->getShippingDescription(); $arrProducts[] = array('id' => 'shipping', 'name' => $shippingDescription, 'price' => $shippingCost, 'qty' => 1, 'tax' => $shippingTax); // kortingen $discount = $quote->getSubtotal() - $quote->getSubtotalWithDiscount(); if ($discount > 0) { $arrProducts[] = array('id' => 'discount', 'name' => __('Discount'), 'price' => $discount * -1, 'qty' => 1, 'tax' => 0); } $data['products'] = $arrProducts; if ($this->_config->isTestMode()) { $data['testmode'] = 1; } $data['ipaddress'] = $quote->getRemoteIp(); \Paynl\Config::setApiToken($this->_config->getApiToken()); \Paynl\Config::setServiceId($this->_config->getServiceId()); $transaction = \Paynl\Transaction::start($data); $onepage->saveOrder(); $this->_redirect($transaction->getRedirectUrl()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong, please try again later')); $this->_redirect('checkout/cart'); } }