public function startTransaction(Order $order, UrlInterface $url)
 {
     $config = new Config($this->_scopeConfig);
     $config->configureSDK();
     $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()->toArray();
     $arrShippingAddress = $order->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, 'extra2' => $quoteId, '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_ordered'], 'tax' => $arrItem['tax_amount']);
         }
         $arrProducts[] = $product;
     }
     //shipping
     $shippingCost = $order->getShippingAddress()->getShippingInclTax();
     $shippingTax = $order->getShippingAddress()->getShippingTaxAmount();
     $shippingDescription = $order->getShippingAddress()->getShippingDescription();
     $arrProducts[] = array('id' => 'shipping', 'name' => $shippingDescription, 'price' => $shippingCost, 'qty' => 1, 'tax' => $shippingTax);
     // kortingen
     $discount = $order->getSubtotal() - $order->getSubtotalWithDiscount();
     if ($discount > 0) {
         $arrProducts[] = array('id' => 'discount', 'name' => __('Discount'), 'price' => $discount * -1, 'qty' => 1, 'tax' => 0);
     }
     $data['products'] = $arrProducts;
     if ($config->isTestMode()) {
         $data['testmode'] = 1;
     }
     $data['ipaddress'] = $order->getRemoteIp();
     $transaction = \Paynl\Transaction::start($data);
     return $transaction->getRedirectUrl();
 }
Example #2
0
 protected function _isAvailable()
 {
     $configured = $this->_config->configureSDK();
     if ($configured) {
         $paymentOptionId = $this->_config->getPaymentOptionId($this->_code);
         $list = Paymentmethods::getList();
         if (isset($list[$paymentOptionId])) {
             return true;
         }
     }
     return false;
 }
Example #3
0
 public function execute()
 {
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $transaction = \Paynl\Transaction::getForReturn();
     if ($transaction->isPaid() || $transaction->isPending()) {
         $resultRedirect = $this->resultRedirectFactory->create();
         return $resultRedirect->setPath('checkout/onepage/success');
     } else {
         //canceled, reorder
         $this->messageManager->addNotice(__('Payment canceled'));
         return $this->_reorder($transaction->getDescription());
     }
 }
Example #4
0
 public function execute()
 {
     $skipFraudDetection = false;
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $params = $this->getRequest()->getParams();
     if (!isset($params['order_id'])) {
         $this->_logger->critical('Exchange: order_id is not set in the request', $params);
         return $this->_result->setContents('FALSE| order_id is not set in the request');
     }
     try {
         $transaction = \Paynl\Transaction::get($params['order_id']);
     } catch (\Exception $e) {
         $this->_logger->critical($e, $params);
         return $this->_result->setContents('FALSE| Error fetching transaction. ' . $e->getMessage());
     }
     if ($transaction->isPending()) {
         return $this->_result->setContents("TRUE| Ignoring pending");
     }
     $orderId = $transaction->getDescription();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderId);
     if (empty($order)) {
         $this->_logger->critical('Cannot load order: ' . $orderId);
         return $this->_result->setContents('FALSE| Cannot load order');
     }
     if ($order->getTotalDue() <= 0) {
         $this->_logger->debug('Total due <= 0, so iam not touching the status of the order: ' . $orderId);
         return $this->_result->setContents('TRUE| Total due <= 0, so iam not touching the status of the order');
     }
     if ($transaction->isPaid()) {
         $payment = $order->getPayment();
         $payment->setTransactionId($transaction->getId());
         $payment->setCurrencyCode($transaction->getPaidCurrency());
         $payment->setIsTransactionClosed(0);
         $payment->registerCaptureNotification($transaction->getPaidCurrencyAmount(), $skipFraudDetection);
         $order->save();
         // notify customer
         $invoice = $payment->getCreatedInvoice();
         if ($invoice && !$order->getEmailSent()) {
             $this->_orderSender->send($order);
             $order->addStatusHistoryComment(__('New order email sent'))->setIsCustomerNotified(true)->save();
         }
         if ($invoice && !$invoice->getEmailSent()) {
             $this->_invoiceSender->send($invoice);
             $order->addStatusHistoryComment(__('You notified customer about invoice #%1.', $invoice->getIncrementId()))->setIsCustomerNotified(true)->save();
         }
         return $this->_result->setContents("TRUE| PAID");
     } elseif ($transaction->isCanceled()) {
         $order->cancel()->save();
         return $this->_result->setContents("TRUE| CANCELED");
     }
 }
Example #5
0
 public function getBanks()
 {
     $show_banks = $this->_scopeConfig->getValue('payment/' . $this->_code . '/bank_selection', 'store');
     if (!$show_banks) {
         return [];
     }
     $cache = $this->getCache();
     $cacheName = 'paynl_banks_' . $this->getPaymentOptionId();
     $banksJson = $cache->load($cacheName);
     if ($banksJson) {
         $banks = json_decode($banksJson);
     } else {
         $config = new Config($this->_scopeConfig);
         $config->configureSDK();
         $banks = \Paynl\Paymentmethods::getBanks($this->getPaymentOptionId());
         $cache->save(json_encode($banks), $cacheName);
     }
     array_unshift($banks, array('id' => '', 'name' => __('Choose your bank'), 'visibleName' => __('Choose your bank')));
     return $banks;
 }
Example #6
0
 public function execute()
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $params = $this->getRequest()->getParams();
     if (!isset($params['orderId'])) {
         $this->messageManager->addNoticeMessage(__('Invalid return, no transactionId specified'));
         $this->_logger->critical('Invalid return, no transactionId specified', $params);
         $resultRedirect->setPath('checkout/cart');
         return $resultRedirect;
     }
     try {
         $transaction = \Paynl\Transaction::get($params['orderId']);
     } catch (\Exception $e) {
         $this->_logger->critical($e, $params);
         $this->messageManager->addExceptionMessage($e, __('There was an error checking the transaction status'));
         $resultRedirect->setPath('checkout/cart');
         return $resultRedirect;
     }
     if ($transaction->isPaid() || $transaction->isPending()) {
         $this->_getCheckoutSession()->start();
         $resultRedirect->setPath('checkout/onepage/success');
     } else {
         //canceled, re-activate quote
         try {
             $this->_getCheckoutSession()->restoreQuote();
             $this->messageManager->addNoticeMessage(__('Payment canceled'));
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $this->_logger->error($e);
             $this->messageManager->addExceptionMessage($e, $e->getMessage());
         } catch (\Exception $e) {
             $this->_logger->error($e);
             $this->messageManager->addExceptionMessage($e, __('Unable to cancel order'));
         }
         $resultRedirect->setPath('checkout/cart');
     }
     return $resultRedirect;
 }
Example #7
0
 public function execute()
 {
     $skipFraudDetection = false;
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $transaction = \Paynl\Transaction::getForExchange();
     if ($transaction->isPending()) {
         die("TRUE| Ignoring pending");
     }
     $orderId = $transaction->getDescription();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderId);
     if (empty($order)) {
         die('FALSE| Cannot load order');
     }
     if ($order->getTotalDue() <= 0) {
         die('TRUE| Total due <= 0, so iam not touching the status if the order');
     }
     if ($transaction->isPaid()) {
         if ($order->getOrderCurrencyCode() != 'EUR') {
             $skipFraudDetection = true;
         }
         $payment = $order->getPayment();
         $payment->setTransactionId($transaction->getId());
         $payment->setCurrencyCode($transaction->getPaidCurrency());
         $payment->setIsTransactionClosed(0);
         $payment->registerCaptureNotification($transaction->getPaidAmount(), $skipFraudDetection);
         $order->save();
         // notify customer
         $invoice = $payment->getCreatedInvoice();
         if ($invoice && !$order->getEmailSent()) {
             $this->_orderSender->send($order);
             $order->addStatusHistoryComment(__('You notified customer about invoice #%1.', $invoice->getIncrementId()))->setIsCustomerNotified(true)->save();
         }
         die("TRUE| PAID");
     } elseif ($transaction->isCanceled()) {
         $order->cancel()->save();
         die("TRUE| CANCELED");
     }
 }
Example #8
0
 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');
     }
 }