Changeset 2892466
- Timestamp:
- 04/03/2023 06:07:16 AM (3 years ago)
- Location:
- omise
- Files:
-
- 12 added
- 48 edited
- 1 copied
-
tags/5.0.0 (copied) (copied from omise/trunk)
-
tags/5.0.0/CHANGELOG.md (modified) (1 diff)
-
tags/5.0.0/assets/css/card-form-customization.css (added)
-
tags/5.0.0/assets/css/omise-css.css (modified) (1 diff)
-
tags/5.0.0/assets/images/green-check.svg (modified) (1 diff)
-
tags/5.0.0/assets/javascripts/card-form-customization.js (added)
-
tags/5.0.0/assets/javascripts/omise-embedded-card.js (added)
-
tags/5.0.0/assets/javascripts/omise-myaccount-card-handler.js (modified) (2 diffs)
-
tags/5.0.0/assets/javascripts/omise-payment-credit-card.js (added)
-
tags/5.0.0/assets/javascripts/omise-payment-form-handler.js (modified) (3 diffs)
-
tags/5.0.0/includes/admin/class-omise-page-card-form-customization.php (added)
-
tags/5.0.0/includes/admin/class-omise-page-settings.php (modified) (1 diff)
-
tags/5.0.0/includes/admin/views/omise-page-card-form-customization.php (added)
-
tags/5.0.0/includes/class-omise-admin.php (modified) (8 diffs)
-
tags/5.0.0/includes/class-omise-callback.php (modified) (4 diffs)
-
tags/5.0.0/includes/class-omise-wc-myaccount.php (modified) (6 diffs)
-
tags/5.0.0/includes/classes/class-omise-card-image.php (modified) (2 diffs)
-
tags/5.0.0/includes/classes/class-omise-customer-card.php (modified) (1 diff)
-
tags/5.0.0/includes/gateway/abstract-omise-payment-base-card.php (modified) (8 diffs)
-
tags/5.0.0/includes/gateway/class-omise-payment-creditcard.php (modified) (7 diffs)
-
tags/5.0.0/includes/gateway/class-omise-payment-googlepay.php (modified) (1 diff)
-
tags/5.0.0/includes/gateway/class-omise-payment-rabbit-linepay.php (modified) (1 diff)
-
tags/5.0.0/includes/gateway/class-omise-payment.php (modified) (1 diff)
-
tags/5.0.0/languages/omise-ja.mo (modified) (previous)
-
tags/5.0.0/languages/omise-ja.po (modified) (2 diffs)
-
tags/5.0.0/languages/omise.pot (modified) (1 diff)
-
tags/5.0.0/omise-woocommerce.php (modified) (5 diffs)
-
tags/5.0.0/readme.txt (modified) (2 diffs)
-
tags/5.0.0/templates/myaccount/my-card.php (modified) (1 diff)
-
tags/5.0.0/templates/payment/form-internetbanking.php (modified) (1 diff)
-
tags/5.0.0/templates/payment/form.php (modified) (2 diffs)
-
trunk/CHANGELOG.md (modified) (1 diff)
-
trunk/assets/css/card-form-customization.css (added)
-
trunk/assets/css/omise-css.css (modified) (1 diff)
-
trunk/assets/images/green-check.svg (modified) (1 diff)
-
trunk/assets/javascripts/card-form-customization.js (added)
-
trunk/assets/javascripts/omise-embedded-card.js (added)
-
trunk/assets/javascripts/omise-myaccount-card-handler.js (modified) (2 diffs)
-
trunk/assets/javascripts/omise-payment-credit-card.js (added)
-
trunk/assets/javascripts/omise-payment-form-handler.js (modified) (3 diffs)
-
trunk/includes/admin/class-omise-page-card-form-customization.php (added)
-
trunk/includes/admin/class-omise-page-settings.php (modified) (1 diff)
-
trunk/includes/admin/views/omise-page-card-form-customization.php (added)
-
trunk/includes/class-omise-admin.php (modified) (8 diffs)
-
trunk/includes/class-omise-callback.php (modified) (4 diffs)
-
trunk/includes/class-omise-wc-myaccount.php (modified) (6 diffs)
-
trunk/includes/classes/class-omise-card-image.php (modified) (2 diffs)
-
trunk/includes/classes/class-omise-customer-card.php (modified) (1 diff)
-
trunk/includes/gateway/abstract-omise-payment-base-card.php (modified) (8 diffs)
-
trunk/includes/gateway/class-omise-payment-creditcard.php (modified) (7 diffs)
-
trunk/includes/gateway/class-omise-payment-googlepay.php (modified) (1 diff)
-
trunk/includes/gateway/class-omise-payment-rabbit-linepay.php (modified) (1 diff)
-
trunk/includes/gateway/class-omise-payment.php (modified) (1 diff)
-
trunk/languages/omise-ja.mo (modified) (previous)
-
trunk/languages/omise-ja.po (modified) (2 diffs)
-
trunk/languages/omise.pot (modified) (1 diff)
-
trunk/omise-woocommerce.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/templates/myaccount/my-card.php (modified) (1 diff)
-
trunk/templates/payment/form-internetbanking.php (modified) (1 diff)
-
trunk/templates/payment/form.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
omise/tags/5.0.0/CHANGELOG.md
r2876857 r2892466 1 1 # CHANGELOG 2 3 4 ### [v5.0.0 _(Apr 3, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.0.0) 5 - Replace credit card form with secure form with a feature flag options to switch between credit card forms. (PR [#354](https://github.com/omise/omise-woocommerce/pull/354)) 6 - Added an admin notice to notify the user to update the current credit card form to embedded form. (PR [#358](https://github.com/omise/omise-woocommerce/pull/358)) 7 - Track the adoption of the secure form. (PR [#359](https://github.com/omise/omise-woocommerce/pull/359)) 8 - Removed SCB and KTB internet banking. (PR [#356](https://github.com/omise/omise-woocommerce/pull/356)) 9 - Bug fix: hanlde Shopeepay cancel payment. (PR [#361](https://github.com/omise/omise-woocommerce/pull/361)) 2 10 3 11 ### [v4.29.0 _(Mar 8, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.29.0) -
omise/tags/5.0.0/assets/css/omise-css.css
r2876857 r2892466 31 31 } 32 32 33 fieldset.card-exists { 33 fieldset.card-exists, 34 .omise-new-card-form.card-exists { 34 35 display: none; 35 36 } 36 37 37 #new_card_info:checked ~ fieldset.card-exists { 38 #new_card_info:checked ~ fieldset.card-exists, 39 #new_card_info:checked ~ .omise-new-card-form.card-exists { 38 40 display: flex; 39 41 } -
omise/tags/5.0.0/assets/images/green-check.svg
r2501460 r2892466 1 < ?xml version="1.0" ?><svg id="Layer_1" style="enable-background:new 0 0 612 792;" version="1.1" viewBox="0 0 612 792" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style type="text/css">2 .st0{fill:#41AD49;} 3 </s tyle><g><path class="st0" d="M562,396c0-141.4-114.6-256-256-256S50,254.6,50,396s114.6,256,256,256S562,537.4,562,396L562,396z M501.7,296.3l-241,241l0,0l-17.2,17.2L110.3,421.3l58.8-58.8l74.5,74.5l199.4-199.4L501.7,296.3L501.7,296.3z"/></g></svg>1 <svg width="18" height="19" viewBox="0 0 18 19" fill="none" xmlns="http://www.w3.org/2000/svg"> 2 <path d="M0 9.25C0 4.29297 4.00781 0.25 9 0.25C13.957 0.25 18 4.29297 18 9.25C18 14.2422 13.957 18.25 9 18.25C4.00781 18.25 0 14.2422 0 9.25ZM13.043 7.70312C13.4297 7.31641 13.4297 6.71875 13.043 6.33203C12.6562 5.94531 12.0586 5.94531 11.6719 6.33203L7.875 10.1289L6.29297 8.58203C5.90625 8.19531 5.30859 8.19531 4.92188 8.58203C4.53516 8.96875 4.53516 9.56641 4.92188 9.95312L7.17188 12.2031C7.55859 12.5898 8.15625 12.5898 8.54297 12.2031L13.043 7.70312Z" fill="#30AD7F"/> 3 </svg> -
omise/tags/5.0.0/assets/javascripts/omise-myaccount-card-handler.js
r2809311 r2892466 61 61 }); 62 62 63 if(Boolean(parseInt(omise_params.secure_form_enabled))) { 64 hideError(); 65 OmiseCard.requestCardToken() 66 } else { 67 saveCardTraditional() 68 } 69 } 70 71 $(".delete_card").click(function(event){ 72 if(confirm('Confirm delete card?')){ 73 let $button = $(this); 74 $button.block({ 75 message: null, 76 overlayCSS: { 77 background: '#fff url(' + omise_params.ajax_loader_url + ') no-repeat center', 78 backgroundSize: '16px 16px', 79 opacity: 0.6 80 } 81 }); 82 delete_card($button.data("card-id"), $button.data("delete-card-nonce")); 83 } 84 }); 85 86 $("#omise_add_new_card").click(function(event){ 87 create_card(); 88 }); 89 90 function saveCardTraditional() { 63 91 let errors = [], 64 92 omise_card = {}, … … 124 152 } 125 153 } 126 127 $(".delete_card").click(function(event){ 128 if(confirm('Confirm delete card?')){ 129 let $button = $(this); 130 $button.block({ 131 message: null, 132 overlayCSS: { 133 background: '#fff url(' + omise_params.ajax_loader_url + ') no-repeat center', 134 backgroundSize: '16px 16px', 135 opacity: 0.6 154 155 function saveCardEmbedded(payload) { 156 const data = { 157 action: "omise_create_card", 158 omise_token: payload.token, 159 omise_nonce: $("#omise_add_card_nonce").val() 160 }; 161 $.post(omise_params.ajax_url, data, 162 function(wp_response){ 163 if(wp_response.id){ 164 window.location.reload(); 165 }else{ 166 showError(wp_response.message, $form); 136 167 } 137 }); 138 delete_card($button.data("card-id"), $button.data("delete-card-nonce")); 139 } 140 }); 141 142 $("#omise_add_new_card").click(function(event){ 143 create_card(); 144 }); 168 }, "json" 169 ); 170 } 171 172 if(Boolean(parseInt(omise_params.secure_form_enabled))) { 173 showOmiseEmbeddedCardForm({ 174 element: document.getElementById('omise-card'), 175 publicKey: omise_params.key, 176 locale: LOCALE, 177 theme: CARD_FORM_THEME ?? 'light', 178 design: FORM_DESIGN, 179 brandIcons: CARD_BRAND_ICONS, 180 hideRememberCard: true, 181 onSuccess: saveCardEmbedded, 182 onError: (error) => { 183 showError(error) 184 $form.unblock() 185 } 186 }) 187 } 145 188 } 146 189 )(jQuery); -
omise/tags/5.0.0/assets/javascripts/omise-payment-form-handler.js
r2809311 r2892466 15 15 16 16 if ($.isArray(message)) { 17 $.each(message, function(i, v) {17 $.each(message, function(i, v) { 18 18 $ulError.append($("<li>" + v + "</li>")); 19 19 }) … … 59 59 60 60 if (0 === $('input.omise_token').length) { 61 $form.block({ 62 message: null, 63 overlayCSS: { 64 background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', 65 backgroundSize: '16px 16px', 66 opacity: 0.6 67 } 68 }); 69 70 let errors = [], 71 omise_card = {}, 72 omise_card_number_field = 'number', 73 omise_card_fields = { 74 'name' : $('#omise_card_name'), 75 'number' : $('#omise_card_number'), 76 'expiration_month' : $('#omise_card_expiration_month'), 77 'expiration_year' : $('#omise_card_expiration_year'), 78 'security_code' : $('#omise_card_security_code') 79 }; 80 81 $.each(omise_card_fields, function(index, field) { 82 omise_card[index] = (index === omise_card_number_field) ? field.val().replace(/\s/g, '') : field.val(); 83 if ("" === omise_card[index]) { 84 errors.push(omise_params['required_card_' + index]); 85 } 86 }); 87 88 if (errors.length > 0) { 89 showError(errors); 90 $form.unblock(); 91 return false; 92 } 93 94 hideError(); 95 96 if(Omise) { 97 Omise.setPublicKey(omise_params.key); 98 Omise.createToken("card", omise_card, function (statusCode, response) { 99 if (statusCode == 200) { 100 $.each(omise_card_fields, function(index, field) { 101 field.val(''); 102 }); 103 104 $form.append('<input type="hidden" class="omise_token" name="omise_token" value="' + response.id + '"/>'); 105 $form.submit(); 106 } else { 107 handleTokensApiError(response); 108 }; 61 (Boolean(omise_params.secure_form_enabled)) 62 ? requestCardToken() 63 : traditionalForm(); 64 return false; 65 } 66 } 67 } 68 69 function traditionalForm() { 70 $form.block({ 71 message: null, 72 overlayCSS: { 73 background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', 74 backgroundSize: '16px 16px', 75 opacity: 0.6 76 } 77 }); 78 79 let errors = [], 80 omise_card = {}, 81 omise_card_number_field = 'number', 82 omise_card_fields = { 83 'name' : $('#omise_card_name'), 84 'number' : $('#omise_card_number'), 85 'expiration_month' : $('#omise_card_expiration_month'), 86 'expiration_year' : $('#omise_card_expiration_year'), 87 'security_code' : $('#omise_card_security_code') 88 }; 89 90 $.each(omise_card_fields, function(index, field) { 91 omise_card[index] = (index === omise_card_number_field) ? field.val().replace(/\s/g, '') : field.val(); 92 if ("" === omise_card[index]) { 93 errors.push(omise_params['required_card_' + index]); 94 } 95 }); 96 97 if (errors.length > 0) { 98 showError(errors); 99 $form.unblock(); 100 return false; 101 } 102 103 hideError(); 104 105 if(Omise) { 106 Omise.setPublicKey(omise_params.key); 107 Omise.createToken("card", omise_card, function (statusCode, response) { 108 if (statusCode == 200) { 109 $.each(omise_card_fields, function(index, field) { 110 field.val(''); 109 111 }); 112 113 $form.append('<input type="hidden" class="omise_token" name="omise_token" value="' + response.id + '"/>'); 114 $form.submit(); 110 115 } else { 111 showError(omise_params.cannot_load_omisejs + '<br/>' + omise_params.check_internet_connection);112 $form.unblock();113 }114 115 return false;116 }116 handleTokensApiError(response); 117 }; 118 }); 119 } else { 120 showError(omise_params.cannot_load_omisejs + '<br/>' + omise_params.check_internet_connection); 121 $form.unblock(); 117 122 } 118 123 } … … 188 193 } 189 194 195 function requestCardToken() { 196 hideError() 197 $form.block({ 198 message: null, 199 overlayCSS: { 200 background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', 201 backgroundSize: '16px 16px', 202 opacity: 0.6 203 } 204 }); 205 const billingAddress = { 206 country: document.getElementById('billing_country').value, 207 postal_code: document.getElementById('billing_postcode').value, 208 state: document.getElementById('billing_state').value, 209 city: document.getElementById('billing_city').value, 210 street1: document.getElementById('billing_address_1').value, 211 street2: document.getElementById('billing_address_2').value, 212 } 213 OmiseCard.requestCardToken(billingAddress) 214 } 215 216 function handleCreateOrder(payload) { 217 $form.unblock(); 218 if (payload.token) { 219 if (payload.remember) { 220 $('.omise_save_customer_card').val(payload.remember) 221 } 222 $form.append('<input type="hidden" class="omise_token" name="omise_token" value="' + payload.token + '"/>'); 223 $form.submit(); 224 } 225 } 226 227 if(Boolean(omise_params.secure_form_enabled)) { 228 $(document).on('updated_checkout', function () { 229 showOmiseEmbeddedCardForm({ 230 element: document.getElementById('omise-card'), 231 publicKey: omise_params.key, 232 hideRememberCard: HIDE_REMEMBER_CARD, 233 locale: LOCALE, 234 theme: CARD_FORM_THEME ?? 'light', 235 design: FORM_DESIGN, 236 brandIcons: CARD_BRAND_ICONS, 237 onSuccess: handleCreateOrder, 238 onError: (error) => { 239 showError(error) 240 $form.unblock() 241 } 242 }) 243 }); 244 } 245 190 246 $(function () { 191 247 $('body').on('checkout_error', function () { -
omise/tags/5.0.0/includes/admin/class-omise-page-settings.php
r2783685 r2892466 57 57 $settings = $page->get_settings(); 58 58 59 $available_payment_methods = array(); 59 // This variable is used in the view. 60 $available_payment_methods = []; 60 61 $capabilities = Omise_Capabilities::retrieve(); 61 62 -
omise/tags/5.0.0/includes/class-omise-admin.php
r2832733 r2892466 2 2 defined( 'ABSPATH' ) or die( "No direct script access allowed." ); 3 3 4 if ( ! class_exists( 'Omise_Admin' ) ) { 5 class Omise_Admin { 4 if (!class_exists('Omise_Admin')) { 5 class Omise_Admin 6 { 6 7 /** 7 8 * The Omise Instance. … … 14 15 * @return \Omise_Admin The instance. 15 16 */ 16 public static function get_instance() { 17 if ( ! self::$the_instance ) { 17 public static function get_instance() 18 { 19 if (!self::$the_instance) { 18 20 self::$the_instance = new self(); 19 21 } … … 25 27 * @since 3.3 26 28 */ 27 public function init() {28 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-admin-page.php';29 public function init() 30 { 29 31 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-page-settings.php'; 30 32 … … 36 38 * Register Omise's custom menu to WordPress admin menus. 37 39 */ 38 public function register_admin_menu() { 39 add_action( 'admin_menu', array( $this, 'wordpress_hook_admin_menu' ) ); 40 public function register_admin_menu() 41 { 42 add_action('admin_menu', [$this, 'wordpress_hook_admin_menu']); 43 add_action('admin_menu', [$this, 'wordpress_hook_card_form_customization']); 40 44 } 41 45 … … 44 48 * Register Omise's custom menu to WordPress admin menus. 45 49 */ 46 public function wordpress_hook_admin_menu() { 47 add_menu_page( __( 'Opn Payments Settings', 'omise' ), 'Opn Payments', 'manage_options', 'omise', array( $this, 'page_settings') ); 50 public function wordpress_hook_admin_menu() 51 { 52 add_menu_page( 53 __('Opn Payments Settings', 'omise'), 54 'Opn Payments', 55 'manage_options', 56 'omise', 57 [$this, 'page_settings'] 58 ); 59 } 60 61 /** 62 * Register Omise's card customization page. 63 */ 64 public function wordpress_hook_card_form_customization() 65 { 66 add_submenu_page( 67 null, 68 __('Custom card form customization', 'omise'), 69 Omise_Page_Card_From_Customization::PAGE_NAME, 70 'manage_options', 71 'omise_card_form_customization', 72 [$this, 'card_form_customization'] 73 ); 48 74 } 49 75 … … 51 77 * Render Omise Setting page. 52 78 */ 53 public function page_settings() { 79 public function page_settings() 80 { 54 81 Omise_Page_Settings::render(); 82 } 83 84 /** 85 * Render Omise card form customization page. 86 */ 87 public function card_form_customization() 88 { 89 Omise_Page_Card_From_Customization::render(); 55 90 } 56 91 … … 58 93 * @since 3.3 59 94 */ 60 public function register_woocommerce_filters() { 61 add_filter( 'woocommerce_order_actions', array( $this, 'woocommerce_filter_order_actions' ) ); 95 public function register_woocommerce_filters() 96 { 97 add_filter( 98 'woocommerce_order_actions', 99 [$this, 'woocommerce_filter_order_actions'] 100 ); 62 101 } 63 102 … … 71 110 * @return array 72 111 */ 73 public function woocommerce_filter_order_actions( $order_actions ) { 112 public function woocommerce_filter_order_actions($order_actions) 113 { 74 114 global $theorder; 75 115 -
omise/tags/5.0.0/includes/class-omise-callback.php
r2876857 r2892466 30 30 { 31 31 $order_id = isset( $_GET['order_id'] ) ? sanitize_text_field( $_GET['order_id'] ) : null; 32 $token = isset( $_GET['token'] ) ? sanitize_text_field( $_GET['token'] ) : null;33 32 $order = wc_get_order( $order_id ); 34 33 … … 74 73 try { 75 74 $this->charge = $this->fetchCharge($this->order->get_transaction_id()); 75 76 // TODO: Remove this if block once the issue is fixed on the server. 77 if ($this->hasShopeepayFailed()) { 78 $this->payment_failed(); 79 return; 80 } 76 81 77 82 switch ( strtolower( $this->charge['status'] ) ) { … … 100 105 101 106 /** 107 * TODO: Remove this if block once the issue is fixed on the server. 108 */ 109 private function hasShopeepayFailed() 110 { 111 $isPaymentMethodShopeepay = 'shopeepay' === $this->charge['source']['type']; 112 $isChargePending = 'pending' === $this->charge['status']; 113 return $isPaymentMethodShopeepay && $isChargePending; 114 } 115 116 /** 102 117 * Resolving a case of undefined charge status 103 118 */ … … 191 206 protected function payment_failed() { 192 207 $message = __( "It seems we've been unable to process your payment properly:<br/>%s", 'omise' ); 193 $failure_message = Omise()->translate( $this->charge['failure_message'] ) . ' (code: ' . $this->charge['failure_code'] . ')'; 208 $failure_message = Omise()->translate( $this->charge['failure_message'] ); 209 $failure_message .= ($this->charge['failure_code']) ? 210 ' (code: ' . $this->charge['failure_code'] . ')' 211 : ' (code: Payment failed)'; // for shopeepay 194 212 195 213 $this->order->add_order_note( sprintf( wp_kses( __( 'OMISE: Payment failed.<br/>%s', 'omise' ), array( 'br' => array() ) ), $failure_message ) ); -
omise/tags/5.0.0/includes/class-omise-wc-myaccount.php
r2795404 r2892466 3 3 4 4 if ( ! class_exists( 'Omise_MyAccount' ) ) { 5 class Omise_MyAccount { 5 class Omise_MyAccount 6 { 6 7 private static $instance; 7 8 private $omise_customer_id; … … 27 28 28 29 $this->customerCard = new OmiseCustomerCard; 30 $this->omiseCardGateway = new Omise_Payment_Creditcard(); 29 31 30 32 add_action( 'woocommerce_after_my_account', array( $this, 'init_panel' ) ); … … 42 44 try { 43 45 $viewData['existingCards'] = $this->customerCard->get($this->omise_customer_id); 46 $viewData['cardFormTheme'] = $this->omiseCardGateway->get_option('card_form_theme'); 47 $viewData['secure_form_enabled'] = (boolean)$this->omiseCardGateway->get_option('secure_form_enabled'); 48 $viewData['formDesign'] = Omise_Page_Card_From_Customization::get_instance()->get_design_setting(); 49 $viewData['cardIcons'] = $this->omiseCardGateway->get_card_icons(); 50 $this->register_omise_my_account_scripts(); 44 51 45 52 Omise_Util::render_view( 'templates/myaccount/my-card.php', $viewData ); 46 $this->register_omise_my_account_scripts();47 53 } catch (Exception $e) { 48 54 // nothing. … … 57 63 wp_enqueue_script( 58 64 'omise-js', 59 'https://cdn.omise.co/omise.js',65 Omise::OMISE_JS_LINK, 60 66 array( 'jquery' ), 61 67 WC_VERSION, 68 true 69 ); 70 71 wp_enqueue_script( 72 'embedded-js', 73 plugins_url( '/assets/javascripts/omise-embedded-card.js', dirname( __FILE__ ) ), 74 [], 75 OMISE_WOOCOMMERCE_PLUGIN_VERSION, 62 76 true 63 77 ); … … 105 119 'number is invalid and brand not supported (unknown)' => __( 'number is invalid and brand not supported (unknown)', 'omise' ), 106 120 'expiration year is invalid, expiration date cannot be in the past, number is invalid, and brand not supported (unknown)' => __( 'expiration year is invalid, expiration date cannot be in the past, number is invalid, and brand not supported (unknown)', 'omise' ), 107 'expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)' => __('expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)', 'omise') 121 'expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)' => __('expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)', 'omise'), 122 'secure_form_enabled' => (boolean)$this->omiseCardGateway->get_option('secure_form_enabled') 108 123 ]; 109 124 } … … 152 167 153 168 try { 154 $card = $this->customerCard->create($t oken, $omiseCustomerId);169 $card = $this->customerCard->create($this->omise_customer_id, $token); 155 170 echo json_encode( $card ); 156 171 } catch( Exception $e ) { -
omise/tags/5.0.0/includes/classes/class-omise-card-image.php
r2720994 r2892466 63 63 64 64 /** 65 * Return the HTML <img> element of Discover logo 66 * 67 * @return string 68 */ 69 public static function get_discover_image() { 70 return self::get_image( 'discover.svg', 'Discover' ); 71 } 72 73 /** 74 * Return the default setting of display the Discover logo 75 * 76 * @return string 77 */ 78 public static function get_discover_default_display() { 79 return 'no'; 80 } 81 82 /** 65 83 * Return the default setting of display the JCB logo 66 84 * … … 128 146 129 147 return false; 148 } 149 150 /** 151 * Check whether the setting for Discover logo is configured and it was set to display or not display 152 * 153 * @param mixed $setting The array that contains key for checking the flag 154 * @return boolean 155 */ 156 public static function is_discover_enabled( $setting ) { 157 return isset( $setting['accept_discover'] ) && $setting['accept_discover'] == 'yes'; 130 158 } 131 159 -
omise/tags/5.0.0/includes/classes/class-omise-customer-card.php
r2795404 r2892466 36 36 * @return string 37 37 */ 38 public function create($customer , $token)38 public function create($customerId, $token) 39 39 { 40 $customer = $this->customer->get($customerId); 40 41 $customer->update( ['card' => $token ]); 41 42 -
omise/tags/5.0.0/includes/gateway/abstract-omise-payment-base-card.php
r2876857 r2892466 28 28 29 29 // Saving card. 30 if (isset($_POST['omise_save_customer_card']) && empty($card_id)) { 30 $saveCustomerCard = $_POST['omise_save_customer_card']; 31 if (isset($saveCustomerCard) && !empty($saveCustomerCard) && empty($card_id)) { 31 32 $cardDetails = $this->saveCard($omise_customer_id, $token, $order_id, $user->ID); 32 33 $omise_customer_id = $cardDetails['customer_id']; … … 58 59 ), 59 60 'return_uri' => $this->getRedirectUrl('omise_callback', $order_id, $order), 60 'metadata' => $this->getMetadata($order_id, $order) 61 'metadata' => $this->getMetadata( 62 $order_id, 63 $order, 64 [ 'secure_form_enabled' => $this->getSecureFormState()] 65 ) 61 66 ]; 62 67 … … 76 81 77 82 return $data; 83 } 84 85 /** 86 * Returns the the secure form state in yes/not format 87 */ 88 private function getSecureFormState() 89 { 90 // tracking the embedded form adoption 91 $omiseCardGateway = new Omise_Payment_Creditcard(); 92 $secureFormEnabled = $omiseCardGateway->get_option('secure_form_enabled'); 93 return (boolean)$secureFormEnabled ? 'yes' : 'no'; 78 94 } 79 95 … … 111 127 112 128 try { 113 $customer->get($omise_customer_id);114 129 $customerCard = new OmiseCustomerCard; 115 $card = $customerCard->create($customer, $token); 130 131 // TODO: Save customer with $omise_customer_id from Embedded form 132 $card = $customerCard->create($omise_customer_id, $token); 116 133 117 134 return [ … … 128 145 // Saved customer ID is not found so we create a new customer and save the customer ID 129 146 $customer_data = $customer->create($user_id, $order_id, $customer_data); 147 130 148 return [ 131 149 'customer_id' => $customer_data['customer_id'], … … 234 252 wp_enqueue_script( 235 253 'omise-js', 236 'https://cdn.omise.co/omise.js',254 Omise::OMISE_JS_LINK, 237 255 [ 'jquery' ], 256 OMISE_WOOCOMMERCE_PLUGIN_VERSION, 257 true 258 ); 259 260 wp_enqueue_script( 261 'embedded-js', 262 plugins_url( '../../assets/javascripts/omise-embedded-card.js', __FILE__ ), 263 [], 238 264 OMISE_WOOCOMMERCE_PLUGIN_VERSION, 239 265 true … … 261 287 public function getParamsForJS() 262 288 { 289 $omiseCardGateway = new Omise_Payment_Creditcard(); 290 263 291 return [ 264 292 'key' => $this->public_key(), … … 334 362 'expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)', 335 363 'omise' 336 ) 364 ), 365 'secure_form_enabled' => (boolean)$omiseCardGateway->get_option('secure_form_enabled') 337 366 ]; 338 367 } -
omise/tags/5.0.0/includes/gateway/class-omise-payment-creditcard.php
r2832733 r2892466 3 3 4 4 class Omise_Payment_Creditcard extends Omise_Payment_Base_Card { 5 public function __construct() { 5 const SECURE_FORM_ENABLED = true; 6 7 public function __construct() 8 { 6 9 parent::__construct(); 7 10 … … 28 31 $this->restricted_countries = array( 'TH', 'JP', 'SG', 'MY' ); 29 32 33 $this->register_omise_credit_card_scripts(); 34 30 35 add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' ); 31 36 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); … … 67 72 array( 68 73 'advanced' => array( 69 'title' => __( 'Advance Settings', 'omise' ),74 'title' => __( 'Advanced Settings', 'omise' ), 70 75 'type' => 'title' 71 76 ), … … 82 87 'desc_tip' => true 83 88 ), 89 'secure_form_enabled' => [ 90 'title' => __( 'Secure form', 'omise' ), 91 'type' => 'select', 92 'description' => __( 'Try the new secure form to accept card payments. The new form features additional controls to ensure PCI-DSS compliance.<br /><strong><em>Using this form will be mandatory in a future release</em></strong>.', 'omise' ), 93 'default' => !self::SECURE_FORM_ENABLED, 94 'options' => array( 95 !self::SECURE_FORM_ENABLED => __( 'No', 'omise' ), 96 self::SECURE_FORM_ENABLED => __( 'Yes', 'omise' ) 97 ) 98 ], 99 100 'card_form_theme' => [ 101 'title' => __( 'Secure form theme', 'omise' ), 102 'type' => 'select', 103 'default' => 'light', 104 'class' => 'wc-enhanced-select', 105 'options' => array( 106 'light' => __( 'Light', 'omise' ), 107 'dark' => __( 'Dark', 'omise' ) 108 ), 109 'description' => wp_kses( 110 __( 'Credit / Debit card form design on checkout page. <br /> <a href="admin.php?page=omise_card_form_customization">Click here for more card form customization.</a>', 'omise' ), 111 ['a' => ['href' => []], 'br' => []] 112 ), 113 ], 84 114 'accept_visa' => array( 85 115 'title' => __( 'Supported card icons', 'omise' ), … … 106 136 'css' => Omise_Card_Image::get_css(), 107 137 'default' => Omise_Card_Image::get_diners_default_display() 138 ), 139 'accept_discover' => array( 140 'type' => 'checkbox', 141 'label' => Omise_Card_Image::get_discover_image(), 142 'css' => Omise_Card_Image::get_css(), 143 'default' => Omise_Card_Image::get_discover_default_display() 108 144 ), 109 145 'accept_amex' => array( … … 118 154 ) 119 155 ) 156 ); 157 } 158 159 private function register_omise_credit_card_scripts() { 160 wp_enqueue_script( 161 'omise-credit-card', 162 plugins_url( '../assets/javascripts/omise-payment-credit-card.js', dirname( __FILE__ ) ), 163 array( 'jquery' ), 164 WC_VERSION, 165 true 120 166 ); 121 167 } … … 146 192 } 147 193 194 $viewData['secure_form_enabled'] = (boolean)$this->get_option('secure_form_enabled'); 195 196 if ($viewData['secure_form_enabled'] === self::SECURE_FORM_ENABLED) { 197 $viewData['card_form_theme'] = $this->get_option('card_form_theme'); 198 $viewData['card_icons'] = $this->get_card_icons(); 199 $viewData['form_design'] = Omise_Page_Card_From_Customization::get_instance()->get_design_setting(); 200 } 201 148 202 Omise_Util::render_view( 'templates/payment/form.php', $viewData ); 149 203 } 150 204 151 205 /** 152 * Get icons of all supported card types 153 * 154 * @see WC_Payment_Gateway::get_icon() 206 * Get card icons for credit card form 155 207 */ 156 public function get_icon() { 157 $icon = ''; 158 159 // TODO: Refactor 'Omise_Card_Image' class that we don't need to pass 160 // these options to check outside this class. 161 $card_icons['accept_amex'] = $this->get_option( 'accept_amex' ); 162 $card_icons['accept_diners'] = $this->get_option( 'accept_diners' ); 163 $card_icons['accept_jcb'] = $this->get_option( 'accept_jcb' ); 164 $card_icons['accept_mastercard'] = $this->get_option( 'accept_mastercard' ); 165 $card_icons['accept_visa'] = $this->get_option( 'accept_visa' ); 166 167 if ( Omise_Card_Image::is_visa_enabled( $card_icons ) ) { 168 $icon .= Omise_Card_Image::get_visa_image(); 208 public function get_card_icons() { 209 $enable_icons = []; 210 $card_icons = [ 211 'amex' => 'accept_amex', 212 'diners' => 'accept_diners', 213 'jcb' => 'accept_jcb', 214 'mastercard' => 'accept_mastercard', 215 'visa' => 'accept_visa', 216 'discover' => 'accept_discover', 217 ]; 218 219 foreach($card_icons as $key => $value) { 220 if($this->get_option($value) == "yes") { 221 $enable_icons[] = $key; 222 } 169 223 } 170 224 171 if ( Omise_Card_Image::is_mastercard_enabled( $card_icons ) ) { 172 $icon .= Omise_Card_Image::get_mastercard_image(); 173 } 174 175 if ( Omise_Card_Image::is_jcb_enabled( $card_icons ) ) { 176 $icon .= Omise_Card_Image::get_jcb_image(); 177 } 178 179 if ( Omise_Card_Image::is_diners_enabled( $card_icons ) ) { 180 $icon .= Omise_Card_Image::get_diners_image(); 181 } 182 183 if ( Omise_Card_Image::is_amex_enabled( $card_icons ) ) { 184 $icon .= Omise_Card_Image::get_amex_image(); 185 } 186 187 return empty( $icon ) ? '' : apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); 225 return $enable_icons; 188 226 } 189 227 } -
omise/tags/5.0.0/includes/gateway/class-omise-payment-googlepay.php
r2832733 r2892466 82 82 array( 83 83 'advanced' => array( 84 'title' => __('Advance Settings', 'omise'),84 'title' => __('Advanced Settings', 'omise'), 85 85 'type' => 'title' 86 86 ), -
omise/tags/5.0.0/includes/gateway/class-omise-payment-rabbit-linepay.php
r2832733 r2892466 59 59 array( 60 60 'advanced' => array( 61 'title' => __( 'Advance Settings', 'omise' ),61 'title' => __( 'Advanced Settings', 'omise' ), 62 62 'type' => 'title' 63 63 ), -
omise/tags/5.0.0/includes/gateway/class-omise-payment.php
r2876857 r2892466 605 605 * @param string $order_id 606 606 * @param object $order 607 */ 608 public function getMetadata($order_id, $order) 607 * @param array $additionalData 608 */ 609 public function getMetadata($order_id, $order, $additionalData = []) 609 610 { 611 // override order_id as a reference for webhook handlers. 612 $orderId = [ 'order_id' => $order_id ]; 613 610 614 return array_merge( 611 615 apply_filters('omise_charge_params_metadata', [], $order), 612 ['order_id' => $order_id] // override order_id as a reference for webhook handlers.616 array_merge($orderId, $additionalData) 613 617 ); 614 618 } -
omise/tags/5.0.0/languages/omise-ja.po
r2832733 r2892466 140 140 141 141 #: includes/gateway/class-omise-payment-creditcard.php:78 142 msgid "Advance Settings"142 msgid "Advanced Settings" 143 143 msgstr "詳細設定" 144 144 … … 586 586 msgid "Please select bank below" 587 587 msgstr "以下から銀行をお選びください" 588 589 #: omise-woocommerce.php:66 590 msgid "Update your plugin to the latest version to enable Secure Form and maximize the security of your customers’ information. You will need to re-customize the credit card checkout form after the upgrade. <a target='_blank' href='https://www.omise.co/woocommerce-plugin'>Learn how to enable Secure Form</a>." 591 msgstr "プラグインを最新バージョンにアップデートし、顧客情報の安全な管理に必要なSecure Formを有効にしてください。アップデート後、クレジットカードの決済フォームを再度カスタマイズする必要があります。<a target='_blank' href='https://www.omise.co/woocommerce-plugin'>Secure Formを有効にする方法はこちらをご確認ください</a>。" -
omise/tags/5.0.0/languages/omise.pot
r2832733 r2892466 139 139 140 140 #: includes/gateway/class-omise-payment-creditcard.php:78 141 msgid "Advance Settings"141 msgid "Advanced Settings" 142 142 msgstr "詳細設定" 143 143 -
omise/tags/5.0.0/omise-woocommerce.php
r2876857 r2892466 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.29.07 * Version: 5.0.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.29.0';25 public $version = '5.0.0'; 26 26 27 27 /** … … 40 40 */ 41 41 protected static $can_initiate = false; 42 43 CONST OMISE_JS_LINK = 'https://cdn.omise.co/omise.js'; 42 44 43 45 /** … … 49 51 add_action('woocommerce_init', array($this, 'init')); 50 52 do_action('omise_initiated'); 53 add_action('admin_notices', [$this, 'embedded_form_notice']); 54 } 55 56 /** 57 * Notice for users informing about embedded form 58 */ 59 public function embedded_form_notice() 60 { 61 $this->omiseCardGateway = new Omise_Payment_Creditcard(); 62 $embedded_form_enabled = $this->omiseCardGateway->get_option('embedded_form_enabled'); 63 64 // hide if user enables the embedded form. 65 if (!(bool)$embedded_form_enabled) { 66 $translation = __('Update your plugin to the latest version to enable Secure Form and maximize the security of your customers’ information. You will need to re-customize the credit card checkout form after the upgrade. <a target="_blank" href="https://www.omise.co/woocommerce-plugin">Learn how to enable Secure Form</a>.', 'omise'); 67 echo "<div class='notice notice-warning is-dismissible'><p><strong>Opn Payments:</strong> $translation</p></div>"; 68 } 69 } 70 71 /** 72 * get plugin assess url 73 */ 74 public static function get_assets_url() { 75 return plugins_url('assets' , __FILE__); 51 76 } 52 77 … … 189 214 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/class-omise-wc-myaccount.php'; 190 215 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/omise-util.php'; 216 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-admin-page.php'; 217 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-page-card-form-customization.php'; 191 218 } 192 219 -
omise/tags/5.0.0/readme.txt
r2876857 r2892466 4 4 Requires at least: 4.3.1 5 5 Tested up to: 6.0.2 6 Stable tag: 4.29.06 Stable tag: 5.0.0 7 7 License: MIT 8 8 License URI: https://opensource.org/licenses/MIT … … 34 34 35 35 == Changelog == 36 37 = 5.0.0 = 38 39 - Replace credit card form with secure form with a feature flag options to switch between credit card forms. (PR [#354](https://github.com/omise/omise-woocommerce/pull/354)) 40 - Added an admin notice to notify the user to update the current credit card form to embedded form. (PR [#358](https://github.com/omise/omise-woocommerce/pull/358)) 41 - Track the adoption of the secure form. (PR [#359](https://github.com/omise/omise-woocommerce/pull/359)) 42 - Removed SCB and KTB internet banking. (PR [#356](https://github.com/omise/omise-woocommerce/pull/356)) 43 - Bug fix: hanlde Shopeepay cancel payment. (PR [#361](https://github.com/omise/omise-woocommerce/pull/361)) 36 44 37 45 = 4.29.0 = -
omise/tags/5.0.0/templates/myaccount/my-card.php
r2783685 r2892466 37 37 <form name="omise_cc_form" id="omise_cc_form"> 38 38 <?php wp_nonce_field('omise_add_card','omise_add_card_nonce'); ?> 39 <fieldset> 40 <?php require_once( __DIR__ . '/../payment/form-creditcard.php' ); ?> 41 <div class="clear"></div> 42 </fieldset> 39 40 <?php if($viewData['secure_form_enabled']): ?> 41 <div id="omise-card" style="width:100%; max-width: 400px;"></div> 42 <?php else: ?> 43 <fieldset> 44 <?php require_once( __DIR__ . '/../payment/form-creditcard.php' ); ?> 45 <div class="clear"></div> 46 </fieldset> 47 <?php endif; ?> 48 43 49 </form> 44 50 <button id="omise_add_new_card" class="button"><?php _e( 'Save card', 'omise' ); ?></button> 45 51 </div> 52 53 <?php if($viewData['secure_form_enabled']): ?> 54 <script> 55 window.CARD_FORM_THEME = "<?php echo $viewData['cardFormTheme'] ?>"; 56 window.FORM_DESIGN = JSON.parse(`<?php echo json_encode($viewData['formDesign']) ?>`); 57 window.CARD_BRAND_ICONS = JSON.parse(`<?php echo json_encode($viewData['cardIcons']) ?>`); 58 window.LOCALE = `<?php echo get_locale(); ?>`; 59 </script> 60 <?php endif; ?> -
omise/tags/5.0.0/templates/payment/form-internetbanking.php
r2501457 r2892466 1 1 <fieldset id="omise-form-internetbanking"> 2 2 <ul class="omise-banks-list"> 3 <!-- SCB -->4 <li class="item">5 <input id="internet_banking_scb" type="radio" name="omise-offsite" value="internet_banking_scb" />6 <label for="internet_banking_scb">7 <div class="bank-logo scb"></div>8 <div class="bank-label">9 <span class="title"><?php _e( 'Siam Commercial Bank', 'omise' ); ?></span><br/>10 <span class="omise-secondary-text"><?php _e( 'Fee: 15 THB (same zone), 30 THB (out zone)', 'omise' ); ?></span>11 </div>12 </label>13 </li>14 15 <!-- KTB -->16 <li class="item">17 <input id="internet_banking_ktb" type="radio" name="omise-offsite" value="internet_banking_ktb" />18 <label for="internet_banking_ktb">19 <div class="bank-logo ktb"></div>20 <div class="bank-label">21 <span class="title"><?php _e( 'Krungthai Bank', 'omise' ); ?></span><br/>22 <span class="omise-secondary-text"><?php _e( 'Fee: 15 THB (same zone), 15 THB (out zone)', 'omise' ); ?></span>23 </div>24 </label>25 </li>26 27 3 <!-- BAY --> 28 4 <li class="item"> -
omise/tags/5.0.0/templates/payment/form.php
r2809311 r2892466 1 <?php $showExistingCards = $viewData['user_logged_in'] && isset( $viewData['existingCards']['data'] ) && sizeof( $viewData['existingCards']['data'] ) > 0; ?> 1 <?php 2 $showExistingCards = $viewData['user_logged_in'] && isset($viewData['existingCards']['data']) && sizeof($viewData['existingCards']['data']) > 0; 3 $hideRememberCard = $viewData['user_logged_in'] ? 'no' : 'yes'; 4 ?> 2 5 3 6 <div id="omise_cc_form"> 4 <?php if ( $showExistingCards) : ?>5 <h3><?php _e( 'Use an existing card', 'omise'); ?></h3>7 <?php if ($showExistingCards) : ?> 8 <h3><?php _e('Use an existing card', 'omise'); ?></h3> 6 9 <ul class="omise-customer-card-list"> 7 <?php foreach ( $viewData['existingCards']['data'] as $row => $card) : ?>10 <?php foreach ($viewData['existingCards']['data'] as $row => $card) : ?> 8 11 <li class="item"> 9 12 <input <?php echo $row === 0 ? 'checked=checked' : ''; ?> id="card-<?php echo $card['id']; ?>" type="radio" name="card_id" value="<?php echo $card['id']; ?>" /> … … 17 20 18 21 <div> 19 <?php if ( $showExistingCards) : ?>22 <?php if($showExistingCards) : ?> 20 23 <input id="new_card_info" type="radio" name="card_id" value="" /> 21 24 <label id="label-new_card_info" for="new_card_info"> 22 <h3><?php _e( 'Create a charge using new card', 'omise'); ?></h3>25 <h3><?php _e('Create a charge using new card', 'omise'); ?></h3> 23 26 </label> 24 27 <?php endif; ?> 25 28 26 <fieldset class="omise-new-card-form <?php echo $showExistingCards ? 'card-exists' : ''; ?>"> 29 <?php if ($viewData['secure_form_enabled']): ?> 30 <div class="omise-new-card-form <?php echo $showExistingCards ? 'card-exists' : ''; ?>"> 31 <div id="omise-card" style="width:100%; max-width: 400px;"></div> 32 <input type="hidden" name="omise_save_customer_card" class="omise_save_customer_card" /> 33 <div class="clear"></div> 34 </div> 35 <?php else: ?> 36 <fieldset class="omise-new-card-form <?php echo $showExistingCards ? 'card-exists' : ''; ?>"> 27 37 28 <?php require_once( 'form-creditcard.php'); ?>38 <?php require_once('form-creditcard.php'); ?> 29 39 30 <div class="clear"></div>40 <div class="clear"></div> 31 41 32 <?php if ( $viewData['user_logged_in']) : ?>33 <div class="omise-form-child omise-remember-card">34 <input type="checkbox" name="omise_save_customer_card" id="omise_save_customer_card" />35 <label for="omise_save_customer_card" class="inline">36 <?php _e( 'Remember this card', 'omise'); ?>37 </label>38 </div>39 <?php endif; ?>42 <?php if ($viewData['user_logged_in']) : ?> 43 <div class="omise-form-child omise-remember-card"> 44 <input type="checkbox" name="omise_save_customer_card" id="omise_save_customer_card" /> 45 <label for="omise_save_customer_card" class="inline"> 46 <?php _e('Remember this card', 'omise'); ?> 47 </label> 48 </div> 49 <?php endif; ?> 40 50 41 <div class="clear"></div> 42 </fieldset> 51 <div class="clear"></div> 52 </fieldset> 53 <?php endif; ?> 43 54 </div> 44 55 </div> 56 <?php if($viewData['secure_form_enabled']): ?> 57 <script> 58 window.CARD_FORM_THEME = "<?php echo $viewData['card_form_theme'] ?>"; 59 window.CARD_BRAND_ICONS = JSON.parse(`<?php echo json_encode($viewData['card_icons']) ?>`); 60 window.FORM_DESIGN = JSON.parse(`<?php echo json_encode($viewData['form_design']) ?>`); 61 window.LOCALE = `<?php echo get_locale(); ?>`; 62 window.HIDE_REMEMBER_CARD = `<?php echo $hideRememberCard ?>` == 'yes' ? true : false; 63 </script> 64 <?php endif; ?> -
omise/trunk/CHANGELOG.md
r2876857 r2892466 1 1 # CHANGELOG 2 3 4 ### [v5.0.0 _(Apr 3, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.0.0) 5 - Replace credit card form with secure form with a feature flag options to switch between credit card forms. (PR [#354](https://github.com/omise/omise-woocommerce/pull/354)) 6 - Added an admin notice to notify the user to update the current credit card form to embedded form. (PR [#358](https://github.com/omise/omise-woocommerce/pull/358)) 7 - Track the adoption of the secure form. (PR [#359](https://github.com/omise/omise-woocommerce/pull/359)) 8 - Removed SCB and KTB internet banking. (PR [#356](https://github.com/omise/omise-woocommerce/pull/356)) 9 - Bug fix: hanlde Shopeepay cancel payment. (PR [#361](https://github.com/omise/omise-woocommerce/pull/361)) 2 10 3 11 ### [v4.29.0 _(Mar 8, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v4.29.0) -
omise/trunk/assets/css/omise-css.css
r2876857 r2892466 31 31 } 32 32 33 fieldset.card-exists { 33 fieldset.card-exists, 34 .omise-new-card-form.card-exists { 34 35 display: none; 35 36 } 36 37 37 #new_card_info:checked ~ fieldset.card-exists { 38 #new_card_info:checked ~ fieldset.card-exists, 39 #new_card_info:checked ~ .omise-new-card-form.card-exists { 38 40 display: flex; 39 41 } -
omise/trunk/assets/images/green-check.svg
r2501460 r2892466 1 < ?xml version="1.0" ?><svg id="Layer_1" style="enable-background:new 0 0 612 792;" version="1.1" viewBox="0 0 612 792" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style type="text/css">2 .st0{fill:#41AD49;} 3 </s tyle><g><path class="st0" d="M562,396c0-141.4-114.6-256-256-256S50,254.6,50,396s114.6,256,256,256S562,537.4,562,396L562,396z M501.7,296.3l-241,241l0,0l-17.2,17.2L110.3,421.3l58.8-58.8l74.5,74.5l199.4-199.4L501.7,296.3L501.7,296.3z"/></g></svg>1 <svg width="18" height="19" viewBox="0 0 18 19" fill="none" xmlns="http://www.w3.org/2000/svg"> 2 <path d="M0 9.25C0 4.29297 4.00781 0.25 9 0.25C13.957 0.25 18 4.29297 18 9.25C18 14.2422 13.957 18.25 9 18.25C4.00781 18.25 0 14.2422 0 9.25ZM13.043 7.70312C13.4297 7.31641 13.4297 6.71875 13.043 6.33203C12.6562 5.94531 12.0586 5.94531 11.6719 6.33203L7.875 10.1289L6.29297 8.58203C5.90625 8.19531 5.30859 8.19531 4.92188 8.58203C4.53516 8.96875 4.53516 9.56641 4.92188 9.95312L7.17188 12.2031C7.55859 12.5898 8.15625 12.5898 8.54297 12.2031L13.043 7.70312Z" fill="#30AD7F"/> 3 </svg> -
omise/trunk/assets/javascripts/omise-myaccount-card-handler.js
r2809311 r2892466 61 61 }); 62 62 63 if(Boolean(parseInt(omise_params.secure_form_enabled))) { 64 hideError(); 65 OmiseCard.requestCardToken() 66 } else { 67 saveCardTraditional() 68 } 69 } 70 71 $(".delete_card").click(function(event){ 72 if(confirm('Confirm delete card?')){ 73 let $button = $(this); 74 $button.block({ 75 message: null, 76 overlayCSS: { 77 background: '#fff url(' + omise_params.ajax_loader_url + ') no-repeat center', 78 backgroundSize: '16px 16px', 79 opacity: 0.6 80 } 81 }); 82 delete_card($button.data("card-id"), $button.data("delete-card-nonce")); 83 } 84 }); 85 86 $("#omise_add_new_card").click(function(event){ 87 create_card(); 88 }); 89 90 function saveCardTraditional() { 63 91 let errors = [], 64 92 omise_card = {}, … … 124 152 } 125 153 } 126 127 $(".delete_card").click(function(event){ 128 if(confirm('Confirm delete card?')){ 129 let $button = $(this); 130 $button.block({ 131 message: null, 132 overlayCSS: { 133 background: '#fff url(' + omise_params.ajax_loader_url + ') no-repeat center', 134 backgroundSize: '16px 16px', 135 opacity: 0.6 154 155 function saveCardEmbedded(payload) { 156 const data = { 157 action: "omise_create_card", 158 omise_token: payload.token, 159 omise_nonce: $("#omise_add_card_nonce").val() 160 }; 161 $.post(omise_params.ajax_url, data, 162 function(wp_response){ 163 if(wp_response.id){ 164 window.location.reload(); 165 }else{ 166 showError(wp_response.message, $form); 136 167 } 137 }); 138 delete_card($button.data("card-id"), $button.data("delete-card-nonce")); 139 } 140 }); 141 142 $("#omise_add_new_card").click(function(event){ 143 create_card(); 144 }); 168 }, "json" 169 ); 170 } 171 172 if(Boolean(parseInt(omise_params.secure_form_enabled))) { 173 showOmiseEmbeddedCardForm({ 174 element: document.getElementById('omise-card'), 175 publicKey: omise_params.key, 176 locale: LOCALE, 177 theme: CARD_FORM_THEME ?? 'light', 178 design: FORM_DESIGN, 179 brandIcons: CARD_BRAND_ICONS, 180 hideRememberCard: true, 181 onSuccess: saveCardEmbedded, 182 onError: (error) => { 183 showError(error) 184 $form.unblock() 185 } 186 }) 187 } 145 188 } 146 189 )(jQuery); -
omise/trunk/assets/javascripts/omise-payment-form-handler.js
r2809311 r2892466 15 15 16 16 if ($.isArray(message)) { 17 $.each(message, function(i, v) {17 $.each(message, function(i, v) { 18 18 $ulError.append($("<li>" + v + "</li>")); 19 19 }) … … 59 59 60 60 if (0 === $('input.omise_token').length) { 61 $form.block({ 62 message: null, 63 overlayCSS: { 64 background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', 65 backgroundSize: '16px 16px', 66 opacity: 0.6 67 } 68 }); 69 70 let errors = [], 71 omise_card = {}, 72 omise_card_number_field = 'number', 73 omise_card_fields = { 74 'name' : $('#omise_card_name'), 75 'number' : $('#omise_card_number'), 76 'expiration_month' : $('#omise_card_expiration_month'), 77 'expiration_year' : $('#omise_card_expiration_year'), 78 'security_code' : $('#omise_card_security_code') 79 }; 80 81 $.each(omise_card_fields, function(index, field) { 82 omise_card[index] = (index === omise_card_number_field) ? field.val().replace(/\s/g, '') : field.val(); 83 if ("" === omise_card[index]) { 84 errors.push(omise_params['required_card_' + index]); 85 } 86 }); 87 88 if (errors.length > 0) { 89 showError(errors); 90 $form.unblock(); 91 return false; 92 } 93 94 hideError(); 95 96 if(Omise) { 97 Omise.setPublicKey(omise_params.key); 98 Omise.createToken("card", omise_card, function (statusCode, response) { 99 if (statusCode == 200) { 100 $.each(omise_card_fields, function(index, field) { 101 field.val(''); 102 }); 103 104 $form.append('<input type="hidden" class="omise_token" name="omise_token" value="' + response.id + '"/>'); 105 $form.submit(); 106 } else { 107 handleTokensApiError(response); 108 }; 61 (Boolean(omise_params.secure_form_enabled)) 62 ? requestCardToken() 63 : traditionalForm(); 64 return false; 65 } 66 } 67 } 68 69 function traditionalForm() { 70 $form.block({ 71 message: null, 72 overlayCSS: { 73 background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', 74 backgroundSize: '16px 16px', 75 opacity: 0.6 76 } 77 }); 78 79 let errors = [], 80 omise_card = {}, 81 omise_card_number_field = 'number', 82 omise_card_fields = { 83 'name' : $('#omise_card_name'), 84 'number' : $('#omise_card_number'), 85 'expiration_month' : $('#omise_card_expiration_month'), 86 'expiration_year' : $('#omise_card_expiration_year'), 87 'security_code' : $('#omise_card_security_code') 88 }; 89 90 $.each(omise_card_fields, function(index, field) { 91 omise_card[index] = (index === omise_card_number_field) ? field.val().replace(/\s/g, '') : field.val(); 92 if ("" === omise_card[index]) { 93 errors.push(omise_params['required_card_' + index]); 94 } 95 }); 96 97 if (errors.length > 0) { 98 showError(errors); 99 $form.unblock(); 100 return false; 101 } 102 103 hideError(); 104 105 if(Omise) { 106 Omise.setPublicKey(omise_params.key); 107 Omise.createToken("card", omise_card, function (statusCode, response) { 108 if (statusCode == 200) { 109 $.each(omise_card_fields, function(index, field) { 110 field.val(''); 109 111 }); 112 113 $form.append('<input type="hidden" class="omise_token" name="omise_token" value="' + response.id + '"/>'); 114 $form.submit(); 110 115 } else { 111 showError(omise_params.cannot_load_omisejs + '<br/>' + omise_params.check_internet_connection);112 $form.unblock();113 }114 115 return false;116 }116 handleTokensApiError(response); 117 }; 118 }); 119 } else { 120 showError(omise_params.cannot_load_omisejs + '<br/>' + omise_params.check_internet_connection); 121 $form.unblock(); 117 122 } 118 123 } … … 188 193 } 189 194 195 function requestCardToken() { 196 hideError() 197 $form.block({ 198 message: null, 199 overlayCSS: { 200 background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', 201 backgroundSize: '16px 16px', 202 opacity: 0.6 203 } 204 }); 205 const billingAddress = { 206 country: document.getElementById('billing_country').value, 207 postal_code: document.getElementById('billing_postcode').value, 208 state: document.getElementById('billing_state').value, 209 city: document.getElementById('billing_city').value, 210 street1: document.getElementById('billing_address_1').value, 211 street2: document.getElementById('billing_address_2').value, 212 } 213 OmiseCard.requestCardToken(billingAddress) 214 } 215 216 function handleCreateOrder(payload) { 217 $form.unblock(); 218 if (payload.token) { 219 if (payload.remember) { 220 $('.omise_save_customer_card').val(payload.remember) 221 } 222 $form.append('<input type="hidden" class="omise_token" name="omise_token" value="' + payload.token + '"/>'); 223 $form.submit(); 224 } 225 } 226 227 if(Boolean(omise_params.secure_form_enabled)) { 228 $(document).on('updated_checkout', function () { 229 showOmiseEmbeddedCardForm({ 230 element: document.getElementById('omise-card'), 231 publicKey: omise_params.key, 232 hideRememberCard: HIDE_REMEMBER_CARD, 233 locale: LOCALE, 234 theme: CARD_FORM_THEME ?? 'light', 235 design: FORM_DESIGN, 236 brandIcons: CARD_BRAND_ICONS, 237 onSuccess: handleCreateOrder, 238 onError: (error) => { 239 showError(error) 240 $form.unblock() 241 } 242 }) 243 }); 244 } 245 190 246 $(function () { 191 247 $('body').on('checkout_error', function () { -
omise/trunk/includes/admin/class-omise-page-settings.php
r2783685 r2892466 57 57 $settings = $page->get_settings(); 58 58 59 $available_payment_methods = array(); 59 // This variable is used in the view. 60 $available_payment_methods = []; 60 61 $capabilities = Omise_Capabilities::retrieve(); 61 62 -
omise/trunk/includes/class-omise-admin.php
r2832733 r2892466 2 2 defined( 'ABSPATH' ) or die( "No direct script access allowed." ); 3 3 4 if ( ! class_exists( 'Omise_Admin' ) ) { 5 class Omise_Admin { 4 if (!class_exists('Omise_Admin')) { 5 class Omise_Admin 6 { 6 7 /** 7 8 * The Omise Instance. … … 14 15 * @return \Omise_Admin The instance. 15 16 */ 16 public static function get_instance() { 17 if ( ! self::$the_instance ) { 17 public static function get_instance() 18 { 19 if (!self::$the_instance) { 18 20 self::$the_instance = new self(); 19 21 } … … 25 27 * @since 3.3 26 28 */ 27 public function init() {28 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-admin-page.php';29 public function init() 30 { 29 31 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-page-settings.php'; 30 32 … … 36 38 * Register Omise's custom menu to WordPress admin menus. 37 39 */ 38 public function register_admin_menu() { 39 add_action( 'admin_menu', array( $this, 'wordpress_hook_admin_menu' ) ); 40 public function register_admin_menu() 41 { 42 add_action('admin_menu', [$this, 'wordpress_hook_admin_menu']); 43 add_action('admin_menu', [$this, 'wordpress_hook_card_form_customization']); 40 44 } 41 45 … … 44 48 * Register Omise's custom menu to WordPress admin menus. 45 49 */ 46 public function wordpress_hook_admin_menu() { 47 add_menu_page( __( 'Opn Payments Settings', 'omise' ), 'Opn Payments', 'manage_options', 'omise', array( $this, 'page_settings') ); 50 public function wordpress_hook_admin_menu() 51 { 52 add_menu_page( 53 __('Opn Payments Settings', 'omise'), 54 'Opn Payments', 55 'manage_options', 56 'omise', 57 [$this, 'page_settings'] 58 ); 59 } 60 61 /** 62 * Register Omise's card customization page. 63 */ 64 public function wordpress_hook_card_form_customization() 65 { 66 add_submenu_page( 67 null, 68 __('Custom card form customization', 'omise'), 69 Omise_Page_Card_From_Customization::PAGE_NAME, 70 'manage_options', 71 'omise_card_form_customization', 72 [$this, 'card_form_customization'] 73 ); 48 74 } 49 75 … … 51 77 * Render Omise Setting page. 52 78 */ 53 public function page_settings() { 79 public function page_settings() 80 { 54 81 Omise_Page_Settings::render(); 82 } 83 84 /** 85 * Render Omise card form customization page. 86 */ 87 public function card_form_customization() 88 { 89 Omise_Page_Card_From_Customization::render(); 55 90 } 56 91 … … 58 93 * @since 3.3 59 94 */ 60 public function register_woocommerce_filters() { 61 add_filter( 'woocommerce_order_actions', array( $this, 'woocommerce_filter_order_actions' ) ); 95 public function register_woocommerce_filters() 96 { 97 add_filter( 98 'woocommerce_order_actions', 99 [$this, 'woocommerce_filter_order_actions'] 100 ); 62 101 } 63 102 … … 71 110 * @return array 72 111 */ 73 public function woocommerce_filter_order_actions( $order_actions ) { 112 public function woocommerce_filter_order_actions($order_actions) 113 { 74 114 global $theorder; 75 115 -
omise/trunk/includes/class-omise-callback.php
r2876857 r2892466 30 30 { 31 31 $order_id = isset( $_GET['order_id'] ) ? sanitize_text_field( $_GET['order_id'] ) : null; 32 $token = isset( $_GET['token'] ) ? sanitize_text_field( $_GET['token'] ) : null;33 32 $order = wc_get_order( $order_id ); 34 33 … … 74 73 try { 75 74 $this->charge = $this->fetchCharge($this->order->get_transaction_id()); 75 76 // TODO: Remove this if block once the issue is fixed on the server. 77 if ($this->hasShopeepayFailed()) { 78 $this->payment_failed(); 79 return; 80 } 76 81 77 82 switch ( strtolower( $this->charge['status'] ) ) { … … 100 105 101 106 /** 107 * TODO: Remove this if block once the issue is fixed on the server. 108 */ 109 private function hasShopeepayFailed() 110 { 111 $isPaymentMethodShopeepay = 'shopeepay' === $this->charge['source']['type']; 112 $isChargePending = 'pending' === $this->charge['status']; 113 return $isPaymentMethodShopeepay && $isChargePending; 114 } 115 116 /** 102 117 * Resolving a case of undefined charge status 103 118 */ … … 191 206 protected function payment_failed() { 192 207 $message = __( "It seems we've been unable to process your payment properly:<br/>%s", 'omise' ); 193 $failure_message = Omise()->translate( $this->charge['failure_message'] ) . ' (code: ' . $this->charge['failure_code'] . ')'; 208 $failure_message = Omise()->translate( $this->charge['failure_message'] ); 209 $failure_message .= ($this->charge['failure_code']) ? 210 ' (code: ' . $this->charge['failure_code'] . ')' 211 : ' (code: Payment failed)'; // for shopeepay 194 212 195 213 $this->order->add_order_note( sprintf( wp_kses( __( 'OMISE: Payment failed.<br/>%s', 'omise' ), array( 'br' => array() ) ), $failure_message ) ); -
omise/trunk/includes/class-omise-wc-myaccount.php
r2795404 r2892466 3 3 4 4 if ( ! class_exists( 'Omise_MyAccount' ) ) { 5 class Omise_MyAccount { 5 class Omise_MyAccount 6 { 6 7 private static $instance; 7 8 private $omise_customer_id; … … 27 28 28 29 $this->customerCard = new OmiseCustomerCard; 30 $this->omiseCardGateway = new Omise_Payment_Creditcard(); 29 31 30 32 add_action( 'woocommerce_after_my_account', array( $this, 'init_panel' ) ); … … 42 44 try { 43 45 $viewData['existingCards'] = $this->customerCard->get($this->omise_customer_id); 46 $viewData['cardFormTheme'] = $this->omiseCardGateway->get_option('card_form_theme'); 47 $viewData['secure_form_enabled'] = (boolean)$this->omiseCardGateway->get_option('secure_form_enabled'); 48 $viewData['formDesign'] = Omise_Page_Card_From_Customization::get_instance()->get_design_setting(); 49 $viewData['cardIcons'] = $this->omiseCardGateway->get_card_icons(); 50 $this->register_omise_my_account_scripts(); 44 51 45 52 Omise_Util::render_view( 'templates/myaccount/my-card.php', $viewData ); 46 $this->register_omise_my_account_scripts();47 53 } catch (Exception $e) { 48 54 // nothing. … … 57 63 wp_enqueue_script( 58 64 'omise-js', 59 'https://cdn.omise.co/omise.js',65 Omise::OMISE_JS_LINK, 60 66 array( 'jquery' ), 61 67 WC_VERSION, 68 true 69 ); 70 71 wp_enqueue_script( 72 'embedded-js', 73 plugins_url( '/assets/javascripts/omise-embedded-card.js', dirname( __FILE__ ) ), 74 [], 75 OMISE_WOOCOMMERCE_PLUGIN_VERSION, 62 76 true 63 77 ); … … 105 119 'number is invalid and brand not supported (unknown)' => __( 'number is invalid and brand not supported (unknown)', 'omise' ), 106 120 'expiration year is invalid, expiration date cannot be in the past, number is invalid, and brand not supported (unknown)' => __( 'expiration year is invalid, expiration date cannot be in the past, number is invalid, and brand not supported (unknown)', 'omise' ), 107 'expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)' => __('expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)', 'omise') 121 'expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)' => __('expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)', 'omise'), 122 'secure_form_enabled' => (boolean)$this->omiseCardGateway->get_option('secure_form_enabled') 108 123 ]; 109 124 } … … 152 167 153 168 try { 154 $card = $this->customerCard->create($t oken, $omiseCustomerId);169 $card = $this->customerCard->create($this->omise_customer_id, $token); 155 170 echo json_encode( $card ); 156 171 } catch( Exception $e ) { -
omise/trunk/includes/classes/class-omise-card-image.php
r2720994 r2892466 63 63 64 64 /** 65 * Return the HTML <img> element of Discover logo 66 * 67 * @return string 68 */ 69 public static function get_discover_image() { 70 return self::get_image( 'discover.svg', 'Discover' ); 71 } 72 73 /** 74 * Return the default setting of display the Discover logo 75 * 76 * @return string 77 */ 78 public static function get_discover_default_display() { 79 return 'no'; 80 } 81 82 /** 65 83 * Return the default setting of display the JCB logo 66 84 * … … 128 146 129 147 return false; 148 } 149 150 /** 151 * Check whether the setting for Discover logo is configured and it was set to display or not display 152 * 153 * @param mixed $setting The array that contains key for checking the flag 154 * @return boolean 155 */ 156 public static function is_discover_enabled( $setting ) { 157 return isset( $setting['accept_discover'] ) && $setting['accept_discover'] == 'yes'; 130 158 } 131 159 -
omise/trunk/includes/classes/class-omise-customer-card.php
r2795404 r2892466 36 36 * @return string 37 37 */ 38 public function create($customer , $token)38 public function create($customerId, $token) 39 39 { 40 $customer = $this->customer->get($customerId); 40 41 $customer->update( ['card' => $token ]); 41 42 -
omise/trunk/includes/gateway/abstract-omise-payment-base-card.php
r2876857 r2892466 28 28 29 29 // Saving card. 30 if (isset($_POST['omise_save_customer_card']) && empty($card_id)) { 30 $saveCustomerCard = $_POST['omise_save_customer_card']; 31 if (isset($saveCustomerCard) && !empty($saveCustomerCard) && empty($card_id)) { 31 32 $cardDetails = $this->saveCard($omise_customer_id, $token, $order_id, $user->ID); 32 33 $omise_customer_id = $cardDetails['customer_id']; … … 58 59 ), 59 60 'return_uri' => $this->getRedirectUrl('omise_callback', $order_id, $order), 60 'metadata' => $this->getMetadata($order_id, $order) 61 'metadata' => $this->getMetadata( 62 $order_id, 63 $order, 64 [ 'secure_form_enabled' => $this->getSecureFormState()] 65 ) 61 66 ]; 62 67 … … 76 81 77 82 return $data; 83 } 84 85 /** 86 * Returns the the secure form state in yes/not format 87 */ 88 private function getSecureFormState() 89 { 90 // tracking the embedded form adoption 91 $omiseCardGateway = new Omise_Payment_Creditcard(); 92 $secureFormEnabled = $omiseCardGateway->get_option('secure_form_enabled'); 93 return (boolean)$secureFormEnabled ? 'yes' : 'no'; 78 94 } 79 95 … … 111 127 112 128 try { 113 $customer->get($omise_customer_id);114 129 $customerCard = new OmiseCustomerCard; 115 $card = $customerCard->create($customer, $token); 130 131 // TODO: Save customer with $omise_customer_id from Embedded form 132 $card = $customerCard->create($omise_customer_id, $token); 116 133 117 134 return [ … … 128 145 // Saved customer ID is not found so we create a new customer and save the customer ID 129 146 $customer_data = $customer->create($user_id, $order_id, $customer_data); 147 130 148 return [ 131 149 'customer_id' => $customer_data['customer_id'], … … 234 252 wp_enqueue_script( 235 253 'omise-js', 236 'https://cdn.omise.co/omise.js',254 Omise::OMISE_JS_LINK, 237 255 [ 'jquery' ], 256 OMISE_WOOCOMMERCE_PLUGIN_VERSION, 257 true 258 ); 259 260 wp_enqueue_script( 261 'embedded-js', 262 plugins_url( '../../assets/javascripts/omise-embedded-card.js', __FILE__ ), 263 [], 238 264 OMISE_WOOCOMMERCE_PLUGIN_VERSION, 239 265 true … … 261 287 public function getParamsForJS() 262 288 { 289 $omiseCardGateway = new Omise_Payment_Creditcard(); 290 263 291 return [ 264 292 'key' => $this->public_key(), … … 334 362 'expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)', 335 363 'omise' 336 ) 364 ), 365 'secure_form_enabled' => (boolean)$omiseCardGateway->get_option('secure_form_enabled') 337 366 ]; 338 367 } -
omise/trunk/includes/gateway/class-omise-payment-creditcard.php
r2832733 r2892466 3 3 4 4 class Omise_Payment_Creditcard extends Omise_Payment_Base_Card { 5 public function __construct() { 5 const SECURE_FORM_ENABLED = true; 6 7 public function __construct() 8 { 6 9 parent::__construct(); 7 10 … … 28 31 $this->restricted_countries = array( 'TH', 'JP', 'SG', 'MY' ); 29 32 33 $this->register_omise_credit_card_scripts(); 34 30 35 add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' ); 31 36 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); … … 67 72 array( 68 73 'advanced' => array( 69 'title' => __( 'Advance Settings', 'omise' ),74 'title' => __( 'Advanced Settings', 'omise' ), 70 75 'type' => 'title' 71 76 ), … … 82 87 'desc_tip' => true 83 88 ), 89 'secure_form_enabled' => [ 90 'title' => __( 'Secure form', 'omise' ), 91 'type' => 'select', 92 'description' => __( 'Try the new secure form to accept card payments. The new form features additional controls to ensure PCI-DSS compliance.<br /><strong><em>Using this form will be mandatory in a future release</em></strong>.', 'omise' ), 93 'default' => !self::SECURE_FORM_ENABLED, 94 'options' => array( 95 !self::SECURE_FORM_ENABLED => __( 'No', 'omise' ), 96 self::SECURE_FORM_ENABLED => __( 'Yes', 'omise' ) 97 ) 98 ], 99 100 'card_form_theme' => [ 101 'title' => __( 'Secure form theme', 'omise' ), 102 'type' => 'select', 103 'default' => 'light', 104 'class' => 'wc-enhanced-select', 105 'options' => array( 106 'light' => __( 'Light', 'omise' ), 107 'dark' => __( 'Dark', 'omise' ) 108 ), 109 'description' => wp_kses( 110 __( 'Credit / Debit card form design on checkout page. <br /> <a href="admin.php?page=omise_card_form_customization">Click here for more card form customization.</a>', 'omise' ), 111 ['a' => ['href' => []], 'br' => []] 112 ), 113 ], 84 114 'accept_visa' => array( 85 115 'title' => __( 'Supported card icons', 'omise' ), … … 106 136 'css' => Omise_Card_Image::get_css(), 107 137 'default' => Omise_Card_Image::get_diners_default_display() 138 ), 139 'accept_discover' => array( 140 'type' => 'checkbox', 141 'label' => Omise_Card_Image::get_discover_image(), 142 'css' => Omise_Card_Image::get_css(), 143 'default' => Omise_Card_Image::get_discover_default_display() 108 144 ), 109 145 'accept_amex' => array( … … 118 154 ) 119 155 ) 156 ); 157 } 158 159 private function register_omise_credit_card_scripts() { 160 wp_enqueue_script( 161 'omise-credit-card', 162 plugins_url( '../assets/javascripts/omise-payment-credit-card.js', dirname( __FILE__ ) ), 163 array( 'jquery' ), 164 WC_VERSION, 165 true 120 166 ); 121 167 } … … 146 192 } 147 193 194 $viewData['secure_form_enabled'] = (boolean)$this->get_option('secure_form_enabled'); 195 196 if ($viewData['secure_form_enabled'] === self::SECURE_FORM_ENABLED) { 197 $viewData['card_form_theme'] = $this->get_option('card_form_theme'); 198 $viewData['card_icons'] = $this->get_card_icons(); 199 $viewData['form_design'] = Omise_Page_Card_From_Customization::get_instance()->get_design_setting(); 200 } 201 148 202 Omise_Util::render_view( 'templates/payment/form.php', $viewData ); 149 203 } 150 204 151 205 /** 152 * Get icons of all supported card types 153 * 154 * @see WC_Payment_Gateway::get_icon() 206 * Get card icons for credit card form 155 207 */ 156 public function get_icon() { 157 $icon = ''; 158 159 // TODO: Refactor 'Omise_Card_Image' class that we don't need to pass 160 // these options to check outside this class. 161 $card_icons['accept_amex'] = $this->get_option( 'accept_amex' ); 162 $card_icons['accept_diners'] = $this->get_option( 'accept_diners' ); 163 $card_icons['accept_jcb'] = $this->get_option( 'accept_jcb' ); 164 $card_icons['accept_mastercard'] = $this->get_option( 'accept_mastercard' ); 165 $card_icons['accept_visa'] = $this->get_option( 'accept_visa' ); 166 167 if ( Omise_Card_Image::is_visa_enabled( $card_icons ) ) { 168 $icon .= Omise_Card_Image::get_visa_image(); 208 public function get_card_icons() { 209 $enable_icons = []; 210 $card_icons = [ 211 'amex' => 'accept_amex', 212 'diners' => 'accept_diners', 213 'jcb' => 'accept_jcb', 214 'mastercard' => 'accept_mastercard', 215 'visa' => 'accept_visa', 216 'discover' => 'accept_discover', 217 ]; 218 219 foreach($card_icons as $key => $value) { 220 if($this->get_option($value) == "yes") { 221 $enable_icons[] = $key; 222 } 169 223 } 170 224 171 if ( Omise_Card_Image::is_mastercard_enabled( $card_icons ) ) { 172 $icon .= Omise_Card_Image::get_mastercard_image(); 173 } 174 175 if ( Omise_Card_Image::is_jcb_enabled( $card_icons ) ) { 176 $icon .= Omise_Card_Image::get_jcb_image(); 177 } 178 179 if ( Omise_Card_Image::is_diners_enabled( $card_icons ) ) { 180 $icon .= Omise_Card_Image::get_diners_image(); 181 } 182 183 if ( Omise_Card_Image::is_amex_enabled( $card_icons ) ) { 184 $icon .= Omise_Card_Image::get_amex_image(); 185 } 186 187 return empty( $icon ) ? '' : apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); 225 return $enable_icons; 188 226 } 189 227 } -
omise/trunk/includes/gateway/class-omise-payment-googlepay.php
r2832733 r2892466 82 82 array( 83 83 'advanced' => array( 84 'title' => __('Advance Settings', 'omise'),84 'title' => __('Advanced Settings', 'omise'), 85 85 'type' => 'title' 86 86 ), -
omise/trunk/includes/gateway/class-omise-payment-rabbit-linepay.php
r2832733 r2892466 59 59 array( 60 60 'advanced' => array( 61 'title' => __( 'Advance Settings', 'omise' ),61 'title' => __( 'Advanced Settings', 'omise' ), 62 62 'type' => 'title' 63 63 ), -
omise/trunk/includes/gateway/class-omise-payment.php
r2876857 r2892466 605 605 * @param string $order_id 606 606 * @param object $order 607 */ 608 public function getMetadata($order_id, $order) 607 * @param array $additionalData 608 */ 609 public function getMetadata($order_id, $order, $additionalData = []) 609 610 { 611 // override order_id as a reference for webhook handlers. 612 $orderId = [ 'order_id' => $order_id ]; 613 610 614 return array_merge( 611 615 apply_filters('omise_charge_params_metadata', [], $order), 612 ['order_id' => $order_id] // override order_id as a reference for webhook handlers.616 array_merge($orderId, $additionalData) 613 617 ); 614 618 } -
omise/trunk/languages/omise-ja.po
r2832733 r2892466 140 140 141 141 #: includes/gateway/class-omise-payment-creditcard.php:78 142 msgid "Advance Settings"142 msgid "Advanced Settings" 143 143 msgstr "詳細設定" 144 144 … … 586 586 msgid "Please select bank below" 587 587 msgstr "以下から銀行をお選びください" 588 589 #: omise-woocommerce.php:66 590 msgid "Update your plugin to the latest version to enable Secure Form and maximize the security of your customers’ information. You will need to re-customize the credit card checkout form after the upgrade. <a target='_blank' href='https://www.omise.co/woocommerce-plugin'>Learn how to enable Secure Form</a>." 591 msgstr "プラグインを最新バージョンにアップデートし、顧客情報の安全な管理に必要なSecure Formを有効にしてください。アップデート後、クレジットカードの決済フォームを再度カスタマイズする必要があります。<a target='_blank' href='https://www.omise.co/woocommerce-plugin'>Secure Formを有効にする方法はこちらをご確認ください</a>。" -
omise/trunk/languages/omise.pot
r2832733 r2892466 139 139 140 140 #: includes/gateway/class-omise-payment-creditcard.php:78 141 msgid "Advance Settings"141 msgid "Advanced Settings" 142 142 msgstr "詳細設定" 143 143 -
omise/trunk/omise-woocommerce.php
r2876857 r2892466 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.29.07 * Version: 5.0.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.29.0';25 public $version = '5.0.0'; 26 26 27 27 /** … … 40 40 */ 41 41 protected static $can_initiate = false; 42 43 CONST OMISE_JS_LINK = 'https://cdn.omise.co/omise.js'; 42 44 43 45 /** … … 49 51 add_action('woocommerce_init', array($this, 'init')); 50 52 do_action('omise_initiated'); 53 add_action('admin_notices', [$this, 'embedded_form_notice']); 54 } 55 56 /** 57 * Notice for users informing about embedded form 58 */ 59 public function embedded_form_notice() 60 { 61 $this->omiseCardGateway = new Omise_Payment_Creditcard(); 62 $embedded_form_enabled = $this->omiseCardGateway->get_option('embedded_form_enabled'); 63 64 // hide if user enables the embedded form. 65 if (!(bool)$embedded_form_enabled) { 66 $translation = __('Update your plugin to the latest version to enable Secure Form and maximize the security of your customers’ information. You will need to re-customize the credit card checkout form after the upgrade. <a target="_blank" href="https://www.omise.co/woocommerce-plugin">Learn how to enable Secure Form</a>.', 'omise'); 67 echo "<div class='notice notice-warning is-dismissible'><p><strong>Opn Payments:</strong> $translation</p></div>"; 68 } 69 } 70 71 /** 72 * get plugin assess url 73 */ 74 public static function get_assets_url() { 75 return plugins_url('assets' , __FILE__); 51 76 } 52 77 … … 189 214 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/class-omise-wc-myaccount.php'; 190 215 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/omise-util.php'; 216 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-admin-page.php'; 217 require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-page-card-form-customization.php'; 191 218 } 192 219 -
omise/trunk/readme.txt
r2876857 r2892466 4 4 Requires at least: 4.3.1 5 5 Tested up to: 6.0.2 6 Stable tag: 4.29.06 Stable tag: 5.0.0 7 7 License: MIT 8 8 License URI: https://opensource.org/licenses/MIT … … 34 34 35 35 == Changelog == 36 37 = 5.0.0 = 38 39 - Replace credit card form with secure form with a feature flag options to switch between credit card forms. (PR [#354](https://github.com/omise/omise-woocommerce/pull/354)) 40 - Added an admin notice to notify the user to update the current credit card form to embedded form. (PR [#358](https://github.com/omise/omise-woocommerce/pull/358)) 41 - Track the adoption of the secure form. (PR [#359](https://github.com/omise/omise-woocommerce/pull/359)) 42 - Removed SCB and KTB internet banking. (PR [#356](https://github.com/omise/omise-woocommerce/pull/356)) 43 - Bug fix: hanlde Shopeepay cancel payment. (PR [#361](https://github.com/omise/omise-woocommerce/pull/361)) 36 44 37 45 = 4.29.0 = -
omise/trunk/templates/myaccount/my-card.php
r2783685 r2892466 37 37 <form name="omise_cc_form" id="omise_cc_form"> 38 38 <?php wp_nonce_field('omise_add_card','omise_add_card_nonce'); ?> 39 <fieldset> 40 <?php require_once( __DIR__ . '/../payment/form-creditcard.php' ); ?> 41 <div class="clear"></div> 42 </fieldset> 39 40 <?php if($viewData['secure_form_enabled']): ?> 41 <div id="omise-card" style="width:100%; max-width: 400px;"></div> 42 <?php else: ?> 43 <fieldset> 44 <?php require_once( __DIR__ . '/../payment/form-creditcard.php' ); ?> 45 <div class="clear"></div> 46 </fieldset> 47 <?php endif; ?> 48 43 49 </form> 44 50 <button id="omise_add_new_card" class="button"><?php _e( 'Save card', 'omise' ); ?></button> 45 51 </div> 52 53 <?php if($viewData['secure_form_enabled']): ?> 54 <script> 55 window.CARD_FORM_THEME = "<?php echo $viewData['cardFormTheme'] ?>"; 56 window.FORM_DESIGN = JSON.parse(`<?php echo json_encode($viewData['formDesign']) ?>`); 57 window.CARD_BRAND_ICONS = JSON.parse(`<?php echo json_encode($viewData['cardIcons']) ?>`); 58 window.LOCALE = `<?php echo get_locale(); ?>`; 59 </script> 60 <?php endif; ?> -
omise/trunk/templates/payment/form-internetbanking.php
r2501457 r2892466 1 1 <fieldset id="omise-form-internetbanking"> 2 2 <ul class="omise-banks-list"> 3 <!-- SCB -->4 <li class="item">5 <input id="internet_banking_scb" type="radio" name="omise-offsite" value="internet_banking_scb" />6 <label for="internet_banking_scb">7 <div class="bank-logo scb"></div>8 <div class="bank-label">9 <span class="title"><?php _e( 'Siam Commercial Bank', 'omise' ); ?></span><br/>10 <span class="omise-secondary-text"><?php _e( 'Fee: 15 THB (same zone), 30 THB (out zone)', 'omise' ); ?></span>11 </div>12 </label>13 </li>14 15 <!-- KTB -->16 <li class="item">17 <input id="internet_banking_ktb" type="radio" name="omise-offsite" value="internet_banking_ktb" />18 <label for="internet_banking_ktb">19 <div class="bank-logo ktb"></div>20 <div class="bank-label">21 <span class="title"><?php _e( 'Krungthai Bank', 'omise' ); ?></span><br/>22 <span class="omise-secondary-text"><?php _e( 'Fee: 15 THB (same zone), 15 THB (out zone)', 'omise' ); ?></span>23 </div>24 </label>25 </li>26 27 3 <!-- BAY --> 28 4 <li class="item"> -
omise/trunk/templates/payment/form.php
r2809311 r2892466 1 <?php $showExistingCards = $viewData['user_logged_in'] && isset( $viewData['existingCards']['data'] ) && sizeof( $viewData['existingCards']['data'] ) > 0; ?> 1 <?php 2 $showExistingCards = $viewData['user_logged_in'] && isset($viewData['existingCards']['data']) && sizeof($viewData['existingCards']['data']) > 0; 3 $hideRememberCard = $viewData['user_logged_in'] ? 'no' : 'yes'; 4 ?> 2 5 3 6 <div id="omise_cc_form"> 4 <?php if ( $showExistingCards) : ?>5 <h3><?php _e( 'Use an existing card', 'omise'); ?></h3>7 <?php if ($showExistingCards) : ?> 8 <h3><?php _e('Use an existing card', 'omise'); ?></h3> 6 9 <ul class="omise-customer-card-list"> 7 <?php foreach ( $viewData['existingCards']['data'] as $row => $card) : ?>10 <?php foreach ($viewData['existingCards']['data'] as $row => $card) : ?> 8 11 <li class="item"> 9 12 <input <?php echo $row === 0 ? 'checked=checked' : ''; ?> id="card-<?php echo $card['id']; ?>" type="radio" name="card_id" value="<?php echo $card['id']; ?>" /> … … 17 20 18 21 <div> 19 <?php if ( $showExistingCards) : ?>22 <?php if($showExistingCards) : ?> 20 23 <input id="new_card_info" type="radio" name="card_id" value="" /> 21 24 <label id="label-new_card_info" for="new_card_info"> 22 <h3><?php _e( 'Create a charge using new card', 'omise'); ?></h3>25 <h3><?php _e('Create a charge using new card', 'omise'); ?></h3> 23 26 </label> 24 27 <?php endif; ?> 25 28 26 <fieldset class="omise-new-card-form <?php echo $showExistingCards ? 'card-exists' : ''; ?>"> 29 <?php if ($viewData['secure_form_enabled']): ?> 30 <div class="omise-new-card-form <?php echo $showExistingCards ? 'card-exists' : ''; ?>"> 31 <div id="omise-card" style="width:100%; max-width: 400px;"></div> 32 <input type="hidden" name="omise_save_customer_card" class="omise_save_customer_card" /> 33 <div class="clear"></div> 34 </div> 35 <?php else: ?> 36 <fieldset class="omise-new-card-form <?php echo $showExistingCards ? 'card-exists' : ''; ?>"> 27 37 28 <?php require_once( 'form-creditcard.php'); ?>38 <?php require_once('form-creditcard.php'); ?> 29 39 30 <div class="clear"></div>40 <div class="clear"></div> 31 41 32 <?php if ( $viewData['user_logged_in']) : ?>33 <div class="omise-form-child omise-remember-card">34 <input type="checkbox" name="omise_save_customer_card" id="omise_save_customer_card" />35 <label for="omise_save_customer_card" class="inline">36 <?php _e( 'Remember this card', 'omise'); ?>37 </label>38 </div>39 <?php endif; ?>42 <?php if ($viewData['user_logged_in']) : ?> 43 <div class="omise-form-child omise-remember-card"> 44 <input type="checkbox" name="omise_save_customer_card" id="omise_save_customer_card" /> 45 <label for="omise_save_customer_card" class="inline"> 46 <?php _e('Remember this card', 'omise'); ?> 47 </label> 48 </div> 49 <?php endif; ?> 40 50 41 <div class="clear"></div> 42 </fieldset> 51 <div class="clear"></div> 52 </fieldset> 53 <?php endif; ?> 43 54 </div> 44 55 </div> 56 <?php if($viewData['secure_form_enabled']): ?> 57 <script> 58 window.CARD_FORM_THEME = "<?php echo $viewData['card_form_theme'] ?>"; 59 window.CARD_BRAND_ICONS = JSON.parse(`<?php echo json_encode($viewData['card_icons']) ?>`); 60 window.FORM_DESIGN = JSON.parse(`<?php echo json_encode($viewData['form_design']) ?>`); 61 window.LOCALE = `<?php echo get_locale(); ?>`; 62 window.HIDE_REMEMBER_CARD = `<?php echo $hideRememberCard ?>` == 'yes' ? true : false; 63 </script> 64 <?php endif; ?>
Note: See TracChangeset
for help on using the changeset viewer.