From 3bcb56c3a4f6f33757b00354f79425424b5a0957 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Wed, 17 Apr 2019 10:52:30 +0200 Subject: [PATCH 01/15] Set the status code to 503 when an exception occurs --- Controller/Checkout/Webhook.php | 5 ++++ .../Controller/Checkout/WebhookTest.php | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Tests/Integration/Controller/Checkout/WebhookTest.php diff --git a/Controller/Checkout/Webhook.php b/Controller/Checkout/Webhook.php index 8f910916a94..581cdf71f3b 100644 --- a/Controller/Checkout/Webhook.php +++ b/Controller/Checkout/Webhook.php @@ -78,6 +78,11 @@ public function execute() } } catch (\Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); + + $result = $this->resultFactory->create(ResultFactory::TYPE_JSON); + $result->setHttpResponseCode(503); + + return $result; } } } diff --git a/Tests/Integration/Controller/Checkout/WebhookTest.php b/Tests/Integration/Controller/Checkout/WebhookTest.php new file mode 100644 index 00000000000..42610b5b8b8 --- /dev/null +++ b/Tests/Integration/Controller/Checkout/WebhookTest.php @@ -0,0 +1,28 @@ +createMock(Mollie::class); + $mollieModel->method('getOrderIdByTransactionId')->willReturn(123); + $mollieModel->method('processTransaction')->willThrowException(new \Exception('[TEST] Something went wrong')); + + $this->_objectManager->addSharedInstance($mollieModel, Mollie::class); + + $this->getRequest()->setMethod(Request::METHOD_POST); + $this->getRequest()->setParams([ + 'id' => 'ord_123ABC', + ]); + + $this->dispatch('mollie/checkout/webhook'); + + $this->assertSame(503, $this->getResponse()->getHttpResponseCode()); + } +} From 2ecd5b0bae4a2a034555ed4f87d54340aed91032 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Fri, 19 Apr 2019 15:02:41 +0200 Subject: [PATCH 02/15] When an adjustment fee is set, the order line won't be refunded in Mollie but will be in Magento --- Model/Client/Orders.php | 59 +++++----------- Service/Order/ProcessAdjustmentFee.php | 94 ++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 41 deletions(-) create mode 100644 Service/Order/ProcessAdjustmentFee.php diff --git a/Model/Client/Orders.php b/Model/Client/Orders.php index 17bd17574ad..bbfc7634d79 100644 --- a/Model/Client/Orders.php +++ b/Model/Client/Orders.php @@ -18,9 +18,9 @@ use Magento\Sales\Model\Order\InvoiceRepository; use Magento\Sales\Model\Service\InvoiceService; use Magento\Checkout\Model\Session\Proxy as CheckoutSession; -use Mollie\Api\Resources\PaymentFactory; use Mollie\Payment\Helper\General as MollieHelper; use Mollie\Payment\Model\OrderLines; +use Mollie\Payment\Service\Order\ProcessAdjustmentFee; /** * Class Orders @@ -73,24 +73,24 @@ class Orders extends AbstractModel */ private $registry; /** - * @var PaymentFactory + * @var ProcessAdjustmentFee */ - private $paymentFactory; + private $adjustmentFee; /** * Orders constructor. * - * @param OrderLines $orderLines - * @param OrderSender $orderSender - * @param InvoiceSender $invoiceSender - * @param InvoiceService $invoiceService - * @param OrderRepository $orderRepository - * @param InvoiceRepository $invoiceRepository - * @param CheckoutSession $checkoutSession - * @param ManagerInterface $messageManager - * @param Registry $registry - * @param MollieHelper $mollieHelper - * @param PaymentFactory $paymentFactory + * @param OrderLines $orderLines + * @param OrderSender $orderSender + * @param InvoiceSender $invoiceSender + * @param InvoiceService $invoiceService + * @param OrderRepository $orderRepository + * @param InvoiceRepository $invoiceRepository + * @param CheckoutSession $checkoutSession + * @param ManagerInterface $messageManager + * @param Registry $registry + * @param MollieHelper $mollieHelper + * @param ProcessAdjustmentFee $adjustmentFee */ public function __construct( OrderLines $orderLines, @@ -103,7 +103,7 @@ public function __construct( ManagerInterface $messageManager, Registry $registry, MollieHelper $mollieHelper, - PaymentFactory $paymentFactory + ProcessAdjustmentFee $adjustmentFee ) { $this->orderLines = $orderLines; $this->orderSender = $orderSender; @@ -115,7 +115,7 @@ public function __construct( $this->messageManager = $messageManager; $this->registry = $registry; $this->mollieHelper = $mollieHelper; - $this->paymentFactory = $paymentFactory; + $this->adjustmentFee = $adjustmentFee; } /** @@ -700,30 +700,7 @@ public function createOrderRefund(Order\Creditmemo $creditmemo, Order $order) /** * Check for creditmemo adjustment fee's, positive and negative. */ - if ($creditmemo->getAdjustment() !== 0.0) { - $mollieOrder = $mollieApi->orders->get($order->getMollieTransactionId(), ['embed' => 'payments']); - $payments = $mollieOrder->_embedded->payments; - - try { - $payment = $this->paymentFactory->create([$mollieApi]); - $payment->id = current($payments)->id; - - $mollieApi->payments->refund($payment, [ - 'amount' => [ - 'currency' => $order->getOrderCurrencyCode(), - 'value' => $this->mollieHelper->formatCurrencyValue( - $creditmemo->getAdjustment(), - $order->getOrderCurrencyCode() - ), - ] - ]); - } catch (\Exception $exception) { - $this->mollieHelper->addTolog('error', $exception->getMessage()); - throw new LocalizedException( - __('Mollie API: %1', $exception->getMessage()) - ); - } - } + $this->adjustmentFee->handle($mollieApi, $order, $creditmemo); /** * Check if Shipping Fee needs to be refunded. @@ -742,7 +719,7 @@ public function createOrderRefund(Order\Creditmemo $creditmemo, Order $order) } } - if (!$creditmemo->getAllItems()) { + if (!$creditmemo->getAllItems() || $this->adjustmentFee->doNotRefundInMollie()) { return $this; } diff --git a/Service/Order/ProcessAdjustmentFee.php b/Service/Order/ProcessAdjustmentFee.php new file mode 100644 index 00000000000..f11600298e7 --- /dev/null +++ b/Service/Order/ProcessAdjustmentFee.php @@ -0,0 +1,94 @@ +mollieHelper = $mollieHelper; + $this->paymentFactory = $paymentFactory; + } + + public function handle(MollieApiClient $mollieApi, OrderInterface $order, CreditmemoInterface $creditmemo) + { + if ($creditmemo->getAdjustment() > 0) { + $this->positive($mollieApi, $order, $creditmemo); + } + + if ($creditmemo->getAdjustmentNegative() < 0) { + $this->negative($mollieApi, $order, $creditmemo); + } + } + + public function doNotRefundInMollie() + { + return $this->doNotRefundInMollie; + } + + private function positive(MollieApiClient $mollieApi, OrderInterface $order, CreditmemoInterface $creditmemo) + { + $this->doNotRefundInMollie = false; + + $this->paymentRefund($mollieApi, $order, $creditmemo->getAdjustment()); + } + + private function negative(MollieApiClient $mollieApi, OrderInterface $order, CreditmemoInterface $creditmemo) + { + $this->doNotRefundInMollie = true; + + $amountToRefund = $creditmemo->getSubtotal() - $creditmemo->getAdjustmentNegative(); + + $this->paymentRefund($mollieApi, $order, $amountToRefund); + } + + private function paymentRefund(MollieApiClient $mollieApi, OrderInterface $order, $amount) + { + $mollieOrder = $mollieApi->orders->get($order->getMollieTransactionId(), ['embed' => 'payments']); + $payments = $mollieOrder->_embedded->payments; + + try { + $payment = $this->paymentFactory->create([$mollieApi]); + $payment->id = current($payments)->id; + + $mollieApi->payments->refund($payment, [ + 'amount' => [ + 'currency' => $order->getOrderCurrencyCode(), + 'value' => $this->mollieHelper->formatCurrencyValue( + $amount, + $order->getOrderCurrencyCode() + ), + ] + ]); + } catch (\Exception $exception) { + $this->mollieHelper->addTolog('error', $exception->getMessage()); + throw new LocalizedException( + __('Mollie API: %1', $exception->getMessage()) + ); + } + } +} \ No newline at end of file From 41e5da120710e92d14ddc63cb31782080d847778 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Fri, 19 Apr 2019 14:15:49 +0200 Subject: [PATCH 03/15] When an exception occurs when the transaction is started, the current order is canceled (if enabled) --- Controller/Checkout/Redirect.php | 63 ++++++++- Tests/Fakes/Model/Methods/IdealFake.php | 15 ++ .../Controller/Checkout/RedirectTest.php | 131 ++++++++++++++++++ etc/adminhtml/system.xml | 14 +- etc/config.xml | 1 + 5 files changed, 213 insertions(+), 11 deletions(-) create mode 100644 Tests/Fakes/Model/Methods/IdealFake.php create mode 100644 Tests/Integration/Controller/Checkout/RedirectTest.php diff --git a/Controller/Checkout/Redirect.php b/Controller/Checkout/Redirect.php index 5a075198217..6731a4d7f4d 100644 --- a/Controller/Checkout/Redirect.php +++ b/Controller/Checkout/Redirect.php @@ -6,7 +6,12 @@ namespace Mollie\Payment\Controller\Checkout; +use Exception; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Payment\Helper\Data as PaymentHelper; +use Magento\Sales\Api\Data\OrderInterface; +use Magento\Sales\Api\OrderManagementInterface; +use Magento\Store\Model\ScopeInterface; use Mollie\Payment\Helper\General as MollieHelper; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; @@ -37,27 +42,41 @@ class Redirect extends Action * @var MollieHelper */ protected $mollieHelper; + /** + * @var OrderManagementInterface + */ + private $orderManagement; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; /** * Redirect constructor. * - * @param Context $context - * @param Session $checkoutSession - * @param PageFactory $resultPageFactory - * @param PaymentHelper $paymentHelper - * @param MollieHelper $mollieHelper + * @param Context $context + * @param Session $checkoutSession + * @param PageFactory $resultPageFactory + * @param PaymentHelper $paymentHelper + * @param MollieHelper $mollieHelper + * @param OrderManagementInterface $orderManagement + * @param ScopeConfigInterface $scopeConfig */ public function __construct( Context $context, Session $checkoutSession, PageFactory $resultPageFactory, PaymentHelper $paymentHelper, - MollieHelper $mollieHelper + MollieHelper $mollieHelper, + OrderManagementInterface $orderManagement, + ScopeConfigInterface $scopeConfig ) { $this->checkoutSession = $checkoutSession; $this->resultPageFactory = $resultPageFactory; $this->paymentHelper = $paymentHelper; $this->mollieHelper = $mollieHelper; + $this->orderManagement = $orderManagement; + $this->scopeConfig = $scopeConfig; parent::__construct($context); } @@ -102,11 +121,41 @@ public function execute() $this->checkoutSession->restoreQuote(); $this->_redirect('checkout/cart'); } - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, __($e->getMessage())); $this->mollieHelper->addTolog('error', $e->getMessage()); $this->checkoutSession->restoreQuote(); + $this->cancelUnprocessedOrder($order, $e->getMessage()); $this->_redirect('checkout/cart'); } } + + private function cancelUnprocessedOrder(OrderInterface $order, $message) + { + if (!empty($order->getMollieTransactionId())) { + return; + } + + if (!$this->scopeConfig->isSetFlag( + 'payment/mollie_general/cancel_failed_orders', + ScopeInterface::SCOPE_STORE + )) { + return; + } + + try { + $historyMessage = __('Canceled because an error occurred while redirecting the customer to Mollie'); + if ($message) { + $historyMessage .= ':
' . PHP_EOL . $message; + } + + $this->orderManagement->cancel($order->getEntityId()); + $order->addCommentToStatusHistory($order->getEntityId(), $historyMessage); + + $this->mollieHelper->addToLog('info', sprintf('Canceled order %s', $order->getIncrementId())); + } catch (Exception $e) { + $message = sprintf('Cannot cancel order %s: %s', $order->getIncrementId(), $e->getMessage()); + $this->mollieHelper->addToLog('error', $message); + } + } } diff --git a/Tests/Fakes/Model/Methods/IdealFake.php b/Tests/Fakes/Model/Methods/IdealFake.php new file mode 100644 index 00000000000..01f75838a22 --- /dev/null +++ b/Tests/Fakes/Model/Methods/IdealFake.php @@ -0,0 +1,15 @@ +_objectManager->get(Session::class)->setLastRealOrderId('100000001'); + + $this->_objectManager->configure([ + 'preferences' => [ + Ideal::class => IdealFake::class, + ], + ]); + + $this->getRequest()->setMethod(Request::METHOD_POST); + $this->dispatch('mollie/checkout/redirect'); + + $newOrder = $this->loadOrder(); + $this->assertEquals(Order::STATE_CANCELED, $newOrder->getState()); + } + + /** + * @magentoConfigFixture current_store payment/mollie_general/cancel_failed_orders 0 + * @magentoDbIsolation disabled + * @magentoDataFixture createOrder + */ + public function testDoesNotCancelWhenDisabled() + { + $this->_objectManager->get(Session::class)->setLastRealOrderId('100000001'); + + $this->_objectManager->configure([ + 'preferences' => [ + Ideal::class => IdealFake::class, + ], + ]); + + $this->getRequest()->setMethod(Request::METHOD_POST); + $this->dispatch('mollie/checkout/redirect'); + + $newOrder = $this->loadOrder(); + $this->assertNotEquals(Order::STATE_CANCELED, $newOrder->getState()); + } + + private function loadOrder() + { + $criteria = $this->_objectManager->create(SearchCriteriaBuilder::class) + ->addFilter('increment_id', '100000001', 'eq')->create(); + + $repository = $this->_objectManager->get(OrderRepositoryInterface::class); + $result = $repository->getList($criteria)->getItems(); + return array_shift($result); + } + + /** + * This is a copy of dev/tests/integration/testsuite/Magento/Sales/_files/order.php, + * but with the Mollie payment method. + * + * @throws \Magento\Framework\Exception\LocalizedException + */ + static public function createOrder() + { + require BP . '/dev/tests/integration/testsuite/Magento/Sales/_files/default_rollback.php'; + require BP . '/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php'; + /** @var \Magento\Catalog\Model\Product $product */ + + $addressData = include BP . '/dev/tests/integration/testsuite/Magento/Sales/_files/address_data.php'; + + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + + $billingAddress = $objectManager->create(OrderAddress::class, ['data' => $addressData]); + $billingAddress->setAddressType('billing'); + + $shippingAddress = clone $billingAddress; + $shippingAddress->setId(null)->setAddressType('shipping'); + + /** @var Payment $payment */ + $payment = $objectManager->create(Payment::class); + $payment->setMethod('mollie_methods_ideal'); + + /** @var OrderItem $orderItem */ + $orderItem = $objectManager->create(OrderItem::class); + $orderItem->setProductId($product->getId()) + ->setQtyOrdered(2) + ->setBasePrice($product->getPrice()) + ->setPrice($product->getPrice()) + ->setRowTotal($product->getPrice()) + ->setProductType('simple'); + + /** @var Order $order */ + $order = $objectManager->create(Order::class); + $order->setIncrementId('100000001') + ->setState(Order::STATE_PROCESSING) + ->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING)) + ->setSubtotal(100) + ->setGrandTotal(100) + ->setBaseSubtotal(100) + ->setBaseGrandTotal(100) + ->setCustomerIsGuest(true) + ->setCustomerEmail('customer@null.com') + ->setBillingAddress($billingAddress) + ->setShippingAddress($shippingAddress) + ->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId()) + ->addItem($orderItem) + ->setPayment($payment); + + /** @var OrderRepositoryInterface $orderRepository */ + $orderRepository = $objectManager->create(OrderRepositoryInterface::class); + $orderRepository->save($order); + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 1fa1adb761b..2dbfca425a8 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -120,9 +120,15 @@ showInWebsite="0" showInStore="0"> Magento\Config\Model\Config\Source\Yesno - payment/mollie_general/transaction_details Display Transaction Details like e.g. IBAN, BIC, Paypal Reference, Card Holder etc. + + + Magento\Config\Model\Config\Source\Yesno + payment/mollie_general/cancel_failed_orders + + @@ -141,9 +147,9 @@ Mollie\Payment\Block\Adminhtml\Render\Heading here.]]> + In case of a warning or error please contact your Developer or Hosting Company. + Specific information about the errors and warnings can be found + here.]]> diff --git a/etc/config.xml b/etc/config.xml index 68fd3380305..92cc7aede37 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -14,6 +14,7 @@ 1 Mollie\Payment\Model\Methods\General 1 + 0 0 From 7de8d42f3cafa33555a70213446a1b15d9b5d434 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Thu, 2 May 2019 13:48:08 +0200 Subject: [PATCH 04/15] Removed the Bitcoin payment method --- Helper/General.php | 1 - Model/Methods/Bitcoin.php | 31 ------ Model/MollieConfigProvider.php | 1 - etc/adminhtml/methods.xml | 1 - etc/adminhtml/methods/bitcoin.xml | 91 ------------------ etc/config.xml | 9 -- etc/payment.xml | 3 - i18n/de_DE.csv | 1 - i18n/en_US.csv | 1 - i18n/es_ES.csv | 1 - i18n/fr_FR.csv | 1 - i18n/nl_NL.csv | 1 - .../templates/form/mollie_paymentlink.phtml | 1 - view/adminhtml/web/images/bitcoin.png | Bin 1543 -> 0 bytes view/frontend/layout/checkout_index_index.xml | 3 - .../web/js/view/payment/method-renderer.js | 1 - 16 files changed, 147 deletions(-) delete mode 100644 Model/Methods/Bitcoin.php delete mode 100644 etc/adminhtml/methods/bitcoin.xml delete mode 100755 view/adminhtml/web/images/bitcoin.png diff --git a/Helper/General.php b/Helper/General.php index d615f9ade28..440e4bb172c 100755 --- a/Helper/General.php +++ b/Helper/General.php @@ -600,7 +600,6 @@ public function getAllActiveMethods($storeId) 'mollie_methods_bancontact', 'mollie_methods_banktransfer', 'mollie_methods_belfius', - 'mollie_methods_bitcoin', 'mollie_methods_creditcard', 'mollie_methods_ideal', 'mollie_methods_kbc', diff --git a/Model/Methods/Bitcoin.php b/Model/Methods/Bitcoin.php deleted file mode 100644 index c052c096218..00000000000 --- a/Model/Methods/Bitcoin.php +++ /dev/null @@ -1,31 +0,0 @@ - - diff --git a/etc/adminhtml/methods/bitcoin.xml b/etc/adminhtml/methods/bitcoin.xml deleted file mode 100644 index c3a08fdea36..00000000000 --- a/etc/adminhtml/methods/bitcoin.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - Magento\Config\Model\Config\Source\Yesno - payment/mollie_methods_bitcoin/active - - - - payment/mollie_methods_bitcoin/title - - 1 - - - - - Mollie\Payment\Model\Adminhtml\Source\Method - payment/mollie_methods_bitcoin/method - - 1 - - Payment API
Use the Payment API Platform for the transactions.

- Order API
Use the new Order API Platform and get additional insights in the orders. - Read more.]]>
-
- - - payment/mollie_methods_bitcoin/payment_description -
- {ordernumber}: The order number for this transaction
- {storename}: The name of the store

- (Note: This only works when the method is set to Payments API) - ]]>
- - payment - 1 - -
- - - Magento\Payment\Model\Config\Source\Allspecificcountries - payment/mollie_methods_bitcoin/allowspecific - - 1 - - - - - Magento\Directory\Model\Config\Source\Country - 1 - payment/mollie_methods_bitcoin/specificcountry - - 1 - - - - - payment/mollie_methods_bitcoin/min_order_total - - 1 - - - - - payment/mollie_methods_bitcoin/max_order_total - - 1 - - - - - validate-number - payment/mollie_methods_bitcoin/sort_order - - 1 - - -
-
\ No newline at end of file diff --git a/etc/config.xml b/etc/config.xml index 68fd3380305..35c6542b12d 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -44,15 +44,6 @@ 0 - - 0 - Mollie\Payment\Model\Methods\Bitcoin - Bitcoin - {ordernumber} - order - 0 - - 0 Mollie\Payment\Model\Methods\Creditcard diff --git a/etc/payment.xml b/etc/payment.xml index 50f82d7cbd7..d7f8f5b1a5d 100644 --- a/etc/payment.xml +++ b/etc/payment.xml @@ -10,9 +10,6 @@ 0 - - 0 - 0 diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index 003589f7f9c..1c97228dcab 100644 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -6,7 +6,6 @@ "Bancontact","Bankkontakt" "Banktransfer","Banküberweisung" "Belfius","Belfius" -"Bitcoin","Bitcoin" "Branding","Branding" "Check the Mollie extension technical requirements by running the self test. In case of a warning or error please contact your Developer or Hosting Company.","Überprüfen Sie die technischen Anforderungen der Mollie Erweiterung, indem Sie einen Selbsttest durchführen. Im Falle einer Warnung oder eines Fehlers kontaktieren Sie bitte Ihren Entwickler oder Ihre Hosting Firma." "Compatibility","Kompatibilität" diff --git a/i18n/en_US.csv b/i18n/en_US.csv index a511dd9edb1..1b6433eb648 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -6,7 +6,6 @@ "Bancontact","Bancontact" "Banktransfer","Banktransfer" "Belfius","Belfius" -"Bitcoin","Bitcoin" "Branding","Branding" "Check the Mollie extension technical requirements by running the self test. In case of a warning or error please contact your Developer or Hosting Company.","Check the Mollie extension technical requirements by running the self test. In case of a warning or error please contact your Developer or Hosting Company." "Compatibility","Compatibility" diff --git a/i18n/es_ES.csv b/i18n/es_ES.csv index 9e313765049..360731334be 100644 --- a/i18n/es_ES.csv +++ b/i18n/es_ES.csv @@ -6,7 +6,6 @@ "Bancontact","Bancontact" "Banktransfer","Transferencia bancaria" "Belfius","Belfius" -"Bitcoin","Bitcoin" "Branding","Branding" "Check the Mollie extension technical requirements by running the self test. In case of a warning or error please contact your Developer or Hosting Company.","Compruebe los requisitos técnicos de la extensión Mollie ejecutando el autodiagnóstico. En caso de una advertencia o error, póngase en contacto con su desarrollador o empresa de hosting." "Compatibility","Compatibilidad" diff --git a/i18n/fr_FR.csv b/i18n/fr_FR.csv index 35d540dd913..b0ca24610fa 100644 --- a/i18n/fr_FR.csv +++ b/i18n/fr_FR.csv @@ -6,7 +6,6 @@ "Bancontact","Bancontact" "Banktransfer","Virement bancaire" "Belfius","Belfius" -"Bitcoin","Bitcoin" "Branding","Marquage" "Check the Mollie extension technical requirements by running the self test. In case of a warning or error please contact your Developer or Hosting Company.","Vérifiez les exigences techniques de l'extension Mollie en exécutant l'auto-test. En cas d'avertissement ou d'erreur, veuillez contacter votre développeur ou votre hébergeur." "Compatibility","Compatibilité" diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index 2ce906429e0..43aff6924ad 100644 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -6,7 +6,6 @@ "Bancontact","Bancontact" "Banktransfer","Banktransfer" "Belfius","Belfius" -"Bitcoin","Bitcoin" "Branding","Branding" "Check the Mollie extension technical requirements by running the self test. In case of a warning or error please contact your Developer or Hosting Company.","Controleer de technische eisen van de Mollie extensie door de zelf test uit te voeren. In het geval van een error of waarschuwing, neem contact op met uw Developer of Hosting Partij." "Compatibility","Compatibility" diff --git a/view/adminhtml/templates/form/mollie_paymentlink.phtml b/view/adminhtml/templates/form/mollie_paymentlink.phtml index b16b2b14b3d..fcf09163c5a 100644 --- a/view/adminhtml/templates/form/mollie_paymentlink.phtml +++ b/view/adminhtml/templates/form/mollie_paymentlink.phtml @@ -24,7 +24,6 @@ $code; ?>" style="display:none"> - diff --git a/view/adminhtml/web/images/bitcoin.png b/view/adminhtml/web/images/bitcoin.png deleted file mode 100755 index f162e8b8e5273e70913958877e8005dd880ff6c3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1543 zcmV+i2Kf1jP)x!iJ#cbI0|80|V|1)R9li`071 z33_zWE;k4`n9G9yKb3_D{~{5z9p@={N!xRdZKV^(iHQ-;c}9=xC#^XL1S>@d%6Kxy z^m??3L>2e?uT)1O$V4Sdf(ZjelW?4LOD-$TIRy~WJtCaDr=(+%?p|pLdzD9mG=0>Q zo2?_Q;{0G@3T``^Gfr8I!=LC`7=I}~Fx}pq?&VSZvUp|5TuN&hr-z8xAQpntSVR7h zDmlgw;zBy{k~p$H)>tpt8!3W*RXd${+ZEz{Kh~st5l#;nsn>y4wM-BWdOagvji^n~p0nl1((Z|WVyWC`=0I*6Cv69a;s^{D z*jQuF7xo9yV5=p9Vt92I($pO^Rc?(cFlMBtzDC;jsrrCFt;Q>8O9UOqu8E#BN5nIA zooVhjb^01^TP+d9>QxeqxvV}x#yV95k%_-lxQDew5TQ~Lyu@^Y9i+C1q4kS}%igW+ zk%$;k;}ukCu#tkiKH-KUPYGqgLYaiqaYpk&{}HQ!JR9RJp_PH>bi?7`B|#AlGN6a(h+% zek?LU)%=6AGe-OUOEgX2#EI_**&qB)YGh(ZjkaZ<*5C>t(i|*bSPRZ{*bYb?Hd5K$ ze%u=BkZB&k=JN*9-sbO#Ujlkl&6ZTaa$$lILNo*BckVdRTaf_!E zt`XrI(7%j1YY4$iZ-#d0u4ZQBj_K6^pbP1V*`9XjA*=t)ZgmwZ$(D*#*KD< zH|@;UTx9+Bnj+{a$hl@0F3eOSCO2F95{c|WE;oU={3g>}A$FcP+ivzv%TFNo|5D@uH-oVsnT$3zLr!Yfor6Ksl@?xd z)$c6$%J4J2nk}CYh+a>1ykHqTnzqUJuRSx{sW~ixEy^uv?nUGEsY#HmAzsy02$2Zl zZr5A25&X`Q^l;3XQ7O~T@dB#f7XBo}*xpDps;tsGVB4Gq(T$002ovPDHLkV1k;r?F9e; diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 07af04da5c6..6f5546f327c 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -31,9 +31,6 @@ true - - true - true diff --git a/view/frontend/web/js/view/payment/method-renderer.js b/view/frontend/web/js/view/payment/method-renderer.js index 23e43f35da7..8f5233e5b6b 100644 --- a/view/frontend/web/js/view/payment/method-renderer.js +++ b/view/frontend/web/js/view/payment/method-renderer.js @@ -18,7 +18,6 @@ define( {type: 'mollie_methods_bancontact', component: defaultComponent}, {type: 'mollie_methods_banktransfer', component: defaultComponent}, {type: 'mollie_methods_belfius', component: defaultComponent}, - {type: 'mollie_methods_bitcoin', component: defaultComponent}, {type: 'mollie_methods_creditcard', component: defaultComponent}, {type: 'mollie_methods_ideal', component: idealComponent}, {type: 'mollie_methods_kbc', component: kbcComponent}, From 6be67a8095b87cde22cdd1674bfc469c1453969d Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Thu, 2 May 2019 15:58:28 +0200 Subject: [PATCH 05/15] Remove all Bitcoin related configuration --- Setup/UpgradeData.php | 51 ++++++++++++++++++++++++++++++++++++++++--- etc/module.xml | 2 +- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index ceb591fd1b6..9dd7bc10b10 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -6,10 +6,13 @@ namespace Mollie\Payment\Setup; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Storage\WriterInterface; use Magento\Sales\Setup\SalesSetupFactory; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; +use Magento\Store\Model\StoreManagerInterface; /** * Class UpgradeData @@ -18,7 +21,6 @@ */ class UpgradeData implements UpgradeDataInterface { - /** * Sales setup factory * @@ -26,15 +28,31 @@ class UpgradeData implements UpgradeDataInterface */ private $salesSetupFactory; + /** + * @var WriterInterface + */ + private $configWriter; + + /** + * @var StoreManagerInterface + */ + private $storeManager; + /** * UpgradeData constructor. * * @param SalesSetupFactory $salesSetupFactory + * @param WriterInterface $configWriter + * @param StoreManagerInterface $storeManager */ public function __construct( - SalesSetupFactory $salesSetupFactory + SalesSetupFactory $salesSetupFactory, + WriterInterface $configWriter, + StoreManagerInterface $storeManager ) { $this->salesSetupFactory = $salesSetupFactory; + $this->configWriter = $configWriter; + $this->storeManager = $storeManager; } /** @@ -47,10 +65,14 @@ public function upgrade( ) { $setup->startSetup(); - if (version_compare($context->getVersion(), "1.4.0", "<")) { + if (version_compare($context->getVersion(), '1.4.0', '<')) { $this->createMollieShipmentId($setup); } + if (version_compare($context->getVersion(), '1.6.0', '<')) { + $this->removeBitcoinConfiguration(); + } + $setup->endSetup(); } @@ -68,4 +90,27 @@ public function createMollieShipmentId($setup) $options = ['type' => 'varchar', 'visible' => false, 'required' => false]; $salesSetup->addAttribute('shipment', 'mollie_shipment_id', $options); } + + private function removeBitcoinConfiguration() + { + $paths = [ + 'payment/mollie_methods_bitcoin/active', + 'payment/mollie_methods_bitcoin/title', + 'payment/mollie_methods_bitcoin/method', + 'payment/mollie_methods_bitcoin/payment_description', + 'payment/mollie_methods_bitcoin/allowspecific', + 'payment/mollie_methods_bitcoin/specificcountry', + 'payment/mollie_methods_bitcoin/min_order_total', + 'payment/mollie_methods_bitcoin/max_order_total', + 'payment/mollie_methods_bitcoin/sort_order', + ]; + + foreach ($this->storeManager->getStores() as $store) { + foreach ($paths as $path) { + $this->configWriter->delete($path, ScopeConfigInterface::SCOPE_TYPE_DEFAULT); + $this->configWriter->delete($path, 'stores', $store->getId()); + $this->configWriter->delete($path, 'websites', $store->getId()); + } + } + } } diff --git a/etc/module.xml b/etc/module.xml index cfb6c3123ec..ca6c6d1b03b 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,4 +1,4 @@ - + From 850a7902975e0b82ce284e6c178f6341051589a9 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Tue, 7 May 2019 19:55:37 +0200 Subject: [PATCH 06/15] Added test --- .../Order/ProcessAdjustmentFeeTest.php | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Tests/Unit/Service/Order/ProcessAdjustmentFeeTest.php diff --git a/Tests/Unit/Service/Order/ProcessAdjustmentFeeTest.php b/Tests/Unit/Service/Order/ProcessAdjustmentFeeTest.php new file mode 100644 index 00000000000..af4dfa5a01f --- /dev/null +++ b/Tests/Unit/Service/Order/ProcessAdjustmentFeeTest.php @@ -0,0 +1,147 @@ +getMockBuilder(PaymentFactory::class); + $mockBuilder->setMethods(['create']); + $paymentFactory = $mockBuilder->getMock(); + $paymentFactory->method('create')->willReturn($this->createMock(Payment::class)); + + $this->objectManager = new ObjectManager($this); + $this->instance = $this->objectManager->getObject(ProcessAdjustmentFee::class, [ + 'paymentFactory' => $paymentFactory, + 'mollieHelper' => $this->objectManager->getObject(General::class) + ]); + } + + public function testRefundsPositive() + { + $creditmemo = $this->createMock(CreditmemoInterface::class); + $creditmemo->method('getAdjustment')->willReturn(123); + + $mollieApi = $this->buildMollieApiMock(); + + $this->paymentEndpoint->expects($this->once())->method('refund')->with( + $this->isInstanceOf(Payment::class), // $payment + $this->callback(function ($argument) { + $this->assertSame('123.00', $argument['amount']['value']); + return true; + }) // $data + ); + + $this->instance->handle($mollieApi, $this->getOrderMock(), $creditmemo); + } + + public function testRefundsNegative() + { + $creditmemo = $this->createMock(CreditmemoInterface::class); + $creditmemo->method('getAdjustmentNegative')->willReturn(-123); + + $mollieApi = $this->buildMollieApiMock(); + + $this->paymentEndpoint->expects($this->once())->method('refund')->with( + $this->isInstanceOf(Payment::class), // $payment + $this->callback(function ($argument) { + $this->assertSame('123.00', $argument['amount']['value']); + return true; + }) // $data + ); + + $this->instance->handle($mollieApi, $this->getOrderMock(), $creditmemo); + } + + public function doNotRefundInMollieProvider() + { + return [ + [123, null, false], + [null, -123, true], + ]; + } + + /** + * @dataProvider doNotRefundInMollieProvider + */ + public function testDoNotRefundInMollie($getAdjustment, $getAdjustmentNegative, $expected) + { + $creditmemo = $this->createMock(CreditmemoInterface::class); + $creditmemo->method('getAdjustment')->willReturn($getAdjustment); + $creditmemo->method('getAdjustmentNegative')->willReturn($getAdjustmentNegative); + + $mollieApi = $this->buildMollieApiMock(); + + $this->paymentEndpoint->method('refund'); + + $this->instance->handle($mollieApi, $this->getOrderMock(), $creditmemo); + + $this->assertSame($expected, $this->instance->doNotRefundInMollie()); + } + + /** + * @param \PHPUnit_Framework_MockObject_MockObject $mollieOrder + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function buildMollieApiMock() + { + $mollieOrder = $this->createMock(MollieOrder::class); + $mollieOrder->_embedded = new \stdClass(); + + $payment = new \stdClass(); + $payment->id = 123; + $mollieOrder->_embedded->payments = [$payment]; + + $this->paymentEndpoint = $this->createMock(PaymentEndpoint::class); + + $mollieApi = $this->createMock(MollieApiClient::class); + $orderEndpoint = $this->createMock(OrderEndpoint::class); + $orderEndpoint->method('get')->willReturn($mollieOrder); + $mollieApi->orders = $orderEndpoint; + $mollieApi->payments = $this->paymentEndpoint; + + return $mollieApi; + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function getOrderMock(): \PHPUnit_Framework_MockObject_MockObject + { + $order = $this->getMockBuilder(OrderInterface::class) + ->setMethods(['getMollieTransactionId', 'getOrderCurrencyCode']) + ->getMockForAbstractClass(); + $order->method('getOrderCurrencyCode')->willReturn('EUR'); + return $order; + } +} From 329a2d341d5b041c2748dc21ad5aaaf375f273fa Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Wed, 8 May 2019 14:20:28 +0200 Subject: [PATCH 07/15] Added Apple Pay --- Helper/General.php | 1 + Model/Methods/ApplePay.php | 25 +++++ Model/MollieConfigProvider.php | 9 +- README.md | 4 +- etc/adminhtml/methods.xml | 1 + etc/adminhtml/methods/applepay.xml | 92 +++++++++++++++++++ etc/config.xml | 9 ++ etc/payment.xml | 3 + view/frontend/layout/checkout_index_index.xml | 3 + .../web/js/view/payment/method-renderer.js | 11 +++ 10 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 Model/Methods/ApplePay.php create mode 100644 etc/adminhtml/methods/applepay.xml diff --git a/Helper/General.php b/Helper/General.php index d615f9ade28..524f749ce52 100755 --- a/Helper/General.php +++ b/Helper/General.php @@ -614,6 +614,7 @@ public function getAllActiveMethods($storeId) 'mollie_methods_klarnasliceit', 'mollie_methods_giftcard', 'mollie_methods_przelewy24', + 'mollie_methods_applepay', ]; foreach ($methodCodes as $methodCode) { diff --git a/Model/Methods/ApplePay.php b/Model/Methods/ApplePay.php new file mode 100644 index 00000000000..de8406565ed --- /dev/null +++ b/Model/Methods/ApplePay.php @@ -0,0 +1,25 @@ +checkoutSession->getQuote(); $amount = $this->mollieHelper->getOrderAmountByQuote($quote); - $params = ["amount[value]" => $amount['value'], - "amount[currency]" => $amount['currency'], - "resource" => "orders" + $params = [ + 'amount[value]' => $amount['value'], + 'amount[currency]' => $amount['currency'], + 'resource' => 'orders', + 'includeWallets' => 'applepay', ]; $apiMethods = $mollieApi->methods->all($params); diff --git a/README.md b/README.md index 14c00f33234..6a8b07fdd27 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,9 @@ Mollie requires no minimum costs, no fixed contracts, no hidden costs. At Mollie - Klarna -- Giftcards +- Giftcards + +- Apple Pay ## Configuration, FAQ and Troubleshooting ## If you experience problems with the extension installation, setup or whenever you need more information about how to setup the Mollie Payment extension in Magento 2.x, please see our [WIKI Page](https://github.com/mollie/magento2/wiki) or send an e-mail to [info@mollie.com](mailto:info@mollie.com) with an exact description of the problem. diff --git a/etc/adminhtml/methods.xml b/etc/adminhtml/methods.xml index 3474226f9ef..64293ec2635 100644 --- a/etc/adminhtml/methods.xml +++ b/etc/adminhtml/methods.xml @@ -24,4 +24,5 @@ + diff --git a/etc/adminhtml/methods/applepay.xml b/etc/adminhtml/methods/applepay.xml new file mode 100644 index 00000000000..a59839411eb --- /dev/null +++ b/etc/adminhtml/methods/applepay.xml @@ -0,0 +1,92 @@ + + + + + + + Magento\Config\Model\Config\Source\Yesno + payment/mollie_methods_applepay/active + Please note: This payment method is only visible when the users device has Apple Pay enabled.]]> + + + + payment/mollie_methods_applepay/title + + 1 + + + + + Mollie\Payment\Model\Adminhtml\Source\Method + payment/mollie_methods_applepay/method + + 1 + + Payment API
Use the Payment API Platform for the transactions.

+ Order API
Use the new Order API Platform and get additional insights in the orders. + Read more.]]>
+
+ + + payment/mollie_methods_applepay/payment_description +
+ {ordernumber}: The order number for this transaction
+ {storename}: The name of the store

+ (Note: This only works when the method is set to Payments API) + ]]>
+ + payment + 1 + +
+ + + Magento\Payment\Model\Config\Source\Allspecificcountries + payment/mollie_methods_applepay/allowspecific + + 1 + + + + + Magento\Directory\Model\Config\Source\Country + 1 + payment/mollie_methods_applepay/specificcountry + + 1 + + + + + payment/mollie_methods_applepay/min_order_total + + 1 + + + + + payment/mollie_methods_applepay/max_order_total + + 1 + + + + + validate-number + payment/mollie_methods_applepay/sort_order + + 1 + + +
+
\ No newline at end of file diff --git a/etc/config.xml b/etc/config.xml index 68fd3380305..00608f4af43 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -186,6 +186,15 @@ 0 + + 0 + Mollie\Payment\Model\Methods\ApplePay + Apple Pay + {ordernumber} + order + 0 + + diff --git a/etc/payment.xml b/etc/payment.xml index 50f82d7cbd7..e395b090309 100644 --- a/etc/payment.xml +++ b/etc/payment.xml @@ -55,5 +55,8 @@ 0 + + 0 + diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 07af04da5c6..0aec70a4fa4 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -76,6 +76,9 @@ true + + true + diff --git a/view/frontend/web/js/view/payment/method-renderer.js b/view/frontend/web/js/view/payment/method-renderer.js index 23e43f35da7..33e11a4ec0d 100644 --- a/view/frontend/web/js/view/payment/method-renderer.js +++ b/view/frontend/web/js/view/payment/method-renderer.js @@ -33,6 +33,17 @@ define( {type: 'mollie_methods_giftcard', component: giftcardComponent}, {type: 'mollie_methods_przelewy24', component: defaultComponent} ]; + + /** + * Only add Apple Pay if the current client supports Apple Pay. + */ + if (window.ApplePaySession && window.ApplePaySession.canMakePayments()) { + methods.push({ + type: 'mollie_methods_applepay', + component: defaultComponent + }); + } + $.each(methods, function (k, method) { if (window.checkoutConfig.payment.isActive[method['type']]) { rendererList.push(method); From 3502f86dda806560d769fe5554bc3f934c2bbdbe Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Wed, 8 May 2019 16:00:04 +0200 Subject: [PATCH 08/15] Added a test for the ApplePay model --- .../Unit/Model/Methods/AbstractMethodTest.php | 100 ++++++++++++++++++ Tests/Unit/Model/Methods/ApplePayTest.php | 32 ++++++ 2 files changed, 132 insertions(+) create mode 100644 Tests/Unit/Model/Methods/AbstractMethodTest.php create mode 100644 Tests/Unit/Model/Methods/ApplePayTest.php diff --git a/Tests/Unit/Model/Methods/AbstractMethodTest.php b/Tests/Unit/Model/Methods/AbstractMethodTest.php new file mode 100644 index 00000000000..62335ec40bf --- /dev/null +++ b/Tests/Unit/Model/Methods/AbstractMethodTest.php @@ -0,0 +1,100 @@ +objectManager = new ObjectManager($this); + } + + public function testHasAnExistingModel() + { + $this->assertTrue(class_exists($this->instance), 'We expect that the class ' . $this->instance . ' exists'); + } + + public function testHasTheCorrectCode() + { + /** + * The parent constructor of this class calls the ObjectManager, which isn't available in unit tests. So skip + * the constructor. + */ + $reflection = new \ReflectionClass($this->instance); + $instance = $reflection->newInstanceWithoutConstructor(); + + $this->assertEquals($this->code, $instance->getCode()); + } + + public function testIsListedAsActiveMethod() + { + $scopeConfig = $this->createMock(ScopeConfigInterface::class); + $scopeConfig->method('getValue')->willReturn(1); + + $context = $this->objectManager->getObject(Context::class, [ + 'scopeConfig' => $scopeConfig, + ]); + + /** @var MollieHelper $helper */ + $helper = $this->objectManager->getObject(MollieHelper::class, [ + 'context' => $context, + ]); + + $methods = $helper->getAllActiveMethods(1); + + $this->assertArrayHasKey($this->code, $methods); + } + + public function testThatTheMethodIsActive() + { + /** @var Method $method */ + $method = $this->objectManager->getObject(Method::class); + $method->id = 'applepay'; + $method->image = new \stdClass; + $method->image->size2x = 'http://www.example.com/image.png'; + + /** @var MethodCollection $methodCollection */ + $methodCollection = $this->objectManager->getObject(MethodCollection::class); + $methodCollection[] = $method; + + $mollieApiClient = $this->createMock(MollieApiClient::class); + $mollieApiClient->methods = $this->createMock(MethodEndpoint::class); + $mollieApiClient->methods->method('all')->willReturn($methodCollection); + + /** @var MollieConfigProvider $instance */ + $instance = $this->objectManager->getObject(MollieConfigProvider::class); + $methods = $instance->getActiveMethods($mollieApiClient); + + $this->assertArrayHasKey($this->code, $methods); + } +} \ No newline at end of file diff --git a/Tests/Unit/Model/Methods/ApplePayTest.php b/Tests/Unit/Model/Methods/ApplePayTest.php new file mode 100644 index 00000000000..27398b5129c --- /dev/null +++ b/Tests/Unit/Model/Methods/ApplePayTest.php @@ -0,0 +1,32 @@ +createMock(MollieApiClient::class); + $mollieApiClient->methods = $this->createMock(MethodEndpoint::class); + + $mollieApiClient->methods->expects($this->once())->method('all')->with($this->callback(function ($arguments) { + $this->assertArrayHasKey('includeWallets', $arguments); + $this->assertEquals('applepay', $arguments['includeWallets']); + + return true; + })); + + /** @var MollieConfigProvider $instance */ + $instance = $this->objectManager->getObject(MollieConfigProvider::class); + $instance->getActiveMethods($mollieApiClient); + } +} From 3290871453cecf16c12771f1fc9c6f66f8920a8e Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Wed, 8 May 2019 20:36:29 +0200 Subject: [PATCH 09/15] Added a few basic tests for all payment methods --- Tests/Unit/Model/Methods/AbstractMethodTest.php | 15 ++++++++++----- Tests/Unit/Model/Methods/ApplePayTest.php | 2 +- Tests/Unit/Model/Methods/BancontactTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/BanktransferTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/BelfiusTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/CreditcardTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/EpsTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/GiftcardTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/GiropayTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/IdealTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/InghomepayTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/KbcTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/KlarnapaylaterTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/KlarnasliceitTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/PaymentlinkTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/PaypalTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/PaysafecardTest.php | 12 ++++++++++++ Tests/Unit/Model/Methods/Przelewy24Test.php | 12 ++++++++++++ Tests/Unit/Model/Methods/SofortTest.php | 12 ++++++++++++ 19 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 Tests/Unit/Model/Methods/BancontactTest.php create mode 100644 Tests/Unit/Model/Methods/BanktransferTest.php create mode 100644 Tests/Unit/Model/Methods/BelfiusTest.php create mode 100644 Tests/Unit/Model/Methods/CreditcardTest.php create mode 100644 Tests/Unit/Model/Methods/EpsTest.php create mode 100644 Tests/Unit/Model/Methods/GiftcardTest.php create mode 100644 Tests/Unit/Model/Methods/GiropayTest.php create mode 100644 Tests/Unit/Model/Methods/IdealTest.php create mode 100644 Tests/Unit/Model/Methods/InghomepayTest.php create mode 100644 Tests/Unit/Model/Methods/KbcTest.php create mode 100644 Tests/Unit/Model/Methods/KlarnapaylaterTest.php create mode 100644 Tests/Unit/Model/Methods/KlarnasliceitTest.php create mode 100644 Tests/Unit/Model/Methods/PaymentlinkTest.php create mode 100644 Tests/Unit/Model/Methods/PaypalTest.php create mode 100644 Tests/Unit/Model/Methods/PaysafecardTest.php create mode 100644 Tests/Unit/Model/Methods/Przelewy24Test.php create mode 100644 Tests/Unit/Model/Methods/SofortTest.php diff --git a/Tests/Unit/Model/Methods/AbstractMethodTest.php b/Tests/Unit/Model/Methods/AbstractMethodTest.php index 62335ec40bf..05473765f0c 100644 --- a/Tests/Unit/Model/Methods/AbstractMethodTest.php +++ b/Tests/Unit/Model/Methods/AbstractMethodTest.php @@ -7,7 +7,6 @@ use Mollie\Api\Resources\Method; use Mollie\Api\Endpoints\MethodEndpoint; use Mollie\Api\Resources\MethodCollection; -use Mollie\Payment\Model\Methods\ApplePay; use Mollie\Payment\Model\MollieConfigProvider; use Mollie\Payment\Helper\General as MollieHelper; use Magento\Framework\App\Config\ScopeConfigInterface; @@ -53,7 +52,7 @@ public function testHasTheCorrectCode() $reflection = new \ReflectionClass($this->instance); $instance = $reflection->newInstanceWithoutConstructor(); - $this->assertEquals($this->code, $instance->getCode()); + $this->assertEquals('mollie_methods_' . $this->code, $instance->getCode()); } public function testIsListedAsActiveMethod() @@ -72,14 +71,19 @@ public function testIsListedAsActiveMethod() $methods = $helper->getAllActiveMethods(1); - $this->assertArrayHasKey($this->code, $methods); + if ($this->code == 'paymentlink') { + $this->assertArrayNotHasKey('mollie_methods_' . $this->code, $methods); + return; + } + + $this->assertArrayHasKey('mollie_methods_' . $this->code, $methods); } public function testThatTheMethodIsActive() { /** @var Method $method */ $method = $this->objectManager->getObject(Method::class); - $method->id = 'applepay'; + $method->id = $this->code; $method->image = new \stdClass; $method->image->size2x = 'http://www.example.com/image.png'; @@ -95,6 +99,7 @@ public function testThatTheMethodIsActive() $instance = $this->objectManager->getObject(MollieConfigProvider::class); $methods = $instance->getActiveMethods($mollieApiClient); - $this->assertArrayHasKey($this->code, $methods); + $this->assertArrayHasKey('mollie_methods_' . $this->code, $methods); + $this->assertEquals($method->image->size2x, $methods['mollie_methods_' . $this->code]['image']); } } \ No newline at end of file diff --git a/Tests/Unit/Model/Methods/ApplePayTest.php b/Tests/Unit/Model/Methods/ApplePayTest.php index 27398b5129c..be490ea1227 100644 --- a/Tests/Unit/Model/Methods/ApplePayTest.php +++ b/Tests/Unit/Model/Methods/ApplePayTest.php @@ -11,7 +11,7 @@ class ApplePayTest extends AbstractMethodTest { protected $instance = ApplePay::class; - protected $code = 'mollie_methods_applepay'; + protected $code = 'applepay'; public function testTheIncludeWalletsParameterIsUsed() { diff --git a/Tests/Unit/Model/Methods/BancontactTest.php b/Tests/Unit/Model/Methods/BancontactTest.php new file mode 100644 index 00000000000..2bc03c7f25e --- /dev/null +++ b/Tests/Unit/Model/Methods/BancontactTest.php @@ -0,0 +1,12 @@ + Date: Fri, 17 May 2019 20:29:56 +0200 Subject: [PATCH 10/15] Updated api method, improved text --- Model/MollieConfigProvider.php | 2 +- etc/adminhtml/methods/applepay.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/MollieConfigProvider.php b/Model/MollieConfigProvider.php index 691cfa4c30f..1fc4796652c 100644 --- a/Model/MollieConfigProvider.php +++ b/Model/MollieConfigProvider.php @@ -214,7 +214,7 @@ public function getActiveMethods($mollieApi) 'resource' => 'orders', 'includeWallets' => 'applepay', ]; - $apiMethods = $mollieApi->methods->all($params); + $apiMethods = $mollieApi->methods->allActive($params); foreach ($apiMethods as $method) { $methodId = 'mollie_methods_' . $method->id; diff --git a/etc/adminhtml/methods/applepay.xml b/etc/adminhtml/methods/applepay.xml index a59839411eb..bb7753bb0a0 100644 --- a/etc/adminhtml/methods/applepay.xml +++ b/etc/adminhtml/methods/applepay.xml @@ -9,7 +9,7 @@ Magento\Config\Model\Config\Source\Yesno payment/mollie_methods_applepay/active - Please note: This payment method is only visible when the users device has Apple Pay enabled.]]> + Please note: This payment method is only visible when the device of the user Apple Pay has enabled.]]>
From ac5c5dec53e8c975a7dea86a9d997f9be00b6013 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Wed, 22 May 2019 14:01:44 +0200 Subject: [PATCH 11/15] Include Apple Pay in the self test --- Helper/Tests.php | 11 +++++++++-- Model/Mollie.php | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Helper/Tests.php b/Helper/Tests.php index c8533126908..4e9747ef779 100644 --- a/Helper/Tests.php +++ b/Helper/Tests.php @@ -66,7 +66,10 @@ public function getMethods($testKey = null, $liveKey = null) try { $availableMethods = []; $mollieApi = $this->mollieModel->loadMollieApi($testKey); - $methods = $mollieApi->methods->all(["resource" => "orders"]); + $methods = $mollieApi->methods->all([ + 'resource' => 'orders', + 'includeWallets' => 'applepay', + ]); foreach ($methods as $apiMethod) { $availableMethods[] = ucfirst($apiMethod->id); @@ -96,7 +99,11 @@ public function getMethods($testKey = null, $liveKey = null) try { $availableMethods = []; $mollieApi = $this->mollieModel->loadMollieApi($liveKey); - $methods = $mollieApi->methods->all(["resource" => "orders"]); + $methods = $mollieApi->methods->all([ + 'resource' => 'orders', + 'includeWallets' => 'applepay', + ]); + foreach ($methods as $apiMethod) { $availableMethods[] = ucfirst($apiMethod->id); } diff --git a/Model/Mollie.php b/Model/Mollie.php index 38b1a6b3205..e3762cb750f 100644 --- a/Model/Mollie.php +++ b/Model/Mollie.php @@ -530,6 +530,9 @@ public function getPaymentMethods($storeId) $mollieApi = $this->loadMollieApi($apiKey); - return $mollieApi->methods->all(["resource" => "orders"]); + return $mollieApi->methods->all([ + 'resource' => 'orders', + 'includeWallets' => 'applepay', + ]); } } From d1895ba6cc095b74c5cd74a4528121457a76faa7 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Fri, 24 May 2019 19:21:00 +0200 Subject: [PATCH 12/15] Removed the window.ApplePaySession.canMakePayments call as it causes errors --- view/frontend/web/js/view/payment/method-renderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/frontend/web/js/view/payment/method-renderer.js b/view/frontend/web/js/view/payment/method-renderer.js index 33e11a4ec0d..70a02f854ab 100644 --- a/view/frontend/web/js/view/payment/method-renderer.js +++ b/view/frontend/web/js/view/payment/method-renderer.js @@ -37,7 +37,7 @@ define( /** * Only add Apple Pay if the current client supports Apple Pay. */ - if (window.ApplePaySession && window.ApplePaySession.canMakePayments()) { + if (window.ApplePaySession) { methods.push({ type: 'mollie_methods_applepay', component: defaultComponent From 0a227919edbaeb9b8d9e31f28636b11614d33fbe Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 27 May 2019 14:46:25 +0200 Subject: [PATCH 13/15] Minor fixes --- Model/MollieConfigProvider.php | 2 +- etc/adminhtml/methods/applepay.xml | 2 +- i18n/en_US.csv | 3 ++- view/adminhtml/web/images/applepay.png | Bin 0 -> 1951 bytes .../web/js/view/payment/method-renderer.js | 12 +++++++++++- 5 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 view/adminhtml/web/images/applepay.png diff --git a/Model/MollieConfigProvider.php b/Model/MollieConfigProvider.php index 1fc4796652c..691cfa4c30f 100644 --- a/Model/MollieConfigProvider.php +++ b/Model/MollieConfigProvider.php @@ -214,7 +214,7 @@ public function getActiveMethods($mollieApi) 'resource' => 'orders', 'includeWallets' => 'applepay', ]; - $apiMethods = $mollieApi->methods->allActive($params); + $apiMethods = $mollieApi->methods->all($params); foreach ($apiMethods as $method) { $methodId = 'mollie_methods_' . $method->id; diff --git a/etc/adminhtml/methods/applepay.xml b/etc/adminhtml/methods/applepay.xml index bb7753bb0a0..1a0837500f0 100644 --- a/etc/adminhtml/methods/applepay.xml +++ b/etc/adminhtml/methods/applepay.xml @@ -9,7 +9,7 @@ Magento\Config\Model\Config\Source\Yesno payment/mollie_methods_applepay/active - Please note: This payment method is only visible when the device of the user Apple Pay has enabled.]]> + Please note: This payment method is only visible when the device of the user Apple Pay has enabled and the checkout is served over HTTPS.]]> diff --git a/i18n/en_US.csv b/i18n/en_US.csv index a511dd9edb1..2ffeac73443 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -81,4 +81,5 @@ "Language Payment Page","Language Payment Page" "Let Mollie automatically detect the language or force the language from the store view.","Let Mollie automatically detect the language or force a language for your store view." "Payment of type %1 has been rejected. Decision is based on order and outcome of risk assessment.","Payment of type %1 has been rejected. Decision is based on order and outcome of risk assessment." -"Warning: we recommend to use a unique payment status for pending Banktransfer payments","Warning: we recommend to use a unique payment status for pending Banktransfer payments" \ No newline at end of file +"Warning: we recommend to use a unique payment status for pending Banktransfer payments","Warning: we recommend to use a unique payment status for pending Banktransfer payments" +"Please note: This payment method is only visible when the device of the user Apple Pay has enabled and the checkout is served over HTTPS.","Please note: This payment method is only visible when the device of the user Apple Pay has enabled and the checkout is served over HTTPS." \ No newline at end of file diff --git a/view/adminhtml/web/images/applepay.png b/view/adminhtml/web/images/applepay.png new file mode 100644 index 0000000000000000000000000000000000000000..d2a13238216791f8ca4ba8f88efaaff003acf67a GIT binary patch literal 1951 zcmbVNeNfY87%#{akq@VwPIMR}awwMcyG^BK*jBCDT5G4ZI!b7R)RLy8K?*v?a9oE> zrGnodxFUFdp@N8q8%%|K>{i5JMoAzEU1PF{z`pbKAYd|z zz!h8tLt&MmDW(Nk1iCCssWD`k4X_c669ch!A!PtVNd&NCsTP~iE&^ZJ6;gYz7y^M8 zDx_HizH~~fPyrI0Kml$Hk8WUcxBwrHVe;4<7@iHV7)$}g5I{^eoyik&7(x~ccy)mk z8(~Zqs-^Q@aZx7`m_m|PAp~V)WW;2!V{l>(#DrlOVz3|BAPJ zsLeo_tfUFI0A7no5}ry==60sQ2VQv$}{R+$eSFBJ%pa_W*8XQj@?gCW`PU5x{+zLn} z-m1eulmaoBEMDPEZ=qhsEky~_I@CCiz%k%OriG?Ac=6vd@DgwQzZrxmryy^;{G)w_ zMO06Ex37nRI=mhy)I!Y=K@H2O+|wb{41Ot>#%t_9wC`FKbtodKsMv3c?2i_MW&Sr)+LZDWs)x9?W7`lmn<)?1C3wSU*sW@_6(Q?|_j*gDdQBh2jAJEy^IV)I|G+ z|LD>|5tE5)zd_weDC2M-=hs4p*%bm|W|PTi=itW+H} z?>KNE{P>Y07d)O!ae`joR97cH);D?b(iz4XuQPUBXs&Mvd zwR+oig-)ltQFrFdCk}^0z+zo&0ymk>X6@?LpS5dy_wL;32oDdRf*{K% zs@P+v1O^87SC^KS-tOxQaXOu?=5g!Sum3bZ-Ff4Cifb>m>1aJy9nOOlf#4=V%jo!{nkUa%2XYvH0u5X`-1>O8V{ zs;<4Op!@c!MHv}Cv>0H*6^C-3aanYW|ZrP8e5gJA?u1k{nS}yLzx5fb9`vr WO`ZTWZeyMImnoMir4@4%bN>PnehoDM literal 0 HcmV?d00001 diff --git a/view/frontend/web/js/view/payment/method-renderer.js b/view/frontend/web/js/view/payment/method-renderer.js index 70a02f854ab..276a4b68937 100644 --- a/view/frontend/web/js/view/payment/method-renderer.js +++ b/view/frontend/web/js/view/payment/method-renderer.js @@ -34,10 +34,20 @@ define( {type: 'mollie_methods_przelewy24', component: defaultComponent} ]; + function canUseApplePay() + { + try { + return window.ApplePaySession && window.ApplePaySession.canMakePayments(); + } catch (error) { + console.warn('Error when trying to check Apple Pay:', error); + return false; + } + } + /** * Only add Apple Pay if the current client supports Apple Pay. */ - if (window.ApplePaySession) { + if (canUseApplePay()) { methods.push({ type: 'mollie_methods_applepay', component: defaultComponent From 8fce852126966ebaa24bb66e6eac7c2edc7e9117 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 27 May 2019 15:04:27 +0200 Subject: [PATCH 14/15] Comment improvement --- etc/adminhtml/methods/applepay.xml | 2 +- i18n/en_US.csv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/adminhtml/methods/applepay.xml b/etc/adminhtml/methods/applepay.xml index 1a0837500f0..375c83ba476 100644 --- a/etc/adminhtml/methods/applepay.xml +++ b/etc/adminhtml/methods/applepay.xml @@ -9,7 +9,7 @@ Magento\Config\Model\Config\Source\Yesno payment/mollie_methods_applepay/active - Please note: This payment method is only visible when the device of the user Apple Pay has enabled and the checkout is served over HTTPS.]]> + Please note: This payment method is only visible when the device of the user Apple Pay has enabled and the checkout is served over HTTPS.]]> diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 2ffeac73443..ab5d449a231 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -82,4 +82,4 @@ "Let Mollie automatically detect the language or force the language from the store view.","Let Mollie automatically detect the language or force a language for your store view." "Payment of type %1 has been rejected. Decision is based on order and outcome of risk assessment.","Payment of type %1 has been rejected. Decision is based on order and outcome of risk assessment." "Warning: we recommend to use a unique payment status for pending Banktransfer payments","Warning: we recommend to use a unique payment status for pending Banktransfer payments" -"Please note: This payment method is only visible when the device of the user Apple Pay has enabled and the checkout is served over HTTPS.","Please note: This payment method is only visible when the device of the user Apple Pay has enabled and the checkout is served over HTTPS." \ No newline at end of file +"Please note: This payment method is only visible when the device of the user Apple Pay has enabled and the checkout is served over HTTPS.","Please note: This payment method is only visible when the device of the user Apple Pay has enabled and the checkout is served over HTTPS." \ No newline at end of file From 7d3ace13b466c8d2b8e624c95b56b267038c2cf3 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Tue, 28 May 2019 10:01:18 +0200 Subject: [PATCH 15/15] PHP 5.6 fix --- Tests/Unit/Service/Order/ProcessAdjustmentFeeTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/Unit/Service/Order/ProcessAdjustmentFeeTest.php b/Tests/Unit/Service/Order/ProcessAdjustmentFeeTest.php index af4dfa5a01f..9e69836b080 100644 --- a/Tests/Unit/Service/Order/ProcessAdjustmentFeeTest.php +++ b/Tests/Unit/Service/Order/ProcessAdjustmentFeeTest.php @@ -136,12 +136,13 @@ private function buildMollieApiMock() /** * @return \PHPUnit_Framework_MockObject_MockObject */ - private function getOrderMock(): \PHPUnit_Framework_MockObject_MockObject + private function getOrderMock() { $order = $this->getMockBuilder(OrderInterface::class) ->setMethods(['getMollieTransactionId', 'getOrderCurrencyCode']) ->getMockForAbstractClass(); $order->method('getOrderCurrencyCode')->willReturn('EUR'); + return $order; } }