Skip to content

Commit ce2f330

Browse files
authored
Merge pull request #59 from xendit/TPI-2798/custom-externalId
Use custom external ID
2 parents 045ee43 + 9197ecf commit ce2f330

12 files changed

+68
-16
lines changed

CHANGELOG.md

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

3+
## 2.3.0 (2020-10-06)
4+
5+
Features:
6+
7+
- Enable custom external ID
8+
39
## 2.2.2 (2020-10-01)
410

511
Bugfix:

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ To activate this feature, you need to follow this additional steps:
5151

5252
## Supported Payment Method
5353
- Credit and Debit Card
54-
- Mandiri VA
55-
- BNI VA
5654
- BCA VA
55+
- BNI VA
5756
- BRI VA
57+
- Mandiri VA
5858
- Permata VA
5959
- Alfamart
60+
- OVO
61+
- Credit Card Subscription
62+
- Credit Card Installment
6063

6164
## Refund Support
6265
Since v1.3.0, online refund (full and partial) is supported for payment through credit and debit card channel.

Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function execute()
2121

2222
$transactionAmount = 0;
2323
$tokenId = '';
24+
$orderProcessed = false;
2425
$orders = [];
2526

2627
if ($method === 'cc_subscription' && !$customerSession->isLoggedIn()) {
@@ -33,6 +34,12 @@ public function execute()
3334
$order = $this->getOrderFactory()->create();
3435
$order ->load($value);
3536

37+
$orderState = $order->getState();
38+
if ($orderState === Order::STATE_PROCESSING && !$order->canInvoice()) {
39+
$orderProcessed = true;
40+
continue;
41+
}
42+
3643
$order ->setState(Order::STATE_PENDING_PAYMENT)
3744
->setStatus(Order::STATE_PENDING_PAYMENT)
3845
->addStatusHistoryComment("Pending Xendit payment.");
@@ -52,6 +59,10 @@ public function execute()
5259
$transactionAmount += (int)$order->getTotalDue();
5360
}
5461

62+
if ($orderProcessed) {
63+
return $this->_redirect('multishipping/checkout/success');
64+
}
65+
5566
if ($method === 'cc') {
5667
$requestData = array(
5768
'token_id' => $tokenId,

Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ public function execute()
1616
$orderIds = explode("-", $rawOrderIds);
1717

1818
$transactionAmount = 0;
19-
20-
$orders = [];
19+
$orderProcessed = false;
20+
$orders = [];
21+
2122
foreach ($orderIds as $key => $value) {
2223
$order = $this->getOrderFactory()->create();
2324
$order->load($value);
2425

26+
$orderState = $order->getState();
27+
if ($orderState === Order::STATE_PROCESSING && !$order->canInvoice()) {
28+
$orderProcessed = true;
29+
continue;
30+
}
31+
2532
$order->setState(Order::STATE_PENDING_PAYMENT)
2633
->setStatus(Order::STATE_PENDING_PAYMENT)
2734
->addStatusHistoryComment("Pending Xendit payment.");
@@ -34,6 +41,10 @@ public function execute()
3441
$billingEmail = $order->getCustomerEmail();
3542
}
3643

44+
if ($orderProcessed) {
45+
return $this->_redirect('multishipping/checkout/success');
46+
}
47+
3748
$preferredMethod = $this->getRequest()->getParam('preferred_method');
3849
$requestData = [
3950
'success_redirect_url' => $this->getDataHelper()->getSuccessUrl(true),

Xendit/M2Invoice/Controller/Checkout/Notification.m22.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ public function handleEwalletCallback($callbackPayload) {
151151
$failureCode = $callbackPayload['failure_code'];
152152
}
153153

154-
$extIdPrefix = $this->dataHelper->getExternalIdPrefix();
155-
// Trimmed external ID from prefix is Magento's order ID
156-
$orderId = ltrim($callbackPayload['external_id'], $extIdPrefix);
154+
$temp = explode('-', $callbackPayload['external_id']);
155+
$orderId = end($temp);
157156
$order = $this->getOrderById($orderId);
158157

159158
return $this->checkOrder($order, true, $callbackPayload, null, $orderId);

Xendit/M2Invoice/Controller/Checkout/Notification.m23.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ public function handleEwalletCallback($callbackPayload) {
162162
$failureCode = $callbackPayload['failure_code'];
163163
}
164164

165-
$extIdPrefix = $this->dataHelper->getExternalIdPrefix();
166-
// Trimmed external ID from prefix is Magento's order ID
167-
$orderId = ltrim($callbackPayload['external_id'], $extIdPrefix);
165+
$temp = explode('-', $callbackPayload['external_id']);
166+
$orderId = end($temp);
168167
$order = $this->getOrderById($orderId);
169168

170169
return $this->checkOrder($order, true, $callbackPayload, null, $orderId);

Xendit/M2Invoice/Helper/ApiRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function getHeaders($isPublicRequest, $preferredMethod = null, $customHe
8585
'Content-Type' => 'application/json',
8686
'x-plugin-name' => 'MAGENTO2',
8787
'user-agent' => 'Magento 2 Module',
88-
'x-plugin-version' => '2.2.2'
88+
'x-plugin-version' => '2.3.0'
8989
];
9090

9191
if ($preferredMethod !== null) {

Xendit/M2Invoice/Helper/Data.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,12 @@ public function getExternalId($orderId, $duplicate = false)
117117

118118
public function getExternalIdPrefix()
119119
{
120-
$storeName = substr(preg_replace("/[^a-z0-9]/mi", "", $this->getStoreManager()->getStore()->getName()), 0, 20);
120+
return $this->m2Invoice->getConfigData('external_id_prefix') . "-" . $this->getStoreName();
121+
}
121122

122-
return "magento-xendit-$storeName";
123+
public function getStoreName()
124+
{
125+
return substr(preg_replace("/[^a-z0-9]/mi", "", $this->getStoreManager()->getStore()->getName()), 0, 20);
123126
}
124127

125128
public function getApiKey()

Xendit/M2Invoice/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": "2.2.2",
5+
"version": "2.3.0",
66
"license": [
77
"GPL-3.0"
88
],

Xendit/M2Invoice/etc/adminhtml/system.xml

+20-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@
103103
shouldEnableSpecificMethod();
104104
specificSelection.prop('size', 6);
105105
106+
var externalIdPrefix = jQuery("input[id*='m2invoice_external_id_prefix']");
107+
jQuery(externalIdPrefix).attr("placeholder", "magento-xendit");
108+
jQuery(externalIdPrefix).attr("maxlength", 50);
109+
110+
var defaultText = "Format: {Prefix}-{Store Name}-{Order ID}<br>Example: <b>"+externalIdPrefix.val()+"-mystore-245</b>";
111+
externalIdPrefix.siblings('.note').children()[0].innerHTML = defaultText;
112+
externalIdPrefix.change(function () {
113+
var newText = "Format: {Prefix}-{Store Name}-{Order ID}<br>Example: <b>"+externalIdPrefix.val()+"-mystore-245</b>";
114+
externalIdPrefix.siblings('.note').children()[0].innerHTML = newText;
115+
});
116+
106117
jQuery("textarea[id*='m2invoice_card_installment_description']").attr("placeholder", "Bayar pesanan dengan cicilan kartu kredit anda melalui Xendit.\nBank yang tersedia: BCA, BRI");
107118
108119
if ( !jQuery("textarea[id*='m2invoice_card_installment_description']").val() ) {
@@ -176,7 +187,15 @@
176187
<source_model>Xendit\M2Invoice\Model\Adminhtml\Source\ChosenMethod</source_model>
177188
<can_be_empty>1</can_be_empty>
178189
</field>
179-
<field id="send_invoice_email" translate="label" type="select" sortOrder="67" showInDefault="1" showInWebsite="1" showInStore="0">
190+
<field id="external_id_prefix" translate="label" type="text" sortOrder="67" showInDefault="1" showInWebsite="1" showInStore="0">
191+
<label>External ID Prefix</label>
192+
<comment>
193+
<![CDATA[Format: {Prefix}-{Store Name}-{Order ID}<br>
194+
Example: <b>magento-xendit-mystore-245</b>]]>
195+
</comment>
196+
<validate>required-entry</validate>
197+
</field>
198+
<field id="send_invoice_email" translate="label" type="select" sortOrder="68" showInDefault="1" showInWebsite="1" showInStore="0">
180199
<label>Send Email Notification</label>
181200
<comment>
182201
Send Xendit payment email notification to end customer when they checkout using bank transfer or retail outlet

Xendit/M2Invoice/etc/config.xml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<validation_key backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
2121
<card_payment_type>form</card_payment_type>
2222
<allowed_method>all</allowed_method>
23+
<external_id_prefix>magento-xendit</external_id_prefix>
2324
<send_invoice_email>1</send_invoice_email>
2425
</m2invoice>
2526
<alfamart>

Xendit/M2Invoice/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="2.2.2" active="true"></module>
3+
<module name="Xendit_M2Invoice" setup_version="2.3.0" active="true"></module>
44
</config>

0 commit comments

Comments
 (0)