Skip to content

Commit fdc2a8a

Browse files
authored
Merge pull request #63 from xendit/TPI-2768/ovo-phone
Tpi 2768/ovo phone
2 parents f4b8367 + de28621 commit fdc2a8a

File tree

10 files changed

+54
-17
lines changed

10 files changed

+54
-17
lines changed

CHANGELOG.md

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

3+
## 2.4.1 (2020-11-06)
4+
5+
Improvements:
6+
7+
- Add OVO phone validation
8+
- Set default order status for Invoice methods
9+
310
## 2.4.0 (2020-11-02)
411

512
Features:

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This module has been tested against the following tech stacks:
77

88
| Magento Version | OS | Database | PHP | Web Server |
99
| --- | --- | --- | --- | --- |
10+
| 2.4.0 | Ubuntu 18.04.2 LTS | MariaDB 10.1.39 | 7.4.1 | Apache 2.4.37 |
1011
| 2.3.2 | Ubuntu 18.04.2 LTS | MariaDB 10.1.39 | 7.2.12 | Apache 2.4.37 |
1112
| 2.2.5 | Debian GNU/Linux 9 | MariaDB 10.3 | 7.0.33 | Apache 2.2 |
1213
| 2.1.18 | Debian GNU/Linux 9 | MariaDB 10.3 | 7.0.33 | Apache 2.4 |

Xendit/M2Invoice/Controller/Checkout/Invoice.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public function execute()
1515
$order = $this->getOrder();
1616
$apiData = $this->getApiRequestData($order);
1717

18-
if ($order->getState() === Order::STATE_PROCESSING) {
18+
if ($order->getState() === Order::STATE_PROCESSING ||
19+
$order->getState() === Order::STATE_PENDING_PAYMENT ||
20+
$order->getState() === Order::STATE_PAYMENT_REVIEW
21+
) {
1922
$this->changePendingPaymentStatus($order);
2023
$invoice = $this->createInvoice($apiData);
2124
$this->addInvoiceData($order, $invoice);

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.4.0'
88+
'x-plugin-version' => '2.4.1'
8989
];
9090

9191
if ($preferredMethod !== null) {

Xendit/M2Invoice/Model/Payment/AbstractInvoice.php

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public function __construct(
7979
}
8080
}
8181

82+
public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
83+
{
84+
$payment->setIsTransactionPending(true);
85+
}
86+
8287
public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
8388
{
8489
if ($quote === null) {

Xendit/M2Invoice/Model/Payment/OVO.php

+17-4
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,29 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount
4242
}
4343

4444
$orderId = $order->getRealOrderId();
45+
$billing = $order->getBillingAddress();
46+
$phone = trim(!empty($additionalData['phone_number']) ? $additionalData['phone_number'] : $billing->getTelephone());
47+
4548
try {
49+
// validate phone number
50+
if (!$phone || strpos($phone, '08') !== 0) {
51+
$message = $this->mapOvoErrorCode('INVALID_PHONE_NUMBER');
52+
throw new \Magento\Framework\Exception\LocalizedException(
53+
new Phrase($message)
54+
);
55+
}
56+
4657
$args = [
4758
'external_id' => $this->dataHelper->getExternalId($orderId),
4859
'amount' => $amount,
49-
'phone' => $additionalData['phone_number'],
60+
'phone' => $phone,
5061
'ewallet_type' => self::DEFAULT_EWALLET_TYPE,
5162
'platform_callback_url' => $this->getXenditCallbackUrl()
5263
];
5364

5465
$ewalletPayment = $this->requestEwalletPayment($args);
5566

56-
if ( isset($ewalletPayment['error_code']) ) {
67+
if (isset($ewalletPayment['error_code'])) {
5768
if ($ewalletPayment['error_code'] == 'DUPLICATE_PAYMENT_REQUEST_ERROR') {
5869
$args = array_replace($args, array(
5970
'external_id' => $this->dataHelper->getExternalId($orderId, true)
@@ -147,9 +158,9 @@ private function processFailedPayment($payment, $message)
147158
$payment->setAdditionalInformation('xendit_failure_reason', $message);
148159
}
149160

150-
private function mapOvoErrorCode($errorCode)
161+
private function mapOvoErrorCode($errorCode, $message = '')
151162
{
152-
switch ( $errorCode ) {
163+
switch ($errorCode) {
153164
case 'USER_DID_NOT_AUTHORIZE_THE_PAYMENT':
154165
return 'Please complete the payment request within 60 seconds.';
155166
case 'USER_DECLINED_THE_TRANSACTION':
@@ -168,6 +179,8 @@ private function mapOvoErrorCode($errorCode)
168179
case 'DEVELOPMENT_MODE_PAYMENT_ACKNOWLEDGED':
169180
return 'Development mode detected. Please refer to our documentations for successful payment
170181
simulation';
182+
case 'INVALID_PHONE_NUMBER':
183+
return 'Phone number is either missing or incorrect. Format should be 08XXXXXXXXX (not using "+62").';
171184
default:
172185
return "Failed to pay with eWallet. Error code: $errorCode";
173186
}

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.4.0",
5+
"version": "2.4.1",
66
"license": [
77
"GPL-3.0"
88
],

Xendit/M2Invoice/etc/config.xml

+17-8
Original file line numberDiff line numberDiff line change
@@ -25,59 +25,65 @@
2525
</m2invoice>
2626
<alfamart>
2727
<active>1</active>
28-
<payment_action>initialize</payment_action><!-- You can use another method like capture  -->
28+
<payment_action>authorize</payment_action><!-- You can use another method like capture  -->
2929
<model>Xendit\M2Invoice\Model\Payment\Alfamart</model>
3030
<title>Alfamart</title>
31+
<order_status>pending_payment</order_status><!-- set default order -->
3132
<is_gateway>1</is_gateway>
3233
<can_initialize>1</can_initialize>
3334
<can_use_checkout>1</can_use_checkout>
3435
<sort_order>1</sort_order>
3536
</alfamart>
3637
<bcava>
3738
<active>1</active>
38-
<payment_action>initialize</payment_action><!-- You can use another method like capture  -->
39+
<payment_action>authorize</payment_action><!-- You can use another method like capture  -->
3940
<model>Xendit\M2Invoice\Model\Payment\BCAVA</model>
4041
<title>Bank Transfer - BCA</title>
42+
<order_status>pending_payment</order_status><!-- set default order -->
4143
<is_gateway>1</is_gateway>
4244
<can_initialize>1</can_initialize>
4345
<can_use_checkout>1</can_use_checkout>
4446
<sort_order>2</sort_order>
4547
</bcava>
4648
<bniva>
4749
<active>1</active>
48-
<payment_action>initialize</payment_action>
50+
<payment_action>authorize</payment_action>
4951
<model>Xendit\M2Invoice\Model\Payment\BNIVA</model>
5052
<title>Bank Transfer - BNI</title>
53+
<order_status>pending_payment</order_status><!-- set default order -->
5154
<is_gateway>1</is_gateway>
5255
<can_initialize>1</can_initialize>
5356
<can_use_checkout>1</can_use_checkout>
5457
<sort_order>3</sort_order>
5558
</bniva>
5659
<briva>
5760
<active>1</active>
58-
<payment_action>initialize</payment_action><!-- You can use another method like capture  -->
61+
<payment_action>authorize</payment_action><!-- You can use another method like capture  -->
5962
<model>Xendit\M2Invoice\Model\Payment\BRIVA</model>
6063
<title>Bank Transfer - BRI</title>
64+
<order_status>pending_payment</order_status><!-- set default order -->
6165
<is_gateway>1</is_gateway>
6266
<can_initialize>1</can_initialize>
6367
<can_use_checkout>1</can_use_checkout>
6468
<sort_order>4</sort_order>
6569
</briva>
6670
<mandiriva>
6771
<active>1</active>
68-
<payment_action>initialize</payment_action><!-- You can use another method like capture  -->
72+
<payment_action>authorize</payment_action><!-- You can use another method like capture  -->
6973
<model>Xendit\M2Invoice\Model\Payment\MandiriVA</model>
7074
<title>Bank Transfer - Mandiri</title>
75+
<order_status>pending_payment</order_status><!-- set default order -->
7176
<is_gateway>1</is_gateway>
7277
<can_initialize>1</can_initialize>
7378
<can_use_checkout>1</can_use_checkout>
7479
<sort_order>5</sort_order>
7580
</mandiriva>
7681
<permatava>
7782
<active>1</active>
78-
<payment_action>initialize</payment_action><!-- You can use another method like capture  -->
83+
<payment_action>authorize</payment_action><!-- You can use another method like capture  -->
7984
<model>Xendit\M2Invoice\Model\Payment\PermataVA</model>
8085
<title>Bank Transfer - Permata</title>
86+
<order_status>pending_payment</order_status><!-- set default order -->
8187
<is_gateway>1</is_gateway>
8288
<can_initialize>1</can_initialize>
8389
<can_use_checkout>1</can_use_checkout>
@@ -121,19 +127,21 @@
121127
</cc_subscription>
122128
<dana>
123129
<active>1</active>
124-
<payment_action>initialize</payment_action>
130+
<payment_action>authorize</payment_action>
125131
<model>Xendit\M2Invoice\Model\Payment\DANA</model>
126132
<title>DANA</title>
133+
<order_status>pending_payment</order_status><!-- set default order -->
127134
<is_gateway>1</is_gateway>
128135
<can_initialize>1</can_initialize>
129136
<can_use_checkout>1</can_use_checkout>
130137
<sort_order>11</sort_order>
131138
</dana>
132139
<indomaret>
133140
<active>1</active>
134-
<payment_action>initialize</payment_action>
141+
<payment_action>authorize</payment_action>
135142
<model>Xendit\M2Invoice\Model\Payment\Indomaret</model>
136143
<title>Indomaret</title>
144+
<order_status>pending_payment</order_status><!-- set default order -->
137145
<is_gateway>1</is_gateway>
138146
<can_initialize>1</can_initialize>
139147
<can_use_checkout>1</can_use_checkout>
@@ -144,6 +152,7 @@
144152
<payment_action>authorize</payment_action>
145153
<model>Xendit\M2Invoice\Model\Payment\OVO</model>
146154
<title>OVO</title>
155+
<order_status>pending_payment</order_status><!-- set default order -->
147156
<is_gateway>1</is_gateway>
148157
<can_initialize>1</can_initialize>
149158
<can_use_checkout>1</can_use_checkout>

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.4.0" active="true"></module>
3+
<module name="Xendit_M2Invoice" setup_version="2.4.1" active="true"></module>
44
</config>

Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/ovo.js

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ define(
141141
},
142142

143143
block: function() {
144-
var overlayBox
145144
if ($("[class='xendit-overlay-box']").length === 0) {
146145
var overlayDiv = $( "<div class='xendit-overlay-box'>" +
147146
"<div id='xendit-overlay-content'>\n" +

0 commit comments

Comments
 (0)