Skip to content

Commit

Permalink
Fix Duitnow bank list issue (#486)
Browse files Browse the repository at this point in the history
* Fix duitnow bank list issue

* Include test for get_bank_list()
  • Loading branch information
aashishgurung authored Nov 11, 2024
1 parent 0ff4e82 commit e60ca98
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '9895ac689bce188c4a74717ce7c149c5');
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'b1a7ad893b10317f131d580cebf99812');
2 changes: 1 addition & 1 deletion includes/blocks/assets/js/build/omise_duitnow_obw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion includes/blocks/assets/js/omise-duitnow-obw.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const DuitNowOBWPaymentMethod = (props) => {
>
<option value="" disabled={true}>-- Select your option --</option>
{
banks.map((bank) => (
Object.values(banks).map((bank) => (
<option
key={bank['code']}
className={bank['code']}
Expand Down
6 changes: 1 addition & 5 deletions includes/blocks/gateways/omise-block-duitnow-obw.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ class Omise_Block_DuitNow_OBW extends Omise_Block_Payment {
protected $name = 'omise_duitnow_obw';

public function set_additional_data() {
if (!$this->gateway->backend) {
$this->gateway->init_payment_config();
}

$this->additional_data = [ 'banks' => $this->gateway->backend->banks ];
$this->additional_data = [ 'banks' => $this->gateway->get_bank_list() ];
}
}
85 changes: 77 additions & 8 deletions includes/gateway/class-omise-payment-duitnow-obw.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public function __construct()
$this->restricted_countries = array('MY');
$this->source_type = 'duitnow_obw';

$this->init_payment_config();

add_action('woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute');
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
add_action('woocommerce_order_action_' . $this->id . '_sync_payment', array($this, 'sync_payment'));
Expand Down Expand Up @@ -58,11 +56,82 @@ public function init_form_fields()
);
}

public function init_payment_config() {
$capabilities = Omise_Capabilities::retrieve();
$this->backend = $capabilities
? $capabilities->getBackendByType($this->source_type)
: null;
public function get_bank_list()
{
return [
'affin' => [
'code' => 'affin',
'name' => 'Affin Bank'
],
'alliance' => [
'code' => 'alliance',
'name' => 'Alliance Bank'
],
'agro' => [
'code' => 'agro',
'name' => 'Agrobank'
],
'ambank' => [
'code' => 'ambank',
'name' => 'AmBank'
],
'cimb' => [
'code' => 'cimb',
'name' => 'CIMB Bank'
],
'islam' => [
'code' => 'islam',
'name' => 'Bank Islam'
],
'rakyat' => [
'code' => 'rakyat',
'name' => 'Bank Rakyat'
],
'muamalat' => [
'code' => 'muamalat',
'name' => 'Bank Muamalat'
],
'bsn' => [
'code' => 'bsn',
'name' => 'Bank Simpanan Nasional'
],
'hongleong' => [
'code' => 'hongleong',
'name' => 'Hong Leong'
],
'hsbc' => [
'code' => 'hsbc',
'name' => 'HSBC Bank'
],
'kfh' => [
'code' => 'kfh',
'name' => 'Kuwait Finance House'
],
'maybank2u' => [
'code' => 'maybank2u',
'name' => 'Maybank'
],
'ocbc' => [
'code' => 'ocbc',
'name' => 'OCBC'
],
'public' => [
'code' => 'public',
'name' => 'Public Bank'
],
'rhb' => [
'code' => 'rhb',
'name' => 'RHB Bank'
],
'sc' => [
'code' => 'sc',
'name' => 'Standard Chartered'
],
'uob' => [
'code' => 'uob',
'name' => 'United Overseas Bank'
],
];
}

/**
Expand All @@ -73,7 +142,7 @@ public function payment_fields()
parent::payment_fields();
Omise_Util::render_view(
'templates/payment/form-duitnow-obw.php',
[ 'duitnow_obw_banklist' => !$this->backend ? $this->backend->banks : [] ]
[ 'duitnow_obw_banklist' => $this->get_bank_list() ]
);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/includes/blocks/gateways/traits/mock-gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public function get_view_data() {
'currency' => 'thb',
];
}

public function get_bank_list() {
return [
'bank1',
'bank2',
];
}
};

$gateway->backend = new class {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@

class Omise_Payment_DuitNow_OBW_Test extends Omise_Offsite_Test
{
private $omise_capability_mock;

public function setUp(): void
{
$this->sourceType = 'duitnow_obw';
parent::setUp();
Monkey\Functions\expect('add_action');
$this->omise_capability_mock = Mockery::mock('alias:Omise_Capabilities');
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-duitnow-obw.php';
}

Expand All @@ -25,9 +22,89 @@ function sanitize_text_field() {
}
}

$this->omise_capability_mock->shouldReceive('retrieve')->once();
$_POST['source'] = ['bank' => 'SCB'];
$obj = new Omise_Payment_DuitNow_OBW();
$this->getChargeTest($obj);
}

public function testGetBankList()
{
$expected = [
'affin' => [
'code' => 'affin',
'name' => 'Affin Bank'
],
'alliance' => [
'code' => 'alliance',
'name' => 'Alliance Bank'
],
'agro' => [
'code' => 'agro',
'name' => 'Agrobank'
],
'ambank' => [
'code' => 'ambank',
'name' => 'AmBank'
],
'cimb' => [
'code' => 'cimb',
'name' => 'CIMB Bank'
],
'islam' => [
'code' => 'islam',
'name' => 'Bank Islam'
],
'rakyat' => [
'code' => 'rakyat',
'name' => 'Bank Rakyat'
],
'muamalat' => [
'code' => 'muamalat',
'name' => 'Bank Muamalat'
],
'bsn' => [
'code' => 'bsn',
'name' => 'Bank Simpanan Nasional'
],
'hongleong' => [
'code' => 'hongleong',
'name' => 'Hong Leong'
],
'hsbc' => [
'code' => 'hsbc',
'name' => 'HSBC Bank'
],
'kfh' => [
'code' => 'kfh',
'name' => 'Kuwait Finance House'
],
'maybank2u' => [
'code' => 'maybank2u',
'name' => 'Maybank'
],
'ocbc' => [
'code' => 'ocbc',
'name' => 'OCBC'
],
'public' => [
'code' => 'public',
'name' => 'Public Bank'
],
'rhb' => [
'code' => 'rhb',
'name' => 'RHB Bank'
],
'sc' => [
'code' => 'sc',
'name' => 'Standard Chartered'
],
'uob' => [
'code' => 'uob',
'name' => 'United Overseas Bank'
],
];
$obj = new Omise_Payment_DuitNow_OBW();
$bankList = $obj->get_bank_list();
$this->assertEquals($expected, $bankList);
}
}

0 comments on commit e60ca98

Please sign in to comment.