Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Citi, Maybank (EzyPay), TTB, UOB installments #236

Merged
merged 3 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions assets/css/omise-css.css
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ ul.omise-banks-list {
border-color: #1e4598;
}

/** Citi **/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why we have these comments as the class names are pretty clear 😅 , but let's keep them to be consistent

.bank-logo.citi {
background: url('../images/citi.svg') #0b689d;
border-color: #0b689d;
}

/** First Choice **/
.bank-logo.first_choice {
background: url('../images/firstchoice.svg') #007bc4;
Expand All @@ -309,8 +315,8 @@ ul.omise-banks-list {

/** KBANK **/
.bank-logo.kbank {
background: url('../images/kbank.svg') #ffffff;
border-color: #ffffff;
background: url('../images/kbank.svg') #fbfbfb;
border-color: #fbfbfb;
}

/** KTB **/
Expand All @@ -321,8 +327,8 @@ ul.omise-banks-list {

/** KTC **/
.bank-logo.ktc {
background: url('../images/ktc.svg') #ffffff;
border-color: #ffffff;
background: url('../images/ktc.svg') #fbfbfb;
border-color: #fbfbfb;
}

/** SCB **/
Expand All @@ -331,6 +337,24 @@ ul.omise-banks-list {
border-color: #4e2e7f;
}

/** TTB **/
.bank-logo.ttb {
background: url('../images/ttb.svg') #fbfbfb;
border-color: #fbfbfb;
}

/** UOB **/
.bank-logo.uob {
background: url('../images/uob.svg') #05377c;
border-color: #05377c;
}

/** MAYBANK **/
.bank-logo.ezypay {
background: url('../images/maybank.svg') #ffcf00;
border-color: #ffcf00;
}

/**
fpx bank logos
**/
Expand Down
7 changes: 7 additions & 0 deletions assets/images/citi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/images/maybank.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/images/ttb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions assets/images/uob.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 36 additions & 5 deletions includes/backends/class-omise-backend-installment.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
/**
* Note: all calculations in this class are based only on Thailand VAT and fee
* as currently Installment feature supported only for merchants
* that have registered with Omise Thailand account.
* Note: The calculations in this class depend on the countries that
* the available installment payments are based on.
*
* @since 3.4
*
Expand Down Expand Up @@ -60,6 +59,34 @@ public function initiate() {
'interest_rate' => 0.74,
'min_allowed_amount' => 500.00,
),

'installment_citi' => array(
'bank_code' => 'citi',
'title' => __( 'Citibank', 'omise' ),
'interest_rate' => 0,
'min_allowed_amount' => 500.00,
),

'installment_ttb' => array(
'bank_code' => 'ttb',
'title' => __( 'TMBThanachart Bank', 'omise' ),
'interest_rate' => 0,
'min_allowed_amount' => 500.00,
),

'installment_uob' => array(
'bank_code' => 'uob',
'title' => __( 'United Overseas Bank', 'omise' ),
'interest_rate' => 0,
'min_allowed_amount' => 500.00,
),

'installment_ezypay' => array(
'bank_code' => 'ezypay',
'title' => __( 'Maybank (EzyPay)', 'omise' ),
'interest_rate' => 0,
'min_allowed_amount' => 500.00,
),
);
}

Expand All @@ -70,8 +97,8 @@ public function initiate() {
* @return array of an available installment providers
*/
public function get_available_providers( $currency, $purchase_amount ) {
// Note: as installment payment at the moment only supports for THB currency, so the
// $purchase_amount is multiplied with 100 to convert the amount into subunit (satang).
// Note: As installment payment at the moment only supports THB and MYR currency, the
// $purchase_amount is multiplied with 100 to convert the amount into subunit (satang and sen).
$providers = $this->capabilities()->getInstallmentBackends( $currency, ( $purchase_amount * 100 ) );

foreach ( $providers as &$provider ) {
Expand All @@ -88,6 +115,10 @@ public function get_available_providers( $currency, $purchase_amount ) {
);
}

usort( $providers, function( $a, $b ) {
return strcmp( $a->provider_name, $b->provider_name );
});

return $providers;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/gateway/class-omise-payment-installment.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct() {

$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->restricted_countries = array( 'TH' );
$this->restricted_countries = array( 'TH', 'MY' );

$this->backend = new Omise_Backend_Installment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ public function get_only_valid_plans_from_given_bbl_unsorted_allowed_installment
), $result );
}

/**
* @test
*/
public function get_only_valid_plans_from_zero_interest_installments() {
$installment_backend = new Omise_Backend_Installment();
$purchase_amount = 2000.00;
$allowed_terms = array( 3, 4, 5 );
$interest_rate = 0;
$min_allowed_amount = 500.00;

$result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount );

$this->assertEquals( 2, count( $result ) );
$this->assertEquals( array(
array( 'term_length' => 3, 'monthly_amount' => 666.67 ),
array( 'term_length' => 4, 'monthly_amount' => 500.00 ),
), $result );
}

/**
* @test
*/
Expand Down