Changeset 3361458
- Timestamp:
- 09/15/2025 03:13:55 AM (7 months ago)
- Location:
- omise
- Files:
-
- 6 added
- 36 edited
- 1 copied
-
tags/6.3.0 (copied) (copied from omise/trunk)
-
tags/6.3.0/CHANGELOG.md (modified) (1 diff)
-
tags/6.3.0/assets/javascripts/omise-payment-atome.js (modified) (2 diffs)
-
tags/6.3.0/assets/javascripts/omise-payment-form-handler.js (modified) (2 diffs)
-
tags/6.3.0/includes/gateway/abstract-omise-payment-offsite.php (modified) (1 diff)
-
tags/6.3.0/includes/gateway/class-omise-payment-atome.php (modified) (2 diffs)
-
tags/6.3.0/includes/gateway/class-omise-payment-installment.php (modified) (1 diff)
-
tags/6.3.0/includes/gateway/class-omise-payment.php (modified) (1 diff)
-
tags/6.3.0/omise-woocommerce.php (modified) (2 diffs)
-
tags/6.3.0/phpunit.xml (modified) (1 diff)
-
tags/6.3.0/readme.txt (modified) (2 diffs)
-
tags/6.3.0/tests/unit/bootstrap.php (added)
-
tags/6.3.0/tests/unit/class-omise-test-case.php (added)
-
tags/6.3.0/tests/unit/class-omise-unit-test.php (modified) (2 diffs)
-
tags/6.3.0/tests/unit/includes/gateway/abstract-omise-payment-offsite-test.php (added)
-
tags/6.3.0/tests/unit/includes/gateway/bootstrap-test-setup.php (modified) (5 diffs)
-
tags/6.3.0/tests/unit/includes/gateway/class-omise-offsite-test.php (modified) (1 diff)
-
tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-atome-test.php (modified) (1 diff)
-
tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php (modified) (1 diff)
-
tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-googlepay-test.php (modified) (1 diff)
-
tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-installment-test.php (modified) (5 diffs)
-
tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php (modified) (3 diffs)
-
trunk/CHANGELOG.md (modified) (1 diff)
-
trunk/assets/javascripts/omise-payment-atome.js (modified) (2 diffs)
-
trunk/assets/javascripts/omise-payment-form-handler.js (modified) (2 diffs)
-
trunk/includes/gateway/abstract-omise-payment-offsite.php (modified) (1 diff)
-
trunk/includes/gateway/class-omise-payment-atome.php (modified) (2 diffs)
-
trunk/includes/gateway/class-omise-payment-installment.php (modified) (1 diff)
-
trunk/includes/gateway/class-omise-payment.php (modified) (1 diff)
-
trunk/omise-woocommerce.php (modified) (2 diffs)
-
trunk/phpunit.xml (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/tests/unit/bootstrap.php (added)
-
trunk/tests/unit/class-omise-test-case.php (added)
-
trunk/tests/unit/class-omise-unit-test.php (modified) (2 diffs)
-
trunk/tests/unit/includes/gateway/abstract-omise-payment-offsite-test.php (added)
-
trunk/tests/unit/includes/gateway/bootstrap-test-setup.php (modified) (5 diffs)
-
trunk/tests/unit/includes/gateway/class-omise-offsite-test.php (modified) (1 diff)
-
trunk/tests/unit/includes/gateway/class-omise-payment-atome-test.php (modified) (1 diff)
-
trunk/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php (modified) (1 diff)
-
trunk/tests/unit/includes/gateway/class-omise-payment-googlepay-test.php (modified) (1 diff)
-
trunk/tests/unit/includes/gateway/class-omise-payment-installment-test.php (modified) (5 diffs)
-
trunk/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
omise/tags/6.3.0/CHANGELOG.md
r3331857 r3361458 1 1 # CHANGELOG 2 3 ## [v6.3.0 _(Sep 3, 2025)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.3.0) 4 5 - Fix WLB installment order description. (PR: [#534](https://github.com/omise/omise-woocommerce/issues/534)) 6 - Fix payment form on Pay for Order page. (PR: [#533](https://github.com/omise/omise-woocommerce/issues/533)) 2 7 3 8 ## [v6.2.2 _(Jul 22, 2025)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.2.2) -
omise/tags/6.3.0/assets/javascripts/omise-payment-atome.js
r2912289 r3361458 39 39 40 40 const phoneNumber = $('#omise_atome_phone_number').val(); 41 41 42 42 if (!phoneNumber) { 43 43 return omiseHandleError('Phone number is required in Atome'); … … 56 56 57 57 $(function () { 58 $('form.checkout ').on('checkout_place_order', function (e) {58 $('form.checkout, form#order_review').on('checkout_place_order', function () { 59 59 return omiseFormHandler(); 60 60 }); -
omise/tags/6.3.0/assets/javascripts/omise-payment-form-handler.js
r3192967 r3361458 1 1 (function ($) { 2 2 const $form = $('form.checkout, form#order_review'); 3 const $formCheckout = $('form.checkout'); // Form in Normal Checkout Page 4 const $formOrderReview = $('form#order_review'); // Form in Pay for Order Page 3 5 4 6 function hideError() { … … 276 278 }); 277 279 278 $( 'form.checkout').unbind('checkout_place_order_omise');279 $( 'form.checkout').on('checkout_place_order_omise', function () {280 $($formCheckout).unbind('checkout_place_order_omise'); 281 $($formCheckout).on('checkout_place_order_omise', function () { 280 282 return omiseFormHandler(); 281 283 }); 282 $( 'form.checkout').unbind('checkout_place_order_omise_installment');283 $( 'form.checkout').on('checkout_place_order_omise_installment', function () {284 $($formCheckout).unbind('checkout_place_order_omise_installment'); 285 $($formCheckout).on('checkout_place_order_omise_installment', function () { 284 286 return omiseInstallmentFormHandler(); 285 287 }); 286 288 287 /* Pay Page Form */ 288 $('form#order_review').on('submit', function () { 289 return omiseFormHandler(); 289 /* Pay for Order Page Form */ 290 $($formOrderReview).on('submit', function () { 291 var selectedPaymentMethod = $('input[name="payment_method"]:checked').val(); 292 293 switch (selectedPaymentMethod) { 294 case 'omise': 295 return omiseFormHandler(); 296 case 'omise_installment': 297 return omiseInstallmentFormHandler(); 298 } 290 299 }); 291 300 292 301 /* Both Forms */ 293 $( 'form.checkout, form#order_review').on('change', '#omise_cc_form input', function() {302 $($form).on('change', '#omise_cc_form input', function() { 294 303 $('.omise_token').remove(); 295 304 $('.omise_source').remove(); 296 305 }); 297 306 298 $( 'form.checkout').on('change', 'input[name="payment_method"]', function() {307 $($form).on('change', 'input[name="payment_method"]', function() { 299 308 setupOmiseForm(); 300 309 }); -
omise/tags/6.3.0/includes/gateway/abstract-omise-payment-offsite.php
r3308831 r3361458 10 10 { 11 11 use Charge_Request_Builder; 12 13 /** 14 * @inheritdoc 15 */ 16 public function payment_fields() { 17 parent::payment_fields(); 18 } 12 19 13 20 /** -
omise/tags/6.3.0/includes/gateway/class-omise-payment-atome.php
r3256918 r3361458 103 103 ]; 104 104 105 $currency = strtolower(get_woocommerce_currency());106 105 $cart = WC()->cart; 107 108 if ($cart->subtotal === 0) { 109 return [ 110 'status' => false, 111 'message' => 'Complimentary products cannot be billed.' 112 ]; 113 } 114 115 if (!isset($limits[$currency])) { 116 return [ 117 'status' => false, 118 'message' => 'Currency not supported' 119 ]; 120 } 121 122 $limit = $limits[$currency]; 123 124 if ($cart->total < $limit['min']) { 106 $cart_subtotal = $cart->subtotal; 107 $cart_total = $cart->total; 108 $cart_currency = strtolower( get_woocommerce_currency() ); 109 110 // For Pay for Order Page 111 if ( is_checkout_pay_page() ) { 112 $order_id = get_query_var('order-pay'); 113 $order = wc_get_order( $order_id ); 114 if ( ! $order ) { 115 throw new Exception( 'Order not found.' ); 116 } 117 118 $cart_subtotal = $order->get_subtotal(); 119 $cart_total = $order->get_total(); 120 $cart_currency = strtolower( $order->get_currency() ); 121 } 122 123 if ( $cart_subtotal === 0 ) { 124 return [ 125 'status' => false, 126 'message' => 'Complimentary products cannot be billed.', 127 ]; 128 } 129 130 if ( ! isset( $limits[ $cart_currency ] ) ) { 131 return [ 132 'status' => false, 133 'message' => 'Currency not supported', 134 ]; 135 } 136 137 $limit = $limits[ $cart_currency ]; 138 139 if ( $cart_total < $limit['min'] ) { 125 140 return [ 126 141 'status' => false, 127 142 'message' => sprintf( 128 "Amount must be greater than %u %s",129 number_format( $limit['min'], 2),130 strtoupper($c urrency)131 ) 132 ]; 133 } 134 135 if ( $cart->total > $limit['max']) {136 return [ 137 'status' => false, 138 'message' => __(139 'Amount must be less than % 1 %2',140 number_format( $limit['max'], 2),141 strtoupper( $currency)142 ) 143 ]; 144 } 145 146 return [ 'status' => true];143 'Amount must be greater than %s %s', 144 number_format( $limit['min'], 2 ), 145 strtoupper($cart_currency), 146 ), 147 ]; 148 } 149 150 if ( $cart_total > $limit['max'] ) { 151 return [ 152 'status' => false, 153 'message' => sprintf( 154 'Amount must be less than %s %s', 155 number_format( $limit['max'], 2 ), 156 strtoupper( $cart_currency ), 157 ), 158 ]; 159 } 160 161 return [ 'status' => true ]; 147 162 } 148 163 … … 164 179 $this->id . "_callback" 165 180 ); 166 181 167 182 $default_phone_selected = isset($_POST['omise_atome_phone_default']) ? 168 183 $_POST['omise_atome_phone_default'] -
omise/tags/6.3.0/includes/gateway/class-omise-payment-installment.php
r3308831 r3361458 130 130 $this->id . "_callback" 131 131 ); 132 $requestData['description'] = 'staging';133 132 $requestData['source'] = isset($_POST['omise_source']) ? wc_clean($_POST['omise_source']) : ''; 134 133 $requestData['card'] = isset($_POST['omise_token']) ? wc_clean($_POST['omise_token']) : ''; 134 135 $custom_wlb_desc = getenv('OMISE_CUSTOM_WLB_ORDER_DESC'); 136 if (!empty($custom_wlb_desc) && !empty($requestData['card'])) { 137 $custom_wlb_desc = sanitize_text_field($custom_wlb_desc); 138 $requestData['description'] = str_replace('{description}', $requestData['description'], $custom_wlb_desc); 139 } 140 135 141 return OmiseCharge::create($requestData); 136 142 } -
omise/tags/6.3.0/includes/gateway/class-omise-payment.php
r3308831 r3361458 114 114 add_filter( 'woocommerce_email_recipient_new_order', 'OmisePluginHelperMailer::disable_merchant_order_on_hold', 10, 2 ); 115 115 add_filter('is_protected_meta', [ $this, 'protectMetadata'], 10, 2); 116 } 117 118 /** 119 * Displayed payment fields. 120 */ 121 public function payment_fields() { 122 parent::payment_fields(); 116 123 } 117 124 -
omise/tags/6.3.0/omise-woocommerce.php
r3331857 r3361458 5 5 * Plugin URI: https://www.omise.co/woocommerce 6 6 * Description: Omise Payments is a WordPress plugin designed specifically for WooCommerce. The plugin adds support for Omise Payment Gateway's payment methods to WooCommerce. 7 * Version: 6. 2.27 * Version: 6.3.0 8 8 * Author: Omise and contributors 9 9 * Author URI: https://github.com/omise/omise-woocommerce/graphs/contributors … … 24 24 * @var string 25 25 */ 26 public $version = '6. 2.2';26 public $version = '6.3.0'; 27 27 28 28 /** -
omise/tags/6.3.0/phpunit.xml
r3308831 r3361458 4 4 backupGlobals="true" 5 5 backupStaticAttributes="false" 6 bootstrap="tests/unit/bootstrap.php" 6 7 colors="true" 7 8 stopOnError="false" -
omise/tags/6.3.0/readme.txt
r3331857 r3361458 4 4 Requires at least: 4.3.1 5 5 Tested up to: 6.8.1 6 Stable tag: 6. 2.26 Stable tag: 6.3.0 7 7 License: MIT 8 8 License URI: https://opensource.org/licenses/MIT … … 34 34 35 35 == Changelog == 36 37 = 6.3.0 = 38 39 - Fix WLB installment order description. (PR: [#534](https://github.com/omise/omise-woocommerce/issues/534)) 40 - Fix payment form on Pay for Order page. (PR: [#533](https://github.com/omise/omise-woocommerce/issues/533)) 36 41 37 42 = 6.2.2 = -
omise/tags/6.3.0/tests/unit/class-omise-unit-test.php
r3312403 r3361458 1 1 <?php 2 3 define( 'ABSPATH', value: '' );4 define( 'OMISE_PUBLIC_KEY', 'pkey_test_12345');5 define( 'OMISE_SECRET_KEY', 'skey_test_12345');6 2 7 3 class Omise_Unit_Test { … … 31 27 } 32 28 29 /** 30 * Mock WordPress _e() function. 31 * 32 * @see wp-includes/l10n.php 33 * @see https://developer.wordpress.org/reference/functions/_e 34 */ 35 function _e( $text, $context, $domain = 'default' ) { 36 echo $text; 37 } 38 33 39 function load_fixture($name) { 34 40 return file_get_contents(__DIR__ . "/../fixtures/{$name}.json"); -
omise/tags/6.3.0/tests/unit/includes/gateway/bootstrap-test-setup.php
r3331857 r3361458 1 1 <?php 2 3 use PHPUnit\Framework\TestCase; 4 use Brain\Monkey; 5 use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; 6 7 /** 8 * Mock abstract WooCommerce's gateway 9 */ 10 abstract class WC_Payment_Gateway 2 abstract class Bootstrap_Test_Setup extends Omise_Test_Case 11 3 { 12 public static $is_available = true; 13 14 public function is_available() 15 { 16 return self::$is_available; 17 } 18 } 19 20 /** 21 * Temporary mock for WP_* class 22 * In the future, we should move to use WP_UnitTestCase 23 */ 24 class WP_Error 25 { 26 public function __construct( 27 public $code = '', 28 public $message = '', 29 public $data = '' 30 ) { 31 } 32 } 33 class WP_REST_Server_Stub 34 { 35 const EDITABLE = 'POST'; 36 const READABLE = 'GET'; 37 } 38 39 abstract class Bootstrap_Test_Setup extends TestCase 40 { 41 // Adds Mockery expectations to the PHPUnit assertions count. 42 use MockeryPHPUnitIntegration; 43 44 public $sourceType; 45 46 protected function setUp(): void 47 { 48 parent::setUp(); 49 Monkey\setUp(); 50 } 51 52 /** 53 * close mockery after tests are done 54 */ 55 protected function tearDown(): void 56 { 57 Monkey\tearDown(); 58 Mockery::close(); 59 parent::tearDown(); 60 } 61 62 public function getOrderMock($expectedAmount, $expectedCurrency) 4 public function getOrderMock($expectedAmount, $expectedCurrency, $properties = []) 63 5 { 64 6 // Create a mock of the $order object … … 66 8 67 9 // Define expectations for the mock 10 $orderMock->allows([ 11 'get_id' => $properties['id'] ?? 123, 12 'get_order_key' => $properties['key'] ?? 'order_kfeERDv', 13 ]); 68 14 $orderMock->shouldReceive('get_currency') 69 ->andReturn( $expectedCurrency);15 ->andReturn(strtoupper($expectedCurrency)); 70 16 $orderMock->shouldReceive('get_total') 71 17 ->andReturn($expectedAmount); // in units … … 94 40 } 95 41 42 public function getCartMock($cartProperties = []) { 43 $cart = Mockery::mock('WC_Cart'); 44 $cart->subtotal = $cartProperties['subtotal'] ?? 0; 45 $cart->total = $cartProperties['total'] ?? 0; 46 47 return $cart; 48 } 49 50 public function getWcMock($cart = null) { 51 $wc = Mockery::mock('WooCommerce'); 52 $wc->cart = $cart ? $cart : $this->getCartMock(); 53 54 return $wc; 55 } 56 96 57 /** 58 * FIXME: Only used in Omise_Payment_Konbini_Test. 59 * We can refactor this into offline payment test class or the test itself. 97 60 * @runInSeparateProcess 98 61 */ … … 142 105 'public_key' => $pkey, 143 106 'secret_key' => $skey, 107 'is_dynamic_webhook_enabled' => false, 144 108 ]); 145 109 $omiseSettingMock->shouldReceive('get_settings')->andReturn([])->byDefault(); … … 185 149 } 186 150 } 151 152 protected function mockRedirectUrl($redirectUrl = 'https://abc.com/order/complete') { 153 $redirectUrlMock = Mockery::mock('alias:RedirectUrl'); 154 $redirectUrlMock->shouldReceive('create')->andReturn($redirectUrl); 155 $redirectUrlMock->shouldReceive('getToken')->andReturn('token123'); 156 157 return $redirectUrlMock; 158 } 187 159 } 188 160 -
omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-offsite-test.php
r3308831 r3361458 5 5 use Brain\Monkey; 6 6 7 /** 8 * @deprecated Please use Omise_Payment_Offsite_Test instead. 9 */ 7 10 abstract class Omise_Offsite_Test extends Bootstrap_Test_Setup 8 11 { -
omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-atome-test.php
r3312403 r3361458 1 1 <?php 2 2 3 require_once __DIR__ . '/class-omise-offsite-test.php';4 5 3 use Brain\Monkey; 6 7 class Omise_Payment_Atome_Test extends Omise_Offsite_Test 8 { 9 protected function setUp(): void 10 { 11 $this->sourceType = 'atome'; 12 parent::setUp(); 13 require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-atome.php'; 14 15 Monkey\Functions\expect('wp_enqueue_script'); 16 Monkey\Functions\expect('wp_kses'); 17 Monkey\Functions\expect('plugins_url'); 18 Monkey\Functions\expect('add_action'); 19 20 // dummy version 21 if (!defined('WC_VERSION')) { 22 define('WC_VERSION', '1.0.0'); 23 } 24 } 25 26 public function testGetChargeRequest() 27 { 28 $expectedAmount = 999999; 29 $expectedCurrency = 'thb'; 30 $orderId = 'order_123'; 31 $orderMock = $this->getOrderMock($expectedAmount, $expectedCurrency); 32 33 $wcProduct = Mockery::mock('overload:WC_Product'); 34 $wcProduct->shouldReceive('get_sku') 35 ->once() 36 ->andReturn('sku_1234'); 37 38 $_POST['omise_atome_phone_default'] = true; 39 40 $obj = new Omise_Payment_Atome(); 41 $result = $obj->get_charge_request($orderId, $orderMock); 42 43 $this->assertEquals($this->sourceType, $result['source']['type']); 44 } 45 46 public function testCharge() 47 { 48 $_POST['omise_atome_phone_default'] = true; 49 $obj = new Omise_Payment_Atome(); 50 $this->getChargeTest($obj); 51 } 4 use voku\helper\HtmlDomParser; 5 6 /** 7 * @runTestsInSeparateProcesses 8 */ 9 class Omise_Payment_Atome_Test extends Omise_Payment_Offsite_Test { 10 11 private $omise_atome; 12 13 protected function setUp(): void { 14 parent::setUp(); 15 16 $this->omise_atome = $this->mock_payment_class( Omise_Payment_Atome::class ); 17 } 18 19 public function test_atome_get_charge_request() { 20 $order_amount = 4566; 21 $order_currency = 'THB'; 22 $order_id = 'order_123'; 23 $order_mock = $this->getOrderMock( $order_amount, $order_currency ); 24 25 $wc_product = Mockery::mock( 'overload:WC_Product' ); 26 $wc_product->shouldReceive( 'get_sku' ) 27 ->once() 28 ->andReturn( 'sku_1234' ); 29 30 $_POST['omise_atome_phone_default'] = true; 31 32 $result = $this->omise_atome->get_charge_request( $order_id, $order_mock ); 33 34 $this->assertEquals( 456600, $result['amount'] ); 35 $this->assertEquals( $order_currency, $result['currency'] ); 36 $this->assertEquals( $order_id, $result['metadata']['order_id'] ); 37 $this->assertEquals( $this->return_uri, $result['return_uri'] ); 38 39 $expected_source = [ 40 'type' => 'atome', 41 'phone_number' => $order_mock->get_billing_phone(), 42 'items' => [ 43 [ 44 'name' => 'T Shirt', 45 'amount' => 60000, 46 'quantity' => 1, 47 'sku' => 'sku_1234', 48 ], 49 ], 50 'shipping' => [ 51 'country' => 'Thailand', 52 'city' => 'Bangkok', 53 'postal_code' => '10110', 54 'state' => 'Bangkok', 55 'street1' => 'Sukumvit Road', 56 ], 57 ]; 58 $this->assertEquals( $expected_source, $result['source'] ); 59 } 60 61 public function test_atome_get_charge_request_with_custom_phone_number() { 62 $order_amount = 4566; 63 $order_currency = 'THB'; 64 $order_id = 'order_123'; 65 $order_mock = $this->getOrderMock( $order_amount, $order_currency ); 66 67 $wc_product = Mockery::mock( 'overload:WC_Product' ); 68 $wc_product->shouldReceive( 'get_sku' ) 69 ->once() 70 ->andReturn( 'sku_1234' ); 71 72 $_POST['omise_atome_phone_default'] = false; 73 $_POST['omise_atome_phone_number'] = '+66123456789'; 74 75 $result = $this->omise_atome->get_charge_request( $order_id, $order_mock ); 76 77 $this->assertEquals( 456600, $result['amount'] ); 78 $this->assertEquals( $order_currency, $result['currency'] ); 79 $this->assertEquals( 'atome', $result['source']['type'] ); 80 $this->assertEquals( '+66123456789', $result['source']['phone_number'] ); 81 } 82 83 public function test_atome_charge() { 84 $order = $this->getOrderMock( 999999, 'THB' ); 85 $_POST['omise_atome_phone_default'] = true; 86 87 $this->perform_charge_test( $this->omise_atome, $order ); 88 } 89 90 public function test_atome_payment_fields_renders_atome_form_on_checkout_page() { 91 $cart = $this->getCartMock( 92 [ 93 'subtotal' => 300, 94 'total' => 380, 95 ] 96 ); 97 $wc = $this->getWcMock( $cart ); 98 99 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 100 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' ); 101 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 102 103 ob_start(); 104 $this->omise_atome->payment_fields(); 105 $output = ob_get_clean(); 106 107 $page = HtmlDomParser::str_get_html( $output ); 108 $this->assertMatchesRegularExpression( '/Atome phone number/', $page->findOne( '#omise-form-atome' )->innertext ); 109 } 110 111 public function test_atome_payment_fields_renders_atome_form_on_pay_for_order_page() { 112 $wc = $this->getWcMock(); 113 $order_mock = $this->getOrderMock( 380, 'THB' ); 114 $order_mock->shouldReceive( 'get_subtotal' )->andReturn( 300 ); 115 116 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 117 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' ); 118 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( true ); 119 Monkey\Functions\expect( 'get_query_var' )->with( 'order-pay' )->andReturn( 456 ); 120 Monkey\Functions\expect( 'wc_get_order' )->with( 456 )->andReturn( $order_mock ); 121 122 ob_start(); 123 $this->omise_atome->payment_fields(); 124 $output = ob_get_clean(); 125 126 $page = HtmlDomParser::str_get_html( $output ); 127 $this->assertMatchesRegularExpression( '/Atome phone number/', $page->findOne( '#omise-form-atome' )->innertext ); 128 } 129 130 public function test_atome_payment_fields_returns_error_if_subtotal_is_zero() { 131 $cart = $this->getCartMock( 132 [ 133 'subtotal' => 0, 134 'total' => 100, 135 ] 136 ); 137 $wc = $this->getWcMock( $cart ); 138 139 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 140 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' ); 141 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 142 143 ob_start(); 144 $this->omise_atome->payment_fields(); 145 $output = ob_get_clean(); 146 147 $this->assertEquals( 'Complimentary products cannot be billed.', trim( $output ) ); 148 } 149 150 public function test_atome_payment_fields_returns_error_if_currency_not_support() { 151 $cart = $this->getCartMock( 152 [ 153 'subtotal' => 100, 154 'total' => 100, 155 ] 156 ); 157 $wc = $this->getWcMock( $cart ); 158 159 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 160 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'USD' ); 161 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 162 163 ob_start(); 164 $this->omise_atome->payment_fields(); 165 $output = ob_get_clean(); 166 167 $this->assertEquals( 'Currency not supported', trim( $output ) ); 168 } 169 170 public function test_atome_payment_fields_returns_error_if_amount_less_than_min_limit() { 171 $cart = $this->getCartMock( 172 [ 173 'subtotal' => 1.4, 174 'total' => 1.4, 175 ] 176 ); 177 $wc = $this->getWcMock( $cart ); 178 179 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 180 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'SGD' ); 181 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 182 183 ob_start(); 184 $this->omise_atome->payment_fields(); 185 $output = ob_get_clean(); 186 187 $this->assertEquals( 'Amount must be greater than 1.50 SGD', trim( $output ) ); 188 } 189 190 public function test_atome_payment_fields_returns_error_if_amount_greater_than_max_limit() { 191 $cart = $this->getCartMock( 192 [ 193 'subtotal' => 20001, 194 'total' => 20001, 195 ] 196 ); 197 $wc = $this->getWcMock( $cart ); 198 199 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 200 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'SGD' ); 201 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 202 203 ob_start(); 204 $this->omise_atome->payment_fields(); 205 $output = ob_get_clean(); 206 207 $this->assertEquals( 'Amount must be less than 20,000.00 SGD', trim( $output ) ); 208 } 209 210 public function test_atome_payment_fields_throws_exception_if_pay_for_order_not_found() { 211 $wc = $this->getWcMock(); 212 213 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 214 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' ); 215 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( true ); 216 Monkey\Functions\expect( 'get_query_var' )->with( 'order-pay' )->andReturn( 456 ); 217 Monkey\Functions\expect( 'wc_get_order' )->with( 456 )->andReturn( false ); 218 219 $this->expectException( Exception::class ); 220 $this->expectExceptionMessage( 'Order not found.' ); 221 222 $this->omise_atome->payment_fields(); 223 } 52 224 } -
omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php
r3308831 r3361458 33 33 $omiseCardImage->shouldReceive('get_discover_image')->once(); 34 34 $omiseCardImage->shouldReceive('get_discover_default_display')->once(); 35 36 // dummy version37 if (!defined('WC_VERSION')) {38 define('WC_VERSION', '1.0.0');39 }40 35 41 36 Monkey\Functions\expect('add_action')->andReturn(null); -
omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-googlepay-test.php
r3209723 r3361458 17 17 Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb'); 18 18 19 // dummy version20 if (!defined('WC_VERSION')) {21 define('WC_VERSION', '1.0.0');22 }23 24 19 $omisePaymentMock = Mockery::mock('overload:Omise_Payment'); 25 20 $omisePaymentMock->shouldReceive('init_settings'); -
omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-installment-test.php
r3312403 r3361458 6 6 7 7 /** 8 * @run InSeparateProcess8 * @runTestsInSeparateProcesses 9 9 * @preserveGlobalState disabled 10 10 */ 11 12 class Omise_Payment_Installment_Test extends Omise_Offsite_Test 11 class Omise_Payment_Installment_Test extends Omise_Payment_Offsite_Test 13 12 { 14 13 protected $backend_installment_mock; 14 private $installment; 15 15 16 16 protected function setUp(): void 17 17 { 18 $this->sourceType = 'installment_ktc';19 18 parent::setUp(); 20 19 21 Monkey\Functions\expect('wp_kses'); 22 Omise_Unit_Test::include_class('backends/class-omise-backend.php'); 23 Omise_Unit_Test::include_class('backends/class-omise-backend-installment.php'); 24 20 $this->installment = $this->mock_payment_class( Omise_Payment_Installment::class ); 25 21 $this->backend_installment_mock = Mockery::mock('Omise_Backend_Installment'); 26 require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-installment.php';27 22 } 28 23 29 p rotected function tearDown(): void24 public function test_installment_get_total_amount_from_admin_order_page() 30 25 { 31 parent::tearDown();32 }33 34 /**35 * @test36 */37 public function get_total_amount_from_admin_order_page()38 {39 Monkey\Functions\expect('add_action');40 41 26 $order = Mockery::mock('WC_Order'); 42 27 Monkey\Functions\expect('wc_get_order')->andReturn($order); … … 50 35 $GLOBALS['wp'] = $wp; 51 36 52 $installment = new Omise_Payment_Installment(); 53 $total = $installment->get_total_amount(); 37 $total = $this->installment->get_total_amount(); 54 38 55 39 $this->assertEquals($total, 999999); 56 40 } 57 41 58 /** 59 * @test 60 */ 61 public function get_total_amount_from_cart() 42 public function test_installment_get_total_amount_from_cart() 62 43 { 63 Monkey\Functions\expect('add_action');64 65 44 $clazz = new stdClass(); 66 45 $clazz->cart = new stdClass(); … … 69 48 Monkey\Functions\expect('WC')->andReturn($clazz); 70 49 71 $installment = new Omise_Payment_Installment(); 72 $total = $installment->get_total_amount(); 50 $total = $this->installment->get_total_amount(); 73 51 74 52 $this->assertEquals($total, 999999); 75 53 } 76 54 77 public function test_ charge()55 public function test_installment_charge() 78 56 { 79 $this->backend_installment_mock->shouldReceive('get_provider');57 putenv('OMISE_CUSTOM_WLB_ORDER_DESC=test'); 80 58 81 Monkey\Functions\expect('add_action'); 59 $order = $this->getOrderMock(4353, 'THB', [ 'id' => 1293 ]); 60 $_POST['omise_source'] = 'source_test_12345'; 82 61 83 $_POST['source'] = ['type' => $this->sourceType]; 84 $_POST[$this->sourceType . '_installment_terms'] = 3; 62 $test_charge_fn = function ($actual) { 63 return $actual == [ 64 'amount' => 435300, 65 'currency' => 'THB', 66 'description' => 'WooCommerce Order id 1293', 67 'return_uri' => $this->return_uri, 68 'source' => 'source_test_12345', 69 'card' => '', 70 'metadata' => [ 71 'order_id' => 1293, 72 ], 73 ]; 74 }; 85 75 86 $obj = new Omise_Payment_Installment(); 87 $this->getChargeTest($obj); 76 $this->perform_charge_test( $this->installment, $order, $test_charge_fn ); 88 77 } 89 78 90 public function test_get_view_data() 79 public function test_installment_wlb_charge() 80 { 81 putenv('OMISE_CUSTOM_WLB_ORDER_DESC'); 82 83 $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]); 84 $_POST['omise_source'] = 'source_test_12345'; 85 $_POST['omise_token'] = 'tokn_test_67890'; 86 87 $test_charge_fn = function ($actual) { 88 return $actual == [ 89 'amount' => 25050, 90 'currency' => 'THB', 91 'description' => 'WooCommerce Order id 400', 92 'return_uri' => $this->return_uri, 93 'source' => 'source_test_12345', 94 'card' => 'tokn_test_67890', 95 'metadata' => [ 96 'order_id' => 400, 97 ], 98 ]; 99 }; 100 101 $this->perform_charge_test( $this->installment, $order, $test_charge_fn ); 102 } 103 104 public function test_installment_wlb_charge_with_custom_description() 105 { 106 putenv('OMISE_CUSTOM_WLB_ORDER_DESC={description} - test'); 107 108 $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]); 109 $_POST['omise_source'] = 'source_test_12345'; 110 $_POST['omise_token'] = 'tokn_test_67890'; 111 112 $test_charge_fn = function ($actual) { 113 return $actual['description'] == 'WooCommerce Order id 400 - test'; 114 }; 115 116 $this->perform_charge_test( $this->installment, $order, $test_charge_fn ); 117 } 118 119 public function test_installment_wlb_charge_with_custom_description_fully_overridden() 120 { 121 putenv('OMISE_CUSTOM_WLB_ORDER_DESC=My order description'); 122 123 $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]); 124 $_POST['omise_source'] = 'source_test_12345'; 125 $_POST['omise_token'] = 'tokn_test_67890'; 126 127 $test_charge_fn = function ($actual) { 128 return $actual['description'] == 'My order description'; 129 }; 130 131 $this->perform_charge_test( $this->installment, $order, $test_charge_fn ); 132 } 133 134 public function test_installment_get_view_data() 91 135 { 92 136 $capability = Mockery::mock('alias:Omise_Capability'); … … 109 153 Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb'); 110 154 111 $c lazz = new stdClass();112 $ clazz->cart = new stdClass();113 $clazz->cart->total = 999999;155 $cart = $this->getCartMock(['total' => 999999]); 156 $wc = $this->getWcMock($cart); 157 Monkey\Functions\expect('WC')->andReturn($wc); 114 158 115 Monkey\Functions\expect('WC')->andReturn($clazz); 116 Monkey\Functions\expect('add_action'); 117 118 $obj = new Omise_Payment_Installment(); 119 $result = $obj->get_view_data(); 159 $result = $this->installment->get_view_data(); 120 160 121 161 $this->assertArrayHasKey('installments_enabled', $result); … … 124 164 } 125 165 126 public function test GetParamsForJS()166 public function test_installment_get_params_for_js() 127 167 { 128 $c lazz = new stdClass();129 $ clazz->cart = new stdClass();130 $clazz->cart->total = 999999;168 $cart = $this->getCartMock(['total' => 999999]); 169 $wc = $this->getWcMock($cart); 170 Monkey\Functions\expect('WC')->andReturn($wc); 131 171 132 Monkey\Functions\expect('WC')->andReturn($clazz); 133 Monkey\Functions\expect('add_action'); 134 $mock = Mockery::mock('overload:Omise_Payment_Offsite'); 135 $instance = new Omise_Payment_Installment($mock); 136 $result = $instance->getParamsForJS(); 172 $result = $this->installment->getParamsForJS(); 137 173 138 $this->assertIsArray($result); 139 $this->assertArrayHasKey('key', $result); 140 $this->assertArrayHasKey('amount', $result); 141 $this->assertEquals('pkey_test_123', $result['key']); 142 $this->assertEquals(99999900, $result['amount']); 174 $this->assertEquals([ 175 'key' => 'pkey_test_123', 176 'amount' => 99999900, 177 ], $result); 143 178 } 144 179 145 public function test ConvertToCents()180 public function test_installment_convert_to_cents() 146 181 { 147 Monkey\Functions\expect('add_action');148 $instance = new Omise_Payment_Installment(); 182 $instance = $this->installment; 183 149 184 $this->assertEquals(100, $instance->convert_to_cents(1.00)); 150 185 $this->assertEquals(150, $instance->convert_to_cents(1.50)); -
omise/tags/6.3.0/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php
r3182037 r3361458 8 8 public $mockWcDateTime; 9 9 public $mockLocalizeScript; 10 public $mockOmisePluginHelper;11 10 public $mockOmisePaymentOffline; 12 11 public $mockOmiseCharge; … … 23 22 $this->mockLocalizeScript = Mockery::mock(); 24 23 $this->mockWcDateTime = Mockery::mock('overload:WC_DateTime'); 25 $this->mockOmisePluginHelper = Mockery::mock('overload:OmisePluginHelperWcOrder')->shouldIgnoreMissing();26 24 $this->mockOmisePaymentOffline = Mockery::mock('overload:Omise_Payment_Offline'); 27 25 $this->mockOmiseCharge = Mockery::mock('overload:OmiseCharge'); … … 79 77 } 80 78 79 Monkey\Functions\when('wc_get_order')->justReturn($this->mockOrder); 80 $this->mockOrder->shouldReceive('get_order_key') 81 ->once() 82 ->andReturn('wc_order_12345'); 83 81 84 $obj = new Omise_Payment_Promptpay(); 82 85 $result = $obj->display_qrcode($this->mockOrder, 'view'); -
omise/trunk/CHANGELOG.md
r3331857 r3361458 1 1 # CHANGELOG 2 3 ## [v6.3.0 _(Sep 3, 2025)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.3.0) 4 5 - Fix WLB installment order description. (PR: [#534](https://github.com/omise/omise-woocommerce/issues/534)) 6 - Fix payment form on Pay for Order page. (PR: [#533](https://github.com/omise/omise-woocommerce/issues/533)) 2 7 3 8 ## [v6.2.2 _(Jul 22, 2025)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.2.2) -
omise/trunk/assets/javascripts/omise-payment-atome.js
r2912289 r3361458 39 39 40 40 const phoneNumber = $('#omise_atome_phone_number').val(); 41 41 42 42 if (!phoneNumber) { 43 43 return omiseHandleError('Phone number is required in Atome'); … … 56 56 57 57 $(function () { 58 $('form.checkout ').on('checkout_place_order', function (e) {58 $('form.checkout, form#order_review').on('checkout_place_order', function () { 59 59 return omiseFormHandler(); 60 60 }); -
omise/trunk/assets/javascripts/omise-payment-form-handler.js
r3192967 r3361458 1 1 (function ($) { 2 2 const $form = $('form.checkout, form#order_review'); 3 const $formCheckout = $('form.checkout'); // Form in Normal Checkout Page 4 const $formOrderReview = $('form#order_review'); // Form in Pay for Order Page 3 5 4 6 function hideError() { … … 276 278 }); 277 279 278 $( 'form.checkout').unbind('checkout_place_order_omise');279 $( 'form.checkout').on('checkout_place_order_omise', function () {280 $($formCheckout).unbind('checkout_place_order_omise'); 281 $($formCheckout).on('checkout_place_order_omise', function () { 280 282 return omiseFormHandler(); 281 283 }); 282 $( 'form.checkout').unbind('checkout_place_order_omise_installment');283 $( 'form.checkout').on('checkout_place_order_omise_installment', function () {284 $($formCheckout).unbind('checkout_place_order_omise_installment'); 285 $($formCheckout).on('checkout_place_order_omise_installment', function () { 284 286 return omiseInstallmentFormHandler(); 285 287 }); 286 288 287 /* Pay Page Form */ 288 $('form#order_review').on('submit', function () { 289 return omiseFormHandler(); 289 /* Pay for Order Page Form */ 290 $($formOrderReview).on('submit', function () { 291 var selectedPaymentMethod = $('input[name="payment_method"]:checked').val(); 292 293 switch (selectedPaymentMethod) { 294 case 'omise': 295 return omiseFormHandler(); 296 case 'omise_installment': 297 return omiseInstallmentFormHandler(); 298 } 290 299 }); 291 300 292 301 /* Both Forms */ 293 $( 'form.checkout, form#order_review').on('change', '#omise_cc_form input', function() {302 $($form).on('change', '#omise_cc_form input', function() { 294 303 $('.omise_token').remove(); 295 304 $('.omise_source').remove(); 296 305 }); 297 306 298 $( 'form.checkout').on('change', 'input[name="payment_method"]', function() {307 $($form).on('change', 'input[name="payment_method"]', function() { 299 308 setupOmiseForm(); 300 309 }); -
omise/trunk/includes/gateway/abstract-omise-payment-offsite.php
r3308831 r3361458 10 10 { 11 11 use Charge_Request_Builder; 12 13 /** 14 * @inheritdoc 15 */ 16 public function payment_fields() { 17 parent::payment_fields(); 18 } 12 19 13 20 /** -
omise/trunk/includes/gateway/class-omise-payment-atome.php
r3256918 r3361458 103 103 ]; 104 104 105 $currency = strtolower(get_woocommerce_currency());106 105 $cart = WC()->cart; 107 108 if ($cart->subtotal === 0) { 109 return [ 110 'status' => false, 111 'message' => 'Complimentary products cannot be billed.' 112 ]; 113 } 114 115 if (!isset($limits[$currency])) { 116 return [ 117 'status' => false, 118 'message' => 'Currency not supported' 119 ]; 120 } 121 122 $limit = $limits[$currency]; 123 124 if ($cart->total < $limit['min']) { 106 $cart_subtotal = $cart->subtotal; 107 $cart_total = $cart->total; 108 $cart_currency = strtolower( get_woocommerce_currency() ); 109 110 // For Pay for Order Page 111 if ( is_checkout_pay_page() ) { 112 $order_id = get_query_var('order-pay'); 113 $order = wc_get_order( $order_id ); 114 if ( ! $order ) { 115 throw new Exception( 'Order not found.' ); 116 } 117 118 $cart_subtotal = $order->get_subtotal(); 119 $cart_total = $order->get_total(); 120 $cart_currency = strtolower( $order->get_currency() ); 121 } 122 123 if ( $cart_subtotal === 0 ) { 124 return [ 125 'status' => false, 126 'message' => 'Complimentary products cannot be billed.', 127 ]; 128 } 129 130 if ( ! isset( $limits[ $cart_currency ] ) ) { 131 return [ 132 'status' => false, 133 'message' => 'Currency not supported', 134 ]; 135 } 136 137 $limit = $limits[ $cart_currency ]; 138 139 if ( $cart_total < $limit['min'] ) { 125 140 return [ 126 141 'status' => false, 127 142 'message' => sprintf( 128 "Amount must be greater than %u %s",129 number_format( $limit['min'], 2),130 strtoupper($c urrency)131 ) 132 ]; 133 } 134 135 if ( $cart->total > $limit['max']) {136 return [ 137 'status' => false, 138 'message' => __(139 'Amount must be less than % 1 %2',140 number_format( $limit['max'], 2),141 strtoupper( $currency)142 ) 143 ]; 144 } 145 146 return [ 'status' => true];143 'Amount must be greater than %s %s', 144 number_format( $limit['min'], 2 ), 145 strtoupper($cart_currency), 146 ), 147 ]; 148 } 149 150 if ( $cart_total > $limit['max'] ) { 151 return [ 152 'status' => false, 153 'message' => sprintf( 154 'Amount must be less than %s %s', 155 number_format( $limit['max'], 2 ), 156 strtoupper( $cart_currency ), 157 ), 158 ]; 159 } 160 161 return [ 'status' => true ]; 147 162 } 148 163 … … 164 179 $this->id . "_callback" 165 180 ); 166 181 167 182 $default_phone_selected = isset($_POST['omise_atome_phone_default']) ? 168 183 $_POST['omise_atome_phone_default'] -
omise/trunk/includes/gateway/class-omise-payment-installment.php
r3308831 r3361458 130 130 $this->id . "_callback" 131 131 ); 132 $requestData['description'] = 'staging';133 132 $requestData['source'] = isset($_POST['omise_source']) ? wc_clean($_POST['omise_source']) : ''; 134 133 $requestData['card'] = isset($_POST['omise_token']) ? wc_clean($_POST['omise_token']) : ''; 134 135 $custom_wlb_desc = getenv('OMISE_CUSTOM_WLB_ORDER_DESC'); 136 if (!empty($custom_wlb_desc) && !empty($requestData['card'])) { 137 $custom_wlb_desc = sanitize_text_field($custom_wlb_desc); 138 $requestData['description'] = str_replace('{description}', $requestData['description'], $custom_wlb_desc); 139 } 140 135 141 return OmiseCharge::create($requestData); 136 142 } -
omise/trunk/includes/gateway/class-omise-payment.php
r3308831 r3361458 114 114 add_filter( 'woocommerce_email_recipient_new_order', 'OmisePluginHelperMailer::disable_merchant_order_on_hold', 10, 2 ); 115 115 add_filter('is_protected_meta', [ $this, 'protectMetadata'], 10, 2); 116 } 117 118 /** 119 * Displayed payment fields. 120 */ 121 public function payment_fields() { 122 parent::payment_fields(); 116 123 } 117 124 -
omise/trunk/omise-woocommerce.php
r3331857 r3361458 5 5 * Plugin URI: https://www.omise.co/woocommerce 6 6 * Description: Omise Payments is a WordPress plugin designed specifically for WooCommerce. The plugin adds support for Omise Payment Gateway's payment methods to WooCommerce. 7 * Version: 6. 2.27 * Version: 6.3.0 8 8 * Author: Omise and contributors 9 9 * Author URI: https://github.com/omise/omise-woocommerce/graphs/contributors … … 24 24 * @var string 25 25 */ 26 public $version = '6. 2.2';26 public $version = '6.3.0'; 27 27 28 28 /** -
omise/trunk/phpunit.xml
r3308831 r3361458 4 4 backupGlobals="true" 5 5 backupStaticAttributes="false" 6 bootstrap="tests/unit/bootstrap.php" 6 7 colors="true" 7 8 stopOnError="false" -
omise/trunk/readme.txt
r3331857 r3361458 4 4 Requires at least: 4.3.1 5 5 Tested up to: 6.8.1 6 Stable tag: 6. 2.26 Stable tag: 6.3.0 7 7 License: MIT 8 8 License URI: https://opensource.org/licenses/MIT … … 34 34 35 35 == Changelog == 36 37 = 6.3.0 = 38 39 - Fix WLB installment order description. (PR: [#534](https://github.com/omise/omise-woocommerce/issues/534)) 40 - Fix payment form on Pay for Order page. (PR: [#533](https://github.com/omise/omise-woocommerce/issues/533)) 36 41 37 42 = 6.2.2 = -
omise/trunk/tests/unit/class-omise-unit-test.php
r3312403 r3361458 1 1 <?php 2 3 define( 'ABSPATH', value: '' );4 define( 'OMISE_PUBLIC_KEY', 'pkey_test_12345');5 define( 'OMISE_SECRET_KEY', 'skey_test_12345');6 2 7 3 class Omise_Unit_Test { … … 31 27 } 32 28 29 /** 30 * Mock WordPress _e() function. 31 * 32 * @see wp-includes/l10n.php 33 * @see https://developer.wordpress.org/reference/functions/_e 34 */ 35 function _e( $text, $context, $domain = 'default' ) { 36 echo $text; 37 } 38 33 39 function load_fixture($name) { 34 40 return file_get_contents(__DIR__ . "/../fixtures/{$name}.json"); -
omise/trunk/tests/unit/includes/gateway/bootstrap-test-setup.php
r3331857 r3361458 1 1 <?php 2 3 use PHPUnit\Framework\TestCase; 4 use Brain\Monkey; 5 use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; 6 7 /** 8 * Mock abstract WooCommerce's gateway 9 */ 10 abstract class WC_Payment_Gateway 2 abstract class Bootstrap_Test_Setup extends Omise_Test_Case 11 3 { 12 public static $is_available = true; 13 14 public function is_available() 15 { 16 return self::$is_available; 17 } 18 } 19 20 /** 21 * Temporary mock for WP_* class 22 * In the future, we should move to use WP_UnitTestCase 23 */ 24 class WP_Error 25 { 26 public function __construct( 27 public $code = '', 28 public $message = '', 29 public $data = '' 30 ) { 31 } 32 } 33 class WP_REST_Server_Stub 34 { 35 const EDITABLE = 'POST'; 36 const READABLE = 'GET'; 37 } 38 39 abstract class Bootstrap_Test_Setup extends TestCase 40 { 41 // Adds Mockery expectations to the PHPUnit assertions count. 42 use MockeryPHPUnitIntegration; 43 44 public $sourceType; 45 46 protected function setUp(): void 47 { 48 parent::setUp(); 49 Monkey\setUp(); 50 } 51 52 /** 53 * close mockery after tests are done 54 */ 55 protected function tearDown(): void 56 { 57 Monkey\tearDown(); 58 Mockery::close(); 59 parent::tearDown(); 60 } 61 62 public function getOrderMock($expectedAmount, $expectedCurrency) 4 public function getOrderMock($expectedAmount, $expectedCurrency, $properties = []) 63 5 { 64 6 // Create a mock of the $order object … … 66 8 67 9 // Define expectations for the mock 10 $orderMock->allows([ 11 'get_id' => $properties['id'] ?? 123, 12 'get_order_key' => $properties['key'] ?? 'order_kfeERDv', 13 ]); 68 14 $orderMock->shouldReceive('get_currency') 69 ->andReturn( $expectedCurrency);15 ->andReturn(strtoupper($expectedCurrency)); 70 16 $orderMock->shouldReceive('get_total') 71 17 ->andReturn($expectedAmount); // in units … … 94 40 } 95 41 42 public function getCartMock($cartProperties = []) { 43 $cart = Mockery::mock('WC_Cart'); 44 $cart->subtotal = $cartProperties['subtotal'] ?? 0; 45 $cart->total = $cartProperties['total'] ?? 0; 46 47 return $cart; 48 } 49 50 public function getWcMock($cart = null) { 51 $wc = Mockery::mock('WooCommerce'); 52 $wc->cart = $cart ? $cart : $this->getCartMock(); 53 54 return $wc; 55 } 56 96 57 /** 58 * FIXME: Only used in Omise_Payment_Konbini_Test. 59 * We can refactor this into offline payment test class or the test itself. 97 60 * @runInSeparateProcess 98 61 */ … … 142 105 'public_key' => $pkey, 143 106 'secret_key' => $skey, 107 'is_dynamic_webhook_enabled' => false, 144 108 ]); 145 109 $omiseSettingMock->shouldReceive('get_settings')->andReturn([])->byDefault(); … … 185 149 } 186 150 } 151 152 protected function mockRedirectUrl($redirectUrl = 'https://abc.com/order/complete') { 153 $redirectUrlMock = Mockery::mock('alias:RedirectUrl'); 154 $redirectUrlMock->shouldReceive('create')->andReturn($redirectUrl); 155 $redirectUrlMock->shouldReceive('getToken')->andReturn('token123'); 156 157 return $redirectUrlMock; 158 } 187 159 } 188 160 -
omise/trunk/tests/unit/includes/gateway/class-omise-offsite-test.php
r3308831 r3361458 5 5 use Brain\Monkey; 6 6 7 /** 8 * @deprecated Please use Omise_Payment_Offsite_Test instead. 9 */ 7 10 abstract class Omise_Offsite_Test extends Bootstrap_Test_Setup 8 11 { -
omise/trunk/tests/unit/includes/gateway/class-omise-payment-atome-test.php
r3312403 r3361458 1 1 <?php 2 2 3 require_once __DIR__ . '/class-omise-offsite-test.php';4 5 3 use Brain\Monkey; 6 7 class Omise_Payment_Atome_Test extends Omise_Offsite_Test 8 { 9 protected function setUp(): void 10 { 11 $this->sourceType = 'atome'; 12 parent::setUp(); 13 require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-atome.php'; 14 15 Monkey\Functions\expect('wp_enqueue_script'); 16 Monkey\Functions\expect('wp_kses'); 17 Monkey\Functions\expect('plugins_url'); 18 Monkey\Functions\expect('add_action'); 19 20 // dummy version 21 if (!defined('WC_VERSION')) { 22 define('WC_VERSION', '1.0.0'); 23 } 24 } 25 26 public function testGetChargeRequest() 27 { 28 $expectedAmount = 999999; 29 $expectedCurrency = 'thb'; 30 $orderId = 'order_123'; 31 $orderMock = $this->getOrderMock($expectedAmount, $expectedCurrency); 32 33 $wcProduct = Mockery::mock('overload:WC_Product'); 34 $wcProduct->shouldReceive('get_sku') 35 ->once() 36 ->andReturn('sku_1234'); 37 38 $_POST['omise_atome_phone_default'] = true; 39 40 $obj = new Omise_Payment_Atome(); 41 $result = $obj->get_charge_request($orderId, $orderMock); 42 43 $this->assertEquals($this->sourceType, $result['source']['type']); 44 } 45 46 public function testCharge() 47 { 48 $_POST['omise_atome_phone_default'] = true; 49 $obj = new Omise_Payment_Atome(); 50 $this->getChargeTest($obj); 51 } 4 use voku\helper\HtmlDomParser; 5 6 /** 7 * @runTestsInSeparateProcesses 8 */ 9 class Omise_Payment_Atome_Test extends Omise_Payment_Offsite_Test { 10 11 private $omise_atome; 12 13 protected function setUp(): void { 14 parent::setUp(); 15 16 $this->omise_atome = $this->mock_payment_class( Omise_Payment_Atome::class ); 17 } 18 19 public function test_atome_get_charge_request() { 20 $order_amount = 4566; 21 $order_currency = 'THB'; 22 $order_id = 'order_123'; 23 $order_mock = $this->getOrderMock( $order_amount, $order_currency ); 24 25 $wc_product = Mockery::mock( 'overload:WC_Product' ); 26 $wc_product->shouldReceive( 'get_sku' ) 27 ->once() 28 ->andReturn( 'sku_1234' ); 29 30 $_POST['omise_atome_phone_default'] = true; 31 32 $result = $this->omise_atome->get_charge_request( $order_id, $order_mock ); 33 34 $this->assertEquals( 456600, $result['amount'] ); 35 $this->assertEquals( $order_currency, $result['currency'] ); 36 $this->assertEquals( $order_id, $result['metadata']['order_id'] ); 37 $this->assertEquals( $this->return_uri, $result['return_uri'] ); 38 39 $expected_source = [ 40 'type' => 'atome', 41 'phone_number' => $order_mock->get_billing_phone(), 42 'items' => [ 43 [ 44 'name' => 'T Shirt', 45 'amount' => 60000, 46 'quantity' => 1, 47 'sku' => 'sku_1234', 48 ], 49 ], 50 'shipping' => [ 51 'country' => 'Thailand', 52 'city' => 'Bangkok', 53 'postal_code' => '10110', 54 'state' => 'Bangkok', 55 'street1' => 'Sukumvit Road', 56 ], 57 ]; 58 $this->assertEquals( $expected_source, $result['source'] ); 59 } 60 61 public function test_atome_get_charge_request_with_custom_phone_number() { 62 $order_amount = 4566; 63 $order_currency = 'THB'; 64 $order_id = 'order_123'; 65 $order_mock = $this->getOrderMock( $order_amount, $order_currency ); 66 67 $wc_product = Mockery::mock( 'overload:WC_Product' ); 68 $wc_product->shouldReceive( 'get_sku' ) 69 ->once() 70 ->andReturn( 'sku_1234' ); 71 72 $_POST['omise_atome_phone_default'] = false; 73 $_POST['omise_atome_phone_number'] = '+66123456789'; 74 75 $result = $this->omise_atome->get_charge_request( $order_id, $order_mock ); 76 77 $this->assertEquals( 456600, $result['amount'] ); 78 $this->assertEquals( $order_currency, $result['currency'] ); 79 $this->assertEquals( 'atome', $result['source']['type'] ); 80 $this->assertEquals( '+66123456789', $result['source']['phone_number'] ); 81 } 82 83 public function test_atome_charge() { 84 $order = $this->getOrderMock( 999999, 'THB' ); 85 $_POST['omise_atome_phone_default'] = true; 86 87 $this->perform_charge_test( $this->omise_atome, $order ); 88 } 89 90 public function test_atome_payment_fields_renders_atome_form_on_checkout_page() { 91 $cart = $this->getCartMock( 92 [ 93 'subtotal' => 300, 94 'total' => 380, 95 ] 96 ); 97 $wc = $this->getWcMock( $cart ); 98 99 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 100 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' ); 101 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 102 103 ob_start(); 104 $this->omise_atome->payment_fields(); 105 $output = ob_get_clean(); 106 107 $page = HtmlDomParser::str_get_html( $output ); 108 $this->assertMatchesRegularExpression( '/Atome phone number/', $page->findOne( '#omise-form-atome' )->innertext ); 109 } 110 111 public function test_atome_payment_fields_renders_atome_form_on_pay_for_order_page() { 112 $wc = $this->getWcMock(); 113 $order_mock = $this->getOrderMock( 380, 'THB' ); 114 $order_mock->shouldReceive( 'get_subtotal' )->andReturn( 300 ); 115 116 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 117 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' ); 118 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( true ); 119 Monkey\Functions\expect( 'get_query_var' )->with( 'order-pay' )->andReturn( 456 ); 120 Monkey\Functions\expect( 'wc_get_order' )->with( 456 )->andReturn( $order_mock ); 121 122 ob_start(); 123 $this->omise_atome->payment_fields(); 124 $output = ob_get_clean(); 125 126 $page = HtmlDomParser::str_get_html( $output ); 127 $this->assertMatchesRegularExpression( '/Atome phone number/', $page->findOne( '#omise-form-atome' )->innertext ); 128 } 129 130 public function test_atome_payment_fields_returns_error_if_subtotal_is_zero() { 131 $cart = $this->getCartMock( 132 [ 133 'subtotal' => 0, 134 'total' => 100, 135 ] 136 ); 137 $wc = $this->getWcMock( $cart ); 138 139 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 140 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' ); 141 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 142 143 ob_start(); 144 $this->omise_atome->payment_fields(); 145 $output = ob_get_clean(); 146 147 $this->assertEquals( 'Complimentary products cannot be billed.', trim( $output ) ); 148 } 149 150 public function test_atome_payment_fields_returns_error_if_currency_not_support() { 151 $cart = $this->getCartMock( 152 [ 153 'subtotal' => 100, 154 'total' => 100, 155 ] 156 ); 157 $wc = $this->getWcMock( $cart ); 158 159 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 160 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'USD' ); 161 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 162 163 ob_start(); 164 $this->omise_atome->payment_fields(); 165 $output = ob_get_clean(); 166 167 $this->assertEquals( 'Currency not supported', trim( $output ) ); 168 } 169 170 public function test_atome_payment_fields_returns_error_if_amount_less_than_min_limit() { 171 $cart = $this->getCartMock( 172 [ 173 'subtotal' => 1.4, 174 'total' => 1.4, 175 ] 176 ); 177 $wc = $this->getWcMock( $cart ); 178 179 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 180 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'SGD' ); 181 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 182 183 ob_start(); 184 $this->omise_atome->payment_fields(); 185 $output = ob_get_clean(); 186 187 $this->assertEquals( 'Amount must be greater than 1.50 SGD', trim( $output ) ); 188 } 189 190 public function test_atome_payment_fields_returns_error_if_amount_greater_than_max_limit() { 191 $cart = $this->getCartMock( 192 [ 193 'subtotal' => 20001, 194 'total' => 20001, 195 ] 196 ); 197 $wc = $this->getWcMock( $cart ); 198 199 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 200 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'SGD' ); 201 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( false ); 202 203 ob_start(); 204 $this->omise_atome->payment_fields(); 205 $output = ob_get_clean(); 206 207 $this->assertEquals( 'Amount must be less than 20,000.00 SGD', trim( $output ) ); 208 } 209 210 public function test_atome_payment_fields_throws_exception_if_pay_for_order_not_found() { 211 $wc = $this->getWcMock(); 212 213 Monkey\Functions\expect( 'WC' )->andReturn( $wc ); 214 Monkey\Functions\expect( 'get_woocommerce_currency' )->andReturn( 'THB' ); 215 Monkey\Functions\expect( 'is_checkout_pay_page' )->andReturn( true ); 216 Monkey\Functions\expect( 'get_query_var' )->with( 'order-pay' )->andReturn( 456 ); 217 Monkey\Functions\expect( 'wc_get_order' )->with( 456 )->andReturn( false ); 218 219 $this->expectException( Exception::class ); 220 $this->expectExceptionMessage( 'Order not found.' ); 221 222 $this->omise_atome->payment_fields(); 223 } 52 224 } -
omise/trunk/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php
r3308831 r3361458 33 33 $omiseCardImage->shouldReceive('get_discover_image')->once(); 34 34 $omiseCardImage->shouldReceive('get_discover_default_display')->once(); 35 36 // dummy version37 if (!defined('WC_VERSION')) {38 define('WC_VERSION', '1.0.0');39 }40 35 41 36 Monkey\Functions\expect('add_action')->andReturn(null); -
omise/trunk/tests/unit/includes/gateway/class-omise-payment-googlepay-test.php
r3209723 r3361458 17 17 Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb'); 18 18 19 // dummy version20 if (!defined('WC_VERSION')) {21 define('WC_VERSION', '1.0.0');22 }23 24 19 $omisePaymentMock = Mockery::mock('overload:Omise_Payment'); 25 20 $omisePaymentMock->shouldReceive('init_settings'); -
omise/trunk/tests/unit/includes/gateway/class-omise-payment-installment-test.php
r3312403 r3361458 6 6 7 7 /** 8 * @run InSeparateProcess8 * @runTestsInSeparateProcesses 9 9 * @preserveGlobalState disabled 10 10 */ 11 12 class Omise_Payment_Installment_Test extends Omise_Offsite_Test 11 class Omise_Payment_Installment_Test extends Omise_Payment_Offsite_Test 13 12 { 14 13 protected $backend_installment_mock; 14 private $installment; 15 15 16 16 protected function setUp(): void 17 17 { 18 $this->sourceType = 'installment_ktc';19 18 parent::setUp(); 20 19 21 Monkey\Functions\expect('wp_kses'); 22 Omise_Unit_Test::include_class('backends/class-omise-backend.php'); 23 Omise_Unit_Test::include_class('backends/class-omise-backend-installment.php'); 24 20 $this->installment = $this->mock_payment_class( Omise_Payment_Installment::class ); 25 21 $this->backend_installment_mock = Mockery::mock('Omise_Backend_Installment'); 26 require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-installment.php';27 22 } 28 23 29 p rotected function tearDown(): void24 public function test_installment_get_total_amount_from_admin_order_page() 30 25 { 31 parent::tearDown();32 }33 34 /**35 * @test36 */37 public function get_total_amount_from_admin_order_page()38 {39 Monkey\Functions\expect('add_action');40 41 26 $order = Mockery::mock('WC_Order'); 42 27 Monkey\Functions\expect('wc_get_order')->andReturn($order); … … 50 35 $GLOBALS['wp'] = $wp; 51 36 52 $installment = new Omise_Payment_Installment(); 53 $total = $installment->get_total_amount(); 37 $total = $this->installment->get_total_amount(); 54 38 55 39 $this->assertEquals($total, 999999); 56 40 } 57 41 58 /** 59 * @test 60 */ 61 public function get_total_amount_from_cart() 42 public function test_installment_get_total_amount_from_cart() 62 43 { 63 Monkey\Functions\expect('add_action');64 65 44 $clazz = new stdClass(); 66 45 $clazz->cart = new stdClass(); … … 69 48 Monkey\Functions\expect('WC')->andReturn($clazz); 70 49 71 $installment = new Omise_Payment_Installment(); 72 $total = $installment->get_total_amount(); 50 $total = $this->installment->get_total_amount(); 73 51 74 52 $this->assertEquals($total, 999999); 75 53 } 76 54 77 public function test_ charge()55 public function test_installment_charge() 78 56 { 79 $this->backend_installment_mock->shouldReceive('get_provider');57 putenv('OMISE_CUSTOM_WLB_ORDER_DESC=test'); 80 58 81 Monkey\Functions\expect('add_action'); 59 $order = $this->getOrderMock(4353, 'THB', [ 'id' => 1293 ]); 60 $_POST['omise_source'] = 'source_test_12345'; 82 61 83 $_POST['source'] = ['type' => $this->sourceType]; 84 $_POST[$this->sourceType . '_installment_terms'] = 3; 62 $test_charge_fn = function ($actual) { 63 return $actual == [ 64 'amount' => 435300, 65 'currency' => 'THB', 66 'description' => 'WooCommerce Order id 1293', 67 'return_uri' => $this->return_uri, 68 'source' => 'source_test_12345', 69 'card' => '', 70 'metadata' => [ 71 'order_id' => 1293, 72 ], 73 ]; 74 }; 85 75 86 $obj = new Omise_Payment_Installment(); 87 $this->getChargeTest($obj); 76 $this->perform_charge_test( $this->installment, $order, $test_charge_fn ); 88 77 } 89 78 90 public function test_get_view_data() 79 public function test_installment_wlb_charge() 80 { 81 putenv('OMISE_CUSTOM_WLB_ORDER_DESC'); 82 83 $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]); 84 $_POST['omise_source'] = 'source_test_12345'; 85 $_POST['omise_token'] = 'tokn_test_67890'; 86 87 $test_charge_fn = function ($actual) { 88 return $actual == [ 89 'amount' => 25050, 90 'currency' => 'THB', 91 'description' => 'WooCommerce Order id 400', 92 'return_uri' => $this->return_uri, 93 'source' => 'source_test_12345', 94 'card' => 'tokn_test_67890', 95 'metadata' => [ 96 'order_id' => 400, 97 ], 98 ]; 99 }; 100 101 $this->perform_charge_test( $this->installment, $order, $test_charge_fn ); 102 } 103 104 public function test_installment_wlb_charge_with_custom_description() 105 { 106 putenv('OMISE_CUSTOM_WLB_ORDER_DESC={description} - test'); 107 108 $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]); 109 $_POST['omise_source'] = 'source_test_12345'; 110 $_POST['omise_token'] = 'tokn_test_67890'; 111 112 $test_charge_fn = function ($actual) { 113 return $actual['description'] == 'WooCommerce Order id 400 - test'; 114 }; 115 116 $this->perform_charge_test( $this->installment, $order, $test_charge_fn ); 117 } 118 119 public function test_installment_wlb_charge_with_custom_description_fully_overridden() 120 { 121 putenv('OMISE_CUSTOM_WLB_ORDER_DESC=My order description'); 122 123 $order = $this->getOrderMock(250.5, 'THB', [ 'id' => 400 ]); 124 $_POST['omise_source'] = 'source_test_12345'; 125 $_POST['omise_token'] = 'tokn_test_67890'; 126 127 $test_charge_fn = function ($actual) { 128 return $actual['description'] == 'My order description'; 129 }; 130 131 $this->perform_charge_test( $this->installment, $order, $test_charge_fn ); 132 } 133 134 public function test_installment_get_view_data() 91 135 { 92 136 $capability = Mockery::mock('alias:Omise_Capability'); … … 109 153 Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb'); 110 154 111 $c lazz = new stdClass();112 $ clazz->cart = new stdClass();113 $clazz->cart->total = 999999;155 $cart = $this->getCartMock(['total' => 999999]); 156 $wc = $this->getWcMock($cart); 157 Monkey\Functions\expect('WC')->andReturn($wc); 114 158 115 Monkey\Functions\expect('WC')->andReturn($clazz); 116 Monkey\Functions\expect('add_action'); 117 118 $obj = new Omise_Payment_Installment(); 119 $result = $obj->get_view_data(); 159 $result = $this->installment->get_view_data(); 120 160 121 161 $this->assertArrayHasKey('installments_enabled', $result); … … 124 164 } 125 165 126 public function test GetParamsForJS()166 public function test_installment_get_params_for_js() 127 167 { 128 $c lazz = new stdClass();129 $ clazz->cart = new stdClass();130 $clazz->cart->total = 999999;168 $cart = $this->getCartMock(['total' => 999999]); 169 $wc = $this->getWcMock($cart); 170 Monkey\Functions\expect('WC')->andReturn($wc); 131 171 132 Monkey\Functions\expect('WC')->andReturn($clazz); 133 Monkey\Functions\expect('add_action'); 134 $mock = Mockery::mock('overload:Omise_Payment_Offsite'); 135 $instance = new Omise_Payment_Installment($mock); 136 $result = $instance->getParamsForJS(); 172 $result = $this->installment->getParamsForJS(); 137 173 138 $this->assertIsArray($result); 139 $this->assertArrayHasKey('key', $result); 140 $this->assertArrayHasKey('amount', $result); 141 $this->assertEquals('pkey_test_123', $result['key']); 142 $this->assertEquals(99999900, $result['amount']); 174 $this->assertEquals([ 175 'key' => 'pkey_test_123', 176 'amount' => 99999900, 177 ], $result); 143 178 } 144 179 145 public function test ConvertToCents()180 public function test_installment_convert_to_cents() 146 181 { 147 Monkey\Functions\expect('add_action');148 $instance = new Omise_Payment_Installment(); 182 $instance = $this->installment; 183 149 184 $this->assertEquals(100, $instance->convert_to_cents(1.00)); 150 185 $this->assertEquals(150, $instance->convert_to_cents(1.50)); -
omise/trunk/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php
r3182037 r3361458 8 8 public $mockWcDateTime; 9 9 public $mockLocalizeScript; 10 public $mockOmisePluginHelper;11 10 public $mockOmisePaymentOffline; 12 11 public $mockOmiseCharge; … … 23 22 $this->mockLocalizeScript = Mockery::mock(); 24 23 $this->mockWcDateTime = Mockery::mock('overload:WC_DateTime'); 25 $this->mockOmisePluginHelper = Mockery::mock('overload:OmisePluginHelperWcOrder')->shouldIgnoreMissing();26 24 $this->mockOmisePaymentOffline = Mockery::mock('overload:Omise_Payment_Offline'); 27 25 $this->mockOmiseCharge = Mockery::mock('overload:OmiseCharge'); … … 79 77 } 80 78 79 Monkey\Functions\when('wc_get_order')->justReturn($this->mockOrder); 80 $this->mockOrder->shouldReceive('get_order_key') 81 ->once() 82 ->andReturn('wc_order_12345'); 83 81 84 $obj = new Omise_Payment_Promptpay(); 82 85 $result = $obj->display_qrcode($this->mockOrder, 'view');
Note: See TracChangeset
for help on using the changeset viewer.