Skip to content

Commit

Permalink
Merge pull request #159 from xendit/TPI-8191/bss-va
Browse files Browse the repository at this point in the history
add BSS VA
  • Loading branch information
andykim authored Jan 11, 2023
2 parents 0908708 + efebc14 commit f4fcd48
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 1 addition & 10 deletions Controller/Checkout/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
11 changes: 6 additions & 5 deletions Controller/Checkout/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -57,7 +55,7 @@ public function execute()
]
);

return $this->redirectToCart($message);
return $this->redirectToCart($e->getMessage());
}
}

Expand Down Expand Up @@ -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)
);
Expand Down
10 changes: 6 additions & 4 deletions Controller/Checkout/InvoiceMultishipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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(
Expand All @@ -140,7 +142,7 @@ public function execute()
]
);

return $this->redirectToCart($message);
return $this->redirectToCart($e->getMessage());
}
}

Expand Down
7 changes: 4 additions & 3 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class Data extends AbstractHelper
{
const XENDIT_M2INVOICE_VERSION = '9.0.1';
const XENDIT_M2INVOICE_VERSION = '10.0.0';

/**
* @var StoreManagerInterface
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
15 changes: 10 additions & 5 deletions Helper/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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;
}
}
}
1 change: 1 addition & 0 deletions Model/Adminhtml/Source/ChosenMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
Expand Down
27 changes: 27 additions & 0 deletions Model/Payment/BSSVA.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Xendit\M2Invoice\Model\Payment;

use Magento\Quote\Api\Data\CartInterface;

/**
* Class BSSVA
* @package Xendit\M2Invoice\Model\Payment
*/
class BSSVA extends AbstractInvoice
{
/**
* Payment Method feature
*
* @var bool
*/
protected $_isInitializeNeeded = true;

/**
* Payment code
*
* @var string
*/
protected $_code = 'bssva';
protected $methodCode = 'BSS';
}
11 changes: 8 additions & 3 deletions Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(
*/
public function getConfig()
{
$config = [
return [
'payment' => [
Config::CODE => [
'xendit_env' => $this->xendit->getConfigData('xendit_env'),
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
1 change: 1 addition & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<include path="Xendit_M2Invoice::virtual_account/bniva.xml"/>
<include path="Xendit_M2Invoice::virtual_account/briva.xml"/>
<include path="Xendit_M2Invoice::virtual_account/bsiva.xml"/>
<include path="Xendit_M2Invoice::virtual_account/bssva.xml"/>
<include path="Xendit_M2Invoice::virtual_account/mandiriva.xml"/>
<include path="Xendit_M2Invoice::virtual_account/permatava.xml"/>
</group>
Expand Down
29 changes: 29 additions & 0 deletions etc/adminhtml/virtual_account/bssva.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
<group id="bssva" translate="label" type="text" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
<label>BSS</label>
<field id="active" translate="label comment" sortOrder="1" type="select" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/bssva/active</config_path>
</field>
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Title</label>
<config_path>payment/bssva/title</config_path>
</field>
<field id="description" translate="label" type="textarea" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Description</label>
<config_path>payment/bssva/description</config_path>
</field>
<field id="min_order_total" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Minimum Order Total</label>
<frontend_class>validate-zero-or-greater</frontend_class>
<config_path>payment/bssva/min_order_total</config_path>
</field>
<field id="max_order_total" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Maximum Order Total</label>
<frontend_class>validate-zero-or-greater</frontend_class>
<config_path>payment/bssva/max_order_total</config_path>
</field>
</group>
</include>
14 changes: 14 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@
<sort_order>7</sort_order>
<currency>IDR</currency>
</bsiva>
<bssva>
<active>1</active>
<payment_action>initialize</payment_action>
<model>Xendit\M2Invoice\Model\Payment\BSSVA</model>
<title>Bank Transfer - BSS</title>
<description>Bayar pesanan dengan transfer bank BSS dengan virtual account melalui Xendit</description>
<min_order_total>1</min_order_total>
<max_order_total>50000000000</max_order_total>
<is_gateway>1</is_gateway>
<can_initialize>1</can_initialize>
<can_use_checkout>1</can_use_checkout>
<sort_order>7</sort_order>
<currency>IDR</currency>
</bssva>
<mandiriva>
<active>1</active>
<payment_action>initialize</payment_action>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Xendit_M2Invoice" setup_version="9.0.1" active="true"></module>
<module name="Xendit_M2Invoice" setup_version="10.0.0" active="true"></module>
</config>
3 changes: 3 additions & 0 deletions etc/payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,8 @@ https://github.com/magento/magento2/blob/2.2.0-rc2.1/app/code/Magento/Multishipp
<method name='atome'>
<allow_multiple_address>1</allow_multiple_address>
</method>
<method name='bssva'>
<allow_multiple_address>1</allow_multiple_address>
</method>
</methods>
</payment>
1 change: 1 addition & 0 deletions view/frontend/layout/multishipping_checkout_billing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<item name="atome" xsi:type="string">Xendit_M2Invoice::multishipping/atome.phtml</item>
<item name="dd_rcbc" xsi:type="string">Xendit_M2Invoice::multishipping/dd_rcbc.phtml</item>
<item name="lbc" xsi:type="string">Xendit_M2Invoice::multishipping/lbc.phtml</item>
<item name="bssva" xsi:type="string">Xendit_M2Invoice::multishipping/bssva.phtml</item>
</argument>
</arguments>
</referenceBlock>
Expand Down
34 changes: 34 additions & 0 deletions view/frontend/templates/multishipping/bssva.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<script>
require([
'uiLayout',
'jquery'
], function (layout, $) {
$(function () {
var paymentMethodData = {
method: 'bssva'
};
layout([
{
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/multishipping/bssva',
name: 'payment_method_bssva',
method: paymentMethodData.method,
item: paymentMethodData
}
]);

if(window.checkoutConfig.payment[paymentMethodData.method].image != ""){
$("label[for=p_method_"+paymentMethodData.method+"]")
.prepend('<img class="xendit-payment-icon" src="'+window.checkoutConfig.payment[paymentMethodData.method].image+'" />');
}

$('body').trigger('contentUpdated');
})
})
</script>
<!-- ko template: getTemplate() --><!-- /ko -->
1 change: 1 addition & 0 deletions view/frontend/web/images/methods/bssva.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions view/frontend/web/js/view/payment/method-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
}
Expand Down
Loading

0 comments on commit f4fcd48

Please sign in to comment.