-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #402 from omise/release-v5.4.0
Release v5.4.0
- Loading branch information
Showing
8 changed files
with
220 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
defined( 'ABSPATH' ) or die( 'No direct script access allowed.' ); | ||
|
||
class Omise_Payment_OCBC_Digital extends Omise_Payment_Offsite { | ||
public function __construct() { | ||
parent::__construct(); | ||
|
||
$this->id = 'omise_ocbc'; | ||
$this->has_fields = false; | ||
$this->method_title = __( 'Opn Payments OCBC Digital', 'omise' ); | ||
$this->method_description = __( 'Accept payment through <strong>OCBC Digital</strong> via Opn Payments payment gateway.', 'omise' ); | ||
$this->supports = [ 'products', 'refunds' ]; | ||
|
||
$this->init_form_fields(); | ||
$this->init_settings(); | ||
|
||
$this->title = $this->get_option( 'title' ); | ||
$this->description = $this->get_option( 'description' ); | ||
$this->restricted_countries = [ 'SG' ]; | ||
$this->source_type = 'mobile_banking_ocbc'; | ||
|
||
add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' ); | ||
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] ); | ||
add_action( 'woocommerce_order_action_' . $this->id . '_sync_payment', [ $this, 'sync_payment' ] ); | ||
} | ||
|
||
/** | ||
* @see WC_Settings_API::init_form_fields() | ||
* @see woocommerce/includes/abstracts/abstract-wc-settings-api.php | ||
*/ | ||
public function init_form_fields() { | ||
$this->form_fields = [ | ||
'enabled' => [ | ||
'title' => __( 'Enable/Disable', 'omise' ), | ||
'type' => 'checkbox', | ||
'label' => __( 'Enable Opn Payments OCBC Digital', 'omise' ), | ||
'default' => 'no' | ||
], | ||
|
||
'title' => [ | ||
'title' => __( 'Title', 'omise' ), | ||
'type' => 'text', | ||
'description' => __( 'This controls the title the user sees during checkout.', 'omise' ), | ||
'default' => __( 'OCBC Digital', 'omise' ), | ||
], | ||
|
||
'description' => [ | ||
'title' => __( 'Description', 'omise' ), | ||
'type' => 'textarea', | ||
'description' => __( 'This controls the description the user sees during checkout.', 'omise' ) | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function charge($order_id, $order) | ||
{ | ||
return OmiseCharge::create($this->get_charge_request($order_id, $order)); | ||
} | ||
|
||
/** | ||
* @order_id integer | ||
* @order object | ||
*/ | ||
public function get_charge_request($order_id, $order) | ||
{ | ||
$currency = $order->get_currency(); | ||
|
||
return [ | ||
'amount' => Omise_Money::to_subunit($order->get_total(), $currency), | ||
'currency' => $currency, | ||
'description' => apply_filters('omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order), | ||
'source' => [ | ||
'type' => $this->source_type, | ||
'platform_type' => Omise_Util::get_platform_type( wc_get_user_agent() ) | ||
], | ||
'return_uri' => $this->getRedirectUrl("{$this->id}_callback", $order_id, $order), | ||
'metadata' => $this->getMetadata($order_id, $order) | ||
]; | ||
} | ||
|
||
/** | ||
* Get icons | ||
* | ||
* @see WC_Payment_Gateway::get_icon() | ||
*/ | ||
public function get_icon() | ||
{ | ||
$icon = Omise_Image::get_image([ | ||
'file' => 'ocbc-digital.png', | ||
'alternate_text' => 'OCBC Digital', | ||
'width' => 60, | ||
]); | ||
return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/class-omise-offsite-test.php'; | ||
|
||
class Omise_Payment_OCBC_Digital_Test extends Offsite_Test | ||
{ | ||
private $obj; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-ocbc-digital.php'; | ||
require_once __DIR__ . '/../../../../includes/classes/class-omise-image.php'; | ||
$this->obj = new Omise_Payment_OCBC_Digital(); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
// destroy object and clear memory | ||
unset($this->obj); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function restrictedCountriesHasRequiredCountries() | ||
{ | ||
$expectedCountries = ['SG']; | ||
$this->assertEqualsCanonicalizing($expectedCountries, $this->obj->restricted_countries); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function sourceTypeIsCorrect() | ||
{ | ||
$this->assertEquals('mobile_banking_ocbc', $this->obj->source_type); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function methodTitleIsCorrect() | ||
{ | ||
$this->assertEquals('Opn Payments OCBC Digital', $this->obj->method_title); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function supportsIsCorrect() | ||
{ | ||
$this->assertEqualsCanonicalizing([ 'products', 'refunds' ], $this->obj->supports); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getIconReturnsCorrectImageLink() | ||
{ | ||
// mocking WP built-in functions | ||
if (!function_exists('plugins_url')) { | ||
function plugins_url() { | ||
return "http://localhost"; | ||
} | ||
} | ||
|
||
if (!function_exists('apply_filters')) { | ||
function apply_filters() { | ||
return "http://localhost/image.png"; | ||
} | ||
} | ||
|
||
$result = $this->obj->get_icon(); | ||
|
||
$this->assertEquals("http://localhost/image.png", $result); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getChargeRequestReturnsCorrectData() | ||
{ | ||
// Create a mock of the $order object | ||
$orderMock = Mockery::mock('WC_Order'); | ||
$expectedCurrency = 'SGD'; | ||
$expectedAmount = 1000000; // in subunits | ||
|
||
// Define expectations for the mock | ||
$orderMock->shouldReceive('get_currency') | ||
->andReturn($expectedCurrency); | ||
$orderMock->shouldReceive('get_total') | ||
->andReturn($expectedAmount/100); // in units | ||
|
||
if (!function_exists('wc_get_user_agent')) { | ||
function wc_get_user_agent() { | ||
return "Chrome Web"; | ||
} | ||
} | ||
|
||
$expectedSourceType = 'mobile_banking_ocbc'; | ||
$order_id = "123"; | ||
$result = $this->obj->get_charge_request($order_id, $orderMock); | ||
$this->assertEquals($expectedAmount, $result['amount']); | ||
$this->assertEquals($expectedCurrency, $result['currency']); | ||
$this->assertEquals($expectedSourceType, $result['source']['type']); | ||
} | ||
} |