Changeset 2852769
- Timestamp:
- 01/23/2023 08:49:04 AM (3 years ago)
- Location:
- omise
- Files:
-
- 2 added
- 34 edited
- 1 copied
-
tags/4.28.0 (copied) (copied from omise/trunk)
-
tags/4.28.0/CHANGELOG.md (modified) (1 diff)
-
tags/4.28.0/assets/css/omise-css.css (modified) (2 diffs)
-
tags/4.28.0/composer.json (modified) (1 diff)
-
tags/4.28.0/includes/admin/views/omise-page-settings.php (modified) (1 diff)
-
tags/4.28.0/includes/backends/class-omise-backend-installment.php (modified) (14 diffs)
-
tags/4.28.0/includes/class-omise-capabilities.php (modified) (4 diffs)
-
tags/4.28.0/includes/gateway/class-omise-payment-alipay.php (modified) (1 diff)
-
tags/4.28.0/includes/gateway/class-omise-payment-billpayment-tesco.php (modified) (8 diffs)
-
tags/4.28.0/includes/gateway/class-omise-payment-installment.php (modified) (7 diffs)
-
tags/4.28.0/includes/gateway/class-omise-payment-shopeepay.php (modified) (4 diffs)
-
tags/4.28.0/includes/libraries/omise-php/lib/omise/OmiseCapabilities.php (modified) (1 diff)
-
tags/4.28.0/omise-util.php (modified) (1 diff)
-
tags/4.28.0/omise-woocommerce.php (modified) (2 diffs)
-
tags/4.28.0/phpunit.xml (modified) (1 diff)
-
tags/4.28.0/readme.txt (modified) (2 diffs)
-
tags/4.28.0/sonar-project.properties (added)
-
tags/4.28.0/templates/payment/form-installment.php (modified) (1 diff)
-
tags/4.28.0/tests/unit/includes/backends/class-omise-backend-installment-test.php (modified) (9 diffs)
-
trunk/CHANGELOG.md (modified) (1 diff)
-
trunk/assets/css/omise-css.css (modified) (2 diffs)
-
trunk/composer.json (modified) (1 diff)
-
trunk/includes/admin/views/omise-page-settings.php (modified) (1 diff)
-
trunk/includes/backends/class-omise-backend-installment.php (modified) (14 diffs)
-
trunk/includes/class-omise-capabilities.php (modified) (4 diffs)
-
trunk/includes/gateway/class-omise-payment-alipay.php (modified) (1 diff)
-
trunk/includes/gateway/class-omise-payment-billpayment-tesco.php (modified) (8 diffs)
-
trunk/includes/gateway/class-omise-payment-installment.php (modified) (7 diffs)
-
trunk/includes/gateway/class-omise-payment-shopeepay.php (modified) (4 diffs)
-
trunk/includes/libraries/omise-php/lib/omise/OmiseCapabilities.php (modified) (1 diff)
-
trunk/omise-util.php (modified) (1 diff)
-
trunk/omise-woocommerce.php (modified) (2 diffs)
-
trunk/phpunit.xml (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/sonar-project.properties (added)
-
trunk/templates/payment/form-installment.php (modified) (1 diff)
-
trunk/tests/unit/includes/backends/class-omise-backend-installment-test.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
omise/tags/4.28.0/CHANGELOG.md
r2832733 r2852769 1 1 # CHANGELOG 2 3 ### [v4.28.0 _(Jan 24, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.28.0) 4 - Added ShopeePay for Thailand and Singapore. (PR [#339](https://github.com/omise/omise-woocommerce/pull/339)) 5 - Rebrand Lotus's Bill Payment. (PR [#336](https://github.com/omise/omise-woocommerce/pull/336)) 6 - Replace ezypay with MBB in installments. (PR [#333](https://github.com/omise/omise-woocommerce/pull/333)) 7 - Fixed the method to get currency to the correct method. (PR [#338](https://github.com/omise/omise-woocommerce/pull/338)) 8 - Code Coverage Integration with Sonarcloud. (PR [#337](https://github.com/omise/omise-woocommerce/pull/337)) 9 - Fix the compatible issue with PHP 7.2 and below. (PR [#342](https://github.com/omise/omise-woocommerce/pull/342)) 2 10 3 11 ### [v4.27.0 _(Dec 7, 2022)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.27.0) -
omise/tags/4.28.0/assets/css/omise-css.css
r2809311 r2852769 65 65 66 66 /** 67 * Omise Bill Payment Tesco67 * Omise Bill Payment Lotus 68 68 * CSS for the 'Thank You' (order-received) page. 69 69 */ … … 404 404 405 405 /** MAYBANK **/ 406 .bank-logo. ezypay{406 .bank-logo.mbb { 407 407 background: url('../images/maybank.svg') #ffcf00; 408 408 border-color: #ffcf00; -
omise/tags/4.28.0/composer.json
r2501457 r2852769 5 5 "license": "MIT", 6 6 "require-dev": { 7 "phpunit/phpunit": "^ 8.1"7 "phpunit/phpunit": "^5.7 || ^9.5" 8 8 } 9 9 } -
omise/tags/4.28.0/includes/admin/views/omise-page-settings.php
r2832733 r2852769 30 30 ) 31 31 ), 32 esc_url( 'https://dashboard.omise.co/v2/settings/keys' ) ,32 esc_url( 'https://dashboard.omise.co/v2/settings/keys' ) 33 33 ); 34 34 ?> -
omise/tags/4.28.0/includes/backends/class-omise-backend-installment.php
r2783685 r2852769 1 1 <?php 2 2 3 /** 3 4 * Note: The calculations in this class depend on the countries that … … 11 12 * @method public calculate_monthly_payment_amount 12 13 */ 13 class Omise_Backend_Installment extends Omise_Backend { 14 class Omise_Backend_Installment extends Omise_Backend 15 { 14 16 /** 15 17 * @var array of known installment providers. … … 17 19 protected static $providers = array(); 18 20 19 public function initiate() { 21 public function initiate() 22 { 20 23 self::$providers = array( 21 24 'installment_first_choice' => array( 22 25 'bank_code' => 'first_choice', 23 'title' => __( 'Krungsri First Choice', 'omise'),26 'title' => __('Krungsri First Choice', 'omise'), 24 27 'interest_rate' => 1.3, 25 28 'min_allowed_amount' => 300.00, … … 28 31 'installment_bay' => array( 29 32 'bank_code' => 'bay', 30 'title' => __( 'Krungsri', 'omise'),33 'title' => __('Krungsri', 'omise'), 31 34 'interest_rate' => 0.8, 32 35 'min_allowed_amount' => 500.00, … … 35 38 'installment_ktc' => array( 36 39 'bank_code' => 'ktc', 37 'title' => __( 'Krungthai Card (KTC)', 'omise'),40 'title' => __('Krungthai Card (KTC)', 'omise'), 38 41 'interest_rate' => 0.8, 39 42 'min_allowed_amount' => 300.00, … … 42 45 'installment_bbl' => array( 43 46 'bank_code' => 'bbl', 44 'title' => __( 'Bangkok Bank', 'omise'),47 'title' => __('Bangkok Bank', 'omise'), 45 48 'interest_rate' => 0.8, 46 49 'min_allowed_amount' => 500.00, … … 49 52 'installment_kbank' => array( 50 53 'bank_code' => 'kbank', 51 'title' => __( 'Kasikorn Bank', 'omise'),54 'title' => __('Kasikorn Bank', 'omise'), 52 55 'interest_rate' => 0.65, 53 56 'min_allowed_amount' => 300.00, … … 56 59 'installment_scb' => array( 57 60 'bank_code' => 'scb', 58 'title' => __( 'Siam Commercial Bank', 'omise'),61 'title' => __('Siam Commercial Bank', 'omise'), 59 62 'interest_rate' => 0.74, 60 63 'min_allowed_amount' => 500.00, … … 63 66 'installment_citi' => array( 64 67 'bank_code' => 'citi', 65 'title' => __( 'Citibank', 'omise'),68 'title' => __('Citibank', 'omise'), 66 69 'interest_rate' => 0, 67 70 'min_allowed_amount' => 500.00, … … 70 73 'installment_ttb' => array( 71 74 'bank_code' => 'ttb', 72 'title' => __( 'TMBThanachart Bank', 'omise'),75 'title' => __('TMBThanachart Bank', 'omise'), 73 76 'interest_rate' => 0, 74 77 'min_allowed_amount' => 500.00, … … 77 80 'installment_uob' => array( 78 81 'bank_code' => 'uob', 79 'title' => __( 'United Overseas Bank', 'omise' ), 80 'interest_rate' => 0, 81 'min_allowed_amount' => 500.00, 82 ), 83 84 'installment_ezypay' => array( 85 'bank_code' => 'ezypay', 86 'title' => __( 'Maybank (EzyPay)', 'omise' ), 87 'interest_rate' => 0, 88 'min_allowed_amount' => 500.00, 82 'title' => __('United Overseas Bank', 'omise'), 83 'interest_rate' => 0, 84 'min_allowed_amount' => 500.00, 85 ), 86 87 'installment_mbb' => array( 88 'bank_code' => 'mbb', 89 'title' => __('Maybank', 'omise'), 90 'interest_rate' => 0, 91 'min_allowed_amount' => 500.00, 92 'zero_interest_installments' => true, 93 'terms_min_allowed_amount' => [ 94 6 => 500.00, 95 12 => 1000.00, 96 18 => 1500.00, 97 24 => 2000.00 98 ] 89 99 ), 90 100 ); 101 } 102 103 public function get_provider($id) 104 { 105 return self::$providers[$id]; 91 106 } 92 107 … … 97 112 * @return array of an available installment providers 98 113 */ 99 public function get_available_providers( $currency, $purchase_amount ) { 114 public function get_available_providers($currency, $purchase_amount) 115 { 100 116 $capabilities = $this->capabilities(); 101 117 102 if ( !$capabilities ){118 if (!$capabilities) { 103 119 return null; 104 120 } 105 121 122 $supportedProviderList = []; 123 106 124 // Note: As installment payment at the moment only supports THB and MYR currency, the 107 125 // $purchase_amount is multiplied with 100 to convert the amount into subunit (satang and sen). 108 $providers = $capabilities->getInstallmentBackends( $currency, ( $purchase_amount * 100 ) ); 109 110 foreach ( $providers as &$provider ) { 111 $provider_detail = self::$providers[ $provider->_id ]; 112 113 $provider->provider_code = str_replace( 'installment_', '', $provider->_id ); 114 $provider->provider_name = isset( $provider_detail ) ? $provider_detail['title'] : strtoupper( $provider->code ); 115 $provider->interest_rate = $capabilities->is_zero_interest() ? 0 : ( $provider_detail['interest_rate'] ); 116 $provider->available_plans = $this->get_available_plans( 117 $purchase_amount, 118 $provider->allowed_installment_terms, 119 $provider->interest_rate, 120 $provider_detail['min_allowed_amount'] 121 ); 126 $providers = $capabilities->getInstallmentBackends($currency, ($purchase_amount * 100)); 127 128 foreach ($providers as &$provider) { 129 if (isset(self::$providers[$provider->_id])) { 130 $provider_detail = self::$providers[$provider->_id]; 131 132 $provider->provider_code = str_replace('installment_', '', $provider->_id); 133 $provider->provider_name = isset($provider_detail) 134 ? $provider_detail['title'] 135 : strtoupper($provider->code); 136 $provider->interest_rate = $capabilities->is_zero_interest() 137 ? 0 : ($provider_detail['interest_rate']); 138 $provider->available_plans = $this->get_available_plans( 139 $purchase_amount, 140 $provider->allowed_installment_terms, 141 $provider->interest_rate, 142 $provider_detail 143 ); 144 if (count($provider->available_plans) > 0) { 145 $supportedProviderList[] = $provider; 146 } 147 } 122 148 } 123 149 124 usort( $providers, function( $a, $b) {125 return strcmp( $a->provider_name, $b->provider_name);150 usort($supportedProviderList, function ($a, $b) { 151 return strcmp($a->provider_name, $b->provider_name); 126 152 }); 127 153 128 return $ providers;154 return $supportedProviderList; 129 155 } 130 156 … … 137 163 * @return array of an filtered available terms 138 164 */ 139 public function get_available_plans( $purchase_amount, $allowed_installment_terms, $interest_rate, $min_allowed_amount ) { 165 public function get_available_plans($purchase_amount, $allowed_installment_terms, $interest_rate, $provider_detail) 166 { 140 167 $plans = array(); 141 168 142 sort( $allowed_installment_terms ); 143 144 foreach ( $allowed_installment_terms as $term_length ) { 145 $monthly_amount = $this->calculate_monthly_payment_amount( $purchase_amount, $term_length, $interest_rate ); 146 147 if ( $monthly_amount < $min_allowed_amount ) { 169 $min_allowed_amount = $provider_detail['min_allowed_amount']; 170 sort($allowed_installment_terms); 171 172 foreach ($allowed_installment_terms as $term_length) { 173 $monthly_amount = $this->calculate_monthly_payment_amount($purchase_amount, $term_length, $interest_rate); 174 175 if (isset($provider_detail['terms_min_allowed_amount'])) { 176 $terms_min_allowed_amount = $provider_detail['terms_min_allowed_amount']; 177 $min_allowed_amount = round($terms_min_allowed_amount[$term_length] / $term_length, 2); 178 } 179 180 if ($monthly_amount < $min_allowed_amount) { 148 181 break; 149 182 } … … 165 198 * @return float of a installment monthly payment (round up to 2 decimals). 166 199 */ 167 public function calculate_monthly_payment_amount( $purchase_amount, $term_length, $interest_rate ) { 200 public function calculate_monthly_payment_amount($purchase_amount, $term_length, $interest_rate) 201 { 168 202 $interest = $purchase_amount * $interest_rate * $term_length / 100; 169 return round( ( $purchase_amount + $interest ) / $term_length, 2);203 return round(($purchase_amount + $interest) / $term_length, 2); 170 204 } 171 205 } -
omise/tags/4.28.0/includes/class-omise-capabilities.php
r2795404 r2852769 157 157 * @return string 158 158 */ 159 public function getTouchNGoBackends() { 160 $params = array(); 161 $params[] = $this->capabilities->backendFilter['type']('touch_n_go'); 162 163 return $this->capabilities->getBackends( $params ); 159 public function getTouchNGoBackends() 160 { 161 return $this->getBackendByType('touch_n_go'); 162 } 163 164 /** 165 * Retrieves backend by type 166 */ 167 public function getBackendByType($sourceType) 168 { 169 $params = []; 170 $params[] = $this->capabilities->backendFilter['type']($sourceType); 171 return $this->capabilities->getBackends($params); 164 172 } 165 173 166 174 /** 167 175 * Retrieves details of fpx bank list from capabilities. 168 * 169 * @return string 170 */ 171 public function getFPXBanks() { 172 $params = array(); 173 $params[] = $this->capabilities->backendFilter['type']('fpx'); 174 175 return $this->capabilities->getBackends( $params ); 176 */ 177 public function getFPXBanks() 178 { 179 return $this->getBackendByType('fpx'); 176 180 } 177 181 … … 189 193 * @return bool True if merchant absorbs the interest or else, false. 190 194 */ 191 public function is_zero_interest() { 195 public function is_zero_interest() 196 { 192 197 return $this->capabilities['zero_interest_installments']; 193 198 } … … 196 201 * @return array list of omise backends sourc_type. 197 202 */ 198 public function get_available_payment_methods() { 203 public function get_available_payment_methods() 204 { 199 205 $backends = $this->getBackends(); 200 206 $backends = json_decode(json_encode($backends), true); … … 202 208 return array_merge(array_column($backends, '_id'),$token_methods); 203 209 } 210 211 /** 212 * Retrieves details of Shopee Pay from capabilities. 213 * 214 * @param string $sourceType 215 */ 216 public function getShopeeBackend($sourceType) 217 { 218 $shopeePaySourceTypes = [Omise_Payment_ShopeePay::ID, Omise_Payment_ShopeePay::JUMPAPP_ID]; 219 220 if (!in_array($sourceType, $shopeePaySourceTypes)) { 221 return null; 222 } 223 224 return $this->getBackendByType($sourceType); 225 } 204 226 } -
omise/tags/4.28.0/includes/gateway/class-omise-payment-alipay.php
r2832733 r2852769 58 58 public function charge($order_id, $order) 59 59 { 60 $currency = $order->get Currency();60 $currency = $order->get_currency(); 61 61 return OmiseCharge::create([ 62 62 'amount' => Omise_Money::to_subunit($order->get_total(), $currency), -
omise/tags/4.28.0/includes/gateway/class-omise-payment-billpayment-tesco.php
r2832733 r2852769 11 11 $this->id = 'omise_billpayment_tesco'; 12 12 $this->has_fields = false; 13 $this->method_title = __( 'Opn Payments Bill Payment: Tesco', 'omise' );13 $this->method_title = __( 'Opn Payments Lotus\'s Bill Payment', 'omise' ); 14 14 $this->method_description = wp_kses( 15 __( 'Accept payments through <strong> TescoBill Payment</strong> via Opn Payments payment gateway.', 'omise' ),15 __( 'Accept payments through <strong>Lotus\'s Bill Payment</strong> via Opn Payments payment gateway.', 'omise' ), 16 16 array( 'strong' => array() ) 17 17 ); … … 41 41 'title' => __( 'Enable/Disable', 'omise' ), 42 42 'type' => 'checkbox', 43 'label' => __( 'Enable Opn Payments TescoBill Payment', 'omise' ),43 'label' => __( 'Enable Opn Payments Lotus\'s Bill Payment', 'omise' ), 44 44 'default' => 'no' 45 45 ), … … 49 49 'type' => 'text', 50 50 'description' => __( 'This controls the title the user sees during checkout.', 'omise' ), 51 'default' => __( ' Bill Payment: Tesco', 'omise' ),51 'default' => __( 'Lotus\'s Bill Payment', 'omise' ), 52 52 ), 53 53 … … 125 125 echo sprintf( 126 126 wp_kses( 127 __( 'Please bring this barcode to pay at Tesco Lotus by:<br/><strong>%1$s %2$s</strong>.', 'omise' ),127 __( 'Please bring this barcode to pay at Lotus\'s by:<br/><strong>%1$s %2$s</strong>.', 'omise' ), 128 128 array( 'br' => array(), 'strong' => array() ) 129 129 ), … … 154 154 __( 155 155 ' 156 Tesco Lotusmay charge a small fee for the transaction.<br/>156 Lotus\'s Bill Payment may charge a small fee for the transaction.<br/> 157 157 If you fail to make payment by the stated time, your order will be automatically canceled. 158 158 ', 'omise' … … 189 189 190 190 /** 191 * Convert a given SVG Bill Payment Tesco's barcode to HTML format.191 * Convert a given SVG Bill Payment Lotus's barcode to HTML format. 192 192 * 193 193 * Note that the SVG barcode contains with the following structure: … … 211 211 * @param string $barcode_svg 212 212 * 213 * @return string of a generated Bill Payment Tesco's barcode in HTML format.213 * @return string of a generated Bill Payment Lotus's barcode in HTML format. 214 214 */ 215 215 public function barcode_svg_to_html( $barcode_svg ) { … … 231 231 // Set HTML attributes based on <rect> node's attributes. 232 232 $div_rect = $xhtml->createElement( 'div' ); 233 $div_rect->setAttribute( 'style', "float: left; position: relative; height: 50px; border-left: $width solid #000000; width: 0; margin-left: $margin" ); 233 $div_rect->setAttribute('style', sprintf( 234 'float: left; position: relative; 235 height: 50px; 236 border-left: %spx solid #000000; 237 width: 0; margin-left: %s', 238 $width, 239 $margin 240 )); 234 241 $div_wrapper->appendChild( $div_rect ); 235 242 -
omise/tags/4.28.0/includes/gateway/class-omise-payment-installment.php
r2832733 r2852769 1 1 <?php 2 defined( 'ABSPATH' ) or die( 'No direct script access allowed.');2 defined('ABSPATH') or die('No direct script access allowed.'); 3 3 4 4 /** 5 5 * @since 3.4 6 6 */ 7 class Omise_Payment_Installment extends Omise_Payment_Offsite { 8 public function __construct() { 7 class Omise_Payment_Installment extends Omise_Payment_Offsite 8 { 9 public function __construct() 10 { 9 11 parent::__construct(); 10 12 11 13 $this->id = 'omise_installment'; 12 14 $this->has_fields = true; 13 $this->method_title = __( 'Opn Payments Installments', 'omise');15 $this->method_title = __('Opn Payments Installments', 'omise'); 14 16 $this->method_description = wp_kses( 15 __( 'Accept <strong>installment payments</strong> via Opn Payments payment gateway.', 'omise'),16 array( 'strong' => array())17 __('Accept <strong>installment payments</strong> via Opn Payments payment gateway.', 'omise'), 18 array('strong' => array()) 17 19 ); 18 $this->supports = array( 'products', 'refunds');20 $this->supports = array('products', 'refunds'); 19 21 20 22 $this->init_form_fields(); 21 23 $this->init_settings(); 22 24 23 $this->title = $this->get_option( 'title');24 $this->description = $this->get_option( 'description');25 $this->restricted_countries = array( 'TH', 'MY');25 $this->title = $this->get_option('title'); 26 $this->description = $this->get_option('description'); 27 $this->restricted_countries = array('TH', 'MY'); 26 28 27 29 $this->backend = new Omise_Backend_Installment; 28 30 29 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ));30 add_action( 'woocommerce_order_action_' . $this->id . '_sync_payment', array( $this, 'sync_payment' ));31 add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute');31 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 32 add_action('woocommerce_order_action_' . $this->id . '_sync_payment', array($this, 'sync_payment')); 33 add_action('woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute'); 32 34 } 33 35 … … 36 38 * @see woocommerce/includes/abstracts/abstract-wc-settings-api.php 37 39 */ 38 public function init_form_fields() { 40 public function init_form_fields() 41 { 39 42 $this->form_fields = array( 40 43 'enabled' => array( 41 'title' => __( 'Enable/Disable', 'omise'),44 'title' => __('Enable/Disable', 'omise'), 42 45 'type' => 'checkbox', 43 'label' => __( 'Enable Opn Payments Installment Payments', 'omise'),46 'label' => __('Enable Opn Payments Installment Payments', 'omise'), 44 47 'default' => 'no' 45 48 ), 46 49 47 50 'title' => array( 48 'title' => __( 'Title', 'omise'),51 'title' => __('Title', 'omise'), 49 52 'type' => 'text', 50 'description' => __( 'This controls the title the user sees during checkout.', 'omise'),51 'default' => __( 'Installments', 'omise'),53 'description' => __('This controls the title the user sees during checkout.', 'omise'), 54 'default' => __('Installments', 'omise'), 52 55 ), 53 56 54 57 'description' => array( 55 'title' => __( 'Description', 'omise'),58 'title' => __('Description', 'omise'), 56 59 'type' => 'textarea', 57 'description' => __( 'This controls the description the user sees during checkout.', 'omise')60 'description' => __('This controls the description the user sees during checkout.', 'omise') 58 61 ), 59 62 ); … … 63 66 * @inheritdoc 64 67 */ 65 public function payment_fields() { 68 public function payment_fields() 69 { 66 70 parent::payment_fields(); 67 71 … … 73 77 'templates/payment/form-installment.php', 74 78 array( 75 'installment_backends' => $this->backend->get_available_providers( $currency, $cart_total),79 'installment_backends' => $this->backend->get_available_providers($currency, $cart_total), 76 80 'is_zero_interest' => $capabilities ? $capabilities->is_zero_interest() : false 77 81 ) … … 85 89 { 86 90 $source_type = isset($_POST['source']['type']) ? $_POST['source']['type'] : ''; 87 $installment_terms = isset( $_POST[ $source_type . '_installment_terms'] ) ? $_POST[$source_type . '_installment_terms'] : '';91 $installment_terms = isset($_POST[$source_type . '_installment_terms']) ? $_POST[$source_type . '_installment_terms'] : ''; 88 92 $currency = $order->get_currency(); 93 $provider = $this->backend->get_provider($source_type); 89 94 90 return OmiseCharge::create([95 $payload = [ 91 96 'amount' => Omise_Money::to_subunit($order->get_total(), $currency), 92 97 'currency' => $currency, … … 98 103 'return_uri' => $this->getRedirectUrl('omise_installment_callback', $order_id, $order), 99 104 'metadata' => $this->getMetadata($order_id, $order) 100 ]); 105 ]; 106 107 if (isset($provider['zero_interest_installments'])) { 108 $payload['zero_interest_installments'] = $provider['zero_interest_installments']; 109 } 110 111 return OmiseCharge::create($payload); 101 112 } 102 113 … … 108 119 * @return array|false 109 120 */ 110 public function is_capability_support( $available_payment_methods ) { 121 public function is_capability_support($available_payment_methods) 122 { 111 123 return preg_grep('/^installment_/', $available_payment_methods); 112 124 } -
omise/tags/4.28.0/includes/gateway/class-omise-payment-shopeepay.php
r2832733 r2852769 2 2 defined( 'ABSPATH' ) or die( 'No direct script access allowed.' ); 3 3 4 class Omise_Payment_ShopeePay extends Omise_Payment_Offsite { 4 class Omise_Payment_ShopeePay extends Omise_Payment_Offsite 5 { 6 /** 7 * Backends identifier 8 * @var string 9 */ 10 const ID = 'shopeepay'; 11 const JUMPAPP_ID = 'shopeepay_jumpapp'; 12 5 13 public function __construct() { 6 14 parent::__construct(); … … 11 19 $this->method_description = __( 'Accept payment through <strong>ShopeePay</strong> via Opn Payments payment gateway.', 'omise' ); 12 20 $this->supports = array( 'products', 'refunds' ); 21 $this->source_type = $this->getSource(); 13 22 14 23 $this->init_form_fields(); … … 17 26 $this->title = $this->get_option( 'title' ); 18 27 $this->description = $this->get_option( 'description' ); 19 $this->restricted_countries = array( 'MY' ); 20 $this->source_type = 'shopeepay'; 28 $this->restricted_countries = array( 'MY', 'TH', 'SG' ); 21 29 22 30 add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' ); … … 70 78 71 79 /** 80 * Return the right ShopeePay backend depending on the platform and availability of 81 * the backend in the capability 82 */ 83 private function getSource() 84 { 85 $capabilities = Omise_Capabilities::retrieve(); 86 $isShopeepayJumpAppEnabled = $capabilities->getShopeeBackend(self::JUMPAPP_ID); 87 $isShopeepayEnabled = $capabilities->getShopeeBackend(self::ID); 88 89 // If user is in mobile and jump app is enabled then return shopeepay_jumpapp as source 90 if (Omise_Util::isMobilePlatform() && !empty($isShopeepayJumpAppEnabled)) { 91 return self::JUMPAPP_ID; 92 } 93 94 // If above condition fails then it means either 95 // 96 // Case 1. 97 // User is using mobile device but jump app is not enabled. 98 // This means shopeepay direct is enabled otherwise this code would not execute. 99 // 100 // Case 2. 101 // Jump app is enabled but user is not using mobile device 102 // 103 // In both cases we will want to show the shopeepay MPM backend first if MPM is enabled. 104 // If MPM is not enabled then it means jump app is enabled because this code would never 105 // execute if none of the shopee backends were disabled. 106 return !empty($isShopeepayEnabled) ? self::ID : self::JUMPAPP_ID; 107 } 108 109 /** 72 110 * Get icons 73 111 * -
omise/tags/4.28.0/includes/libraries/omise-php/lib/omise/OmiseCapabilities.php
r2783685 r2852769 127 127 return function ($backend) use ($amount, $defMin, $defMax) { 128 128 // temporary hack for now to correct min value for installments to fixed minimum (different to normal charge minimum) 129 if ($backend->type === 'installment' ) {129 if ($backend->type === 'installment' && get_woocommerce_currency() === 'THB') { 130 130 $min = self::INSTALLMENT_MINIMUM; 131 131 } else { -
omise/tags/4.28.0/omise-util.php
r2588190 r2852769 36 36 return null; 37 37 } 38 39 /** 40 * Check if current platform is mobile or not 41 */ 42 public static function isMobilePlatform() 43 { 44 return null !== self::get_platform_type(wc_get_user_agent()); 45 } 38 46 } 39 47 } 40 ?> -
omise/tags/4.28.0/omise-woocommerce.php
r2832733 r2852769 5 5 * Plugin URI: https://www.omise.co/woocommerce 6 6 * Description: Opn Payments is a WordPress plugin designed specifically for WooCommerce. The plugin adds support for Opn Payments Payment Gateway's payment methods to WooCommerce. 7 * Version: 4.2 7.07 * Version: 4.28.0 8 8 * Author: Opn Payments and contributors 9 9 * Author URI: https://github.com/omise/omise-woocommerce/graphs/contributors … … 23 23 * @var string 24 24 */ 25 public $version = '4.2 7.0';25 public $version = '4.28.0'; 26 26 27 27 /** -
omise/tags/4.28.0/phpunit.xml
r2501457 r2852769 16 16 </testsuite> 17 17 </testsuites> 18 <coverage> 19 <include> 20 <directory suffix=".php">./*</directory> 21 </include> 22 <exclude> 23 <directory suffix=".php">tests</directory> 24 <directory suffix=".php">vendor</directory> 25 </exclude> 26 </coverage> 18 27 </phpunit> -
omise/tags/4.28.0/readme.txt
r2832733 r2852769 4 4 Requires at least: 4.3.1 5 5 Tested up to: 6.0.2 6 Stable tag: 4.2 7.06 Stable tag: 4.28.0 7 7 License: MIT 8 8 License URI: https://opensource.org/licenses/MIT … … 34 34 35 35 == Changelog == 36 37 = 4.28.0 = 38 39 - Added ShopeePay for Thailand and Singapore. (PR [#339](https://github.com/omise/omise-woocommerce/pull/339)) 40 - Rebrand Lotus's Bill Payment. (PR [#336](https://github.com/omise/omise-woocommerce/pull/336)) 41 - Replace ezypay with MBB in installments. (PR [#333](https://github.com/omise/omise-woocommerce/pull/333)) 42 - Fixed the method to get currency to the correct method. (PR [#338](https://github.com/omise/omise-woocommerce/pull/338)) 43 - Code Coverage Integration with Sonarcloud. (PR [#337](https://github.com/omise/omise-woocommerce/pull/337)) 44 - Fix the compatible issue with PHP 7.2 and below. (PR [#342](https://github.com/omise/omise-woocommerce/pull/342)) 36 45 37 46 = 4.27.0 = -
omise/tags/4.28.0/templates/payment/form-installment.php
r2809311 r2852769 47 47 <?php else: ?> 48 48 <p> 49 <?php echo __( 'There are no installment plans available for this purchase amount (minimum amount is 2,000 THB).', 'omise' ); ?> 49 <?php 50 if(get_woocommerce_currency() === 'THB') { 51 echo __( 'There are no installment plans available for this purchase amount (minimum amount is 2,000 THB).', 'omise' ); 52 } else { 53 echo __( 'Purchase Amount is lower than the monthly minimum payment amount.', 'omise' ); 54 } 55 ?> 50 56 </p> 51 57 <?php endif; ?> -
omise/tags/4.28.0/tests/unit/includes/backends/class-omise-backend-installment-test.php
r2621135 r2852769 1 1 <?php 2 2 3 use PHPUnit\Framework\TestCase; 4 3 5 require_once __DIR__ . '/../../class-omise-unit-test.php'; 4 6 5 class Omise_Backend_Installment_Test extends TestCase { 6 public static function setUpBeforeClass(): void { 7 Omise_Unit_Test::include_class( 'backends/class-omise-backend.php' ); 8 Omise_Unit_Test::include_class( 'backends/class-omise-backend-installment.php' ); 9 } 10 11 /** 12 * @test 13 */ 14 public function get_only_valid_plans_from_given_bay_allowed_installment_terms() { 15 $installment_backend = new Omise_Backend_Installment(); 16 $purchase_amount = 2000.00; 17 $allowed_terms = array( 3, 4, 6, 9, 10 ); 18 $interest_rate = 0.8; 19 $min_allowed_amount = 500.00; 20 21 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 22 23 $this->assertEquals( 2, count( $result ) ); 24 $this->assertEquals( array( 25 array( 'term_length' => 3, 'monthly_amount' => 682.67 ), 26 array( 'term_length' => 4, 'monthly_amount' => 516.00 ), 27 ), $result ); 28 } 29 30 /** 31 * @test 32 */ 33 public function get_only_valid_plans_from_given_kbank_allowed_installment_terms() { 34 $installment_backend = new Omise_Backend_Installment(); 35 $purchase_amount = 2000.00; 36 $allowed_terms = array( 3, 4, 6, 10 ); 7 class Omise_Backend_Installment_Test extends TestCase 8 { 9 public static function setUpBeforeClass(): void 10 { 11 Omise_Unit_Test::include_class('backends/class-omise-backend.php'); 12 Omise_Unit_Test::include_class('backends/class-omise-backend-installment.php'); 13 } 14 15 /** 16 * @test 17 */ 18 public function get_only_valid_plans_from_given_bay_allowed_installment_terms() 19 { 20 $installment_backend = new Omise_Backend_Installment(); 21 $purchase_amount = 2000.00; 22 $allowed_terms = array(3, 4, 6, 9, 10); 23 $interest_rate = 0.8; 24 $provider = $installment_backend->get_provider('installment_bay'); 25 26 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 27 28 $this->assertEquals(2, count($result)); 29 $this->assertEquals(array( 30 array('term_length' => 3, 'monthly_amount' => 682.67), 31 array('term_length' => 4, 'monthly_amount' => 516.00), 32 ), $result); 33 } 34 35 /** 36 * @test 37 */ 38 public function get_only_valid_plans_from_given_kbank_allowed_installment_terms() 39 { 40 $installment_backend = new Omise_Backend_Installment(); 41 $purchase_amount = 2000.00; 42 $allowed_terms = array(3, 4, 6, 10); 37 43 $interest_rate = 0.65; 38 $min_allowed_amount = 300.00; 39 40 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 41 42 $this->assertEquals( 3, count( $result ) ); 43 $this->assertEquals( array( 44 array( 'term_length' => 3, 'monthly_amount' => 679.67 ), 45 array( 'term_length' => 4, 'monthly_amount' => 513.00 ), 46 array( 'term_length' => 6, 'monthly_amount' => 346.33 ), 47 ), $result ); 48 } 49 50 /** 51 * @test 52 */ 53 public function get_only_valid_plans_from_given_scb_allowed_installment_terms() { 54 $installment_backend = new Omise_Backend_Installment(); 55 $purchase_amount = 2000.00; 56 $allowed_terms = array( 3, 4, 6, 8, 10 ); 44 $provider = $installment_backend->get_provider('installment_kbank'); 45 46 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 47 48 $this->assertEquals(3, count($result)); 49 $this->assertEquals(array( 50 array('term_length' => 3, 'monthly_amount' => 679.67), 51 array('term_length' => 4, 'monthly_amount' => 513.00), 52 array('term_length' => 6, 'monthly_amount' => 346.33), 53 ), $result); 54 } 55 56 /** 57 * @test 58 */ 59 public function get_only_valid_plans_from_given_scb_allowed_installment_terms() 60 { 61 $installment_backend = new Omise_Backend_Installment(); 62 $purchase_amount = 2000.00; 63 $allowed_terms = array(3, 4, 6, 8, 10); 57 64 $interest_rate = 0.74; 58 $min_allowed_amount = 500.00; 59 60 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 61 62 $this->assertEquals( 2, count( $result ) ); 63 $this->assertEquals( array( 64 array( 'term_length' => 3, 'monthly_amount' => 681.47 ), 65 array( 'term_length' => 4, 'monthly_amount' => 514.80 ), 66 ), $result ); 67 } 68 69 /** 70 * @test 71 */ 72 public function get_only_valid_plans_from_given_bbl_allowed_installment_terms() { 65 $provider = $installment_backend->get_provider('installment_scb'); 66 67 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 68 69 $this->assertEquals(2, count($result)); 70 $this->assertEquals(array( 71 array('term_length' => 3, 'monthly_amount' => 681.47), 72 array('term_length' => 4, 'monthly_amount' => 514.80), 73 ), $result); 74 } 75 76 /** 77 * @test 78 */ 79 public function get_only_valid_plans_from_given_bbl_allowed_installment_terms() 80 { 73 81 $installment_backend = new Omise_Backend_Installment(); 74 82 $purchase_amount = 3000.00; 75 $allowed_terms = array( 3, 4, 6, 8, 10 ); 76 $interest_rate = 0.8; 77 $min_allowed_amount = 500.00; 78 79 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 80 81 $this->assertEquals( 3, count( $result ) ); 82 $this->assertEquals( array( 83 array( 'term_length' => 3, 'monthly_amount' => 1024.00 ), 84 array( 'term_length' => 4, 'monthly_amount' => 774.00 ), 85 array( 'term_length' => 6, 'monthly_amount' => 524.00 ), 86 ), $result ); 87 } 88 89 /** 90 * @test 91 */ 92 public function get_only_valid_plans_from_given_bbl_unsorted_allowed_installment_terms() { 83 $allowed_terms = array(3, 4, 6, 8, 10); 84 $interest_rate = 0.8; 85 $provider = $installment_backend->get_provider('installment_bbl'); 86 87 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 88 89 $this->assertEquals(3, count($result)); 90 $this->assertEquals(array( 91 array('term_length' => 3, 'monthly_amount' => 1024.00), 92 array('term_length' => 4, 'monthly_amount' => 774.00), 93 array('term_length' => 6, 'monthly_amount' => 524.00), 94 ), $result); 95 } 96 97 /** 98 * @test 99 */ 100 public function get_only_valid_plans_from_given_mbb_allowed_installment_terms() 101 { 102 $installment_backend = new Omise_Backend_Installment(); 103 $purchase_amount = 20000.00; 104 $allowed_terms = array(6, 12, 18, 24); 105 $interest_rate = 0.8; 106 $provider = $installment_backend->get_provider('installment_mbb'); 107 108 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 109 110 $this->assertEquals(4, count($result)); 111 $this->assertEquals(array( 112 array('term_length' => 6, 'monthly_amount' => 3493.33), 113 array('term_length' => 12, 'monthly_amount' => 1826.67), 114 array('term_length' => 18, 'monthly_amount' => 1271.11), 115 array('term_length' => 24, 'monthly_amount' => 993.33), 116 ), $result); 117 } 118 119 /** 120 * @test 121 */ 122 public function get_only_valid_plans_from_given_bbl_unsorted_allowed_installment_terms() 123 { 93 124 $installment_backend = new Omise_Backend_Installment(); 94 125 $purchase_amount = 3000.00; 95 $allowed_terms = array( 3, 10, 4, 8, 6 ); 96 $interest_rate = 0.8; 97 $min_allowed_amount = 500.00; 98 99 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 100 101 $this->assertEquals( 3, count( $result ) ); 102 $this->assertEquals( array( 103 array( 'term_length' => 3, 'monthly_amount' => 1024.00 ), 104 array( 'term_length' => 4, 'monthly_amount' => 774.00 ), 105 array( 'term_length' => 6, 'monthly_amount' => 524.00 ), 106 ), $result ); 107 } 108 109 /** 110 * @test 111 */ 112 public function get_only_valid_plans_from_zero_interest_installments() { 113 $installment_backend = new Omise_Backend_Installment(); 114 $purchase_amount = 2000.00; 115 $allowed_terms = array( 3, 4, 5 ); 126 $allowed_terms = array(3, 10, 4, 8, 6); 127 $interest_rate = 0.8; 128 $provider = $installment_backend->get_provider('installment_bbl'); 129 130 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 131 132 $this->assertEquals(3, count($result)); 133 $this->assertEquals(array( 134 array('term_length' => 3, 'monthly_amount' => 1024.00), 135 array('term_length' => 4, 'monthly_amount' => 774.00), 136 array('term_length' => 6, 'monthly_amount' => 524.00), 137 ), $result); 138 } 139 140 /** 141 * @test 142 */ 143 public function get_only_valid_plans_from_zero_interest_installments() 144 { 145 $installment_backend = new Omise_Backend_Installment(); 146 $purchase_amount = 2000.00; 147 $allowed_terms = array(3, 4, 5); 116 148 $interest_rate = 0; 117 $min_allowed_amount = 500.00; 118 119 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 120 121 $this->assertEquals( 2, count( $result ) ); 122 $this->assertEquals( array( 123 array( 'term_length' => 3, 'monthly_amount' => 666.67 ), 124 array( 'term_length' => 4, 'monthly_amount' => 500.00 ), 125 ), $result ); 126 } 127 128 /** 129 * @test 130 */ 131 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_1() { 149 $provider = $installment_backend->get_provider('installment_bbl'); 150 151 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 152 153 $this->assertEquals(2, count($result)); 154 $this->assertEquals(array( 155 array('term_length' => 3, 'monthly_amount' => 666.67), 156 array('term_length' => 4, 'monthly_amount' => 500.00), 157 ), $result); 158 } 159 160 /** 161 * @test 162 */ 163 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_1() 164 { 132 165 $installment_backend = new Omise_Backend_Installment(); 133 166 $purchase_amount = 10000.00; … … 135 168 $interest_rate = 0.8; 136 169 137 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 138 139 $this->assertEquals( 1080.00, $result ); 140 } 141 142 /** 143 * @test 144 */ 145 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_2() { 170 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 171 172 $this->assertEquals(1080.00, $result); 173 } 174 175 /** 176 * @test 177 */ 178 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_2() 179 { 146 180 $installment_backend = new Omise_Backend_Installment(); 147 181 $purchase_amount = 17900.00; … … 149 183 $interest_rate = 0.69; 150 184 151 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 152 153 $this->assertEquals( 3106.84, $result ); 154 } 155 156 /** 157 * @test 158 */ 159 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_3() { 185 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 186 187 $this->assertEquals(3106.84, $result); 188 } 189 190 /** 191 * @test 192 */ 193 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_3() 194 { 160 195 $installment_backend = new Omise_Backend_Installment(); 161 196 $purchase_amount = 5000.00; … … 163 198 $interest_rate = 0.8; 164 199 165 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 166 167 $this->assertEquals( 540.00, $result ); 168 } 169 170 /** 171 * @test 172 */ 173 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_4() { 200 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 201 202 $this->assertEquals(540.00, $result); 203 } 204 205 /** 206 * @test 207 */ 208 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_4() 209 { 174 210 $installment_backend = new Omise_Backend_Installment(); 175 211 $purchase_amount = 3000.00; … … 177 213 $interest_rate = 0.74; 178 214 179 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 180 181 $this->assertEquals( 772.20, $result ); 182 } 183 184 /** 185 * @test 186 */ 187 public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_1() { 215 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 216 217 $this->assertEquals(772.20, $result); 218 } 219 220 /** 221 * @test 222 */ 223 public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_1() 224 { 188 225 $installment_backend = new Omise_Backend_Installment(); 189 226 $purchase_amount = 10000.00; … … 191 228 $interest_rate = 0; 192 229 193 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 194 195 $this->assertEquals( 1000.00, $result ); 196 } 197 198 /** 199 * @test 200 */ 201 public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_2() { 230 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 231 232 $this->assertEquals(1000.00, $result); 233 } 234 235 /** 236 * @test 237 */ 238 public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_2() 239 { 202 240 $installment_backend = new Omise_Backend_Installment(); 203 241 $purchase_amount = 5000.00; … … 205 243 $interest_rate = 0; 206 244 207 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate);208 209 $this->assertEquals( 833.33, $result);245 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 246 247 $this->assertEquals(833.33, $result); 210 248 } 211 249 } … … 218 256 * @see includes/class-omise-capabilities 219 257 */ 220 class Omise_Capabilities { 258 class Omise_Capabilities 259 { 221 260 /** 222 261 * @var self … … 224 263 protected static $the_instance = null; 225 264 226 public static function retrieve() { 265 public static function retrieve() 266 { 227 267 self::$the_instance = self::$the_instance ?: new self(); 228 268 return self::$the_instance; 229 269 } 230 270 231 public function is_zero_interest() { 271 public function is_zero_interest() 272 { 232 273 return false; 233 274 } -
omise/trunk/CHANGELOG.md
r2832733 r2852769 1 1 # CHANGELOG 2 3 ### [v4.28.0 _(Jan 24, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.28.0) 4 - Added ShopeePay for Thailand and Singapore. (PR [#339](https://github.com/omise/omise-woocommerce/pull/339)) 5 - Rebrand Lotus's Bill Payment. (PR [#336](https://github.com/omise/omise-woocommerce/pull/336)) 6 - Replace ezypay with MBB in installments. (PR [#333](https://github.com/omise/omise-woocommerce/pull/333)) 7 - Fixed the method to get currency to the correct method. (PR [#338](https://github.com/omise/omise-woocommerce/pull/338)) 8 - Code Coverage Integration with Sonarcloud. (PR [#337](https://github.com/omise/omise-woocommerce/pull/337)) 9 - Fix the compatible issue with PHP 7.2 and below. (PR [#342](https://github.com/omise/omise-woocommerce/pull/342)) 2 10 3 11 ### [v4.27.0 _(Dec 7, 2022)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.27.0) -
omise/trunk/assets/css/omise-css.css
r2809311 r2852769 65 65 66 66 /** 67 * Omise Bill Payment Tesco67 * Omise Bill Payment Lotus 68 68 * CSS for the 'Thank You' (order-received) page. 69 69 */ … … 404 404 405 405 /** MAYBANK **/ 406 .bank-logo. ezypay{406 .bank-logo.mbb { 407 407 background: url('../images/maybank.svg') #ffcf00; 408 408 border-color: #ffcf00; -
omise/trunk/composer.json
r2501457 r2852769 5 5 "license": "MIT", 6 6 "require-dev": { 7 "phpunit/phpunit": "^ 8.1"7 "phpunit/phpunit": "^5.7 || ^9.5" 8 8 } 9 9 } -
omise/trunk/includes/admin/views/omise-page-settings.php
r2832733 r2852769 30 30 ) 31 31 ), 32 esc_url( 'https://dashboard.omise.co/v2/settings/keys' ) ,32 esc_url( 'https://dashboard.omise.co/v2/settings/keys' ) 33 33 ); 34 34 ?> -
omise/trunk/includes/backends/class-omise-backend-installment.php
r2783685 r2852769 1 1 <?php 2 2 3 /** 3 4 * Note: The calculations in this class depend on the countries that … … 11 12 * @method public calculate_monthly_payment_amount 12 13 */ 13 class Omise_Backend_Installment extends Omise_Backend { 14 class Omise_Backend_Installment extends Omise_Backend 15 { 14 16 /** 15 17 * @var array of known installment providers. … … 17 19 protected static $providers = array(); 18 20 19 public function initiate() { 21 public function initiate() 22 { 20 23 self::$providers = array( 21 24 'installment_first_choice' => array( 22 25 'bank_code' => 'first_choice', 23 'title' => __( 'Krungsri First Choice', 'omise'),26 'title' => __('Krungsri First Choice', 'omise'), 24 27 'interest_rate' => 1.3, 25 28 'min_allowed_amount' => 300.00, … … 28 31 'installment_bay' => array( 29 32 'bank_code' => 'bay', 30 'title' => __( 'Krungsri', 'omise'),33 'title' => __('Krungsri', 'omise'), 31 34 'interest_rate' => 0.8, 32 35 'min_allowed_amount' => 500.00, … … 35 38 'installment_ktc' => array( 36 39 'bank_code' => 'ktc', 37 'title' => __( 'Krungthai Card (KTC)', 'omise'),40 'title' => __('Krungthai Card (KTC)', 'omise'), 38 41 'interest_rate' => 0.8, 39 42 'min_allowed_amount' => 300.00, … … 42 45 'installment_bbl' => array( 43 46 'bank_code' => 'bbl', 44 'title' => __( 'Bangkok Bank', 'omise'),47 'title' => __('Bangkok Bank', 'omise'), 45 48 'interest_rate' => 0.8, 46 49 'min_allowed_amount' => 500.00, … … 49 52 'installment_kbank' => array( 50 53 'bank_code' => 'kbank', 51 'title' => __( 'Kasikorn Bank', 'omise'),54 'title' => __('Kasikorn Bank', 'omise'), 52 55 'interest_rate' => 0.65, 53 56 'min_allowed_amount' => 300.00, … … 56 59 'installment_scb' => array( 57 60 'bank_code' => 'scb', 58 'title' => __( 'Siam Commercial Bank', 'omise'),61 'title' => __('Siam Commercial Bank', 'omise'), 59 62 'interest_rate' => 0.74, 60 63 'min_allowed_amount' => 500.00, … … 63 66 'installment_citi' => array( 64 67 'bank_code' => 'citi', 65 'title' => __( 'Citibank', 'omise'),68 'title' => __('Citibank', 'omise'), 66 69 'interest_rate' => 0, 67 70 'min_allowed_amount' => 500.00, … … 70 73 'installment_ttb' => array( 71 74 'bank_code' => 'ttb', 72 'title' => __( 'TMBThanachart Bank', 'omise'),75 'title' => __('TMBThanachart Bank', 'omise'), 73 76 'interest_rate' => 0, 74 77 'min_allowed_amount' => 500.00, … … 77 80 'installment_uob' => array( 78 81 'bank_code' => 'uob', 79 'title' => __( 'United Overseas Bank', 'omise' ), 80 'interest_rate' => 0, 81 'min_allowed_amount' => 500.00, 82 ), 83 84 'installment_ezypay' => array( 85 'bank_code' => 'ezypay', 86 'title' => __( 'Maybank (EzyPay)', 'omise' ), 87 'interest_rate' => 0, 88 'min_allowed_amount' => 500.00, 82 'title' => __('United Overseas Bank', 'omise'), 83 'interest_rate' => 0, 84 'min_allowed_amount' => 500.00, 85 ), 86 87 'installment_mbb' => array( 88 'bank_code' => 'mbb', 89 'title' => __('Maybank', 'omise'), 90 'interest_rate' => 0, 91 'min_allowed_amount' => 500.00, 92 'zero_interest_installments' => true, 93 'terms_min_allowed_amount' => [ 94 6 => 500.00, 95 12 => 1000.00, 96 18 => 1500.00, 97 24 => 2000.00 98 ] 89 99 ), 90 100 ); 101 } 102 103 public function get_provider($id) 104 { 105 return self::$providers[$id]; 91 106 } 92 107 … … 97 112 * @return array of an available installment providers 98 113 */ 99 public function get_available_providers( $currency, $purchase_amount ) { 114 public function get_available_providers($currency, $purchase_amount) 115 { 100 116 $capabilities = $this->capabilities(); 101 117 102 if ( !$capabilities ){118 if (!$capabilities) { 103 119 return null; 104 120 } 105 121 122 $supportedProviderList = []; 123 106 124 // Note: As installment payment at the moment only supports THB and MYR currency, the 107 125 // $purchase_amount is multiplied with 100 to convert the amount into subunit (satang and sen). 108 $providers = $capabilities->getInstallmentBackends( $currency, ( $purchase_amount * 100 ) ); 109 110 foreach ( $providers as &$provider ) { 111 $provider_detail = self::$providers[ $provider->_id ]; 112 113 $provider->provider_code = str_replace( 'installment_', '', $provider->_id ); 114 $provider->provider_name = isset( $provider_detail ) ? $provider_detail['title'] : strtoupper( $provider->code ); 115 $provider->interest_rate = $capabilities->is_zero_interest() ? 0 : ( $provider_detail['interest_rate'] ); 116 $provider->available_plans = $this->get_available_plans( 117 $purchase_amount, 118 $provider->allowed_installment_terms, 119 $provider->interest_rate, 120 $provider_detail['min_allowed_amount'] 121 ); 126 $providers = $capabilities->getInstallmentBackends($currency, ($purchase_amount * 100)); 127 128 foreach ($providers as &$provider) { 129 if (isset(self::$providers[$provider->_id])) { 130 $provider_detail = self::$providers[$provider->_id]; 131 132 $provider->provider_code = str_replace('installment_', '', $provider->_id); 133 $provider->provider_name = isset($provider_detail) 134 ? $provider_detail['title'] 135 : strtoupper($provider->code); 136 $provider->interest_rate = $capabilities->is_zero_interest() 137 ? 0 : ($provider_detail['interest_rate']); 138 $provider->available_plans = $this->get_available_plans( 139 $purchase_amount, 140 $provider->allowed_installment_terms, 141 $provider->interest_rate, 142 $provider_detail 143 ); 144 if (count($provider->available_plans) > 0) { 145 $supportedProviderList[] = $provider; 146 } 147 } 122 148 } 123 149 124 usort( $providers, function( $a, $b) {125 return strcmp( $a->provider_name, $b->provider_name);150 usort($supportedProviderList, function ($a, $b) { 151 return strcmp($a->provider_name, $b->provider_name); 126 152 }); 127 153 128 return $ providers;154 return $supportedProviderList; 129 155 } 130 156 … … 137 163 * @return array of an filtered available terms 138 164 */ 139 public function get_available_plans( $purchase_amount, $allowed_installment_terms, $interest_rate, $min_allowed_amount ) { 165 public function get_available_plans($purchase_amount, $allowed_installment_terms, $interest_rate, $provider_detail) 166 { 140 167 $plans = array(); 141 168 142 sort( $allowed_installment_terms ); 143 144 foreach ( $allowed_installment_terms as $term_length ) { 145 $monthly_amount = $this->calculate_monthly_payment_amount( $purchase_amount, $term_length, $interest_rate ); 146 147 if ( $monthly_amount < $min_allowed_amount ) { 169 $min_allowed_amount = $provider_detail['min_allowed_amount']; 170 sort($allowed_installment_terms); 171 172 foreach ($allowed_installment_terms as $term_length) { 173 $monthly_amount = $this->calculate_monthly_payment_amount($purchase_amount, $term_length, $interest_rate); 174 175 if (isset($provider_detail['terms_min_allowed_amount'])) { 176 $terms_min_allowed_amount = $provider_detail['terms_min_allowed_amount']; 177 $min_allowed_amount = round($terms_min_allowed_amount[$term_length] / $term_length, 2); 178 } 179 180 if ($monthly_amount < $min_allowed_amount) { 148 181 break; 149 182 } … … 165 198 * @return float of a installment monthly payment (round up to 2 decimals). 166 199 */ 167 public function calculate_monthly_payment_amount( $purchase_amount, $term_length, $interest_rate ) { 200 public function calculate_monthly_payment_amount($purchase_amount, $term_length, $interest_rate) 201 { 168 202 $interest = $purchase_amount * $interest_rate * $term_length / 100; 169 return round( ( $purchase_amount + $interest ) / $term_length, 2);203 return round(($purchase_amount + $interest) / $term_length, 2); 170 204 } 171 205 } -
omise/trunk/includes/class-omise-capabilities.php
r2795404 r2852769 157 157 * @return string 158 158 */ 159 public function getTouchNGoBackends() { 160 $params = array(); 161 $params[] = $this->capabilities->backendFilter['type']('touch_n_go'); 162 163 return $this->capabilities->getBackends( $params ); 159 public function getTouchNGoBackends() 160 { 161 return $this->getBackendByType('touch_n_go'); 162 } 163 164 /** 165 * Retrieves backend by type 166 */ 167 public function getBackendByType($sourceType) 168 { 169 $params = []; 170 $params[] = $this->capabilities->backendFilter['type']($sourceType); 171 return $this->capabilities->getBackends($params); 164 172 } 165 173 166 174 /** 167 175 * Retrieves details of fpx bank list from capabilities. 168 * 169 * @return string 170 */ 171 public function getFPXBanks() { 172 $params = array(); 173 $params[] = $this->capabilities->backendFilter['type']('fpx'); 174 175 return $this->capabilities->getBackends( $params ); 176 */ 177 public function getFPXBanks() 178 { 179 return $this->getBackendByType('fpx'); 176 180 } 177 181 … … 189 193 * @return bool True if merchant absorbs the interest or else, false. 190 194 */ 191 public function is_zero_interest() { 195 public function is_zero_interest() 196 { 192 197 return $this->capabilities['zero_interest_installments']; 193 198 } … … 196 201 * @return array list of omise backends sourc_type. 197 202 */ 198 public function get_available_payment_methods() { 203 public function get_available_payment_methods() 204 { 199 205 $backends = $this->getBackends(); 200 206 $backends = json_decode(json_encode($backends), true); … … 202 208 return array_merge(array_column($backends, '_id'),$token_methods); 203 209 } 210 211 /** 212 * Retrieves details of Shopee Pay from capabilities. 213 * 214 * @param string $sourceType 215 */ 216 public function getShopeeBackend($sourceType) 217 { 218 $shopeePaySourceTypes = [Omise_Payment_ShopeePay::ID, Omise_Payment_ShopeePay::JUMPAPP_ID]; 219 220 if (!in_array($sourceType, $shopeePaySourceTypes)) { 221 return null; 222 } 223 224 return $this->getBackendByType($sourceType); 225 } 204 226 } -
omise/trunk/includes/gateway/class-omise-payment-alipay.php
r2832733 r2852769 58 58 public function charge($order_id, $order) 59 59 { 60 $currency = $order->get Currency();60 $currency = $order->get_currency(); 61 61 return OmiseCharge::create([ 62 62 'amount' => Omise_Money::to_subunit($order->get_total(), $currency), -
omise/trunk/includes/gateway/class-omise-payment-billpayment-tesco.php
r2832733 r2852769 11 11 $this->id = 'omise_billpayment_tesco'; 12 12 $this->has_fields = false; 13 $this->method_title = __( 'Opn Payments Bill Payment: Tesco', 'omise' );13 $this->method_title = __( 'Opn Payments Lotus\'s Bill Payment', 'omise' ); 14 14 $this->method_description = wp_kses( 15 __( 'Accept payments through <strong> TescoBill Payment</strong> via Opn Payments payment gateway.', 'omise' ),15 __( 'Accept payments through <strong>Lotus\'s Bill Payment</strong> via Opn Payments payment gateway.', 'omise' ), 16 16 array( 'strong' => array() ) 17 17 ); … … 41 41 'title' => __( 'Enable/Disable', 'omise' ), 42 42 'type' => 'checkbox', 43 'label' => __( 'Enable Opn Payments TescoBill Payment', 'omise' ),43 'label' => __( 'Enable Opn Payments Lotus\'s Bill Payment', 'omise' ), 44 44 'default' => 'no' 45 45 ), … … 49 49 'type' => 'text', 50 50 'description' => __( 'This controls the title the user sees during checkout.', 'omise' ), 51 'default' => __( ' Bill Payment: Tesco', 'omise' ),51 'default' => __( 'Lotus\'s Bill Payment', 'omise' ), 52 52 ), 53 53 … … 125 125 echo sprintf( 126 126 wp_kses( 127 __( 'Please bring this barcode to pay at Tesco Lotus by:<br/><strong>%1$s %2$s</strong>.', 'omise' ),127 __( 'Please bring this barcode to pay at Lotus\'s by:<br/><strong>%1$s %2$s</strong>.', 'omise' ), 128 128 array( 'br' => array(), 'strong' => array() ) 129 129 ), … … 154 154 __( 155 155 ' 156 Tesco Lotusmay charge a small fee for the transaction.<br/>156 Lotus\'s Bill Payment may charge a small fee for the transaction.<br/> 157 157 If you fail to make payment by the stated time, your order will be automatically canceled. 158 158 ', 'omise' … … 189 189 190 190 /** 191 * Convert a given SVG Bill Payment Tesco's barcode to HTML format.191 * Convert a given SVG Bill Payment Lotus's barcode to HTML format. 192 192 * 193 193 * Note that the SVG barcode contains with the following structure: … … 211 211 * @param string $barcode_svg 212 212 * 213 * @return string of a generated Bill Payment Tesco's barcode in HTML format.213 * @return string of a generated Bill Payment Lotus's barcode in HTML format. 214 214 */ 215 215 public function barcode_svg_to_html( $barcode_svg ) { … … 231 231 // Set HTML attributes based on <rect> node's attributes. 232 232 $div_rect = $xhtml->createElement( 'div' ); 233 $div_rect->setAttribute( 'style', "float: left; position: relative; height: 50px; border-left: $width solid #000000; width: 0; margin-left: $margin" ); 233 $div_rect->setAttribute('style', sprintf( 234 'float: left; position: relative; 235 height: 50px; 236 border-left: %spx solid #000000; 237 width: 0; margin-left: %s', 238 $width, 239 $margin 240 )); 234 241 $div_wrapper->appendChild( $div_rect ); 235 242 -
omise/trunk/includes/gateway/class-omise-payment-installment.php
r2832733 r2852769 1 1 <?php 2 defined( 'ABSPATH' ) or die( 'No direct script access allowed.');2 defined('ABSPATH') or die('No direct script access allowed.'); 3 3 4 4 /** 5 5 * @since 3.4 6 6 */ 7 class Omise_Payment_Installment extends Omise_Payment_Offsite { 8 public function __construct() { 7 class Omise_Payment_Installment extends Omise_Payment_Offsite 8 { 9 public function __construct() 10 { 9 11 parent::__construct(); 10 12 11 13 $this->id = 'omise_installment'; 12 14 $this->has_fields = true; 13 $this->method_title = __( 'Opn Payments Installments', 'omise');15 $this->method_title = __('Opn Payments Installments', 'omise'); 14 16 $this->method_description = wp_kses( 15 __( 'Accept <strong>installment payments</strong> via Opn Payments payment gateway.', 'omise'),16 array( 'strong' => array())17 __('Accept <strong>installment payments</strong> via Opn Payments payment gateway.', 'omise'), 18 array('strong' => array()) 17 19 ); 18 $this->supports = array( 'products', 'refunds');20 $this->supports = array('products', 'refunds'); 19 21 20 22 $this->init_form_fields(); 21 23 $this->init_settings(); 22 24 23 $this->title = $this->get_option( 'title');24 $this->description = $this->get_option( 'description');25 $this->restricted_countries = array( 'TH', 'MY');25 $this->title = $this->get_option('title'); 26 $this->description = $this->get_option('description'); 27 $this->restricted_countries = array('TH', 'MY'); 26 28 27 29 $this->backend = new Omise_Backend_Installment; 28 30 29 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ));30 add_action( 'woocommerce_order_action_' . $this->id . '_sync_payment', array( $this, 'sync_payment' ));31 add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute');31 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 32 add_action('woocommerce_order_action_' . $this->id . '_sync_payment', array($this, 'sync_payment')); 33 add_action('woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute'); 32 34 } 33 35 … … 36 38 * @see woocommerce/includes/abstracts/abstract-wc-settings-api.php 37 39 */ 38 public function init_form_fields() { 40 public function init_form_fields() 41 { 39 42 $this->form_fields = array( 40 43 'enabled' => array( 41 'title' => __( 'Enable/Disable', 'omise'),44 'title' => __('Enable/Disable', 'omise'), 42 45 'type' => 'checkbox', 43 'label' => __( 'Enable Opn Payments Installment Payments', 'omise'),46 'label' => __('Enable Opn Payments Installment Payments', 'omise'), 44 47 'default' => 'no' 45 48 ), 46 49 47 50 'title' => array( 48 'title' => __( 'Title', 'omise'),51 'title' => __('Title', 'omise'), 49 52 'type' => 'text', 50 'description' => __( 'This controls the title the user sees during checkout.', 'omise'),51 'default' => __( 'Installments', 'omise'),53 'description' => __('This controls the title the user sees during checkout.', 'omise'), 54 'default' => __('Installments', 'omise'), 52 55 ), 53 56 54 57 'description' => array( 55 'title' => __( 'Description', 'omise'),58 'title' => __('Description', 'omise'), 56 59 'type' => 'textarea', 57 'description' => __( 'This controls the description the user sees during checkout.', 'omise')60 'description' => __('This controls the description the user sees during checkout.', 'omise') 58 61 ), 59 62 ); … … 63 66 * @inheritdoc 64 67 */ 65 public function payment_fields() { 68 public function payment_fields() 69 { 66 70 parent::payment_fields(); 67 71 … … 73 77 'templates/payment/form-installment.php', 74 78 array( 75 'installment_backends' => $this->backend->get_available_providers( $currency, $cart_total),79 'installment_backends' => $this->backend->get_available_providers($currency, $cart_total), 76 80 'is_zero_interest' => $capabilities ? $capabilities->is_zero_interest() : false 77 81 ) … … 85 89 { 86 90 $source_type = isset($_POST['source']['type']) ? $_POST['source']['type'] : ''; 87 $installment_terms = isset( $_POST[ $source_type . '_installment_terms'] ) ? $_POST[$source_type . '_installment_terms'] : '';91 $installment_terms = isset($_POST[$source_type . '_installment_terms']) ? $_POST[$source_type . '_installment_terms'] : ''; 88 92 $currency = $order->get_currency(); 93 $provider = $this->backend->get_provider($source_type); 89 94 90 return OmiseCharge::create([95 $payload = [ 91 96 'amount' => Omise_Money::to_subunit($order->get_total(), $currency), 92 97 'currency' => $currency, … … 98 103 'return_uri' => $this->getRedirectUrl('omise_installment_callback', $order_id, $order), 99 104 'metadata' => $this->getMetadata($order_id, $order) 100 ]); 105 ]; 106 107 if (isset($provider['zero_interest_installments'])) { 108 $payload['zero_interest_installments'] = $provider['zero_interest_installments']; 109 } 110 111 return OmiseCharge::create($payload); 101 112 } 102 113 … … 108 119 * @return array|false 109 120 */ 110 public function is_capability_support( $available_payment_methods ) { 121 public function is_capability_support($available_payment_methods) 122 { 111 123 return preg_grep('/^installment_/', $available_payment_methods); 112 124 } -
omise/trunk/includes/gateway/class-omise-payment-shopeepay.php
r2832733 r2852769 2 2 defined( 'ABSPATH' ) or die( 'No direct script access allowed.' ); 3 3 4 class Omise_Payment_ShopeePay extends Omise_Payment_Offsite { 4 class Omise_Payment_ShopeePay extends Omise_Payment_Offsite 5 { 6 /** 7 * Backends identifier 8 * @var string 9 */ 10 const ID = 'shopeepay'; 11 const JUMPAPP_ID = 'shopeepay_jumpapp'; 12 5 13 public function __construct() { 6 14 parent::__construct(); … … 11 19 $this->method_description = __( 'Accept payment through <strong>ShopeePay</strong> via Opn Payments payment gateway.', 'omise' ); 12 20 $this->supports = array( 'products', 'refunds' ); 21 $this->source_type = $this->getSource(); 13 22 14 23 $this->init_form_fields(); … … 17 26 $this->title = $this->get_option( 'title' ); 18 27 $this->description = $this->get_option( 'description' ); 19 $this->restricted_countries = array( 'MY' ); 20 $this->source_type = 'shopeepay'; 28 $this->restricted_countries = array( 'MY', 'TH', 'SG' ); 21 29 22 30 add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' ); … … 70 78 71 79 /** 80 * Return the right ShopeePay backend depending on the platform and availability of 81 * the backend in the capability 82 */ 83 private function getSource() 84 { 85 $capabilities = Omise_Capabilities::retrieve(); 86 $isShopeepayJumpAppEnabled = $capabilities->getShopeeBackend(self::JUMPAPP_ID); 87 $isShopeepayEnabled = $capabilities->getShopeeBackend(self::ID); 88 89 // If user is in mobile and jump app is enabled then return shopeepay_jumpapp as source 90 if (Omise_Util::isMobilePlatform() && !empty($isShopeepayJumpAppEnabled)) { 91 return self::JUMPAPP_ID; 92 } 93 94 // If above condition fails then it means either 95 // 96 // Case 1. 97 // User is using mobile device but jump app is not enabled. 98 // This means shopeepay direct is enabled otherwise this code would not execute. 99 // 100 // Case 2. 101 // Jump app is enabled but user is not using mobile device 102 // 103 // In both cases we will want to show the shopeepay MPM backend first if MPM is enabled. 104 // If MPM is not enabled then it means jump app is enabled because this code would never 105 // execute if none of the shopee backends were disabled. 106 return !empty($isShopeepayEnabled) ? self::ID : self::JUMPAPP_ID; 107 } 108 109 /** 72 110 * Get icons 73 111 * -
omise/trunk/includes/libraries/omise-php/lib/omise/OmiseCapabilities.php
r2783685 r2852769 127 127 return function ($backend) use ($amount, $defMin, $defMax) { 128 128 // temporary hack for now to correct min value for installments to fixed minimum (different to normal charge minimum) 129 if ($backend->type === 'installment' ) {129 if ($backend->type === 'installment' && get_woocommerce_currency() === 'THB') { 130 130 $min = self::INSTALLMENT_MINIMUM; 131 131 } else { -
omise/trunk/omise-util.php
r2588190 r2852769 36 36 return null; 37 37 } 38 39 /** 40 * Check if current platform is mobile or not 41 */ 42 public static function isMobilePlatform() 43 { 44 return null !== self::get_platform_type(wc_get_user_agent()); 45 } 38 46 } 39 47 } 40 ?> -
omise/trunk/omise-woocommerce.php
r2832733 r2852769 5 5 * Plugin URI: https://www.omise.co/woocommerce 6 6 * Description: Opn Payments is a WordPress plugin designed specifically for WooCommerce. The plugin adds support for Opn Payments Payment Gateway's payment methods to WooCommerce. 7 * Version: 4.2 7.07 * Version: 4.28.0 8 8 * Author: Opn Payments and contributors 9 9 * Author URI: https://github.com/omise/omise-woocommerce/graphs/contributors … … 23 23 * @var string 24 24 */ 25 public $version = '4.2 7.0';25 public $version = '4.28.0'; 26 26 27 27 /** -
omise/trunk/phpunit.xml
r2501457 r2852769 16 16 </testsuite> 17 17 </testsuites> 18 <coverage> 19 <include> 20 <directory suffix=".php">./*</directory> 21 </include> 22 <exclude> 23 <directory suffix=".php">tests</directory> 24 <directory suffix=".php">vendor</directory> 25 </exclude> 26 </coverage> 18 27 </phpunit> -
omise/trunk/readme.txt
r2832733 r2852769 4 4 Requires at least: 4.3.1 5 5 Tested up to: 6.0.2 6 Stable tag: 4.2 7.06 Stable tag: 4.28.0 7 7 License: MIT 8 8 License URI: https://opensource.org/licenses/MIT … … 34 34 35 35 == Changelog == 36 37 = 4.28.0 = 38 39 - Added ShopeePay for Thailand and Singapore. (PR [#339](https://github.com/omise/omise-woocommerce/pull/339)) 40 - Rebrand Lotus's Bill Payment. (PR [#336](https://github.com/omise/omise-woocommerce/pull/336)) 41 - Replace ezypay with MBB in installments. (PR [#333](https://github.com/omise/omise-woocommerce/pull/333)) 42 - Fixed the method to get currency to the correct method. (PR [#338](https://github.com/omise/omise-woocommerce/pull/338)) 43 - Code Coverage Integration with Sonarcloud. (PR [#337](https://github.com/omise/omise-woocommerce/pull/337)) 44 - Fix the compatible issue with PHP 7.2 and below. (PR [#342](https://github.com/omise/omise-woocommerce/pull/342)) 36 45 37 46 = 4.27.0 = -
omise/trunk/templates/payment/form-installment.php
r2809311 r2852769 47 47 <?php else: ?> 48 48 <p> 49 <?php echo __( 'There are no installment plans available for this purchase amount (minimum amount is 2,000 THB).', 'omise' ); ?> 49 <?php 50 if(get_woocommerce_currency() === 'THB') { 51 echo __( 'There are no installment plans available for this purchase amount (minimum amount is 2,000 THB).', 'omise' ); 52 } else { 53 echo __( 'Purchase Amount is lower than the monthly minimum payment amount.', 'omise' ); 54 } 55 ?> 50 56 </p> 51 57 <?php endif; ?> -
omise/trunk/tests/unit/includes/backends/class-omise-backend-installment-test.php
r2621135 r2852769 1 1 <?php 2 2 3 use PHPUnit\Framework\TestCase; 4 3 5 require_once __DIR__ . '/../../class-omise-unit-test.php'; 4 6 5 class Omise_Backend_Installment_Test extends TestCase { 6 public static function setUpBeforeClass(): void { 7 Omise_Unit_Test::include_class( 'backends/class-omise-backend.php' ); 8 Omise_Unit_Test::include_class( 'backends/class-omise-backend-installment.php' ); 9 } 10 11 /** 12 * @test 13 */ 14 public function get_only_valid_plans_from_given_bay_allowed_installment_terms() { 15 $installment_backend = new Omise_Backend_Installment(); 16 $purchase_amount = 2000.00; 17 $allowed_terms = array( 3, 4, 6, 9, 10 ); 18 $interest_rate = 0.8; 19 $min_allowed_amount = 500.00; 20 21 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 22 23 $this->assertEquals( 2, count( $result ) ); 24 $this->assertEquals( array( 25 array( 'term_length' => 3, 'monthly_amount' => 682.67 ), 26 array( 'term_length' => 4, 'monthly_amount' => 516.00 ), 27 ), $result ); 28 } 29 30 /** 31 * @test 32 */ 33 public function get_only_valid_plans_from_given_kbank_allowed_installment_terms() { 34 $installment_backend = new Omise_Backend_Installment(); 35 $purchase_amount = 2000.00; 36 $allowed_terms = array( 3, 4, 6, 10 ); 7 class Omise_Backend_Installment_Test extends TestCase 8 { 9 public static function setUpBeforeClass(): void 10 { 11 Omise_Unit_Test::include_class('backends/class-omise-backend.php'); 12 Omise_Unit_Test::include_class('backends/class-omise-backend-installment.php'); 13 } 14 15 /** 16 * @test 17 */ 18 public function get_only_valid_plans_from_given_bay_allowed_installment_terms() 19 { 20 $installment_backend = new Omise_Backend_Installment(); 21 $purchase_amount = 2000.00; 22 $allowed_terms = array(3, 4, 6, 9, 10); 23 $interest_rate = 0.8; 24 $provider = $installment_backend->get_provider('installment_bay'); 25 26 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 27 28 $this->assertEquals(2, count($result)); 29 $this->assertEquals(array( 30 array('term_length' => 3, 'monthly_amount' => 682.67), 31 array('term_length' => 4, 'monthly_amount' => 516.00), 32 ), $result); 33 } 34 35 /** 36 * @test 37 */ 38 public function get_only_valid_plans_from_given_kbank_allowed_installment_terms() 39 { 40 $installment_backend = new Omise_Backend_Installment(); 41 $purchase_amount = 2000.00; 42 $allowed_terms = array(3, 4, 6, 10); 37 43 $interest_rate = 0.65; 38 $min_allowed_amount = 300.00; 39 40 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 41 42 $this->assertEquals( 3, count( $result ) ); 43 $this->assertEquals( array( 44 array( 'term_length' => 3, 'monthly_amount' => 679.67 ), 45 array( 'term_length' => 4, 'monthly_amount' => 513.00 ), 46 array( 'term_length' => 6, 'monthly_amount' => 346.33 ), 47 ), $result ); 48 } 49 50 /** 51 * @test 52 */ 53 public function get_only_valid_plans_from_given_scb_allowed_installment_terms() { 54 $installment_backend = new Omise_Backend_Installment(); 55 $purchase_amount = 2000.00; 56 $allowed_terms = array( 3, 4, 6, 8, 10 ); 44 $provider = $installment_backend->get_provider('installment_kbank'); 45 46 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 47 48 $this->assertEquals(3, count($result)); 49 $this->assertEquals(array( 50 array('term_length' => 3, 'monthly_amount' => 679.67), 51 array('term_length' => 4, 'monthly_amount' => 513.00), 52 array('term_length' => 6, 'monthly_amount' => 346.33), 53 ), $result); 54 } 55 56 /** 57 * @test 58 */ 59 public function get_only_valid_plans_from_given_scb_allowed_installment_terms() 60 { 61 $installment_backend = new Omise_Backend_Installment(); 62 $purchase_amount = 2000.00; 63 $allowed_terms = array(3, 4, 6, 8, 10); 57 64 $interest_rate = 0.74; 58 $min_allowed_amount = 500.00; 59 60 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 61 62 $this->assertEquals( 2, count( $result ) ); 63 $this->assertEquals( array( 64 array( 'term_length' => 3, 'monthly_amount' => 681.47 ), 65 array( 'term_length' => 4, 'monthly_amount' => 514.80 ), 66 ), $result ); 67 } 68 69 /** 70 * @test 71 */ 72 public function get_only_valid_plans_from_given_bbl_allowed_installment_terms() { 65 $provider = $installment_backend->get_provider('installment_scb'); 66 67 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 68 69 $this->assertEquals(2, count($result)); 70 $this->assertEquals(array( 71 array('term_length' => 3, 'monthly_amount' => 681.47), 72 array('term_length' => 4, 'monthly_amount' => 514.80), 73 ), $result); 74 } 75 76 /** 77 * @test 78 */ 79 public function get_only_valid_plans_from_given_bbl_allowed_installment_terms() 80 { 73 81 $installment_backend = new Omise_Backend_Installment(); 74 82 $purchase_amount = 3000.00; 75 $allowed_terms = array( 3, 4, 6, 8, 10 ); 76 $interest_rate = 0.8; 77 $min_allowed_amount = 500.00; 78 79 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 80 81 $this->assertEquals( 3, count( $result ) ); 82 $this->assertEquals( array( 83 array( 'term_length' => 3, 'monthly_amount' => 1024.00 ), 84 array( 'term_length' => 4, 'monthly_amount' => 774.00 ), 85 array( 'term_length' => 6, 'monthly_amount' => 524.00 ), 86 ), $result ); 87 } 88 89 /** 90 * @test 91 */ 92 public function get_only_valid_plans_from_given_bbl_unsorted_allowed_installment_terms() { 83 $allowed_terms = array(3, 4, 6, 8, 10); 84 $interest_rate = 0.8; 85 $provider = $installment_backend->get_provider('installment_bbl'); 86 87 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 88 89 $this->assertEquals(3, count($result)); 90 $this->assertEquals(array( 91 array('term_length' => 3, 'monthly_amount' => 1024.00), 92 array('term_length' => 4, 'monthly_amount' => 774.00), 93 array('term_length' => 6, 'monthly_amount' => 524.00), 94 ), $result); 95 } 96 97 /** 98 * @test 99 */ 100 public function get_only_valid_plans_from_given_mbb_allowed_installment_terms() 101 { 102 $installment_backend = new Omise_Backend_Installment(); 103 $purchase_amount = 20000.00; 104 $allowed_terms = array(6, 12, 18, 24); 105 $interest_rate = 0.8; 106 $provider = $installment_backend->get_provider('installment_mbb'); 107 108 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 109 110 $this->assertEquals(4, count($result)); 111 $this->assertEquals(array( 112 array('term_length' => 6, 'monthly_amount' => 3493.33), 113 array('term_length' => 12, 'monthly_amount' => 1826.67), 114 array('term_length' => 18, 'monthly_amount' => 1271.11), 115 array('term_length' => 24, 'monthly_amount' => 993.33), 116 ), $result); 117 } 118 119 /** 120 * @test 121 */ 122 public function get_only_valid_plans_from_given_bbl_unsorted_allowed_installment_terms() 123 { 93 124 $installment_backend = new Omise_Backend_Installment(); 94 125 $purchase_amount = 3000.00; 95 $allowed_terms = array( 3, 10, 4, 8, 6 ); 96 $interest_rate = 0.8; 97 $min_allowed_amount = 500.00; 98 99 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 100 101 $this->assertEquals( 3, count( $result ) ); 102 $this->assertEquals( array( 103 array( 'term_length' => 3, 'monthly_amount' => 1024.00 ), 104 array( 'term_length' => 4, 'monthly_amount' => 774.00 ), 105 array( 'term_length' => 6, 'monthly_amount' => 524.00 ), 106 ), $result ); 107 } 108 109 /** 110 * @test 111 */ 112 public function get_only_valid_plans_from_zero_interest_installments() { 113 $installment_backend = new Omise_Backend_Installment(); 114 $purchase_amount = 2000.00; 115 $allowed_terms = array( 3, 4, 5 ); 126 $allowed_terms = array(3, 10, 4, 8, 6); 127 $interest_rate = 0.8; 128 $provider = $installment_backend->get_provider('installment_bbl'); 129 130 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 131 132 $this->assertEquals(3, count($result)); 133 $this->assertEquals(array( 134 array('term_length' => 3, 'monthly_amount' => 1024.00), 135 array('term_length' => 4, 'monthly_amount' => 774.00), 136 array('term_length' => 6, 'monthly_amount' => 524.00), 137 ), $result); 138 } 139 140 /** 141 * @test 142 */ 143 public function get_only_valid_plans_from_zero_interest_installments() 144 { 145 $installment_backend = new Omise_Backend_Installment(); 146 $purchase_amount = 2000.00; 147 $allowed_terms = array(3, 4, 5); 116 148 $interest_rate = 0; 117 $min_allowed_amount = 500.00; 118 119 $result = $installment_backend->get_available_plans( $purchase_amount, $allowed_terms, $interest_rate, $min_allowed_amount ); 120 121 $this->assertEquals( 2, count( $result ) ); 122 $this->assertEquals( array( 123 array( 'term_length' => 3, 'monthly_amount' => 666.67 ), 124 array( 'term_length' => 4, 'monthly_amount' => 500.00 ), 125 ), $result ); 126 } 127 128 /** 129 * @test 130 */ 131 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_1() { 149 $provider = $installment_backend->get_provider('installment_bbl'); 150 151 $result = $installment_backend->get_available_plans($purchase_amount, $allowed_terms, $interest_rate, $provider); 152 153 $this->assertEquals(2, count($result)); 154 $this->assertEquals(array( 155 array('term_length' => 3, 'monthly_amount' => 666.67), 156 array('term_length' => 4, 'monthly_amount' => 500.00), 157 ), $result); 158 } 159 160 /** 161 * @test 162 */ 163 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_1() 164 { 132 165 $installment_backend = new Omise_Backend_Installment(); 133 166 $purchase_amount = 10000.00; … … 135 168 $interest_rate = 0.8; 136 169 137 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 138 139 $this->assertEquals( 1080.00, $result ); 140 } 141 142 /** 143 * @test 144 */ 145 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_2() { 170 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 171 172 $this->assertEquals(1080.00, $result); 173 } 174 175 /** 176 * @test 177 */ 178 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_2() 179 { 146 180 $installment_backend = new Omise_Backend_Installment(); 147 181 $purchase_amount = 17900.00; … … 149 183 $interest_rate = 0.69; 150 184 151 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 152 153 $this->assertEquals( 3106.84, $result ); 154 } 155 156 /** 157 * @test 158 */ 159 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_3() { 185 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 186 187 $this->assertEquals(3106.84, $result); 188 } 189 190 /** 191 * @test 192 */ 193 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_3() 194 { 160 195 $installment_backend = new Omise_Backend_Installment(); 161 196 $purchase_amount = 5000.00; … … 163 198 $interest_rate = 0.8; 164 199 165 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 166 167 $this->assertEquals( 540.00, $result ); 168 } 169 170 /** 171 * @test 172 */ 173 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_4() { 200 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 201 202 $this->assertEquals(540.00, $result); 203 } 204 205 /** 206 * @test 207 */ 208 public function correctly_calculating_monthly_payment_amount_as_buyer_absorbs_case_4() 209 { 174 210 $installment_backend = new Omise_Backend_Installment(); 175 211 $purchase_amount = 3000.00; … … 177 213 $interest_rate = 0.74; 178 214 179 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 180 181 $this->assertEquals( 772.20, $result ); 182 } 183 184 /** 185 * @test 186 */ 187 public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_1() { 215 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 216 217 $this->assertEquals(772.20, $result); 218 } 219 220 /** 221 * @test 222 */ 223 public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_1() 224 { 188 225 $installment_backend = new Omise_Backend_Installment(); 189 226 $purchase_amount = 10000.00; … … 191 228 $interest_rate = 0; 192 229 193 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate ); 194 195 $this->assertEquals( 1000.00, $result ); 196 } 197 198 /** 199 * @test 200 */ 201 public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_2() { 230 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 231 232 $this->assertEquals(1000.00, $result); 233 } 234 235 /** 236 * @test 237 */ 238 public function correctly_calculating_monthly_payment_amount_as_merchant_absorbs_case_2() 239 { 202 240 $installment_backend = new Omise_Backend_Installment(); 203 241 $purchase_amount = 5000.00; … … 205 243 $interest_rate = 0; 206 244 207 $result = $installment_backend->calculate_monthly_payment_amount( $purchase_amount, $term, $interest_rate);208 209 $this->assertEquals( 833.33, $result);245 $result = $installment_backend->calculate_monthly_payment_amount($purchase_amount, $term, $interest_rate); 246 247 $this->assertEquals(833.33, $result); 210 248 } 211 249 } … … 218 256 * @see includes/class-omise-capabilities 219 257 */ 220 class Omise_Capabilities { 258 class Omise_Capabilities 259 { 221 260 /** 222 261 * @var self … … 224 263 protected static $the_instance = null; 225 264 226 public static function retrieve() { 265 public static function retrieve() 266 { 227 267 self::$the_instance = self::$the_instance ?: new self(); 228 268 return self::$the_instance; 229 269 } 230 270 231 public function is_zero_interest() { 271 public function is_zero_interest() 272 { 232 273 return false; 233 274 }
Note: See TracChangeset
for help on using the changeset viewer.