From 7bec3ebf8363d875de87e8ed9c5ca099ab12d2d1 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 10 Jan 2023 11:17:56 +0700 Subject: [PATCH 1/2] add BSS VA --- CHANGELOG.md | 4 + Controller/Checkout/AbstractAction.php | 11 +-- Helper/Data.php | 7 +- Model/Adminhtml/Source/ChosenMethod.php | 1 + Model/Payment/BSSVA.php | 27 +++++++ Model/Ui/ConfigProvider.php | 11 ++- composer.json | 2 +- etc/adminhtml/system.xml | 1 + etc/adminhtml/virtual_account/bssva.xml | 29 +++++++ etc/config.xml | 14 ++++ etc/module.xml | 2 +- etc/payment.xml | 3 + .../layout/multishipping_checkout_billing.xml | 1 + .../templates/multishipping/bssva.phtml | 34 ++++++++ view/frontend/web/images/methods/bssva.svg | 1 + .../web/js/view/payment/method-renderer.js | 4 + .../js/view/payment/method-renderer/bssva.js | 78 +++++++++++++++++++ .../method-renderer/multishipping/bssva.js | 21 +++++ 18 files changed, 233 insertions(+), 18 deletions(-) create mode 100644 Model/Payment/BSSVA.php create mode 100644 etc/adminhtml/virtual_account/bssva.xml create mode 100644 view/frontend/templates/multishipping/bssva.phtml create mode 100644 view/frontend/web/images/methods/bssva.svg create mode 100644 view/frontend/web/js/view/payment/method-renderer/bssva.js create mode 100644 view/frontend/web/js/view/payment/method-renderer/multishipping/bssva.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 14efd131..3a9dfa04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 10.0.0 (2022-01-10) +Features: +- Add new IDR payment: BSS VA + ## 9.0.1 (2022-12-16) Features: - Implement Xendit metric diff --git a/Controller/Checkout/AbstractAction.php b/Controller/Checkout/AbstractAction.php index 530f0ccf..2a2780ff 100644 --- a/Controller/Checkout/AbstractAction.php +++ b/Controller/Checkout/AbstractAction.php @@ -512,18 +512,9 @@ protected function orderValidToCreateXenditInvoice(Order $order): bool protected function getPreferredMethod(Order $order) { $payment = $order->getPayment(); - $preferredMethod = $this->getDataHelper()->xenditPaymentMethod( + return $this->getDataHelper()->xenditPaymentMethod( $payment->getMethod() ); - - switch ($preferredMethod) { - case 'cc': - return 'CREDIT_CARD'; - case 'shopeepayph': - return 'SHOPEEPAY'; - default: - return $preferredMethod; - } } /** diff --git a/Helper/Data.php b/Helper/Data.php index 8264b84d..b50d48dd 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -30,7 +30,7 @@ */ class Data extends AbstractHelper { - const XENDIT_M2INVOICE_VERSION = '9.0.1'; + const XENDIT_M2INVOICE_VERSION = '10.0.0'; /** * @var StoreManagerInterface @@ -399,12 +399,13 @@ public function mapSalesRuleType($type) public function getXenditPaymentList(): array { return [ - "cc" => "cc", + "cc" => "credit_card", "bcava" => "bca", "bniva" => "bni", "bjbva" => "bjb", "briva" => "bri", "bsiva" => "bsi", + "bssva" => "sahabat_sampoerna", "mandiriva" => "mandiri", "permatava" => "permata", "alfamart" => "alfamart", @@ -429,7 +430,7 @@ public function getXenditPaymentList(): array "dp_ecpay_loan" => "dp_ecpay_loan", "dp_ecpay_school" => "dp_ecpay_school", "cashalo" => "cashalo", - "shopeepayph" => "shopeepayph", + "shopeepayph" => "shopeepay", "uangme" => "uangme", "astrapay" => "astrapay", "akulaku" => "akulaku", diff --git a/Model/Adminhtml/Source/ChosenMethod.php b/Model/Adminhtml/Source/ChosenMethod.php index 064e8ac2..6d334d84 100644 --- a/Model/Adminhtml/Source/ChosenMethod.php +++ b/Model/Adminhtml/Source/ChosenMethod.php @@ -26,6 +26,7 @@ public function toOptionArray($isMultiselect = false) ['value' => 'bniva', 'label' => __('Bank Transfer BNI')], ['value' => 'briva', 'label' => __('Bank Transfer BRI')], ['value' => 'bsiva', 'label' => __('Bank Transfer BSI')], + ['value' => 'bssva', 'label' => __('Bank Transfer BSS')], ['value' => 'mandiriva', 'label' => __('Bank Transfer Mandiri')], ['value' => 'permatava', 'label' => __('Bank Transfer Permata')], ['value' => 'cc', 'label' => __('Credit Card')], diff --git a/Model/Payment/BSSVA.php b/Model/Payment/BSSVA.php new file mode 100644 index 00000000..88b803f7 --- /dev/null +++ b/Model/Payment/BSSVA.php @@ -0,0 +1,27 @@ + [ Config::CODE => [ 'xendit_env' => $this->xendit->getConfigData('xendit_env'), @@ -332,9 +332,14 @@ public function getConfig() 'description' => $this->xenditHelper->getPaymentDescription("lbc"), 'image' => $this->xenditHelper->getPaymentImage('lbc') ], + 'bssva' => [ + 'title' => $this->xenditHelper->getPaymentTitle("bssva"), + 'min_order_amount' => $this->xenditHelper->getPaymentMinOrderAmount("bssva"), + 'max_order_amount' => $this->xenditHelper->getPaymentMaxOrderAmount("bssva"), + 'description' => $this->xenditHelper->getPaymentDescription("bssva"), + 'image' => $this->xenditHelper->getPaymentImage('bssva') + ], ] ]; - - return $config; } } diff --git a/composer.json b/composer.json index dc275c84..a3403204 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "xendit/m2invoice", "description": "Xendit Payment Gateway Module", "type": "magento2-module", - "version": "9.0.1", + "version": "10.0.0", "license": [ "GPL-3.0" ], diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index f1133ec9..9a9bbea1 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -165,6 +165,7 @@ + diff --git a/etc/adminhtml/virtual_account/bssva.xml b/etc/adminhtml/virtual_account/bssva.xml new file mode 100644 index 00000000..d97bab59 --- /dev/null +++ b/etc/adminhtml/virtual_account/bssva.xml @@ -0,0 +1,29 @@ + + + + + + + Magento\Config\Model\Config\Source\Yesno + payment/bssva/active + + + + payment/bssva/title + + + + payment/bssva/description + + + + validate-zero-or-greater + payment/bssva/min_order_total + + + + validate-zero-or-greater + payment/bssva/max_order_total + + + diff --git a/etc/config.xml b/etc/config.xml index c0f302f8..a5d08b80 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -147,6 +147,20 @@ 7 IDR + + 1 + initialize + Xendit\M2Invoice\Model\Payment\BSSVA + Bank Transfer - BSS + Bayar pesanan dengan transfer bank BSS dengan virtual account melalui Xendit + 1 + 50000000000 + 1 + 1 + 1 + 7 + IDR + 1 initialize diff --git a/etc/module.xml b/etc/module.xml index fe9b2def..744b2e54 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,4 +1,4 @@ - + diff --git a/etc/payment.xml b/etc/payment.xml index b5404134..d838a94e 100644 --- a/etc/payment.xml +++ b/etc/payment.xml @@ -120,5 +120,8 @@ https://github.com/magento/magento2/blob/2.2.0-rc2.1/app/code/Magento/Multishipp 1 + + 1 + diff --git a/view/frontend/layout/multishipping_checkout_billing.xml b/view/frontend/layout/multishipping_checkout_billing.xml index 54a5a3b0..7d8d278c 100644 --- a/view/frontend/layout/multishipping_checkout_billing.xml +++ b/view/frontend/layout/multishipping_checkout_billing.xml @@ -45,6 +45,7 @@ Xendit_M2Invoice::multishipping/atome.phtml Xendit_M2Invoice::multishipping/dd_rcbc.phtml Xendit_M2Invoice::multishipping/lbc.phtml + Xendit_M2Invoice::multishipping/bssva.phtml diff --git a/view/frontend/templates/multishipping/bssva.phtml b/view/frontend/templates/multishipping/bssva.phtml new file mode 100644 index 00000000..0cad3252 --- /dev/null +++ b/view/frontend/templates/multishipping/bssva.phtml @@ -0,0 +1,34 @@ + + + diff --git a/view/frontend/web/images/methods/bssva.svg b/view/frontend/web/images/methods/bssva.svg new file mode 100644 index 00000000..2a1ef6d6 --- /dev/null +++ b/view/frontend/web/images/methods/bssva.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/view/frontend/web/js/view/payment/method-renderer.js b/view/frontend/web/js/view/payment/method-renderer.js index ce51ebdc..6785d942 100644 --- a/view/frontend/web/js/view/payment/method-renderer.js +++ b/view/frontend/web/js/view/payment/method-renderer.js @@ -158,6 +158,10 @@ define( type: 'lbc', component: 'Xendit_M2Invoice/js/view/payment/method-renderer/lbc' }, + { + type: 'bssva', + component: 'Xendit_M2Invoice/js/view/payment/method-renderer/bssva' + } ); return Component.extend({}); } diff --git a/view/frontend/web/js/view/payment/method-renderer/bssva.js b/view/frontend/web/js/view/payment/method-renderer/bssva.js new file mode 100644 index 00000000..d145118a --- /dev/null +++ b/view/frontend/web/js/view/payment/method-renderer/bssva.js @@ -0,0 +1,78 @@ +define( + [ + 'Magento_Checkout/js/view/payment/default', + 'mage/url', + 'Magento_Checkout/js/model/quote', + ], + function ( + Component, + url, + quote, + ) { + 'use strict'; + + var self; + + return Component.extend({ + defaults: { + template: 'Xendit_M2Invoice/payment/invoiceva', + redirectAfterPlaceOrder: false, + }, + + initialize: function() { + this._super(); + self = this; + }, + + getCode: function() { + return 'bssva'; + }, + + getMethod: function() { + return 'BSS'; + }, + + getMethodImage: function () { + return window.checkoutConfig.payment[this.item.method].image; + }, + + getTest: function() { + return '1'; + }, + + getDescription: function() { + return window.checkoutConfig.payment.bssva.description; + }, + + getTestDescription: function () { + var environment = window.checkoutConfig.payment.xendit.xendit_env; + + if (environment !== 'test') { + return {}; + } + + return { + prefix: window.checkoutConfig.payment.xendit.test_prefix, + content: window.checkoutConfig.payment.xendit.test_content + }; + }, + + afterPlaceOrder: function () { + window.location.replace(url.build(`xendit/checkout/invoice`)); + }, + + validate: function() { + var billingAddress = quote.billingAddress(); + + self.messageContainer.clear(); + + if (!billingAddress) { + self.messageContainer.addErrorMessage({'message': 'Please enter your billing address'}); + return false; + } + + return true; + } + }); + } +); diff --git a/view/frontend/web/js/view/payment/method-renderer/multishipping/bssva.js b/view/frontend/web/js/view/payment/method-renderer/multishipping/bssva.js new file mode 100644 index 00000000..4340ad00 --- /dev/null +++ b/view/frontend/web/js/view/payment/method-renderer/multishipping/bssva.js @@ -0,0 +1,21 @@ +define( + [ + 'Xendit_M2Invoice/js/view/payment/method-renderer/bssva' + ], + function ( + Component + ) { + 'use strict'; + + return Component.extend({ + defaults: { + template: 'Xendit_M2Invoice/payment/multishipping/description', + redirectAfterPlaceOrder: false, + }, + + getMethodImage: function () { + return window.checkoutConfig.payment[this.item.method].image; + } + }); + } +); From 8f9d61b826f2f11c9bafe4d11ddab9cff7e4753a Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 11 Jan 2023 09:40:16 +0700 Subject: [PATCH 2/2] Improve error message --- Controller/Checkout/Invoice.php | 11 ++++++----- Controller/Checkout/InvoiceMultishipping.php | 10 ++++++---- Helper/ErrorHandler.php | 15 ++++++++++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Controller/Checkout/Invoice.php b/Controller/Checkout/Invoice.php index 6b0d4853..b453d4ee 100644 --- a/Controller/Checkout/Invoice.php +++ b/Controller/Checkout/Invoice.php @@ -40,9 +40,7 @@ public function execute() $this->_redirect('checkout/cart'); } } catch (\Throwable $e) { - $message = 'Exception caught on xendit/checkout/invoice: ' . $e->getMessage(); - - $this->getLogger()->debug('Exception caught on xendit/checkout/invoice: ' . $message); + $this->getLogger()->debug('Exception caught on xendit/checkout/invoice: ' . $e->getMessage()); $this->getLogger()->debug($e->getTraceAsString()); $this->cancelOrder($order, $e->getMessage()); @@ -57,7 +55,7 @@ public function execute() ] ); - return $this->redirectToCart($message); + return $this->redirectToCart($e->getMessage()); } } @@ -140,7 +138,10 @@ private function createInvoice($requestData) ); } if (isset($invoice['error_code'])) { - $message = $this->getErrorHandler()->mapInvoiceErrorCode($invoice['error_code']); + $message = $this->getErrorHandler()->mapInvoiceErrorCode( + $invoice['error_code'], + str_replace('{{currency}}', $requestData['currency'], $invoice['message'] ?? '') + ); throw new LocalizedException( new Phrase($message) ); diff --git a/Controller/Checkout/InvoiceMultishipping.php b/Controller/Checkout/InvoiceMultishipping.php index 849bf3cc..4391a66a 100644 --- a/Controller/Checkout/InvoiceMultishipping.php +++ b/Controller/Checkout/InvoiceMultishipping.php @@ -115,7 +115,10 @@ public function execute() $invoice = $this->createInvoice($requestData); if (!empty($invoice) && isset($invoice['error_code'])) { - $message = $this->getErrorHandler()->mapInvoiceErrorCode($invoice['error_code']); + $message = $this->getErrorHandler()->mapInvoiceErrorCode( + $invoice['error_code'], + str_replace('{{currency}}', $currency, $invoice['message'] ?? '') + ); // cancel order and redirect to cart return $this->processFailedPayment($orderIds, $message); } @@ -127,8 +130,7 @@ public function execute() $resultRedirect->setUrl($redirectUrl); return $resultRedirect; } catch (\Throwable $e) { - $message = 'Exception caught on xendit/checkout/redirect: ' . $e->getMessage(); - $this->getLogger()->info($message); + $this->getLogger()->info('Exception caught on xendit/checkout/redirect: ' . $e->getMessage()); // log metric error $this->metricHelper->sendMetric( @@ -140,7 +142,7 @@ public function execute() ] ); - return $this->redirectToCart($message); + return $this->redirectToCart($e->getMessage()); } } diff --git a/Helper/ErrorHandler.php b/Helper/ErrorHandler.php index 63648c5e..40e2a8bf 100644 --- a/Helper/ErrorHandler.php +++ b/Helper/ErrorHandler.php @@ -10,13 +10,18 @@ class ErrorHandler { /** * @param $errorCode - * @return string + * @param string $message + * @return array|string|string[] */ - public function mapInvoiceErrorCode($errorCode) - { + public function mapInvoiceErrorCode( + $errorCode, + string $message = '' + ) { + $defaultMessage = "Failed to pay with Invoice. Error code: $errorCode"; switch ($errorCode) { + case 'UNSUPPORTED_CURRENCY': case 'API_VALIDATION_ERROR': - return 'Inputs are failing validation. The errors field contains details about which fields are violating validation.'; + return !empty($message) ? $message : $defaultMessage; case 'INVALID_JSON_FORMAT': return 'The request body is not a valid JSON format.'; case 'MINIMAL_TRANSFER_AMOUNT_ERROR': @@ -40,7 +45,7 @@ public function mapInvoiceErrorCode($errorCode) case 'MERCHANT_NOT_FOUND': return 'You are not registered yet to use this payment method.'; default: - return "Failed to pay with Invoice. Error code: $errorCode"; + return $defaultMessage; } } }