Skip to content

Commit f058020

Browse files
authored
add new payment channels (#170)
* add new payment channels * update readme * Fix CIMB * disable jenius + bdo * disable jenius + bdo * Fix mobile number format (#171) * Fix mobile number format * fix lint --------- Co-authored-by: andy <[email protected]> --------- Co-authored-by: Andy Kim <[email protected]>
1 parent b314bdc commit f058020

39 files changed

+1243
-12
lines changed

CHANGELOG.md

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

3+
## 11.0.0 (2023-10-17)
4+
Improvements:
5+
- Raise AstraPay limit to 20M IDR
6+
- Add BDO Direct Debit
7+
- Add CIMB VA
8+
- Add Direct Debit (ChinaBank)
9+
- Add JeniusPay
10+
311
## 10.0.4 (2023-05-23)
412
Improvements:
513
- Update new ShopeePay icon

Helper/Data.php

+21-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
class Data extends AbstractHelper
3232
{
33-
const XENDIT_M2INVOICE_VERSION = '10.0.4';
33+
const XENDIT_M2INVOICE_VERSION = '11.0.0';
3434

3535
/**
3636
* @var StoreManagerInterface
@@ -107,6 +107,11 @@ class Data extends AbstractHelper
107107
*/
108108
protected $categoryRepository;
109109

110+
/**
111+
* @var PhoneNumberFormat $phoneNumberFormatHelper
112+
*/
113+
protected $phoneNumberFormatHelper;
114+
110115
/**
111116
* Data constructor.
112117
*
@@ -126,6 +131,7 @@ class Data extends AbstractHelper
126131
* @param OrderNotifier $orderNotifier
127132
* @param AssetRepository $assetRepository
128133
* @param CategoryRepository $categoryRepository
134+
* @param PhoneNumberFormat $phoneNumberFormatHelper
129135
*/
130136
public function __construct(
131137
Context $context,
@@ -143,7 +149,8 @@ public function __construct(
143149
DbTransaction $dbTransaction,
144150
OrderNotifier $orderNotifier,
145151
AssetRepository $assetRepository,
146-
CategoryRepository $categoryRepository
152+
CategoryRepository $categoryRepository,
153+
\Xendit\M2Invoice\Helper\PhoneNumberFormat $phoneNumberFormatHelper
147154
) {
148155
$this->storeManager = $storeManager;
149156
$this->xendit = $xendit;
@@ -160,6 +167,7 @@ public function __construct(
160167
$this->orderNotifier = $orderNotifier;
161168
$this->assetRepository = $assetRepository;
162169
$this->categoryRepository = $categoryRepository;
170+
$this->phoneNumberFormatHelper = $phoneNumberFormatHelper;
163171

164172
parent::__construct($context);
165173
}
@@ -436,7 +444,11 @@ public function getXenditPaymentList(): array
436444
"akulaku" => "akulaku",
437445
"atome" => "atome",
438446
"dd_rcbc" => "dd_rcbc",
439-
"lbc" => "lbc"
447+
"lbc" => "lbc",
448+
"jeniuspay" => "jeniuspay",
449+
"dd_chinabank" => "dd_chinabank",
450+
"cimbva" => "cimb",
451+
"dd_bdo_epay" => "dd_bdo_epay"
440452
];
441453
}
442454

@@ -596,10 +608,14 @@ public function extractXenditInvoiceCustomerFromOrder(Order $order): array
596608
$customerObject = [
597609
'given_names' => $order->getCustomerFirstname(),
598610
'surname' => $order->getCustomerLastname(),
599-
'email' => $order->getCustomerEmail(),
600-
'mobile_number' => $shippingAddress->getTelephone()
611+
'email' => $order->getCustomerEmail()
601612
];
602613

614+
$mobileNumber = $this->phoneNumberFormatHelper->formatNumber($shippingAddress->getTelephone(), $shippingAddress->getCountryId());
615+
if (!empty($mobileNumber)) {
616+
$customerObject['mobile_number'] = $mobileNumber;
617+
}
618+
603619
$customerObject = array_filter($customerObject);
604620
$addressObject = $this->extractXenditInvoiceCustomerAddress($shippingAddress);
605621
if (!empty($addressObject)) {

Helper/PhoneNumberFormat.php

+276
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
<?php
2+
namespace Xendit\M2Invoice\Helper;
3+
4+
use Magento\Framework\App\Helper\AbstractHelper;
5+
6+
class PhoneNumberFormat extends AbstractHelper
7+
{
8+
const COUNTRY_CODE_PHONE_MAPPING = [
9+
'AD'=>'376',
10+
'AE'=>'971',
11+
'AF'=>'93',
12+
'AG'=>'1268',
13+
'AI'=>'1264',
14+
'AL'=>'355',
15+
'AM'=>'374',
16+
'AN'=>'599',
17+
'AO'=>'244',
18+
'AQ'=>'672',
19+
'AR'=>'54',
20+
'AS'=>'1684',
21+
'AT'=>'43',
22+
'AU'=>'61',
23+
'AW'=>'297',
24+
'AZ'=>'994',
25+
'BA'=>'387',
26+
'BB'=>'1246',
27+
'BD'=>'880',
28+
'BE'=>'32',
29+
'BF'=>'226',
30+
'BG'=>'359',
31+
'BH'=>'973',
32+
'BI'=>'257',
33+
'BJ'=>'229',
34+
'BL'=>'590',
35+
'BM'=>'1441',
36+
'BN'=>'673',
37+
'BO'=>'591',
38+
'BR'=>'55',
39+
'BS'=>'1242',
40+
'BT'=>'975',
41+
'BW'=>'267',
42+
'BY'=>'375',
43+
'BZ'=>'501',
44+
'CA'=>'1',
45+
'CC'=>'61',
46+
'CD'=>'243',
47+
'CF'=>'236',
48+
'CG'=>'242',
49+
'CH'=>'41',
50+
'CI'=>'225',
51+
'CK'=>'682',
52+
'CL'=>'56',
53+
'CM'=>'237',
54+
'CN'=>'86',
55+
'CO'=>'57',
56+
'CR'=>'506',
57+
'CU'=>'53',
58+
'CV'=>'238',
59+
'CX'=>'61',
60+
'CY'=>'357',
61+
'CZ'=>'420',
62+
'DE'=>'49',
63+
'DJ'=>'253',
64+
'DK'=>'45',
65+
'DM'=>'1767',
66+
'DO'=>'1809',
67+
'DZ'=>'213',
68+
'EC'=>'593',
69+
'EE'=>'372',
70+
'EG'=>'20',
71+
'ER'=>'291',
72+
'ES'=>'34',
73+
'ET'=>'251',
74+
'FI'=>'358',
75+
'FJ'=>'679',
76+
'FK'=>'500',
77+
'FM'=>'691',
78+
'FO'=>'298',
79+
'FR'=>'33',
80+
'GA'=>'241',
81+
'GB'=>'44',
82+
'GD'=>'1473',
83+
'GE'=>'995',
84+
'GH'=>'233',
85+
'GI'=>'350',
86+
'GL'=>'299',
87+
'GM'=>'220',
88+
'GN'=>'224',
89+
'GQ'=>'240',
90+
'GR'=>'30',
91+
'GT'=>'502',
92+
'GU'=>'1671',
93+
'GW'=>'245',
94+
'GY'=>'592',
95+
'HK'=>'852',
96+
'HN'=>'504',
97+
'HR'=>'385',
98+
'HT'=>'509',
99+
'HU'=>'36',
100+
'ID'=>'62',
101+
'IE'=>'353',
102+
'IL'=>'972',
103+
'IM'=>'44',
104+
'IN'=>'91',
105+
'IQ'=>'964',
106+
'IR'=>'98',
107+
'IS'=>'354',
108+
'IT'=>'39',
109+
'JM'=>'1876',
110+
'JO'=>'962',
111+
'JP'=>'81',
112+
'KE'=>'254',
113+
'KG'=>'996',
114+
'KH'=>'855',
115+
'KI'=>'686',
116+
'KM'=>'269',
117+
'KN'=>'1869',
118+
'KP'=>'850',
119+
'KR'=>'82',
120+
'KW'=>'965',
121+
'KY'=>'1345',
122+
'KZ'=>'7',
123+
'LA'=>'856',
124+
'LB'=>'961',
125+
'LC'=>'1758',
126+
'LI'=>'423',
127+
'LK'=>'94',
128+
'LR'=>'231',
129+
'LS'=>'266',
130+
'LT'=>'370',
131+
'LU'=>'352',
132+
'LV'=>'371',
133+
'LY'=>'218',
134+
'MA'=>'212',
135+
'MC'=>'377',
136+
'MD'=>'373',
137+
'ME'=>'382',
138+
'MF'=>'1599',
139+
'MG'=>'261',
140+
'MH'=>'692',
141+
'MK'=>'389',
142+
'ML'=>'223',
143+
'MM'=>'95',
144+
'MN'=>'976',
145+
'MO'=>'853',
146+
'MP'=>'1670',
147+
'MR'=>'222',
148+
'MS'=>'1664',
149+
'MT'=>'356',
150+
'MU'=>'230',
151+
'MV'=>'960',
152+
'MW'=>'265',
153+
'MX'=>'52',
154+
'MY'=>'60',
155+
'MZ'=>'258',
156+
'NA'=>'264',
157+
'NC'=>'687',
158+
'NE'=>'227',
159+
'NG'=>'234',
160+
'NI'=>'505',
161+
'NL'=>'31',
162+
'NO'=>'47',
163+
'NP'=>'977',
164+
'NR'=>'674',
165+
'NU'=>'683',
166+
'NZ'=>'64',
167+
'OM'=>'968',
168+
'PA'=>'507',
169+
'PE'=>'51',
170+
'PF'=>'689',
171+
'PG'=>'675',
172+
'PH'=>'63',
173+
'PK'=>'92',
174+
'PL'=>'48',
175+
'PM'=>'508',
176+
'PN'=>'870',
177+
'PR'=>'1',
178+
'PT'=>'351',
179+
'PW'=>'680',
180+
'PY'=>'595',
181+
'QA'=>'974',
182+
'RO'=>'40',
183+
'RS'=>'381',
184+
'RU'=>'7',
185+
'RW'=>'250',
186+
'SA'=>'966',
187+
'SB'=>'677',
188+
'SC'=>'248',
189+
'SD'=>'249',
190+
'SE'=>'46',
191+
'SG'=>'65',
192+
'SH'=>'290',
193+
'SI'=>'386',
194+
'SK'=>'421',
195+
'SL'=>'232',
196+
'SM'=>'378',
197+
'SN'=>'221',
198+
'SO'=>'252',
199+
'SR'=>'597',
200+
'ST'=>'239',
201+
'SV'=>'503',
202+
'SY'=>'963',
203+
'SZ'=>'268',
204+
'TC'=>'1649',
205+
'TD'=>'235',
206+
'TG'=>'228',
207+
'TH'=>'66',
208+
'TJ'=>'992',
209+
'TK'=>'690',
210+
'TL'=>'670',
211+
'TM'=>'993',
212+
'TN'=>'216',
213+
'TO'=>'676',
214+
'TR'=>'90',
215+
'TT'=>'1868',
216+
'TV'=>'688',
217+
'TW'=>'886',
218+
'TZ'=>'255',
219+
'UA'=>'380',
220+
'UG'=>'256',
221+
'US'=>'1',
222+
'UY'=>'598',
223+
'UZ'=>'998',
224+
'VA'=>'39',
225+
'VC'=>'1784',
226+
'VE'=>'58',
227+
'VG'=>'1284',
228+
'VI'=>'1340',
229+
'VN'=>'84',
230+
'VU'=>'678',
231+
'WF'=>'681',
232+
'WS'=>'685',
233+
'XK'=>'381',
234+
'YE'=>'967',
235+
'YT'=>'262',
236+
'ZA'=>'27',
237+
'ZM'=>'260',
238+
'ZW'=>'263'
239+
];
240+
241+
/**
242+
* @param string $countryCode
243+
* @return string
244+
*/
245+
protected function getCountryPhoneCode(string $countryCode): string
246+
{
247+
if (empty($countryCode)) {
248+
return '';
249+
}
250+
return self::COUNTRY_CODE_PHONE_MAPPING[$countryCode] ?: '';
251+
}
252+
253+
/**
254+
* @param string $phoneNumber
255+
* @return array|string|string[]|null
256+
*/
257+
protected function cleanUp(string $phoneNumber)
258+
{
259+
return preg_replace("/[^0-9]/", "", trim($phoneNumber));
260+
}
261+
262+
/**
263+
* @param string $phoneNumber
264+
* @param string $countryCode
265+
* @return array|string|string[]|null
266+
*/
267+
public function formatNumber(string $phoneNumber, string $countryCode)
268+
{
269+
if (empty($phoneNumber)) {
270+
return '';
271+
}
272+
273+
$countryPhoneCode = $this->getCountryPhoneCode($countryCode);
274+
return preg_replace('/^(?:\+?' . $countryPhoneCode . '|0)?/', '+' . $countryPhoneCode, $this->cleanUp($phoneNumber));
275+
}
276+
}

Model/Adminhtml/Source/ChosenMethod.php

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public function toOptionArray($isMultiselect = false)
5858
['value' => 'atome', 'label' => __('Atome')],
5959
['value' => 'dd_rcbc', 'label' => __('Direct Debit (RCBC)')],
6060
['value' => 'lbc', 'label' => __('LBC')],
61+
['value' => 'jeniuspay', 'label' => __('Jenius Pay')],
62+
['value' => 'dd_chinabank', 'label' => __('Direct Debit (ChinaBank)')],
63+
['value' => 'cimbva', 'label' => __('Bank Transfer CIMB')],
64+
['value' => 'dd_bdo_epay', 'label' => __('Direct Debit (BDO)')],
6165
];
6266

6367
if (!$isMultiselect) {

0 commit comments

Comments
 (0)