Skip to content

Commit f4fcd48

Browse files
authored
Merge pull request #159 from xendit/TPI-8191/bss-va
add BSS VA
2 parents 0908708 + efebc14 commit f4fcd48

File tree

21 files changed

+255
-32
lines changed

21 files changed

+255
-32
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 10.0.0 (2022-01-10)
4+
Features:
5+
- Add new IDR payment: BSS VA
6+
37
## 9.0.1 (2022-12-16)
48
Features:
59
- Implement Xendit metric

Controller/Checkout/AbstractAction.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -512,18 +512,9 @@ protected function orderValidToCreateXenditInvoice(Order $order): bool
512512
protected function getPreferredMethod(Order $order)
513513
{
514514
$payment = $order->getPayment();
515-
$preferredMethod = $this->getDataHelper()->xenditPaymentMethod(
515+
return $this->getDataHelper()->xenditPaymentMethod(
516516
$payment->getMethod()
517517
);
518-
519-
switch ($preferredMethod) {
520-
case 'cc':
521-
return 'CREDIT_CARD';
522-
case 'shopeepayph':
523-
return 'SHOPEEPAY';
524-
default:
525-
return $preferredMethod;
526-
}
527518
}
528519

529520
/**

Controller/Checkout/Invoice.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public function execute()
4040
$this->_redirect('checkout/cart');
4141
}
4242
} catch (\Throwable $e) {
43-
$message = 'Exception caught on xendit/checkout/invoice: ' . $e->getMessage();
44-
45-
$this->getLogger()->debug('Exception caught on xendit/checkout/invoice: ' . $message);
43+
$this->getLogger()->debug('Exception caught on xendit/checkout/invoice: ' . $e->getMessage());
4644
$this->getLogger()->debug($e->getTraceAsString());
4745

4846
$this->cancelOrder($order, $e->getMessage());
@@ -57,7 +55,7 @@ public function execute()
5755
]
5856
);
5957

60-
return $this->redirectToCart($message);
58+
return $this->redirectToCart($e->getMessage());
6159
}
6260
}
6361

@@ -140,7 +138,10 @@ private function createInvoice($requestData)
140138
);
141139
}
142140
if (isset($invoice['error_code'])) {
143-
$message = $this->getErrorHandler()->mapInvoiceErrorCode($invoice['error_code']);
141+
$message = $this->getErrorHandler()->mapInvoiceErrorCode(
142+
$invoice['error_code'],
143+
str_replace('{{currency}}', $requestData['currency'], $invoice['message'] ?? '')
144+
);
144145
throw new LocalizedException(
145146
new Phrase($message)
146147
);

Controller/Checkout/InvoiceMultishipping.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ public function execute()
115115
$invoice = $this->createInvoice($requestData);
116116

117117
if (!empty($invoice) && isset($invoice['error_code'])) {
118-
$message = $this->getErrorHandler()->mapInvoiceErrorCode($invoice['error_code']);
118+
$message = $this->getErrorHandler()->mapInvoiceErrorCode(
119+
$invoice['error_code'],
120+
str_replace('{{currency}}', $currency, $invoice['message'] ?? '')
121+
);
119122
// cancel order and redirect to cart
120123
return $this->processFailedPayment($orderIds, $message);
121124
}
@@ -127,8 +130,7 @@ public function execute()
127130
$resultRedirect->setUrl($redirectUrl);
128131
return $resultRedirect;
129132
} catch (\Throwable $e) {
130-
$message = 'Exception caught on xendit/checkout/redirect: ' . $e->getMessage();
131-
$this->getLogger()->info($message);
133+
$this->getLogger()->info('Exception caught on xendit/checkout/redirect: ' . $e->getMessage());
132134

133135
// log metric error
134136
$this->metricHelper->sendMetric(
@@ -140,7 +142,7 @@ public function execute()
140142
]
141143
);
142144

143-
return $this->redirectToCart($message);
145+
return $this->redirectToCart($e->getMessage());
144146
}
145147
}
146148

Helper/Data.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
class Data extends AbstractHelper
3232
{
33-
const XENDIT_M2INVOICE_VERSION = '9.0.1';
33+
const XENDIT_M2INVOICE_VERSION = '10.0.0';
3434

3535
/**
3636
* @var StoreManagerInterface
@@ -399,12 +399,13 @@ public function mapSalesRuleType($type)
399399
public function getXenditPaymentList(): array
400400
{
401401
return [
402-
"cc" => "cc",
402+
"cc" => "credit_card",
403403
"bcava" => "bca",
404404
"bniva" => "bni",
405405
"bjbva" => "bjb",
406406
"briva" => "bri",
407407
"bsiva" => "bsi",
408+
"bssva" => "sahabat_sampoerna",
408409
"mandiriva" => "mandiri",
409410
"permatava" => "permata",
410411
"alfamart" => "alfamart",
@@ -429,7 +430,7 @@ public function getXenditPaymentList(): array
429430
"dp_ecpay_loan" => "dp_ecpay_loan",
430431
"dp_ecpay_school" => "dp_ecpay_school",
431432
"cashalo" => "cashalo",
432-
"shopeepayph" => "shopeepayph",
433+
"shopeepayph" => "shopeepay",
433434
"uangme" => "uangme",
434435
"astrapay" => "astrapay",
435436
"akulaku" => "akulaku",

Helper/ErrorHandler.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ class ErrorHandler
1010
{
1111
/**
1212
* @param $errorCode
13-
* @return string
13+
* @param string $message
14+
* @return array|string|string[]
1415
*/
15-
public function mapInvoiceErrorCode($errorCode)
16-
{
16+
public function mapInvoiceErrorCode(
17+
$errorCode,
18+
string $message = ''
19+
) {
20+
$defaultMessage = "Failed to pay with Invoice. Error code: $errorCode";
1721
switch ($errorCode) {
22+
case 'UNSUPPORTED_CURRENCY':
1823
case 'API_VALIDATION_ERROR':
19-
return 'Inputs are failing validation. The errors field contains details about which fields are violating validation.';
24+
return !empty($message) ? $message : $defaultMessage;
2025
case 'INVALID_JSON_FORMAT':
2126
return 'The request body is not a valid JSON format.';
2227
case 'MINIMAL_TRANSFER_AMOUNT_ERROR':
@@ -40,7 +45,7 @@ public function mapInvoiceErrorCode($errorCode)
4045
case 'MERCHANT_NOT_FOUND':
4146
return 'You are not registered yet to use this payment method.';
4247
default:
43-
return "Failed to pay with Invoice. Error code: $errorCode";
48+
return $defaultMessage;
4449
}
4550
}
4651
}

Model/Adminhtml/Source/ChosenMethod.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function toOptionArray($isMultiselect = false)
2626
['value' => 'bniva', 'label' => __('Bank Transfer BNI')],
2727
['value' => 'briva', 'label' => __('Bank Transfer BRI')],
2828
['value' => 'bsiva', 'label' => __('Bank Transfer BSI')],
29+
['value' => 'bssva', 'label' => __('Bank Transfer BSS')],
2930
['value' => 'mandiriva', 'label' => __('Bank Transfer Mandiri')],
3031
['value' => 'permatava', 'label' => __('Bank Transfer Permata')],
3132
['value' => 'cc', 'label' => __('Credit Card')],

Model/Payment/BSSVA.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Xendit\M2Invoice\Model\Payment;
4+
5+
use Magento\Quote\Api\Data\CartInterface;
6+
7+
/**
8+
* Class BSSVA
9+
* @package Xendit\M2Invoice\Model\Payment
10+
*/
11+
class BSSVA extends AbstractInvoice
12+
{
13+
/**
14+
* Payment Method feature
15+
*
16+
* @var bool
17+
*/
18+
protected $_isInitializeNeeded = true;
19+
20+
/**
21+
* Payment code
22+
*
23+
* @var string
24+
*/
25+
protected $_code = 'bssva';
26+
protected $methodCode = 'BSS';
27+
}

Model/Ui/ConfigProvider.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959
*/
6060
public function getConfig()
6161
{
62-
$config = [
62+
return [
6363
'payment' => [
6464
Config::CODE => [
6565
'xendit_env' => $this->xendit->getConfigData('xendit_env'),
@@ -332,9 +332,14 @@ public function getConfig()
332332
'description' => $this->xenditHelper->getPaymentDescription("lbc"),
333333
'image' => $this->xenditHelper->getPaymentImage('lbc')
334334
],
335+
'bssva' => [
336+
'title' => $this->xenditHelper->getPaymentTitle("bssva"),
337+
'min_order_amount' => $this->xenditHelper->getPaymentMinOrderAmount("bssva"),
338+
'max_order_amount' => $this->xenditHelper->getPaymentMaxOrderAmount("bssva"),
339+
'description' => $this->xenditHelper->getPaymentDescription("bssva"),
340+
'image' => $this->xenditHelper->getPaymentImage('bssva')
341+
],
335342
]
336343
];
337-
338-
return $config;
339344
}
340345
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "xendit/m2invoice",
33
"description": "Xendit Payment Gateway Module",
44
"type": "magento2-module",
5-
"version": "9.0.1",
5+
"version": "10.0.0",
66
"license": [
77
"GPL-3.0"
88
],

etc/adminhtml/system.xml

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<include path="Xendit_M2Invoice::virtual_account/bniva.xml"/>
166166
<include path="Xendit_M2Invoice::virtual_account/briva.xml"/>
167167
<include path="Xendit_M2Invoice::virtual_account/bsiva.xml"/>
168+
<include path="Xendit_M2Invoice::virtual_account/bssva.xml"/>
168169
<include path="Xendit_M2Invoice::virtual_account/mandiriva.xml"/>
169170
<include path="Xendit_M2Invoice::virtual_account/permatava.xml"/>
170171
</group>
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0"?>
2+
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
3+
<group id="bssva" translate="label" type="text" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
4+
<label>BSS</label>
5+
<field id="active" translate="label comment" sortOrder="1" type="select" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
6+
<label>Enable</label>
7+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
8+
<config_path>payment/bssva/active</config_path>
9+
</field>
10+
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
11+
<label>Title</label>
12+
<config_path>payment/bssva/title</config_path>
13+
</field>
14+
<field id="description" translate="label" type="textarea" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
15+
<label>Description</label>
16+
<config_path>payment/bssva/description</config_path>
17+
</field>
18+
<field id="min_order_total" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
19+
<label>Minimum Order Total</label>
20+
<frontend_class>validate-zero-or-greater</frontend_class>
21+
<config_path>payment/bssva/min_order_total</config_path>
22+
</field>
23+
<field id="max_order_total" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
24+
<label>Maximum Order Total</label>
25+
<frontend_class>validate-zero-or-greater</frontend_class>
26+
<config_path>payment/bssva/max_order_total</config_path>
27+
</field>
28+
</group>
29+
</include>

etc/config.xml

+14
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@
147147
<sort_order>7</sort_order>
148148
<currency>IDR</currency>
149149
</bsiva>
150+
<bssva>
151+
<active>1</active>
152+
<payment_action>initialize</payment_action>
153+
<model>Xendit\M2Invoice\Model\Payment\BSSVA</model>
154+
<title>Bank Transfer - BSS</title>
155+
<description>Bayar pesanan dengan transfer bank BSS dengan virtual account melalui Xendit</description>
156+
<min_order_total>1</min_order_total>
157+
<max_order_total>50000000000</max_order_total>
158+
<is_gateway>1</is_gateway>
159+
<can_initialize>1</can_initialize>
160+
<can_use_checkout>1</can_use_checkout>
161+
<sort_order>7</sort_order>
162+
<currency>IDR</currency>
163+
</bssva>
150164
<mandiriva>
151165
<active>1</active>
152166
<payment_action>initialize</payment_action>

etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Xendit_M2Invoice" setup_version="9.0.1" active="true"></module>
3+
<module name="Xendit_M2Invoice" setup_version="10.0.0" active="true"></module>
44
</config>

etc/payment.xml

+3
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,8 @@ https://github.com/magento/magento2/blob/2.2.0-rc2.1/app/code/Magento/Multishipp
120120
<method name='atome'>
121121
<allow_multiple_address>1</allow_multiple_address>
122122
</method>
123+
<method name='bssva'>
124+
<allow_multiple_address>1</allow_multiple_address>
125+
</method>
123126
</methods>
124127
</payment>

view/frontend/layout/multishipping_checkout_billing.xml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<item name="atome" xsi:type="string">Xendit_M2Invoice::multishipping/atome.phtml</item>
4646
<item name="dd_rcbc" xsi:type="string">Xendit_M2Invoice::multishipping/dd_rcbc.phtml</item>
4747
<item name="lbc" xsi:type="string">Xendit_M2Invoice::multishipping/lbc.phtml</item>
48+
<item name="bssva" xsi:type="string">Xendit_M2Invoice::multishipping/bssva.phtml</item>
4849
</argument>
4950
</arguments>
5051
</referenceBlock>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
?>
7+
<script>
8+
require([
9+
'uiLayout',
10+
'jquery'
11+
], function (layout, $) {
12+
$(function () {
13+
var paymentMethodData = {
14+
method: 'bssva'
15+
};
16+
layout([
17+
{
18+
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/multishipping/bssva',
19+
name: 'payment_method_bssva',
20+
method: paymentMethodData.method,
21+
item: paymentMethodData
22+
}
23+
]);
24+
25+
if(window.checkoutConfig.payment[paymentMethodData.method].image != ""){
26+
$("label[for=p_method_"+paymentMethodData.method+"]")
27+
.prepend('<img class="xendit-payment-icon" src="'+window.checkoutConfig.payment[paymentMethodData.method].image+'" />');
28+
}
29+
30+
$('body').trigger('contentUpdated');
31+
})
32+
})
33+
</script>
34+
<!-- ko template: getTemplate() --><!-- /ko -->

view/frontend/web/images/methods/bssva.svg

+1
Loading

view/frontend/web/js/view/payment/method-renderer.js

+4
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ define(
158158
type: 'lbc',
159159
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/lbc'
160160
},
161+
{
162+
type: 'bssva',
163+
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/bssva'
164+
}
161165
);
162166
return Component.extend({});
163167
}

0 commit comments

Comments
 (0)