From 1dc5622431a14df8d4ccc94c8b7b0fa3e68a19df Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Mon, 5 Oct 2020 19:31:35 +0700 Subject: [PATCH 1/3] Use custom external id --- .../Controller/Checkout/Notification.m22.php | 5 ++--- .../Controller/Checkout/Notification.m23.php | 5 ++--- Xendit/M2Invoice/Helper/Data.php | 7 +++++-- Xendit/M2Invoice/etc/adminhtml/system.xml | 21 ++++++++++++++++++- Xendit/M2Invoice/etc/config.xml | 1 + 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/Notification.m22.php b/Xendit/M2Invoice/Controller/Checkout/Notification.m22.php index 2f6b15d2..10ca647f 100755 --- a/Xendit/M2Invoice/Controller/Checkout/Notification.m22.php +++ b/Xendit/M2Invoice/Controller/Checkout/Notification.m22.php @@ -151,9 +151,8 @@ public function handleEwalletCallback($callbackPayload) { $failureCode = $callbackPayload['failure_code']; } - $extIdPrefix = $this->dataHelper->getExternalIdPrefix(); - // Trimmed external ID from prefix is Magento's order ID - $orderId = ltrim($callbackPayload['external_id'], $extIdPrefix); + $temp = explode('-', $callbackPayload['external_id']); + $orderId = end($temp); $order = $this->getOrderById($orderId); return $this->checkOrder($order, true, $callbackPayload, null, $orderId); diff --git a/Xendit/M2Invoice/Controller/Checkout/Notification.m23.php b/Xendit/M2Invoice/Controller/Checkout/Notification.m23.php index 72fec658..7f98237f 100755 --- a/Xendit/M2Invoice/Controller/Checkout/Notification.m23.php +++ b/Xendit/M2Invoice/Controller/Checkout/Notification.m23.php @@ -162,9 +162,8 @@ public function handleEwalletCallback($callbackPayload) { $failureCode = $callbackPayload['failure_code']; } - $extIdPrefix = $this->dataHelper->getExternalIdPrefix(); - // Trimmed external ID from prefix is Magento's order ID - $orderId = ltrim($callbackPayload['external_id'], $extIdPrefix); + $temp = explode('-', $callbackPayload['external_id']); + $orderId = end($temp); $order = $this->getOrderById($orderId); return $this->checkOrder($order, true, $callbackPayload, null, $orderId); diff --git a/Xendit/M2Invoice/Helper/Data.php b/Xendit/M2Invoice/Helper/Data.php index 91b3a2e1..0a93a2fe 100644 --- a/Xendit/M2Invoice/Helper/Data.php +++ b/Xendit/M2Invoice/Helper/Data.php @@ -117,9 +117,12 @@ public function getExternalId($orderId, $duplicate = false) public function getExternalIdPrefix() { - $storeName = substr(preg_replace("/[^a-z0-9]/mi", "", $this->getStoreManager()->getStore()->getName()), 0, 20); + return $this->m2Invoice->getConfigData('external_id_prefix') . "-" . $this->getStoreName(); + } - return "magento-xendit-$storeName"; + public function getStoreName() + { + return substr(preg_replace("/[^a-z0-9]/mi", "", $this->getStoreManager()->getStore()->getName()), 0, 20); } public function getApiKey() diff --git a/Xendit/M2Invoice/etc/adminhtml/system.xml b/Xendit/M2Invoice/etc/adminhtml/system.xml index 60ca92dc..ce326f38 100644 --- a/Xendit/M2Invoice/etc/adminhtml/system.xml +++ b/Xendit/M2Invoice/etc/adminhtml/system.xml @@ -103,6 +103,17 @@ shouldEnableSpecificMethod(); specificSelection.prop('size', 6); + var externalIdPrefix = jQuery("input[id*='m2invoice_external_id_prefix']"); + jQuery(externalIdPrefix).attr("placeholder", "magento-xendit"); + jQuery(externalIdPrefix).attr("maxlength", 50); + + var defaultText = "Format: {Prefix}-{Store Name}-{Order ID}
Example: "+externalIdPrefix.val()+"-mystore-245"; + externalIdPrefix.siblings('.note').children()[0].innerHTML = defaultText; + externalIdPrefix.change(function () { + var newText = "Format: {Prefix}-{Store Name}-{Order ID}
Example: "+externalIdPrefix.val()+"-mystore-245"; + externalIdPrefix.siblings('.note').children()[0].innerHTML = newText; + }); + jQuery("textarea[id*='m2invoice_card_installment_description']").attr("placeholder", "Bayar pesanan dengan cicilan kartu kredit anda melalui Xendit.\nBank yang tersedia: BCA, BRI"); if ( !jQuery("textarea[id*='m2invoice_card_installment_description']").val() ) { @@ -176,7 +187,15 @@ Xendit\M2Invoice\Model\Adminhtml\Source\ChosenMethod 1 - + + + + + Example: magento-xendit-mystore-245]]> + + required-entry + + Send Xendit payment email notification to end customer when they checkout using bank transfer or retail outlet diff --git a/Xendit/M2Invoice/etc/config.xml b/Xendit/M2Invoice/etc/config.xml index eea25de0..8f8622b7 100644 --- a/Xendit/M2Invoice/etc/config.xml +++ b/Xendit/M2Invoice/etc/config.xml @@ -20,6 +20,7 @@ form all + magento-xendit 1 From c08ddf8164192e28d5f86aea383d8b9f5846dfc7 Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Tue, 6 Oct 2020 08:35:04 +0700 Subject: [PATCH 2/3] update version & changelog --- CHANGELOG.md | 6 ++++++ README.md | 7 +++++-- Xendit/M2Invoice/Helper/ApiRequest.php | 2 +- Xendit/M2Invoice/composer.json | 2 +- Xendit/M2Invoice/etc/module.xml | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbbd3893..8a4a57cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## 2.3.0 (2020-10-06) + +Features: + +- Enable custom external ID + ## 2.2.2 (2020-10-01) Bugfix: diff --git a/README.md b/README.md index 03a9f9b2..2979181d 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,15 @@ To activate this feature, you need to follow this additional steps: ## Supported Payment Method - Credit and Debit Card -- Mandiri VA -- BNI VA - BCA VA +- BNI VA - BRI VA +- Mandiri VA - Permata VA - Alfamart +- OVO +- Credit Card Subscription +- Credit Card Installment ## Refund Support Since v1.3.0, online refund (full and partial) is supported for payment through credit and debit card channel. diff --git a/Xendit/M2Invoice/Helper/ApiRequest.php b/Xendit/M2Invoice/Helper/ApiRequest.php index f39ddcd3..6c3c014b 100644 --- a/Xendit/M2Invoice/Helper/ApiRequest.php +++ b/Xendit/M2Invoice/Helper/ApiRequest.php @@ -85,7 +85,7 @@ private function getHeaders($isPublicRequest, $preferredMethod = null, $customHe 'Content-Type' => 'application/json', 'x-plugin-name' => 'MAGENTO2', 'user-agent' => 'Magento 2 Module', - 'x-plugin-version' => '2.2.2' + 'x-plugin-version' => '2.3.0' ]; if ($preferredMethod !== null) { diff --git a/Xendit/M2Invoice/composer.json b/Xendit/M2Invoice/composer.json index bbd8900d..dcaa3ae0 100644 --- a/Xendit/M2Invoice/composer.json +++ b/Xendit/M2Invoice/composer.json @@ -2,7 +2,7 @@ "name": "xendit/m2invoice", "description": "Xendit Payment Gateway Module", "type": "magento2-module", - "version": "2.2.2", + "version": "2.3.0", "license": [ "GPL-3.0" ], diff --git a/Xendit/M2Invoice/etc/module.xml b/Xendit/M2Invoice/etc/module.xml index 713d44fa..30f53ffc 100644 --- a/Xendit/M2Invoice/etc/module.xml +++ b/Xendit/M2Invoice/etc/module.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file From c57c82e1aaea83d26f8a938dc8975f06753ec853 Mon Sep 17 00:00:00 2001 From: Aulia Hakiem Date: Tue, 6 Oct 2020 14:32:29 +0700 Subject: [PATCH 3/3] fix redirect making order pending again --- .../Controller/Checkout/CCMultishipping.php | 11 +++++++++++ .../Controller/Checkout/InvoiceMultishipping.php | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php index 30b5d9db..b12d0b9f 100644 --- a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php +++ b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php @@ -21,6 +21,7 @@ public function execute() $transactionAmount = 0; $tokenId = ''; + $orderProcessed = false; $orders = []; if ($method === 'cc_subscription' && !$customerSession->isLoggedIn()) { @@ -33,6 +34,12 @@ public function execute() $order = $this->getOrderFactory()->create(); $order ->load($value); + $orderState = $order->getState(); + if ($orderState === Order::STATE_PROCESSING && !$order->canInvoice()) { + $orderProcessed = true; + continue; + } + $order ->setState(Order::STATE_PENDING_PAYMENT) ->setStatus(Order::STATE_PENDING_PAYMENT) ->addStatusHistoryComment("Pending Xendit payment."); @@ -52,6 +59,10 @@ public function execute() $transactionAmount += (int)$order->getTotalDue(); } + if ($orderProcessed) { + return $this->_redirect('multishipping/checkout/success'); + } + if ($method === 'cc') { $requestData = array( 'token_id' => $tokenId, diff --git a/Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php index 7bb791ed..c167cb18 100644 --- a/Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php +++ b/Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php @@ -16,12 +16,19 @@ public function execute() $orderIds = explode("-", $rawOrderIds); $transactionAmount = 0; - - $orders = []; + $orderProcessed = false; + $orders = []; + foreach ($orderIds as $key => $value) { $order = $this->getOrderFactory()->create(); $order->load($value); + $orderState = $order->getState(); + if ($orderState === Order::STATE_PROCESSING && !$order->canInvoice()) { + $orderProcessed = true; + continue; + } + $order->setState(Order::STATE_PENDING_PAYMENT) ->setStatus(Order::STATE_PENDING_PAYMENT) ->addStatusHistoryComment("Pending Xendit payment."); @@ -34,6 +41,10 @@ public function execute() $billingEmail = $order->getCustomerEmail(); } + if ($orderProcessed) { + return $this->_redirect('multishipping/checkout/success'); + } + $preferredMethod = $this->getRequest()->getParam('preferred_method'); $requestData = [ 'success_redirect_url' => $this->getDataHelper()->getSuccessUrl(true),