Plugin Directory

Changeset 2892466


Ignore:
Timestamp:
04/03/2023 06:07:16 AM (3 years ago)
Author:
omise
Message:

Update to version 5.0.0 from GitHub

Location:
omise
Files:
12 added
48 edited
1 copied

Legend:

Unmodified
Added
Removed
  • omise/tags/5.0.0/CHANGELOG.md

    r2876857 r2892466  
    11# 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))
    210
    311### [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  
    3131}
    3232
    33 fieldset.card-exists {
     33fieldset.card-exists,
     34.omise-new-card-form.card-exists {
    3435    display: none;
    3536}
    3637
    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 {
    3840    display: flex;
    3941}
  • 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 </style><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  
    6161        });
    6262
     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() {
    6391        let errors                  = [],
    6492            omise_card              = {},
     
    124152        }
    125153    }
    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);
    136167                }
    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    }
    145188}
    146189)(jQuery);
  • omise/tags/5.0.0/assets/javascripts/omise-payment-form-handler.js

    r2809311 r2892466  
    1515
    1616        if ($.isArray(message)) {
    17             $.each(message, function(i,v) {
     17            $.each(message, function(i, v) {
    1818                $ulError.append($("<li>" + v + "</li>"));
    1919            })
     
    5959
    6060            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('');
    109111                    });
     112
     113                    $form.append('<input type="hidden" class="omise_token" name="omise_token" value="' + response.id + '"/>');
     114                    $form.submit();
    110115                } 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();
    117122        }
    118123    }
     
    188193    }
    189194
     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
    190246    $(function () {
    191247        $('body').on('checkout_error', function () {
  • omise/tags/5.0.0/includes/admin/class-omise-page-settings.php

    r2783685 r2892466  
    5757        $settings = $page->get_settings();
    5858       
    59         $available_payment_methods = array();
     59        // This variable is used in the view.
     60        $available_payment_methods = [];
    6061        $capabilities = Omise_Capabilities::retrieve();
    6162
  • omise/tags/5.0.0/includes/class-omise-admin.php

    r2832733 r2892466  
    22defined( 'ABSPATH' ) or die( "No direct script access allowed." );
    33
    4 if ( ! class_exists( 'Omise_Admin' ) ) {
    5     class Omise_Admin {
     4if (!class_exists('Omise_Admin')) {
     5    class Omise_Admin
     6    {
    67        /**
    78         * The Omise Instance.
     
    1415         * @return \Omise_Admin  The instance.
    1516         */
    16         public static function get_instance() {
    17             if ( ! self::$the_instance ) {
     17        public static function get_instance()
     18        {
     19            if (!self::$the_instance) {
    1820                self::$the_instance = new self();
    1921            }
     
    2527         * @since 3.3
    2628         */
    27         public function init() {
    28             require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-admin-page.php';
     29        public function init()
     30        {
    2931            require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-page-settings.php';
    3032
     
    3638         * Register Omise's custom menu to WordPress admin menus.
    3739         */
    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']);
    4044        }
    4145
     
    4448         * Register Omise's custom menu to WordPress admin menus.
    4549         */
    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            );
    4874        }
    4975
     
    5177         * Render Omise Setting page.
    5278         */
    53         public function page_settings() {
     79        public function page_settings()
     80        {
    5481            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();
    5590        }
    5691
     
    5893         * @since 3.3
    5994         */
    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            );
    62101        }
    63102
     
    71110         * @return array
    72111         */
    73         public function woocommerce_filter_order_actions( $order_actions ) {
     112        public function woocommerce_filter_order_actions($order_actions)
     113        {
    74114            global $theorder;
    75115
  • omise/tags/5.0.0/includes/class-omise-callback.php

    r2876857 r2892466  
    3030    {
    3131        $order_id = isset( $_GET['order_id'] ) ? sanitize_text_field( $_GET['order_id'] ) : null;
    32         $token = isset( $_GET['token'] ) ? sanitize_text_field( $_GET['token'] ) : null;
    3332        $order = wc_get_order( $order_id );
    3433
     
    7473        try {
    7574            $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            }
    7681
    7782            switch ( strtolower( $this->charge['status'] ) ) {
     
    100105
    101106    /**
     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    /**
    102117     * Resolving a case of undefined charge status
    103118     */
     
    191206    protected function payment_failed() {
    192207        $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
    194212
    195213        $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  
    33
    44if ( ! class_exists( 'Omise_MyAccount' ) ) {
    5     class Omise_MyAccount {
     5    class Omise_MyAccount
     6    {
    67        private static $instance;
    78        private $omise_customer_id;
     
    2728
    2829            $this->customerCard = new OmiseCustomerCard;
     30            $this->omiseCardGateway = new Omise_Payment_Creditcard();
    2931
    3032            add_action( 'woocommerce_after_my_account', array( $this, 'init_panel' ) );
     
    4244                try {
    4345                    $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();
    4451
    4552                    Omise_Util::render_view( 'templates/myaccount/my-card.php', $viewData );
    46                     $this->register_omise_my_account_scripts();
    4753                } catch (Exception $e) {
    4854                    // nothing.
     
    5763            wp_enqueue_script(
    5864                'omise-js',
    59                 'https://cdn.omise.co/omise.js',
     65                Omise::OMISE_JS_LINK,
    6066                array( 'jquery' ),
    6167                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,
    6276                true
    6377            );
     
    105119                'number is invalid and brand not supported (unknown)' => __( 'number is invalid and brand not supported (unknown)', 'omise' ),
    106120                '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')
    108123            ];
    109124        }
     
    152167
    153168            try {
    154                 $card = $this->customerCard->create($token, $omiseCustomerId);
     169                $card = $this->customerCard->create($this->omise_customer_id, $token);
    155170                echo json_encode( $card );
    156171            } catch( Exception $e ) {
  • omise/tags/5.0.0/includes/classes/class-omise-card-image.php

    r2720994 r2892466  
    6363
    6464        /**
     65         * Return the HTML &lt;img&gt; 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        /**
    6583         * Return the default setting of display the JCB logo
    6684         *
     
    128146
    129147            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';
    130158        }
    131159
  • omise/tags/5.0.0/includes/classes/class-omise-customer-card.php

    r2795404 r2892466  
    3636         * @return string
    3737         */
    38         public function create($customer, $token)
     38        public function create($customerId, $token)
    3939        {
     40            $customer = $this->customer->get($customerId);
    4041            $customer->update( ['card' => $token ]);
    4142
  • omise/tags/5.0.0/includes/gateway/abstract-omise-payment-base-card.php

    r2876857 r2892466  
    2828
    2929        // 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)) {
    3132            $cardDetails = $this->saveCard($omise_customer_id, $token, $order_id, $user->ID);
    3233            $omise_customer_id = $cardDetails['customer_id'];
     
    5859            ),
    5960            '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            )
    6166        ];
    6267
     
    7681
    7782        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';
    7894    }
    7995
     
    111127
    112128            try {
    113                 $customer->get($omise_customer_id);
    114129                $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);
    116133
    117134                return [
     
    128145                // Saved customer ID is not found so we create a new customer and save the customer ID
    129146                $customer_data = $customer->create($user_id, $order_id, $customer_data);
     147
    130148                return [
    131149                    'customer_id' => $customer_data['customer_id'],
     
    234252            wp_enqueue_script(
    235253                'omise-js',
    236                 'https://cdn.omise.co/omise.js',
     254                Omise::OMISE_JS_LINK,
    237255                [ '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                [],
    238264                OMISE_WOOCOMMERCE_PLUGIN_VERSION,
    239265                true
     
    261287    public function getParamsForJS()
    262288    {
     289        $omiseCardGateway = new Omise_Payment_Creditcard();
     290
    263291        return [
    264292            'key'                            => $this->public_key(),
     
    334362                'expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)',
    335363                'omise'
    336             )
     364            ),
     365            'secure_form_enabled'   => (boolean)$omiseCardGateway->get_option('secure_form_enabled')
    337366        ];
    338367    }
  • omise/tags/5.0.0/includes/gateway/class-omise-payment-creditcard.php

    r2832733 r2892466  
    33
    44class Omise_Payment_Creditcard extends Omise_Payment_Base_Card {
    5     public function __construct() {
     5    const SECURE_FORM_ENABLED = true;
     6
     7    public function __construct()
     8    {
    69        parent::__construct();
    710
     
    2831        $this->restricted_countries = array( 'TH', 'JP', 'SG', 'MY' );
    2932
     33        $this->register_omise_credit_card_scripts();
     34
    3035        add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' );
    3136        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
     
    6772            array(
    6873                'advanced' => array(
    69                     'title'       => __( 'Advance Settings', 'omise' ),
     74                    'title'       => __( 'Advanced Settings', 'omise' ),
    7075                    'type'        => 'title'
    7176                ),
     
    8287                    'desc_tip'    => true
    8388                ),
     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                ],
    84114                'accept_visa' => array(
    85115                    'title'       => __( 'Supported card icons', 'omise' ),
     
    106136                    'css'         => Omise_Card_Image::get_css(),
    107137                    '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()
    108144                ),
    109145                'accept_amex' => array(
     
    118154                )
    119155            )
     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
    120166        );
    121167    }
     
    146192        }
    147193
     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
    148202        Omise_Util::render_view( 'templates/payment/form.php', $viewData );
    149203    }
    150204
    151205    /**
    152      * Get icons of all supported card types
    153      *
    154      * @see WC_Payment_Gateway::get_icon()
     206     * Get card icons for credit card form
    155207     */
    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            }
    169223        }
    170224
    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;
    188226    }
    189227}
  • omise/tags/5.0.0/includes/gateway/class-omise-payment-googlepay.php

    r2832733 r2892466  
    8282            array(
    8383                'advanced' => array(
    84                     'title'       => __('Advance Settings', 'omise'),
     84                    'title'       => __('Advanced Settings', 'omise'),
    8585                    'type'        => 'title'
    8686                ),
  • omise/tags/5.0.0/includes/gateway/class-omise-payment-rabbit-linepay.php

    r2832733 r2892466  
    5959            array(
    6060                'advanced' => array(
    61                     'title'       => __( 'Advance Settings', 'omise' ),
     61                    'title'       => __( 'Advanced Settings', 'omise' ),
    6262                    'type'        => 'title'
    6363                ),
  • omise/tags/5.0.0/includes/gateway/class-omise-payment.php

    r2876857 r2892466  
    605605     * @param string $order_id
    606606     * @param object $order
    607      */
    608     public function getMetadata($order_id, $order)
     607     * @param array $additionalData
     608     */
     609    public function getMetadata($order_id, $order, $additionalData = [])
    609610    {
     611        // override order_id as a reference for webhook handlers.
     612        $orderId = [ 'order_id' => $order_id ];
     613
    610614        return array_merge(
    611615            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)
    613617        );
    614618    }
  • omise/tags/5.0.0/languages/omise-ja.po

    r2832733 r2892466  
    140140
    141141#: includes/gateway/class-omise-payment-creditcard.php:78
    142 msgid "Advance Settings"
     142msgid "Advanced Settings"
    143143msgstr "詳細設定"
    144144
     
    586586msgid "Please select bank below"
    587587msgstr "以下から銀行をお選びください"
     588
     589#: omise-woocommerce.php:66
     590msgid "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>."
     591msgstr "プラグインを最新バージョンにアップデートし、顧客情報の安全な管理に必要な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  
    139139
    140140#: includes/gateway/class-omise-payment-creditcard.php:78
    141 msgid "Advance Settings"
     141msgid "Advanced Settings"
    142142msgstr "詳細設定"
    143143
  • omise/tags/5.0.0/omise-woocommerce.php

    r2876857 r2892466  
    55 * Plugin URI:  https://www.omise.co/woocommerce
    66 * 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.0
     7 * Version:     5.0.0
    88 * Author:      Opn Payments and contributors
    99 * Author URI:  https://github.com/omise/omise-woocommerce/graphs/contributors
     
    2323     * @var string
    2424     */
    25     public $version = '4.29.0';
     25    public $version = '5.0.0';
    2626
    2727    /**
     
    4040     */
    4141    protected static $can_initiate = false;
     42
     43    CONST OMISE_JS_LINK = 'https://cdn.omise.co/omise.js';
    4244
    4345    /**
     
    4951        add_action('woocommerce_init', array($this, 'init'));
    5052        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__);
    5176    }
    5277
     
    189214        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/class-omise-wc-myaccount.php';
    190215        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';
    191218    }
    192219
  • omise/tags/5.0.0/readme.txt

    r2876857 r2892466  
    44Requires at least: 4.3.1
    55Tested up to: 6.0.2
    6 Stable tag: 4.29.0
     6Stable tag: 5.0.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== 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))
    3644
    3745= 4.29.0 =
  • omise/tags/5.0.0/templates/myaccount/my-card.php

    r2783685 r2892466  
    3737    <form name="omise_cc_form" id="omise_cc_form">
    3838        <?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
    4349    </form>
    4450    <button id="omise_add_new_card" class="button"><?php _e( 'Save card', 'omise' ); ?></button>
    4551</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  
    11<fieldset id="omise-form-internetbanking">
    22    <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 
    273        <!-- BAY -->
    284        <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?>
    25
    36<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>
    69        <ul class="omise-customer-card-list">
    7             <?php foreach ( $viewData['existingCards']['data'] as $row => $card ) : ?>
     10            <?php foreach ($viewData['existingCards']['data'] as $row => $card) : ?>
    811                <li class="item">
    912                    <input <?php echo $row === 0 ? 'checked=checked' : ''; ?> id="card-<?php echo $card['id']; ?>" type="radio" name="card_id" value="<?php echo $card['id']; ?>" />
     
    1720
    1821    <div>
    19         <?php if ( $showExistingCards ) : ?>
     22        <?php if($showExistingCards) : ?>
    2023            <input id="new_card_info" type="radio" name="card_id" value="" />
    2124            <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>
    2326            </label>
    2427        <?php endif; ?>
    2528
    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' : ''; ?>">
    2737
    28             <?php require_once( 'form-creditcard.php' ); ?>
     38                <?php require_once('form-creditcard.php'); ?>
    2939
    30             <div class="clear"></div>
     40                <div class="clear"></div>
    3141
    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; ?>
    4050
    41             <div class="clear"></div>
    42         </fieldset>
     51                <div class="clear"></div>
     52            </fieldset>
     53        <?php endif; ?>
    4354    </div>
    4455</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  
    11# 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))
    210
    311### [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  
    3131}
    3232
    33 fieldset.card-exists {
     33fieldset.card-exists,
     34.omise-new-card-form.card-exists {
    3435    display: none;
    3536}
    3637
    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 {
    3840    display: flex;
    3941}
  • 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 </style><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  
    6161        });
    6262
     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() {
    6391        let errors                  = [],
    6492            omise_card              = {},
     
    124152        }
    125153    }
    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);
    136167                }
    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    }
    145188}
    146189)(jQuery);
  • omise/trunk/assets/javascripts/omise-payment-form-handler.js

    r2809311 r2892466  
    1515
    1616        if ($.isArray(message)) {
    17             $.each(message, function(i,v) {
     17            $.each(message, function(i, v) {
    1818                $ulError.append($("<li>" + v + "</li>"));
    1919            })
     
    5959
    6060            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('');
    109111                    });
     112
     113                    $form.append('<input type="hidden" class="omise_token" name="omise_token" value="' + response.id + '"/>');
     114                    $form.submit();
    110115                } 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();
    117122        }
    118123    }
     
    188193    }
    189194
     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
    190246    $(function () {
    191247        $('body').on('checkout_error', function () {
  • omise/trunk/includes/admin/class-omise-page-settings.php

    r2783685 r2892466  
    5757        $settings = $page->get_settings();
    5858       
    59         $available_payment_methods = array();
     59        // This variable is used in the view.
     60        $available_payment_methods = [];
    6061        $capabilities = Omise_Capabilities::retrieve();
    6162
  • omise/trunk/includes/class-omise-admin.php

    r2832733 r2892466  
    22defined( 'ABSPATH' ) or die( "No direct script access allowed." );
    33
    4 if ( ! class_exists( 'Omise_Admin' ) ) {
    5     class Omise_Admin {
     4if (!class_exists('Omise_Admin')) {
     5    class Omise_Admin
     6    {
    67        /**
    78         * The Omise Instance.
     
    1415         * @return \Omise_Admin  The instance.
    1516         */
    16         public static function get_instance() {
    17             if ( ! self::$the_instance ) {
     17        public static function get_instance()
     18        {
     19            if (!self::$the_instance) {
    1820                self::$the_instance = new self();
    1921            }
     
    2527         * @since 3.3
    2628         */
    27         public function init() {
    28             require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-admin-page.php';
     29        public function init()
     30        {
    2931            require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/admin/class-omise-page-settings.php';
    3032
     
    3638         * Register Omise's custom menu to WordPress admin menus.
    3739         */
    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']);
    4044        }
    4145
     
    4448         * Register Omise's custom menu to WordPress admin menus.
    4549         */
    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            );
    4874        }
    4975
     
    5177         * Render Omise Setting page.
    5278         */
    53         public function page_settings() {
     79        public function page_settings()
     80        {
    5481            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();
    5590        }
    5691
     
    5893         * @since 3.3
    5994         */
    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            );
    62101        }
    63102
     
    71110         * @return array
    72111         */
    73         public function woocommerce_filter_order_actions( $order_actions ) {
     112        public function woocommerce_filter_order_actions($order_actions)
     113        {
    74114            global $theorder;
    75115
  • omise/trunk/includes/class-omise-callback.php

    r2876857 r2892466  
    3030    {
    3131        $order_id = isset( $_GET['order_id'] ) ? sanitize_text_field( $_GET['order_id'] ) : null;
    32         $token = isset( $_GET['token'] ) ? sanitize_text_field( $_GET['token'] ) : null;
    3332        $order = wc_get_order( $order_id );
    3433
     
    7473        try {
    7574            $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            }
    7681
    7782            switch ( strtolower( $this->charge['status'] ) ) {
     
    100105
    101106    /**
     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    /**
    102117     * Resolving a case of undefined charge status
    103118     */
     
    191206    protected function payment_failed() {
    192207        $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
    194212
    195213        $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  
    33
    44if ( ! class_exists( 'Omise_MyAccount' ) ) {
    5     class Omise_MyAccount {
     5    class Omise_MyAccount
     6    {
    67        private static $instance;
    78        private $omise_customer_id;
     
    2728
    2829            $this->customerCard = new OmiseCustomerCard;
     30            $this->omiseCardGateway = new Omise_Payment_Creditcard();
    2931
    3032            add_action( 'woocommerce_after_my_account', array( $this, 'init_panel' ) );
     
    4244                try {
    4345                    $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();
    4451
    4552                    Omise_Util::render_view( 'templates/myaccount/my-card.php', $viewData );
    46                     $this->register_omise_my_account_scripts();
    4753                } catch (Exception $e) {
    4854                    // nothing.
     
    5763            wp_enqueue_script(
    5864                'omise-js',
    59                 'https://cdn.omise.co/omise.js',
     65                Omise::OMISE_JS_LINK,
    6066                array( 'jquery' ),
    6167                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,
    6276                true
    6377            );
     
    105119                'number is invalid and brand not supported (unknown)' => __( 'number is invalid and brand not supported (unknown)', 'omise' ),
    106120                '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')
    108123            ];
    109124        }
     
    152167
    153168            try {
    154                 $card = $this->customerCard->create($token, $omiseCustomerId);
     169                $card = $this->customerCard->create($this->omise_customer_id, $token);
    155170                echo json_encode( $card );
    156171            } catch( Exception $e ) {
  • omise/trunk/includes/classes/class-omise-card-image.php

    r2720994 r2892466  
    6363
    6464        /**
     65         * Return the HTML &lt;img&gt; 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        /**
    6583         * Return the default setting of display the JCB logo
    6684         *
     
    128146
    129147            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';
    130158        }
    131159
  • omise/trunk/includes/classes/class-omise-customer-card.php

    r2795404 r2892466  
    3636         * @return string
    3737         */
    38         public function create($customer, $token)
     38        public function create($customerId, $token)
    3939        {
     40            $customer = $this->customer->get($customerId);
    4041            $customer->update( ['card' => $token ]);
    4142
  • omise/trunk/includes/gateway/abstract-omise-payment-base-card.php

    r2876857 r2892466  
    2828
    2929        // 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)) {
    3132            $cardDetails = $this->saveCard($omise_customer_id, $token, $order_id, $user->ID);
    3233            $omise_customer_id = $cardDetails['customer_id'];
     
    5859            ),
    5960            '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            )
    6166        ];
    6267
     
    7681
    7782        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';
    7894    }
    7995
     
    111127
    112128            try {
    113                 $customer->get($omise_customer_id);
    114129                $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);
    116133
    117134                return [
     
    128145                // Saved customer ID is not found so we create a new customer and save the customer ID
    129146                $customer_data = $customer->create($user_id, $order_id, $customer_data);
     147
    130148                return [
    131149                    'customer_id' => $customer_data['customer_id'],
     
    234252            wp_enqueue_script(
    235253                'omise-js',
    236                 'https://cdn.omise.co/omise.js',
     254                Omise::OMISE_JS_LINK,
    237255                [ '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                [],
    238264                OMISE_WOOCOMMERCE_PLUGIN_VERSION,
    239265                true
     
    261287    public function getParamsForJS()
    262288    {
     289        $omiseCardGateway = new Omise_Payment_Creditcard();
     290
    263291        return [
    264292            'key'                            => $this->public_key(),
     
    334362                'expiration month is not between 1 and 12, expiration date is invalid, number is invalid, and brand not supported (unknown)',
    335363                'omise'
    336             )
     364            ),
     365            'secure_form_enabled'   => (boolean)$omiseCardGateway->get_option('secure_form_enabled')
    337366        ];
    338367    }
  • omise/trunk/includes/gateway/class-omise-payment-creditcard.php

    r2832733 r2892466  
    33
    44class Omise_Payment_Creditcard extends Omise_Payment_Base_Card {
    5     public function __construct() {
     5    const SECURE_FORM_ENABLED = true;
     6
     7    public function __construct()
     8    {
    69        parent::__construct();
    710
     
    2831        $this->restricted_countries = array( 'TH', 'JP', 'SG', 'MY' );
    2932
     33        $this->register_omise_credit_card_scripts();
     34
    3035        add_action( 'woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute' );
    3136        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
     
    6772            array(
    6873                'advanced' => array(
    69                     'title'       => __( 'Advance Settings', 'omise' ),
     74                    'title'       => __( 'Advanced Settings', 'omise' ),
    7075                    'type'        => 'title'
    7176                ),
     
    8287                    'desc_tip'    => true
    8388                ),
     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                ],
    84114                'accept_visa' => array(
    85115                    'title'       => __( 'Supported card icons', 'omise' ),
     
    106136                    'css'         => Omise_Card_Image::get_css(),
    107137                    '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()
    108144                ),
    109145                'accept_amex' => array(
     
    118154                )
    119155            )
     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
    120166        );
    121167    }
     
    146192        }
    147193
     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
    148202        Omise_Util::render_view( 'templates/payment/form.php', $viewData );
    149203    }
    150204
    151205    /**
    152      * Get icons of all supported card types
    153      *
    154      * @see WC_Payment_Gateway::get_icon()
     206     * Get card icons for credit card form
    155207     */
    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            }
    169223        }
    170224
    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;
    188226    }
    189227}
  • omise/trunk/includes/gateway/class-omise-payment-googlepay.php

    r2832733 r2892466  
    8282            array(
    8383                'advanced' => array(
    84                     'title'       => __('Advance Settings', 'omise'),
     84                    'title'       => __('Advanced Settings', 'omise'),
    8585                    'type'        => 'title'
    8686                ),
  • omise/trunk/includes/gateway/class-omise-payment-rabbit-linepay.php

    r2832733 r2892466  
    5959            array(
    6060                'advanced' => array(
    61                     'title'       => __( 'Advance Settings', 'omise' ),
     61                    'title'       => __( 'Advanced Settings', 'omise' ),
    6262                    'type'        => 'title'
    6363                ),
  • omise/trunk/includes/gateway/class-omise-payment.php

    r2876857 r2892466  
    605605     * @param string $order_id
    606606     * @param object $order
    607      */
    608     public function getMetadata($order_id, $order)
     607     * @param array $additionalData
     608     */
     609    public function getMetadata($order_id, $order, $additionalData = [])
    609610    {
     611        // override order_id as a reference for webhook handlers.
     612        $orderId = [ 'order_id' => $order_id ];
     613
    610614        return array_merge(
    611615            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)
    613617        );
    614618    }
  • omise/trunk/languages/omise-ja.po

    r2832733 r2892466  
    140140
    141141#: includes/gateway/class-omise-payment-creditcard.php:78
    142 msgid "Advance Settings"
     142msgid "Advanced Settings"
    143143msgstr "詳細設定"
    144144
     
    586586msgid "Please select bank below"
    587587msgstr "以下から銀行をお選びください"
     588
     589#: omise-woocommerce.php:66
     590msgid "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>."
     591msgstr "プラグインを最新バージョンにアップデートし、顧客情報の安全な管理に必要なSecure Formを有効にしてください。アップデート後、クレジットカードの決済フォームを再度カスタマイズする必要があります。<a target='_blank' href='https://www.omise.co/woocommerce-plugin'>Secure Formを有効にする方法はこちらをご確認ください</a>。"
  • omise/trunk/languages/omise.pot

    r2832733 r2892466  
    139139
    140140#: includes/gateway/class-omise-payment-creditcard.php:78
    141 msgid "Advance Settings"
     141msgid "Advanced Settings"
    142142msgstr "詳細設定"
    143143
  • omise/trunk/omise-woocommerce.php

    r2876857 r2892466  
    55 * Plugin URI:  https://www.omise.co/woocommerce
    66 * 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.0
     7 * Version:     5.0.0
    88 * Author:      Opn Payments and contributors
    99 * Author URI:  https://github.com/omise/omise-woocommerce/graphs/contributors
     
    2323     * @var string
    2424     */
    25     public $version = '4.29.0';
     25    public $version = '5.0.0';
    2626
    2727    /**
     
    4040     */
    4141    protected static $can_initiate = false;
     42
     43    CONST OMISE_JS_LINK = 'https://cdn.omise.co/omise.js';
    4244
    4345    /**
     
    4951        add_action('woocommerce_init', array($this, 'init'));
    5052        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__);
    5176    }
    5277
     
    189214        require_once OMISE_WOOCOMMERCE_PLUGIN_PATH . '/includes/class-omise-wc-myaccount.php';
    190215        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';
    191218    }
    192219
  • omise/trunk/readme.txt

    r2876857 r2892466  
    44Requires at least: 4.3.1
    55Tested up to: 6.0.2
    6 Stable tag: 4.29.0
     6Stable tag: 5.0.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    3434
    3535== 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))
    3644
    3745= 4.29.0 =
  • omise/trunk/templates/myaccount/my-card.php

    r2783685 r2892466  
    3737    <form name="omise_cc_form" id="omise_cc_form">
    3838        <?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
    4349    </form>
    4450    <button id="omise_add_new_card" class="button"><?php _e( 'Save card', 'omise' ); ?></button>
    4551</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  
    11<fieldset id="omise-form-internetbanking">
    22    <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 
    273        <!-- BAY -->
    284        <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?>
    25
    36<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>
    69        <ul class="omise-customer-card-list">
    7             <?php foreach ( $viewData['existingCards']['data'] as $row => $card ) : ?>
     10            <?php foreach ($viewData['existingCards']['data'] as $row => $card) : ?>
    811                <li class="item">
    912                    <input <?php echo $row === 0 ? 'checked=checked' : ''; ?> id="card-<?php echo $card['id']; ?>" type="radio" name="card_id" value="<?php echo $card['id']; ?>" />
     
    1720
    1821    <div>
    19         <?php if ( $showExistingCards ) : ?>
     22        <?php if($showExistingCards) : ?>
    2023            <input id="new_card_info" type="radio" name="card_id" value="" />
    2124            <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>
    2326            </label>
    2427        <?php endif; ?>
    2528
    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' : ''; ?>">
    2737
    28             <?php require_once( 'form-creditcard.php' ); ?>
     38                <?php require_once('form-creditcard.php'); ?>
    2939
    30             <div class="clear"></div>
     40                <div class="clear"></div>
    3141
    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; ?>
    4050
    41             <div class="clear"></div>
    42         </fieldset>
     51                <div class="clear"></div>
     52            </fieldset>
     53        <?php endif; ?>
    4354    </div>
    4455</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.