Skip to content

Commit

Permalink
add new payment channels (#170)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
andykim and andykim authored Oct 23, 2023
1 parent b314bdc commit f058020
Show file tree
Hide file tree
Showing 39 changed files with 1,243 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## 11.0.0 (2023-10-17)
Improvements:
- Raise AstraPay limit to 20M IDR
- Add BDO Direct Debit
- Add CIMB VA
- Add Direct Debit (ChinaBank)
- Add JeniusPay

## 10.0.4 (2023-05-23)
Improvements:
- Update new ShopeePay icon
Expand Down
26 changes: 21 additions & 5 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 = '10.0.4';
const XENDIT_M2INVOICE_VERSION = '11.0.0';

/**
* @var StoreManagerInterface
Expand Down Expand Up @@ -107,6 +107,11 @@ class Data extends AbstractHelper
*/
protected $categoryRepository;

/**
* @var PhoneNumberFormat $phoneNumberFormatHelper
*/
protected $phoneNumberFormatHelper;

/**
* Data constructor.
*
Expand All @@ -126,6 +131,7 @@ class Data extends AbstractHelper
* @param OrderNotifier $orderNotifier
* @param AssetRepository $assetRepository
* @param CategoryRepository $categoryRepository
* @param PhoneNumberFormat $phoneNumberFormatHelper
*/
public function __construct(
Context $context,
Expand All @@ -143,7 +149,8 @@ public function __construct(
DbTransaction $dbTransaction,
OrderNotifier $orderNotifier,
AssetRepository $assetRepository,
CategoryRepository $categoryRepository
CategoryRepository $categoryRepository,
\Xendit\M2Invoice\Helper\PhoneNumberFormat $phoneNumberFormatHelper
) {
$this->storeManager = $storeManager;
$this->xendit = $xendit;
Expand All @@ -160,6 +167,7 @@ public function __construct(
$this->orderNotifier = $orderNotifier;
$this->assetRepository = $assetRepository;
$this->categoryRepository = $categoryRepository;
$this->phoneNumberFormatHelper = $phoneNumberFormatHelper;

parent::__construct($context);
}
Expand Down Expand Up @@ -436,7 +444,11 @@ public function getXenditPaymentList(): array
"akulaku" => "akulaku",
"atome" => "atome",
"dd_rcbc" => "dd_rcbc",
"lbc" => "lbc"
"lbc" => "lbc",
"jeniuspay" => "jeniuspay",
"dd_chinabank" => "dd_chinabank",
"cimbva" => "cimb",
"dd_bdo_epay" => "dd_bdo_epay"
];
}

Expand Down Expand Up @@ -596,10 +608,14 @@ public function extractXenditInvoiceCustomerFromOrder(Order $order): array
$customerObject = [
'given_names' => $order->getCustomerFirstname(),
'surname' => $order->getCustomerLastname(),
'email' => $order->getCustomerEmail(),
'mobile_number' => $shippingAddress->getTelephone()
'email' => $order->getCustomerEmail()
];

$mobileNumber = $this->phoneNumberFormatHelper->formatNumber($shippingAddress->getTelephone(), $shippingAddress->getCountryId());
if (!empty($mobileNumber)) {
$customerObject['mobile_number'] = $mobileNumber;
}

$customerObject = array_filter($customerObject);
$addressObject = $this->extractXenditInvoiceCustomerAddress($shippingAddress);
if (!empty($addressObject)) {
Expand Down
276 changes: 276 additions & 0 deletions Helper/PhoneNumberFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
<?php
namespace Xendit\M2Invoice\Helper;

use Magento\Framework\App\Helper\AbstractHelper;

class PhoneNumberFormat extends AbstractHelper
{
const COUNTRY_CODE_PHONE_MAPPING = [
'AD'=>'376',
'AE'=>'971',
'AF'=>'93',
'AG'=>'1268',
'AI'=>'1264',
'AL'=>'355',
'AM'=>'374',
'AN'=>'599',
'AO'=>'244',
'AQ'=>'672',
'AR'=>'54',
'AS'=>'1684',
'AT'=>'43',
'AU'=>'61',
'AW'=>'297',
'AZ'=>'994',
'BA'=>'387',
'BB'=>'1246',
'BD'=>'880',
'BE'=>'32',
'BF'=>'226',
'BG'=>'359',
'BH'=>'973',
'BI'=>'257',
'BJ'=>'229',
'BL'=>'590',
'BM'=>'1441',
'BN'=>'673',
'BO'=>'591',
'BR'=>'55',
'BS'=>'1242',
'BT'=>'975',
'BW'=>'267',
'BY'=>'375',
'BZ'=>'501',
'CA'=>'1',
'CC'=>'61',
'CD'=>'243',
'CF'=>'236',
'CG'=>'242',
'CH'=>'41',
'CI'=>'225',
'CK'=>'682',
'CL'=>'56',
'CM'=>'237',
'CN'=>'86',
'CO'=>'57',
'CR'=>'506',
'CU'=>'53',
'CV'=>'238',
'CX'=>'61',
'CY'=>'357',
'CZ'=>'420',
'DE'=>'49',
'DJ'=>'253',
'DK'=>'45',
'DM'=>'1767',
'DO'=>'1809',
'DZ'=>'213',
'EC'=>'593',
'EE'=>'372',
'EG'=>'20',
'ER'=>'291',
'ES'=>'34',
'ET'=>'251',
'FI'=>'358',
'FJ'=>'679',
'FK'=>'500',
'FM'=>'691',
'FO'=>'298',
'FR'=>'33',
'GA'=>'241',
'GB'=>'44',
'GD'=>'1473',
'GE'=>'995',
'GH'=>'233',
'GI'=>'350',
'GL'=>'299',
'GM'=>'220',
'GN'=>'224',
'GQ'=>'240',
'GR'=>'30',
'GT'=>'502',
'GU'=>'1671',
'GW'=>'245',
'GY'=>'592',
'HK'=>'852',
'HN'=>'504',
'HR'=>'385',
'HT'=>'509',
'HU'=>'36',
'ID'=>'62',
'IE'=>'353',
'IL'=>'972',
'IM'=>'44',
'IN'=>'91',
'IQ'=>'964',
'IR'=>'98',
'IS'=>'354',
'IT'=>'39',
'JM'=>'1876',
'JO'=>'962',
'JP'=>'81',
'KE'=>'254',
'KG'=>'996',
'KH'=>'855',
'KI'=>'686',
'KM'=>'269',
'KN'=>'1869',
'KP'=>'850',
'KR'=>'82',
'KW'=>'965',
'KY'=>'1345',
'KZ'=>'7',
'LA'=>'856',
'LB'=>'961',
'LC'=>'1758',
'LI'=>'423',
'LK'=>'94',
'LR'=>'231',
'LS'=>'266',
'LT'=>'370',
'LU'=>'352',
'LV'=>'371',
'LY'=>'218',
'MA'=>'212',
'MC'=>'377',
'MD'=>'373',
'ME'=>'382',
'MF'=>'1599',
'MG'=>'261',
'MH'=>'692',
'MK'=>'389',
'ML'=>'223',
'MM'=>'95',
'MN'=>'976',
'MO'=>'853',
'MP'=>'1670',
'MR'=>'222',
'MS'=>'1664',
'MT'=>'356',
'MU'=>'230',
'MV'=>'960',
'MW'=>'265',
'MX'=>'52',
'MY'=>'60',
'MZ'=>'258',
'NA'=>'264',
'NC'=>'687',
'NE'=>'227',
'NG'=>'234',
'NI'=>'505',
'NL'=>'31',
'NO'=>'47',
'NP'=>'977',
'NR'=>'674',
'NU'=>'683',
'NZ'=>'64',
'OM'=>'968',
'PA'=>'507',
'PE'=>'51',
'PF'=>'689',
'PG'=>'675',
'PH'=>'63',
'PK'=>'92',
'PL'=>'48',
'PM'=>'508',
'PN'=>'870',
'PR'=>'1',
'PT'=>'351',
'PW'=>'680',
'PY'=>'595',
'QA'=>'974',
'RO'=>'40',
'RS'=>'381',
'RU'=>'7',
'RW'=>'250',
'SA'=>'966',
'SB'=>'677',
'SC'=>'248',
'SD'=>'249',
'SE'=>'46',
'SG'=>'65',
'SH'=>'290',
'SI'=>'386',
'SK'=>'421',
'SL'=>'232',
'SM'=>'378',
'SN'=>'221',
'SO'=>'252',
'SR'=>'597',
'ST'=>'239',
'SV'=>'503',
'SY'=>'963',
'SZ'=>'268',
'TC'=>'1649',
'TD'=>'235',
'TG'=>'228',
'TH'=>'66',
'TJ'=>'992',
'TK'=>'690',
'TL'=>'670',
'TM'=>'993',
'TN'=>'216',
'TO'=>'676',
'TR'=>'90',
'TT'=>'1868',
'TV'=>'688',
'TW'=>'886',
'TZ'=>'255',
'UA'=>'380',
'UG'=>'256',
'US'=>'1',
'UY'=>'598',
'UZ'=>'998',
'VA'=>'39',
'VC'=>'1784',
'VE'=>'58',
'VG'=>'1284',
'VI'=>'1340',
'VN'=>'84',
'VU'=>'678',
'WF'=>'681',
'WS'=>'685',
'XK'=>'381',
'YE'=>'967',
'YT'=>'262',
'ZA'=>'27',
'ZM'=>'260',
'ZW'=>'263'
];

/**
* @param string $countryCode
* @return string
*/
protected function getCountryPhoneCode(string $countryCode): string
{
if (empty($countryCode)) {
return '';
}
return self::COUNTRY_CODE_PHONE_MAPPING[$countryCode] ?: '';
}

/**
* @param string $phoneNumber
* @return array|string|string[]|null
*/
protected function cleanUp(string $phoneNumber)
{
return preg_replace("/[^0-9]/", "", trim($phoneNumber));
}

/**
* @param string $phoneNumber
* @param string $countryCode
* @return array|string|string[]|null
*/
public function formatNumber(string $phoneNumber, string $countryCode)
{
if (empty($phoneNumber)) {
return '';
}

$countryPhoneCode = $this->getCountryPhoneCode($countryCode);
return preg_replace('/^(?:\+?' . $countryPhoneCode . '|0)?/', '+' . $countryPhoneCode, $this->cleanUp($phoneNumber));
}
}
4 changes: 4 additions & 0 deletions Model/Adminhtml/Source/ChosenMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function toOptionArray($isMultiselect = false)
['value' => 'atome', 'label' => __('Atome')],
['value' => 'dd_rcbc', 'label' => __('Direct Debit (RCBC)')],
['value' => 'lbc', 'label' => __('LBC')],
['value' => 'jeniuspay', 'label' => __('Jenius Pay')],
['value' => 'dd_chinabank', 'label' => __('Direct Debit (ChinaBank)')],
['value' => 'cimbva', 'label' => __('Bank Transfer CIMB')],
['value' => 'dd_bdo_epay', 'label' => __('Direct Debit (BDO)')],
];

if (!$isMultiselect) {
Expand Down
Loading

0 comments on commit f058020

Please sign in to comment.