Plugin Directory

Changeset 2980555


Ignore:
Timestamp:
10/18/2023 09:19:27 AM (2 years ago)
Author:
abubacker
Message:

Added a new configuration to toggle surcharge for debit transactions

Location:
valorpos
Files:
28 edited
1 copied

Legend:

Unmodified
Added
Removed
  • valorpos/tags/7.4.0/README.txt

    r2960359 r2980555  
    33Tags: payment, payment gateway, credit card, valor pay, valor paytech
    44Requires at least: 5.0
    5 Tested up to: 6.2.2
     5Tested up to: 6.3.1
    66Requires PHP: 7.0
    7 Stable tag: 7.3.1
     7Stable tag: 7.4.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4141== Changelog ==
    4242
     43= 7.4.0 =
     44* Added a new configuration to toggle surcharge for debit transactions. This configuration determines whether a surcharge should be applied to debit transactions or not.
     45
    4346= 7.3.1 =
    4447* Update plugin title.
  • valorpos/tags/7.4.0/admin/class-wc-valorpay-admin.php

    r2918841 r2980555  
    2222 * @package    Wc_Valorpay
    2323 * @subpackage Wc_Valorpay/admin
    24  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     24 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2525 */
    2626class Wc_Valorpay_Admin {
  • valorpos/tags/7.4.0/includes/class-wc-valorpay-activator.php

    r2883367 r2980555  
    1818 * @package    Wc_Valorpay
    1919 * @subpackage Wc_Valorpay/includes
    20  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     20 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2121 */
    2222class Wc_Valorpay_Activator {
  • valorpos/tags/7.4.0/includes/class-wc-valorpay-api.php

    r2918841 r2980555  
    2121 * @package    Wc_Valorpay
    2222 * @subpackage Wc_Valorpay/includes
    23  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     23 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2424 */
    2525class WC_ValorPay_API {
     
    2727     * Sandbox payment URL
    2828     */
    29     const WC_VALORPAY_SANDBOX_URL = 'https://securelinktest.valorpaytech.com:4430/';
     29    const WC_VALORPAY_SANDBOX_URL = 'https://securelink-staging.valorpaytech.com:4430/';
    3030    /**
    3131     * Live payment URL
     
    3535     * Sandbox OTP refund URL
    3636     */
    37     const WC_VALORPAY_REFUND_OTP_SANDBOX_URL = 'https://2fademo.isoaccess.com/?main_action=Manage2FA&operation=ecommRefund';
     37    const WC_VALORPAY_REFUND_OTP_SANDBOX_URL = 'https://2fa-staging.valorpaytech.com:4430/?main_action=Manage2FA&operation=ecommRefund';
    3838    /**
    3939     * Live OTP refund URL
    4040     */
    4141    const WC_VALORPAY_REFUND_OTP_URL = 'https://2fa.valorpaytech.com/?main_action=Manage2FA&operation=ecommRefund';
     42    /**
     43     * Create page token action
     44     */
     45    const WC_VALORPAY_PAGE_TOKEN_ACTION = 'clientToken';
     46    /**
     47     * Bin lookup action
     48     */
     49    const WC_VALORPAY_BIN_LOOKUP_ACTION = 'binLookup';
    4250
    4351    /**
     
    138146        $payload  = $this->get_payload( $order, $amount, 'send_otp' );
    139147        $response = $this->post_transaction( $payload, 'send_otp' );
     148        return $response;
     149    }
     150
     151    /**
     152     * Create checkout page token
     153     *
     154     * @since 7.4.0
     155     * @return object JSON response
     156     */
     157    public function create_checkout_page_token() {
     158        $payload  = array(
     159            'appid'    => $this->gateway->appid,
     160            'appkey'   => $this->gateway->appkey,
     161            'epi'      => $this->gateway->epi,
     162            'txn_type' => self::WC_VALORPAY_PAGE_TOKEN_ACTION,
     163        );
     164        $response = $this->post_transaction( wp_json_encode( $payload ) );
     165        return $response;
     166    }
     167
     168    /**
     169     * Get bin details
     170     *
     171     * @since 7.4.0
     172     *
     173     * @param string $bin_number Bin Number.
     174     * @param string $client_token Client Token.
     175     * @return object JSON response
     176     */
     177    public function bin_lookup( $bin_number, $client_token ) {
     178        $payload  = array(
     179            'client_token' => $client_token,
     180            'bin'          => $bin_number,
     181            'epi'          => $this->gateway->epi,
     182            'txn_type'     => self::WC_VALORPAY_BIN_LOOKUP_ACTION,
     183        );
     184        $response = $this->post_transaction( wp_json_encode( $payload ), 'bin_lookup' );
    140185        return $response;
    141186    }
     
    156201        $data         = array();
    157202        if ( 'sale' === $transaction_type ) {
    158             $surcharge_indicator = 0;
     203            $surcharge_indicator = ( 'yes' === $this->gateway->surcharge_indicator ) ? 1 : 0;
    159204            $custom_fee          = 0;
    160             if ( 'yes' === $this->gateway->surcharge_indicator && 0 < count( $order->get_fees() ) ) {
    161                 $surcharge_indicator = 1;
    162                 if ( 'sale' === $transaction_type ) {
     205            if ( 1 === $surcharge_indicator && 0 < count( $order->get_fees() ) ) {
     206                $cal_for_debit = ( 'D' === WC()->session->get( 'valor_card_type' ) ) && 'no' !== $this->gateway->surcharge_for_debit;
     207                if ( $cal_for_debit || ( 'D' !== WC()->session->get( 'valor_card_type' ) ) ) {
    163208                    foreach ( $order->get_fees() as $item_fee ) {
    164209                        if ( $item_fee->get_name() === $this->gateway->surcharge_label ) {
     
    170215                }
    171216            }
     217            $surcharge_data = array(
     218                'surchargeIndicator' => $surcharge_indicator,
     219                'surchargeAmount'    => $custom_fee,
     220            );
     221
    172222            $billing_first_name = wc_clean( $order->get_billing_first_name() );
    173223            $billing_last_name  = wc_clean( $order->get_billing_last_name() );
     
    189239            $valorpay_avs_zip    = ( isset( $_POST['valorpay_avs_zip'] ) && $_POST['valorpay_avs_zip'] ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) : wc_clean( substr( $billing_postcode, 0, 10 ) ); // phpcs:ignore
    190240            $valorpay_avs_street = ( isset( $_POST['valorpay_avs_street'] ) && $_POST['valorpay_avs_street'] ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) : wc_clean( $billing_address ); // phpcs:ignore
    191             $valorpay_terms = ( isset( $_POST['valorpay_terms'] ) && $_POST['valorpay_terms'] ) ? 1 : 0; // phpcs:ignore
     241            $valorpay_terms      = ( isset( $_POST['valorpay_terms'] ) && $_POST['valorpay_terms'] ) ? 1 : 0; // phpcs:ignore
    192242
    193243            $card_number = str_replace( ' ', '', ( isset( $_POST['wc_valorpay-card-number'] ) ) ? sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) : '' ); // phpcs:ignore
    194244            $data        = array(
    195                 'appid'              => $this->gateway->appid,
    196                 'appkey'             => $this->gateway->appkey,
    197                 'epi'                => $this->gateway->epi,
    198                 'txn_type'           => $this->gateway->payment_action,
    199                 'amount'             => wc_clean( $amount ),
    200                 'phone'              => $billing_phone,
    201                 'email'              => $billing_email,
    202                 'uid'                => $order_number,
    203                 'tax_amount'         => number_format( $tax_amount, '2', '.', '' ),
    204                 'ip'                 => $ip_address,
    205                 'surchargeIndicator' => $surcharge_indicator,
    206                 'surchargeAmount'    => $custom_fee,
    207                 'address1'           => $valorpay_avs_street,
    208                 'address2'           => wc_clean( $billing_address2 ),
    209                 'city'               => wc_clean( substr( $billing_city, 0, 40 ) ),
    210                 'state'              => wc_clean( substr( $billing_state, 0, 40 ) ),
    211                 'zip'                => $valorpay_avs_zip,
    212                 'billing_country'    => wc_clean( substr( $billing_country, 0, 60 ) ),
    213                 'shipping_country'   => wc_clean( substr( $shipping_country, 0, 60 ) ),
    214                 'status'             => 'Y',
    215                 'terms_checked'      => $valorpay_terms,
    216             );
     245                'appid'            => $this->gateway->appid,
     246                'appkey'           => $this->gateway->appkey,
     247                'epi'              => $this->gateway->epi,
     248                'txn_type'         => $this->gateway->payment_action,
     249                'amount'           => wc_clean( $amount ),
     250                'phone'            => $billing_phone,
     251                'email'            => $billing_email,
     252                'uid'              => $order_number,
     253                'tax_amount'       => number_format( $tax_amount, '2', '.', '' ),
     254                'ip'               => $ip_address,
     255                'address1'         => $valorpay_avs_street,
     256                'address2'         => wc_clean( $billing_address2 ),
     257                'city'             => wc_clean( substr( $billing_city, 0, 40 ) ),
     258                'state'            => wc_clean( substr( $billing_state, 0, 40 ) ),
     259                'zip'              => $valorpay_avs_zip,
     260                'billing_country'  => wc_clean( substr( $billing_country, 0, 60 ) ),
     261                'shipping_country' => wc_clean( substr( $shipping_country, 0, 60 ) ),
     262                'status'           => 'Y',
     263                'terms_checked'    => $valorpay_terms,
     264            ) + $surcharge_data;
    217265
    218266            if ( $card ) {
     
    287335        $response = wp_remote_post( $api_url, $args );
    288336        if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
    289             return new WP_Error( 'valorpos_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
     337            return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
    290338        }
    291339        $parsed_response = json_decode( preg_replace( '/\xEF\xBB\xBF/', '', $response['body'] ) );
    292340        if ( 'send_otp' === $transaction_type ) {
    293341            if ( ! isset( $parsed_response->error_code ) ) {
    294                 return new WP_Error( 'valorpos_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
     342                return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
    295343            }
    296344            if ( 'S00' !== $parsed_response->error_code ) {
    297345                $error_msg = sprintf( '%s', $parsed_response->error_desc );
    298                 return new WP_Error( 'valorpos_error', $error_msg );
     346                return new WP_Error( 'valorpay_error', $error_msg );
     347            }
     348        } elseif ( 'bin_lookup' === $transaction_type ) {
     349            if ( ! isset( $parsed_response->card_type ) ) {
     350                return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
    299351            }
    300352        } else {
    301353            if ( ! isset( $parsed_response->error_no ) ) {
    302                 return new WP_Error( 'valorpos_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
     354                return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
    303355            }
    304356            if ( 'S00' !== $parsed_response->error_no ) {
    305357                $error_msg = sprintf( '%s ( %s )', $parsed_response->mesg, $parsed_response->desc );
    306                 return new WP_Error( 'valorpos_error', $error_msg );
     358                return new WP_Error( 'valorpay_error', $error_msg );
    307359            }
    308360        }
  • valorpos/tags/7.4.0/includes/class-wc-valorpay-deactivator.php

    r2883367 r2980555  
    2222 * @package    Wc_Valorpay
    2323 * @subpackage Wc_Valorpay/includes
    24  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     24 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2525 */
    2626class Wc_Valorpay_Deactivator {
  • valorpos/tags/7.4.0/includes/class-wc-valorpay-gateway-loader.php

    r2883367 r2980555  
    2222 * @package    Wc_Valorpay
    2323 * @subpackage Wc_Valorpay/includes
    24  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     24 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2525 */
    2626class Wc_Valorpay_Gateway_Loader {
  • valorpos/tags/7.4.0/includes/class-wc-valorpay-gateway.php

    r2960359 r2980555  
    1919 * @package    Wc_Valorpay
    2020 * @subpackage Wc_Valorpay/includes
    21  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     21 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2222 * @uses WC_Payment_Gateway_CC
    2323 */
     
    9797     */
    9898    public $surcharge_flat_rate;
     99
     100    /**
     101     * Valor Pay surcharge for debit.
     102     *
     103     * @var string
     104     */
     105    public $surcharge_for_debit;
    99106
    100107    /**
     
    166173        $this->surcharge_percentage          = $this->get_option( 'surcharge_percentage' );
    167174        $this->surcharge_flat_rate           = $this->get_option( 'surcharge_flat_rate' );
     175        $this->surcharge_for_debit           = $this->get_option( 'surcharge_for_debit' );
    168176        $this->cardtypes                     = $this->get_option( 'cardtypes' );
    169177        $this->avs_type                      = $this->get_option( 'avs_type' );
     
    322330    public function validate_fields() {
    323331        try {
     332            $valorpay_avs_type = ( isset( $_POST['valorpay_avs_type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_type'] ) ) : ''; // phpcs:ignore
     333            if ( 'zip' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) {
     334                if ( ! isset( $_POST['valorpay_avs_zip'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) { // phpcs:ignore
     335                    throw new Exception( __( 'Zip Code is required.', 'wc-valorpay' ) );
     336                }
     337                if ( isset( $_POST['valorpay_avs_zip'] ) && sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) && ! preg_match( '/^([a-zA-Z0-9_-]){4,6}$/', sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) ) { // phpcs:ignore
     338                    throw new Exception( __( 'Enter a valid Zip Code.', 'wc-valorpay' ) );
     339                }
     340            }
     341            if ( 'address' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) {
     342                if ( ! isset( $_POST['valorpay_avs_street'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) { // phpcs:ignore
     343                    throw new Exception( __( 'Street No is required.', 'wc-valorpay' ) );
     344                }
     345                if ( isset( $_POST['valorpay_avs_street'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) > 25 ) { // phpcs:ignore
     346                    throw new Exception( __( 'Enter a valid Street No.', 'wc-valorpay' ) );
     347                }
     348            }
    324349            if ( isset( $_POST['wc-wc_valorpay-payment-token'] ) && 'new' !== wc_clean( $_POST['wc-wc_valorpay-payment-token'] ) ) { // phpcs:ignore
    325350                return true;
     
    526551                'default'     => 0,
    527552                'description' => __( 'Flat rate  will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $', 'wc-valorpay' ),
     553            ),
     554            'surcharge_for_debit'           => array(
     555                'title'       => __( 'Surcharge For Debit', 'wc-valorpay' ),
     556                'label'       => __( 'Enable Surcharge For Debit', 'wc-valorpay' ),
     557                'type'        => 'checkbox',
     558                'description' => __( 'Enable surcharge for debit', 'wc-valorpay' ),
     559                'default'     => 'yes',
    528560            ),
    529561            'avs_type'                      => array(
     
    704736                    $exp_date            = $exp_month . substr( $exp_year, -2 );
    705737                    $response->card_type = $valorpay_api->get_card_type( str_replace( ' ', '', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) ) ); // phpcs:ignore
    706                     $this->save_card( $response, $exp_date );
     738                    $this->save_card( $response, $exp_date, ( 'D' === WC()->session->get( 'valor_card_type' ) ) ? 1 : 0 );
    707739                }
    708740
     
    722754                );
    723755            } else {
    724                 if ( isset( $response->errors['valorpos_error'][0] ) ) {
     756                if ( isset( $response->errors['valorpay_error'][0] ) ) {
    725757                    /* translators: %s: API Error Message. */
    726                     $order->add_order_note( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpos_error'][0] ) );
     758                    $order->add_order_note( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpay_error'][0] ) );
    727759                    $this->add_failed_count_by_ip( $order );
    728760                    /* translators: %s: API Error Message. */
    729                     throw new Exception( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpos_error'][0] ) );
     761                    throw new Exception( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpay_error'][0] ) );
    730762                }
    731763                throw new Exception( __( 'Unable to process the transaction using Valor Pay, please try again.', 'wc-valorpay' ) );
     
    744776     * Save card.
    745777     *
    746      * @param Object $response Response.
     778     * @param object $response Response.
    747779     * @param string $exp_date Expiry Date.
     780     * @param int    $is_debit Is Debit Card.
    748781     * @return void
    749782     */
    750     protected function save_card( $response, $exp_date ) {
     783    protected function save_card( $response, $exp_date, $is_debit ) {
    751784        if ( $response->token ) {
    752785            $token = new WC_Payment_Token_CC();
     
    758791            $token->set_expiry_year( '20' . substr( $exp_date, -2 ) );
    759792            $token->set_user_id( get_current_user_id() );
     793            $token->add_meta_data( 'is_debit', $is_debit );
    760794            $token->save();
    761795        }
  • valorpos/tags/7.4.0/includes/class-wc-valorpay-i18n.php

    r2883367 r2980555  
    2626 * @package    Wc_Valorpay
    2727 * @subpackage Wc_Valorpay/includes
    28  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     28 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2929 */
    3030class Wc_Valorpay_I18n {
  • valorpos/tags/7.4.0/includes/class-wc-valorpay-loader.php

    r2883367 r2980555  
    2323 * @package    Wc_Valorpay
    2424 * @subpackage Wc_Valorpay/includes
    25  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     25 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2626 */
    2727class Wc_Valorpay_Loader {
  • valorpos/tags/7.4.0/includes/class-wc-valorpay.php

    r2918841 r2980555  
    2525 * @package    Wc_Valorpay
    2626 * @subpackage Wc_Valorpay/includes
    27  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     27 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2828 */
    2929class Wc_Valorpay {
     
    197197
    198198        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts_and_styles' );
    199         $this->loader->add_action( 'woocommerce_after_checkout_validation', $plugin_public, 'valorpay_avs_checkout_validation', 10, 2 );
    200199        $this->loader->add_action( 'woocommerce_cart_calculate_fees', $plugin_public, 'valorpay_custom_surcharge' );
    201200        $this->loader->add_action( 'woocommerce_before_checkout_form', $plugin_public, 'valorpay_before_checkout_form' );
    202         $this->loader->add_action( 'woocommerce_after_checkout_form', $plugin_public, 'valorpay_checkout_script' );
     201        $this->loader->add_action( 'woocommerce_review_order_before_payment', $plugin_public, 'valorpay_update_token_card_type' );
    203202        $this->loader->add_filter( 'woocommerce_available_payment_gateways', $plugin_public, 'valorpay_disable_payment_gateway_failed_orders' );
     203        $this->loader->add_action( 'wc_ajax_valorpay_create_page_token', $plugin_public, 'valorpay_create_page_token' );
     204        $this->loader->add_action( 'wc_ajax_valorpay_bin_lookup', $plugin_public, 'valorpay_bin_lookup' );
     205        $this->loader->add_action( 'wc_ajax_valorpay_token_card_type', $plugin_public, 'valorpay_token_card_type' );
    204206
    205207    }
  • valorpos/tags/7.4.0/languages/wc-valorpay.pot

    r2960359 r2980555  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Valor Pay 7.3.0\n"
    6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-valorpay\n"
     5"Project-Id-Version: Valor Pay 7.4.0\n"
     6"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/valorpos\n"
    77"Last-Translator: Valor Paytech LLC <sales@valorpaytech.com>\n"
    88"MIME-Version: 1.0\n"
    99"Content-Type: text/plain; charset=UTF-8\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "POT-Creation-Date: 2023-05-19T15:31:04+05:30\n"
    12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     11"POT-Creation-Date: 2023-10-18T08:57:12+00:00\n"
     12"PO-Revision-Date: 2023-10-18T08:57:12+00:00\n"
    1313"X-Generator: WP-CLI 2.7.1\n"
    1414"X-Domain: wc-valorpay\n"
    1515
    1616#. Plugin Name of the plugin
    17 #: includes/class-wc-valorpay-gateway.php:455
     17#: includes/class-wc-valorpay-gateway.php:480
    1818msgid "Valor Pay"
    1919msgstr ""
     
    6969
    7070#: admin/partials/wc-valorpay-admin-failure-tracker.php:18
    71 #: includes/class-wc-valorpay-gateway.php:543
     71#: includes/class-wc-valorpay-gateway.php:575
    7272msgid "Payment Failed Tracker"
    7373msgstr ""
     
    122122msgstr ""
    123123
    124 #: includes/class-wc-valorpay-api.php:289
    125 #: includes/class-wc-valorpay-api.php:294
    126 #: includes/class-wc-valorpay-api.php:302
     124#: includes/class-wc-valorpay-api.php:337
     125#: includes/class-wc-valorpay-api.php:342
     126#: includes/class-wc-valorpay-api.php:350
     127#: includes/class-wc-valorpay-api.php:354
    127128msgid "There was a problem connecting to the payment gateway."
    128129msgstr ""
    129130
    130 #: includes/class-wc-valorpay-gateway.php:143
     131#: includes/class-wc-valorpay-gateway.php:150
    131132msgid "ValorPay Plugin"
    132133msgstr ""
    133134
    134 #: includes/class-wc-valorpay-gateway.php:144
     135#: includes/class-wc-valorpay-gateway.php:151
    135136msgid "Take payments via Valorpay."
    136137msgstr ""
    137138
    138 #: includes/class-wc-valorpay-gateway.php:176
     139#: includes/class-wc-valorpay-gateway.php:184
    139140msgid "TEST MODE ENABLED. Use test card number 4111111111111111 with 999 as CVC and a future expiration date."
    140141msgstr ""
    141142
    142 #: includes/class-wc-valorpay-gateway.php:200
     143#: includes/class-wc-valorpay-gateway.php:208
    143144msgid "Unsupported currency:"
    144145msgstr ""
    145146
    146 #: includes/class-wc-valorpay-gateway.php:203
     147#: includes/class-wc-valorpay-gateway.php:211
    147148msgid "Valor Pay accepts only USD."
    148149msgstr ""
    149150
    150151#. translators: %s: Settings URL.
    151 #: includes/class-wc-valorpay-gateway.php:215
     152#: includes/class-wc-valorpay-gateway.php:223
    152153msgid "Valor Pay error: The APP ID is required.  %s"
    153154msgstr ""
    154155
    155 #: includes/class-wc-valorpay-gateway.php:216
    156 #: includes/class-wc-valorpay-gateway.php:227
    157 #: includes/class-wc-valorpay-gateway.php:236
     156#: includes/class-wc-valorpay-gateway.php:224
     157#: includes/class-wc-valorpay-gateway.php:235
     158#: includes/class-wc-valorpay-gateway.php:244
    158159msgid "Click here to update your Valor Pay settings."
    159160msgstr ""
    160161
    161162#. translators: %s: Settings URL.
    162 #: includes/class-wc-valorpay-gateway.php:226
     163#: includes/class-wc-valorpay-gateway.php:234
    163164msgid "Valor Pay error: The APP KEY is required.  %s"
    164165msgstr ""
    165166
    166167#. translators: %s: Settings URL.
    167 #: includes/class-wc-valorpay-gateway.php:235
     168#: includes/class-wc-valorpay-gateway.php:243
    168169msgid "Valor Pay error: The EPI is required.  %s"
    169170msgstr ""
    170171
    171 #: includes/class-wc-valorpay-gateway.php:332
     172#: includes/class-wc-valorpay-gateway.php:335
     173msgid "Zip Code is required."
     174msgstr ""
     175
     176#: includes/class-wc-valorpay-gateway.php:338
     177msgid "Enter a valid Zip Code."
     178msgstr ""
     179
     180#: includes/class-wc-valorpay-gateway.php:343
     181msgid "Street No is required."
     182msgstr ""
     183
     184#: includes/class-wc-valorpay-gateway.php:346
     185msgid "Enter a valid Street No."
     186msgstr ""
     187
     188#: includes/class-wc-valorpay-gateway.php:357
    172189msgid "Card number is invalid"
    173190msgstr ""
    174191
    175 #: includes/class-wc-valorpay-gateway.php:336
     192#: includes/class-wc-valorpay-gateway.php:361
    176193msgid "Not a valid card"
    177194msgstr ""
    178195
    179 #: includes/class-wc-valorpay-gateway.php:339
     196#: includes/class-wc-valorpay-gateway.php:364
    180197msgid "Card number  expired"
    181198msgstr ""
    182199
    183 #: includes/class-wc-valorpay-gateway.php:342
     200#: includes/class-wc-valorpay-gateway.php:367
    184201msgid "Card security code is invalid (only digits are allowed)"
    185202msgstr ""
    186203
    187204#. translators: 1: Terms and Conditions URL.
    188 #: includes/class-wc-valorpay-gateway.php:378
     205#: includes/class-wc-valorpay-gateway.php:403
    189206msgid "I agree to the <a href=\"%s\" target=\"_blank\">Terms and Conditions</a>"
    190207msgstr ""
    191208
    192 #: includes/class-wc-valorpay-gateway.php:409
    193 #: includes/class-wc-valorpay-gateway.php:410
     209#: includes/class-wc-valorpay-gateway.php:434
     210#: includes/class-wc-valorpay-gateway.php:435
    194211msgid "Zip Code"
    195212msgstr ""
    196213
    197 #: includes/class-wc-valorpay-gateway.php:423
    198 #: includes/class-wc-valorpay-gateway.php:424
     214#: includes/class-wc-valorpay-gateway.php:448
     215#: includes/class-wc-valorpay-gateway.php:449
    199216msgid "Street No"
    200217msgstr ""
    201218
    202 #: includes/class-wc-valorpay-gateway.php:445
     219#: includes/class-wc-valorpay-gateway.php:470
    203220msgid "Enable/Disable"
    204221msgstr ""
    205222
    206 #: includes/class-wc-valorpay-gateway.php:446
     223#: includes/class-wc-valorpay-gateway.php:471
    207224msgid "Enable Valor Pay"
    208225msgstr ""
    209226
    210 #: includes/class-wc-valorpay-gateway.php:452
     227#: includes/class-wc-valorpay-gateway.php:477
    211228msgid "Title"
    212229msgstr ""
    213230
    214 #: includes/class-wc-valorpay-gateway.php:454
     231#: includes/class-wc-valorpay-gateway.php:479
    215232msgid "This controls the title which the user sees during checkout."
    216233msgstr ""
    217234
    218 #: includes/class-wc-valorpay-gateway.php:459
     235#: includes/class-wc-valorpay-gateway.php:484
    219236msgid "Use Sandbox"
    220237msgstr ""
    221238
    222 #: includes/class-wc-valorpay-gateway.php:460
     239#: includes/class-wc-valorpay-gateway.php:485
    223240msgid "Enable sandbox mode - live payments will not be taken if enabled."
    224241msgstr ""
    225242
    226 #: includes/class-wc-valorpay-gateway.php:466
     243#: includes/class-wc-valorpay-gateway.php:491
    227244msgid "APP ID"
    228245msgstr ""
    229246
    230 #: includes/class-wc-valorpay-gateway.php:468
     247#: includes/class-wc-valorpay-gateway.php:493
    231248msgid "Please email support@valorpaytech.com to get to know about your APP ID, ( In demo mode APP ID is not needed )"
    232249msgstr ""
    233250
    234 #: includes/class-wc-valorpay-gateway.php:472
     251#: includes/class-wc-valorpay-gateway.php:497
    235252msgid "APP KEY"
    236253msgstr ""
    237254
    238 #: includes/class-wc-valorpay-gateway.php:474
     255#: includes/class-wc-valorpay-gateway.php:499
    239256msgid "Please email support@valorpaytech.com to get to know about your APP KEY, ( In demo mode APP KEY is not needed )"
    240257msgstr ""
    241258
    242 #: includes/class-wc-valorpay-gateway.php:478
     259#: includes/class-wc-valorpay-gateway.php:503
    243260msgid "EPI"
    244261msgstr ""
    245262
    246 #: includes/class-wc-valorpay-gateway.php:480
     263#: includes/class-wc-valorpay-gateway.php:505
    247264msgid "Please email support@valorpaytech.com to get to know about your EPI ID, ( In demo mode EPI ID is not needed )"
    248265msgstr ""
    249266
    250 #: includes/class-wc-valorpay-gateway.php:484
     267#: includes/class-wc-valorpay-gateway.php:509
    251268msgid "Payment Method"
    252269msgstr ""
    253270
    254 #: includes/class-wc-valorpay-gateway.php:494
     271#: includes/class-wc-valorpay-gateway.php:519
    255272msgid "Surcharge Mode"
    256273msgstr ""
    257274
    258 #: includes/class-wc-valorpay-gateway.php:495
    259 #: includes/class-wc-valorpay-gateway.php:502
     275#: includes/class-wc-valorpay-gateway.php:520
     276#: includes/class-wc-valorpay-gateway.php:527
    260277msgid "Enable Surcharge Mode"
    261278msgstr ""
    262279
    263 #: includes/class-wc-valorpay-gateway.php:497
     280#: includes/class-wc-valorpay-gateway.php:522
    264281msgid "Enable only if you want all transactions to be fall on surcharge mode, Merchant must have got an Surcharge MID inorder to work"
    265282msgstr ""
    266283
    267 #: includes/class-wc-valorpay-gateway.php:501
     284#: includes/class-wc-valorpay-gateway.php:526
    268285msgid "Surcharge Type"
    269286msgstr ""
    270287
    271 #: includes/class-wc-valorpay-gateway.php:511
    272 #: includes/class-wc-valorpay-gateway.php:512
     288#: includes/class-wc-valorpay-gateway.php:536
     289#: includes/class-wc-valorpay-gateway.php:537
    273290msgid "Surcharge Label"
    274291msgstr ""
    275292
    276 #: includes/class-wc-valorpay-gateway.php:517
     293#: includes/class-wc-valorpay-gateway.php:542
    277294msgid "Surcharge %"
    278295msgstr ""
    279296
    280 #: includes/class-wc-valorpay-gateway.php:521
     297#: includes/class-wc-valorpay-gateway.php:546
    281298msgid "Percentage will apply only on enabling on surcharge Indicator to true and Surcharge type is set fo Surcharge %"
    282299msgstr ""
    283300
    284 #: includes/class-wc-valorpay-gateway.php:524
     301#: includes/class-wc-valorpay-gateway.php:549
    285302msgid "Flat Rate $"
    286303msgstr ""
    287304
    288 #: includes/class-wc-valorpay-gateway.php:527
     305#: includes/class-wc-valorpay-gateway.php:552
    289306msgid "Flat rate  will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $"
    290307msgstr ""
    291308
    292 #: includes/class-wc-valorpay-gateway.php:530
     309#: includes/class-wc-valorpay-gateway.php:555
     310msgid "Surcharge For Debit"
     311msgstr ""
     312
     313#: includes/class-wc-valorpay-gateway.php:556
     314msgid "Enable Surcharge For Debit"
     315msgstr ""
     316
     317#: includes/class-wc-valorpay-gateway.php:558
     318msgid "Enable surcharge for debit"
     319msgstr ""
     320
     321#: includes/class-wc-valorpay-gateway.php:562
    293322msgid "AVS"
    294323msgstr ""
    295324
    296 #: includes/class-wc-valorpay-gateway.php:540
     325#: includes/class-wc-valorpay-gateway.php:572
    297326msgid "The address verification service will add a text field to the checkout page based on the above option."
    298327msgstr ""
    299328
    300 #: includes/class-wc-valorpay-gateway.php:544
     329#: includes/class-wc-valorpay-gateway.php:576
    301330msgid "Enable Protection"
    302331msgstr ""
    303332
    304333#. translators: 1: Tracker URL.
    305 #: includes/class-wc-valorpay-gateway.php:548
     334#: includes/class-wc-valorpay-gateway.php:580
    306335msgid "Disable the payment method in the checkout page for failed transactions. <a id=\"valorpay-goto-tracker\" href=\"%s\">Unblock IP</a>"
    307336msgstr ""
    308337
    309 #: includes/class-wc-valorpay-gateway.php:554
     338#: includes/class-wc-valorpay-gateway.php:586
    310339msgid "Declined Transaction Count"
    311340msgstr ""
    312341
    313 #: includes/class-wc-valorpay-gateway.php:555
     342#: includes/class-wc-valorpay-gateway.php:587
    314343msgid "Number of declined transaction count."
    315344msgstr ""
    316345
    317 #: includes/class-wc-valorpay-gateway.php:559
     346#: includes/class-wc-valorpay-gateway.php:591
    318347msgid "3"
    319348msgstr ""
    320349
    321 #: includes/class-wc-valorpay-gateway.php:560
     350#: includes/class-wc-valorpay-gateway.php:592
    322351msgid "5"
    323352msgstr ""
    324353
    325 #: includes/class-wc-valorpay-gateway.php:561
     354#: includes/class-wc-valorpay-gateway.php:593
    326355msgid "6"
    327356msgstr ""
    328357
    329 #: includes/class-wc-valorpay-gateway.php:565
     358#: includes/class-wc-valorpay-gateway.php:597
    330359msgid "Block Payment For"
    331360msgstr ""
    332361
    333 #: includes/class-wc-valorpay-gateway.php:566
     362#: includes/class-wc-valorpay-gateway.php:598
    334363msgid "Minutes to block payment gateway in checkout."
    335364msgstr ""
    336365
    337 #: includes/class-wc-valorpay-gateway.php:570
     366#: includes/class-wc-valorpay-gateway.php:602
    338367msgid "1 min"
    339368msgstr ""
    340369
    341 #: includes/class-wc-valorpay-gateway.php:571
     370#: includes/class-wc-valorpay-gateway.php:603
    342371msgid "5 min"
    343372msgstr ""
    344373
    345 #: includes/class-wc-valorpay-gateway.php:572
     374#: includes/class-wc-valorpay-gateway.php:604
    346375msgid "10 min"
    347376msgstr ""
    348377
    349 #: includes/class-wc-valorpay-gateway.php:573
     378#: includes/class-wc-valorpay-gateway.php:605
    350379msgid "1 hour"
    351380msgstr ""
    352381
    353 #: includes/class-wc-valorpay-gateway.php:574
     382#: includes/class-wc-valorpay-gateway.php:606
    354383msgid "3 hour"
    355384msgstr ""
    356385
    357 #: includes/class-wc-valorpay-gateway.php:575
     386#: includes/class-wc-valorpay-gateway.php:607
    358387msgid "5 hour"
    359388msgstr ""
    360389
    361 #: includes/class-wc-valorpay-gateway.php:576
     390#: includes/class-wc-valorpay-gateway.php:608
    362391msgid "10 hour"
    363392msgstr ""
    364393
    365 #: includes/class-wc-valorpay-gateway.php:577
     394#: includes/class-wc-valorpay-gateway.php:609
    366395msgid "1 day"
    367396msgstr ""
    368397
    369 #: includes/class-wc-valorpay-gateway.php:581
     398#: includes/class-wc-valorpay-gateway.php:613
    370399msgid "Accepted Cards"
    371400msgstr ""
    372401
    373 #: includes/class-wc-valorpay-gateway.php:585
     402#: includes/class-wc-valorpay-gateway.php:617
    374403msgid "Select the card types to accept."
    375404msgstr ""
    376405
    377406#. translators: 1: Maximum percentage.
    378 #: includes/class-wc-valorpay-gateway.php:624
     407#: includes/class-wc-valorpay-gateway.php:656
    379408msgid "Surcharge percentage cannot be more than %s"
    380409msgstr ""
    381410
    382411#. translators: 1: Maximum flat rate.
    383 #: includes/class-wc-valorpay-gateway.php:629
     412#: includes/class-wc-valorpay-gateway.php:661
    384413msgid "Surcharge flat rate cannot be more than %s"
    385414msgstr ""
    386415
    387 #: includes/class-wc-valorpay-gateway.php:674
     416#: includes/class-wc-valorpay-gateway.php:706
    388417msgid "Invalid card information."
    389418msgstr ""
    390419
    391420#. translators: 1: Error Message, 2: Amount, 3: Line Break, 4: Approval Code, 5: Line Break, 6: RRN Number.
    392 #: includes/class-wc-valorpay-gateway.php:690
     421#: includes/class-wc-valorpay-gateway.php:722
    393422msgid "Valor Pay %1$s for %2$s.%3$s <strong>Approval Code:</strong> %4$s.%5$s <strong>RRN:</strong> %6$s"
    394423msgstr ""
    395424
    396425#. translators: %s: API Error Message.
    397 #: includes/class-wc-valorpay-gateway.php:726
    398 #: includes/class-wc-valorpay-gateway.php:729
     426#: includes/class-wc-valorpay-gateway.php:758
     427#: includes/class-wc-valorpay-gateway.php:761
    399428msgid "Payment error: %s"
    400429msgstr ""
    401430
    402 #: includes/class-wc-valorpay-gateway.php:731
     431#: includes/class-wc-valorpay-gateway.php:763
    403432msgid "Unable to process the transaction using Valor Pay, please try again."
    404433msgstr ""
    405434
    406435#. translators: 1: Disable Time, 2: Unblock IP URL, 3: Customer IP.
    407 #: includes/class-wc-valorpay-gateway.php:790
     436#: includes/class-wc-valorpay-gateway.php:824
    408437msgid "Valor Pay method is disabled for %1$s. <a target=\"_blank\" href=\"%2$s\">To Unblock IP</a> %3$s"
    409438msgstr ""
    410439
    411 #: includes/class-wc-valorpay-gateway.php:853
     440#: includes/class-wc-valorpay-gateway.php:887
    412441msgid "Refund failed."
    413442msgstr ""
    414443
    415444#. translators: 1: Amount, 2: Line Break, 3: Approval code, 4: Line Break, 5: RRN Code
    416 #: includes/class-wc-valorpay-gateway.php:865
     445#: includes/class-wc-valorpay-gateway.php:899
    417446msgid "Valor Pay Refund for %1$s.%2$s <strong>Approval Code:</strong> %3$s.%4$s <strong>RRN:</strong> %5$s"
    418447msgstr ""
    419448
    420 #: public/class-wc-valorpay-public.php:80
     449#: public/class-wc-valorpay-public.php:88
    421450msgid "Please enter a card number"
    422451msgstr ""
    423452
    424 #: public/class-wc-valorpay-public.php:81
     453#: public/class-wc-valorpay-public.php:89
    425454msgid "Invalid card number"
    426455msgstr ""
    427456
    428 #: public/class-wc-valorpay-public.php:82
     457#: public/class-wc-valorpay-public.php:90
    429458msgid "Card is expired"
    430459msgstr ""
    431460
    432 #: public/class-wc-valorpay-public.php:83
     461#: public/class-wc-valorpay-public.php:91
    433462msgid "Please enter card expiry date"
    434463msgstr ""
    435464
    436 #: public/class-wc-valorpay-public.php:84
     465#: public/class-wc-valorpay-public.php:92
    437466msgid "Please enter a CVC"
    438467msgstr ""
    439468
    440 #: public/class-wc-valorpay-public.php:85
     469#: public/class-wc-valorpay-public.php:93
    441470msgid "Invalid CVC length"
    442471msgstr ""
    443472
    444 #: public/class-wc-valorpay-public.php:86
     473#: public/class-wc-valorpay-public.php:94
    445474msgid "Please enter a zip code"
    446475msgstr ""
    447476
    448 #: public/class-wc-valorpay-public.php:87
     477#: public/class-wc-valorpay-public.php:95
    449478msgid "Invalid zip code"
    450479msgstr ""
    451480
    452 #: public/class-wc-valorpay-public.php:88
     481#: public/class-wc-valorpay-public.php:96
    453482msgid "Please enter a street address"
    454483msgstr ""
    455484
    456 #: public/class-wc-valorpay-public.php:108
    457 msgid "Zip Code is required."
    458 msgstr ""
    459 
    460 #: public/class-wc-valorpay-public.php:111
    461 msgid "Enter a valid Zip Code."
    462 msgstr ""
    463 
    464 #: public/class-wc-valorpay-public.php:116
    465 msgid "Street No is required."
    466 msgstr ""
    467 
    468 #: public/class-wc-valorpay-public.php:119
    469 msgid "Enter a valid Street No."
    470 msgstr ""
     485#: public/class-wc-valorpay-public.php:97
     486msgid "Unable to process payment. Please try again."
     487msgstr ""
     488
     489#: public/class-wc-valorpay-public.php:244
     490#: public/class-wc-valorpay-public.php:272
     491#: public/class-wc-valorpay-public.php:312
     492msgid "Invalid request method."
     493msgstr ""
     494
     495#: public/class-wc-valorpay-public.php:251
     496#: public/class-wc-valorpay-public.php:282
     497msgid "Payment gateway missing."
     498msgstr ""
     499
     500#: public/class-wc-valorpay-public.php:257
     501msgid "Unable to create page token."
     502msgstr ""
     503
     504#: public/class-wc-valorpay-public.php:278
     505#: public/class-wc-valorpay-public.php:318
     506msgid "Invalid request."
     507msgstr ""
     508
     509#: public/class-wc-valorpay-public.php:299
     510msgid "Unable to lookup bin."
     511msgstr ""
     512
     513#: public/class-wc-valorpay-public.php:338
     514msgid "Unable to set card type."
     515msgstr ""
  • valorpos/tags/7.4.0/public/class-wc-valorpay-public.php

    r2918841 r2980555  
    1919 * @package    Wc_Valorpay
    2020 * @subpackage Wc_Valorpay/public
    21  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     21 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2222 */
    2323class Wc_Valorpay_Public {
     
    6060     * @since    1.0.0
    6161     */
     62    /**
     63     * Register the JavaScript and CSS for the public area.
     64     *
     65     * @since    1.0.0
     66     */
    6267    public function enqueue_scripts_and_styles() {
    6368        if ( is_checkout() ) {
     69            $all_payment_methods = WC()->payment_gateways()->payment_gateways();
     70            if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) {
     71                return;
     72            }
     73
    6474            wp_enqueue_style( $this->plugin_name, plugins_url( 'css/wc-valorpay-checkout.css', __FILE__ ), array(), $this->version );
    65         }
    66     }
    67 
    68     /**
    69      * Register the JavaScript for the public-facing side of the site.
    70      *
    71      * @since    1.0.0
    72      */
    73     public function valorpay_checkout_script() {
    74 
    75         wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-checkout.js', array( 'jquery' ), $this->version, false );
    76         wp_localize_script(
    77             $this->plugin_name,
    78             'valorpay_checkout_object',
    79             array(
    80                 'error_card'            => __( 'Please enter a card number', 'wc-valorpay' ),
    81                 'invalid_card'          => __( 'Invalid card number', 'wc-valorpay' ),
    82                 'expiry_card'           => __( 'Card is expired', 'wc-valorpay' ),
    83                 'invalid_expiry'        => __( 'Please enter card expiry date', 'wc-valorpay' ),
    84                 'error_cvv'             => __( 'Please enter a CVC', 'wc-valorpay' ),
    85                 'invalid_cvv'           => __( 'Invalid CVC length', 'wc-valorpay' ),
    86                 'avs_zip_error'         => __( 'Please enter a zip code', 'wc-valorpay' ),
    87                 'invalid_avs_zip_error' => __( 'Invalid zip code', 'wc-valorpay' ),
    88                 'avs_street_error'      => __( 'Please enter a street address', 'wc-valorpay' ),
    89             )
    90         );
    91 
    92     }
    93 
    94     /**
    95      * AVS checkout validation
    96      *
    97      * @since 1.0.0
    98      *
    99      * @param  array    $fields   An array of posted data.
    100      * @param  WP_Error $errors Validation errors.
    101      * @return void
    102      */
    103     public function valorpay_avs_checkout_validation( $fields, $errors ) {
    104         if ( ( isset( $fields['payment_method'] ) && 'wc_valorpay' === $fields['payment_method'] ) ) {
    105             $valorpay_avs_type = ( isset( $_POST['valorpay_avs_type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_type'] ) ) : ''; // phpcs:ignore
    106             if ( 'zip' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) {
    107                 if ( ! isset( $_POST['valorpay_avs_zip'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) { // phpcs:ignore
    108                     $errors->add( 'validation', __( 'Zip Code is required.', 'wc-valorpay' ) );
    109                 }
    110                 if ( isset( $_POST['valorpay_avs_zip'] ) && sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) && ! preg_match( '/^([a-zA-Z0-9_-]){4,6}$/', sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) ) { // phpcs:ignore
    111                     $errors->add( 'validation', __( 'Enter a valid Zip Code.', 'wc-valorpay' ) );
    112                 }
    113             }
    114             if ( 'address' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) {
    115                 if ( ! isset( $_POST['valorpay_avs_street'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) { // phpcs:ignore
    116                     $errors->add( 'validation', __( 'Street No is required.', 'wc-valorpay' ) );
    117                 }
    118                 if ( isset( $_POST['valorpay_avs_street'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) > 25 ) { // phpcs:ignore
    119                     $errors->add( 'validation', __( 'Enter a valid Street No.', 'wc-valorpay' ) );
    120                 }
    121             }
     75            wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-checkout.js', array( 'jquery' ), $this->version, false );
     76            wp_localize_script(
     77                $this->plugin_name,
     78                'valorpay_checkout_object',
     79                array(
     80                    'ajax_url'              => admin_url( 'admin-ajax.php' ),
     81                    'wc_ajax_action'        => WC_AJAX::get_endpoint( '%%endpoint_url%%' ),
     82                    'ct_ajax_action'        => 'valorpay_create_page_token',
     83                    'ct_ajax_nonce'         => wp_create_nonce( 'valorpay_create_page_token' ),
     84                    'bl_ajax_action'        => 'valorpay_bin_lookup',
     85                    'bl_ajax_nonce'         => wp_create_nonce( 'valorpay_bin_lookup' ),
     86                    'card_type_ajax_action' => 'valorpay_token_card_type',
     87                    'card_type_ajax_nonce'  => wp_create_nonce( 'valorpay_token_card_type' ),
     88                    'error_card'            => __( 'Please enter a card number', 'wc-valorpay' ),
     89                    'invalid_card'          => __( 'Invalid card number', 'wc-valorpay' ),
     90                    'expiry_card'           => __( 'Card is expired', 'wc-valorpay' ),
     91                    'invalid_expiry'        => __( 'Please enter card expiry date', 'wc-valorpay' ),
     92                    'error_cvv'             => __( 'Please enter a CVC', 'wc-valorpay' ),
     93                    'invalid_cvv'           => __( 'Invalid CVC length', 'wc-valorpay' ),
     94                    'avs_zip_error'         => __( 'Please enter a zip code', 'wc-valorpay' ),
     95                    'invalid_avs_zip_error' => __( 'Invalid zip code', 'wc-valorpay' ),
     96                    'avs_street_error'      => __( 'Please enter a street address', 'wc-valorpay' ),
     97                    'card_token_error'      => __( 'Unable to process payment. Please try again.', 'wc-valorpay' ),
     98                )
     99            );
    122100        }
    123101    }
     
    138116
    139117        if ( 'wc_valorpay' === $payment_method && 'yes' === $valorpay->surcharge_indicator && 'yes' === $valorpay->enabled ) {
     118            if ( 'D' === WC()->session->get( 'valor_card_type' ) && 'no' === $valorpay->surcharge_for_debit ) {
     119                return;
     120            }
    140121            $surcharge = 0;
    141122            if ( 'percentage' === $valorpay->surcharge_type ) {
     
    228209        }
    229210    }
     211
     212    /**
     213     * Fetch card type for the default save token.
     214     *
     215     * @since 7.4.0
     216     */
     217    public function valorpay_update_token_card_type() {
     218        $current_user_id = get_current_user_id();
     219        if ( $current_user_id ) {
     220            $token = WC_Payment_Tokens::get_customer_default_token( $current_user_id );
     221            if ( ! $token || null === $token ) {
     222                WC()->session->__unset( 'valor_card_type' );
     223            } elseif ( 'wc_valorpay' === $token->get_gateway_id() ) {
     224                $card_type = $token->get_meta( 'is_debit' ) === '1' ? 'D' : 'C';
     225                // Check if card type not same.
     226                if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) {
     227                    WC()->session->set( 'valor_card_type', $card_type );
     228                }
     229            } else {
     230                WC()->session->__unset( 'valor_card_type' );
     231            }
     232        } else {
     233            WC()->session->__unset( 'valor_card_type' );
     234        }
     235    }
     236
     237    /**
     238     * Create page token.
     239     *
     240     * @since 7.4.0
     241     */
     242    public function valorpay_create_page_token() {
     243        if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
     244            wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) );
     245        }
     246        if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_create_page_token' ) ) {
     247            wp_send_json_error( 'invalid_nonce' );
     248        }
     249        $all_payment_methods = WC()->payment_gateways()->payment_gateways();
     250        if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) {
     251            wp_send_json_error( array( 'message' => __( 'Payment gateway missing.', 'wc-valorpay' ) ) );
     252        }
     253        $valorpay     = $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ];
     254        $valorpay_api = new WC_ValorPay_API( $valorpay );
     255        $api_response = $valorpay_api->create_checkout_page_token();
     256        if ( is_wp_error( $api_response ) || ! is_object( $api_response ) || ! isset( $api_response->clientToken ) ) { // phpcs:ignore
     257            wp_send_json_error( array( 'message' => __( 'Unable to create page token.', 'wc-valorpay' ) ) );
     258        } else {
     259            wp_send_json_success( array( 'token' => $api_response->clientToken ) ); // phpcs:ignore
     260        }
     261    }
     262
     263    /**
     264     * Bin lookup.
     265     *
     266     * @since 7.4.0
     267     * @throws Exception If error.
     268     */
     269    public function valorpay_bin_lookup() {
     270        try {
     271            if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
     272                wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) );
     273            }
     274            if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_bin_lookup' ) ) {
     275                wp_send_json_error( 'invalid_nonce' );
     276            }
     277            if ( ! isset( $_REQUEST['client_token'] ) || ! isset( $_REQUEST['bin'] ) ) {
     278                wp_send_json_error( array( 'message' => __( 'Invalid request.', 'wc-valorpay' ) ) );
     279            }
     280            $all_payment_methods = WC()->payment_gateways()->payment_gateways();
     281            if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) {
     282                wp_send_json_error( array( 'message' => __( 'Payment gateway missing.', 'wc-valorpay' ) ) );
     283            }
     284            $need_update  = false;
     285            $valorpay     = $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ];
     286            $valorpay_api = new WC_ValorPay_API( $valorpay );
     287            $api_response = $valorpay_api->bin_lookup( sanitize_text_field( wp_unslash( $_REQUEST['bin'] ) ), sanitize_text_field( wp_unslash( $_REQUEST['client_token'] ) ) );
     288            if ( is_wp_error( $api_response ) ) { // phpcs:ignore
     289                throw new Exception( 'Error' );
     290            }
     291            $card_type = $api_response->card_type;
     292            // If card type same as previous value, no need to update.
     293            if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) {
     294                WC()->session->set( 'valor_card_type', $api_response->card_type );
     295                $need_update = true;
     296            }
     297            wp_send_json_success( $need_update );
     298        } catch ( Exception $ex ) {
     299            wp_send_json_error( array( 'message' => __( 'Unable to lookup bin.', 'wc-valorpay' ) ) );
     300        }
     301    }
     302
     303    /**
     304     * Get token card type.
     305     *
     306     * @since 7.4.0
     307     * @throws Exception If error.
     308     */
     309    public function valorpay_token_card_type() {
     310        try {
     311            if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
     312                wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) );
     313            }
     314            if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_token_card_type' ) ) {
     315                wp_send_json_error( 'invalid_nonce' );
     316            }
     317            if ( ! isset( $_REQUEST['token_id'] ) ) {
     318                wp_send_json_error( array( 'message' => __( 'Invalid request.', 'wc-valorpay' ) ) );
     319            }
     320            $need_update = false;
     321            $token_id    = sanitize_text_field( wp_unslash( $_REQUEST['token_id'] ) );
     322            if ( 'new' !== $token_id ) {
     323                $payment_token = WC_Payment_Tokens::get( $token_id );
     324                if ( $payment_token ) {
     325                    $card_type = $payment_token->get_meta( 'is_debit' ) === '1' ? 'D' : 'C';
     326                    // Check if the payment token exists.
     327                    if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) {
     328                        WC()->session->set( 'valor_card_type', $card_type );
     329                        $need_update = true;
     330                    }
     331                }
     332            } else {
     333                WC()->session->__unset( 'valor_card_type' );
     334                $need_update = true;
     335            }
     336            wp_send_json_success( $need_update );
     337        } catch ( Exception $ex ) {
     338            wp_send_json_error( array( 'message' => __( 'Unable to set card type.', 'wc-valorpay' ) ) );
     339        }
     340    }
    230341}
  • valorpos/tags/7.4.0/public/js/wc-valorpay-checkout.js

    r2918841 r2980555  
    66 */
    77
    8 (function($) {
    9   "use strict";
    10 
    11   var validcard = false;
    12   var validcardexpiry = false;
    13   var validcvc = false;
    14   let luhnCheck = function(num) {
    15       var digit, digits, odd, sum, _i, _len;
    16       odd = true;
    17       sum = 0;
    18       digits = (num + "").split("").reverse();
    19       for (_i = 0, _len = digits.length; _i < _len; _i++) {
    20           digit = digits[_i];
    21           digit = parseInt(digit, 10);
    22           if ((odd = !odd)) {
    23               digit *= 2;
    24           }
    25           if (digit > 9) {
    26               digit -= 9;
    27           }
    28           sum += digit;
    29       }
    30       return sum % 10 === 0.0;
    31   };
    32 
    33   $(document).ready(function() {
    34       $("body").on("change", 'input[name="payment_method"]', function() {
    35           $("body").trigger("update_checkout");
    36       });
    37       $("body").on("blur", 'input[name="wc_valorpay-card-number"]', function() {
    38           if ($("#payment_method_wc_valorpay").is(":checked")) {
    39               var cardNum = $(this).val().replace(/ /g, "");
    40               var isValid = luhnCheck(cardNum);
    41 
    42               if (cardNum === "") {
    43                   $(this).addClass("error-class");
    44                   if (!$(this).next().hasClass("error-message")) {
    45                       $(
    46                           '<span class="error-message" style="color:red;">' +
    47                           valorpay_checkout_object.error_card +
    48                           "</span>"
    49                       ).insertAfter($(this));
    50                   }
    51                   $("#wc-wc_valorpay-card-number-error").remove();
    52                   validcard = false;
    53                   $(this).parent().addClass("woocommerce-invalid");
    54               } else if (!isValid) {
    55                   $(this).addClass("error-class");
    56                   if (!$(this).next().hasClass("error-message")) {
    57                       $(
    58                           '<span class="error-message" style="color:red;">' +
    59                           valorpay_checkout_object.invalid_card +
    60                           "</span>"
    61                       ).insertAfter($(this));
    62                   }
    63                   $("#wc-wc_valorpay-card-number-error").remove();
    64                   validcard = false;
    65                   $(this).parent().addClass("woocommerce-invalid");
    66               } else {
    67                   $(this).removeClass("error-class");
    68                   $(this).next(".error-message").remove();
    69                   validcard = true;
    70                   $(this).parent().removeClass("woocommerce-invalid");
    71               }
    72           }
    73       });
    74       $("body").on("focus", 'input[name="wc_valorpay-card-number"]', function() {
    75           if (!$(this).val()) {
    76               $(this).removeClass("error-class");
    77               $(this).next(".error-message").remove();
    78           }
    79       });
    80       $("body").on("blur", 'input[name="wc_valorpay-card-expiry"]', function() {
    81           if ($("#payment_method_wc_valorpay").is(":checked")) {
    82               var expiry = $(this).val().replace(/ /g, "");
    83               if (expiry === "") {
    84                   $(this).addClass("error-class");
    85                   if (!$(this).next().hasClass("error-message")) {
    86                       $(
    87                           '<span class="error-message" style="color:red;">' +
    88                           valorpay_checkout_object.invalid_expiry +
    89                           "</span>"
    90                       ).insertAfter($(this));
    91                   }
    92                   validcardexpiry = false;
    93                   $(this).parent().addClass("woocommerce-invalid");
    94               } else {
    95                   var parts = expiry.split("/");
    96                   var month = parseInt(parts[0], 10);
    97                   var year = parseInt(parts[1], 10);
    98                   if (year < 100) {
    99                       year += 2000;
    100                   }
    101                   if (!validateCardExpiry(month, year)) {
    102                       $(this).addClass("error-class");
    103                       if (!$(this).next().hasClass("error-message")) {
    104                           $(
    105                               '<span class="error-message" style="color:red;">' +
    106                               valorpay_checkout_object.expiry_card +
    107                               "</span>"
    108                           ).insertAfter($(this));
    109                       }
    110                       validcardexpiry = false;
    111                       $(this).parent().addClass("woocommerce-invalid");
    112                   } else {
    113                       $(this).removeClass("error-class");
    114                       $(this).next(".error-message").remove();
    115                       validcardexpiry = true;
    116                       $(this).parent().removeClass("woocommerce-invalid");
    117                   }
    118               }
    119           }
    120       });
    121 
    122       $("body").on("focus", 'input[name="wc_valorpay-card-expiry"]', function() {
    123           $(this).removeClass("error-class");
    124           $(this).next(".error-message").remove();
    125       });
    126       $("body").on("blur", "#wc_valorpay-card-cvc", function() {
    127           if ($("#payment_method_wc_valorpay").is(":checked")) {
    128               var cvcNum = $(this).val().trim();
    129               if (cvcNum === "") {
    130                   $(this).addClass("error-class");
    131                   if (!$(this).next().hasClass("error-message")) {
    132                       $(
    133                           '<span class="error-message" style="color:red;">' +
    134                           valorpay_checkout_object.error_cvv +
    135                           "</span>"
    136                       ).insertAfter($(this));
    137                   }
    138                   validcvc = false;
    139                   $(this).parent().addClass("woocommerce-invalid");
    140               } else if (cvcNum.length != 3 && cvcNum.length != 4) {
    141                   $(this).addClass("error-class");
    142                   if (!$(this).next().hasClass("error-message")) {
    143                       $(
    144                           '<span class="error-message" style="color:red;">' +
    145                           valorpay_checkout_object.invalid_cvv +
    146                           "</span>"
    147                       ).insertAfter($(this));
    148                   }
    149                   validcvc = false;
    150                   $(this).parent().addClass("woocommerce-invalid");
    151               } else {
    152                   $(this).removeClass("error-class");
    153                   $(this).next(".error-message").remove();
    154                   validcvc = true;
    155                   $(this).parent().removeClass("woocommerce-invalid");
    156               }
    157           }
    158       });
    159       $("body").on("focus", 'input[name="wc_valorpay-card-cvc"]', function() {
    160           $(this).removeClass("error-class");
    161           $(this).next(".error-message").remove();
    162       });
    163       $("form.woocommerce-checkout").on(
    164         "checkout_place_order_wc_valorpay",
    165         function() {
    166  
    167  
    168             var cardNumb = $('input[name="wc_valorpay-card-number"]').val();
    169             const isToken = $('#wc-wc_valorpay-payment-token-new');
    170             if (
    171                 isToken.length && !isToken.is(":checked")
    172             ) {
    173                 var avserrorIsValidsave = addAVSErrors();
    174                 // Do something if the radio button is checked
    175  
    176                 if (avserrorIsValidsave) {
    177                    
    178                     return true;
    179                 } else {
     8(function ($) {
     9    "use strict";
     10    var wc_valorpay_form = {
     11        validCard: false,
     12        validCardExpiry: false,
     13        validCvc: false,
     14        checkoutFormClass: "form.woocommerce-checkout",
     15        cardNumberInput: "#wc_valorpay-card-number",
     16        cardExpiryInput: "#wc_valorpay-card-expiry",
     17        cardCvvInput: "#wc_valorpay-card-cvc",
     18        clientTokenInit: false,
     19        clientToken: "",
     20        tokenGenerateInterval: null,
     21        tokenExpiryMin: 5,
     22        prevSelectedToken: false,
     23        /**
     24         * Initialize.
     25         */
     26        init: function () {
     27            // On payment method switch update checkout.
     28            $( document.body ).on(
     29                "change",
     30                'input[name="payment_method"]',
     31                this.updateCheckout
     32            );
     33            $( document.body ).on(
     34                "click",
     35                'input[name="wc-wc_valorpay-payment-token"]',
     36                this.surChargeCalculation
     37            );
     38            this.validateCardForm();
     39            this.createPageToken();
     40            this.startReCreatePageToken();
     41            $( wc_valorpay_form.checkoutFormClass ).on(
     42                "checkout_place_order_wc_valorpay",
     43                this.valorPayPlaceOrder
     44            );
     45        },
     46        /**
     47         * On payment gateway change update the checkout.
     48         */
     49        updateCheckout: function () {
     50            $( document.body ).trigger( "update_checkout" );
     51        },
     52        /**
     53         * On token switch
     54         */
     55        surChargeCalculation: function () {
     56            const checkedValue  = $('input[name="wc-wc_valorpay-payment-token"]:checked').val();
     57            if(wc_valorpay_form.prevSelectedToken !=  checkedValue) {
     58                if((checkedValue === 'new' && !$( wc_valorpay_form.cardNumberInput ).val()) || checkedValue !== 'new') {
     59                    wc_valorpay_form.tokenCardType(checkedValue);
     60                } else {
     61                    $( wc_valorpay_form.cardNumberInput ).trigger( "blur" );
     62                }
     63                wc_valorpay_form.prevSelectedToken = checkedValue;
     64            }
     65        },
     66        /**
     67         * Block checkout page UI.
     68         */
     69        block: function () {
     70            $( wc_valorpay_form.checkoutFormClass ).block(
     71                {
     72                    message: null,
     73                    overlayCSS: {
     74                        background: "#fff",
     75                        opacity: 0.6,
     76                    },
     77                }
     78            );
     79        },
     80        /**
     81         * Unblock checkout page UI.
     82         */
     83        unblock: function () {
     84            $( wc_valorpay_form.checkoutFormClass ).unblock();
     85        },
     86        /**
     87         * Create page or client token.
     88         */
     89        createPageToken: function () {
     90            $.ajax(
     91                {
     92                    type: "POST",
     93                    url: valorpay_checkout_object.wc_ajax_action
     94                    .toString()
     95                    .replace( "%%endpoint_url%%", valorpay_checkout_object.ct_ajax_action ),
     96                    data: {
     97                        nonce: valorpay_checkout_object.ct_ajax_nonce,
     98                    },
     99                    success: function (response) {
     100                        if (response.success) {
     101                            wc_valorpay_form.clientToken = response.data.token;
     102                        }
     103                    },
     104                }
     105            );
     106        },
     107        /**
     108         * Bin lookup.
     109         */
     110        binLookUp: function () {
     111            var cardNumber = $( wc_valorpay_form.cardNumberInput )
     112            .val()
     113            .replace( / /g, "" );
     114            $.ajax(
     115                {
     116                    type: "POST",
     117                    url: valorpay_checkout_object.wc_ajax_action
     118                    .toString()
     119                    .replace( "%%endpoint_url%%", valorpay_checkout_object.bl_ajax_action ),
     120                    data: {
     121                        nonce: valorpay_checkout_object.bl_ajax_nonce,
     122                        client_token: wc_valorpay_form.clientToken,
     123                        bin: cardNumber.substring(0, 6)
     124                    },
     125                    success: function (response) {
     126                        if (response.success && response.data) {
     127                            wc_valorpay_form.updateCheckout();
     128                        }
     129                    },
     130                }
     131            );
     132        },
     133        /**
     134         * Token card type.
     135         */
     136        tokenCardType: function (tokenId) {
     137            $.ajax(
     138                {
     139                    type: "POST",
     140                    url: valorpay_checkout_object.wc_ajax_action
     141                    .toString()
     142                    .replace( "%%endpoint_url%%", valorpay_checkout_object.card_type_ajax_action ),
     143                    data: {
     144                        nonce: valorpay_checkout_object.card_type_ajax_nonce,
     145                        token_id: tokenId,
     146                    },
     147                    success: function (response) {
     148                        if (response.success && response.data) {
     149                            wc_valorpay_form.updateCheckout();
     150                        }
     151                    },
     152                }
     153            );
     154        },
     155        /**
     156         * Recreate page token on every token expiry minutes.
     157         */
     158        startReCreatePageToken: function () {
     159            wc_valorpay_form.tokenGenerateInterval = setInterval(
     160                function () {
     161                    wc_valorpay_form.createPageToken();
     162                },
     163                wc_valorpay_form.tokenExpiryMin * 60 * 1000
     164            );
     165        },
     166        /**
     167         * Convert expiry date to MMYY format.
     168         */
     169        convertToMMYY: function (dateString) {
     170            // Remove any leading/trailing spaces.
     171            dateString = dateString.trim();
     172
     173            // Split the string into month and year parts.
     174            var parts = dateString.split( "/" );
     175            var month = parseInt( parts[0] );
     176            var year  = parseInt( parts[1] );
     177
     178            // Extract the year part based on the input format.
     179            if (year < 100) {
     180                // Format is MM/YY .
     181                year += 2000; // Assuming years below 100 are in the 21st century.
     182            }
     183
     184            // Format the month and year as MMYY .
     185            var formattedDate = ("0" + month).slice( -2 ) + ("0" + year).slice( -2 );
     186
     187            return formattedDate;
     188        },
     189        /**
     190         * Validate card checkout field.
     191         */
     192        validateCardForm: function () {
     193            this.validateCardNumber();
     194            this.validateCardExpiry();
     195            this.validateCardCvv();
     196        },
     197        /**
     198         * Add error to form field.
     199         *
     200         * @param {jQuery} currentEle The current element.
     201         * @param {string} errorMsg Error Message.
     202         */
     203        addErrorMessage: function (currentEle, errorMsg) {
     204            currentEle.addClass( "error-class" );
     205            if ( ! currentEle.next().hasClass( "error-message" )) {
     206                $(
     207                    '<span class="error-message" style="color:red;">' +
     208                    errorMsg +
     209                    "</span>"
     210                ).insertAfter( currentEle );
     211                currentEle.closest( ".form-row" ).addClass( "woocommerce-invalid" );
     212            }
     213        },
     214        /**
     215         * Remove error from the form field.
     216         *
     217         * @param {jQuery} currentEle The current element.
     218         */
     219        removeErrorMessage: function (currentEle) {
     220            currentEle.removeClass( "error-class" );
     221            currentEle.next( ".error-message" ).remove();
     222            currentEle.closest( ".form-row" ).removeClass( "woocommerce-invalid" );
     223        },
     224        /**
     225         * Validate card number field.
     226         */
     227        validateCardNumber: function () {
     228            $( "body" ).on(
     229                "blur",
     230                this.cardNumberInput,
     231                function () {
     232                    var cardNum = $( this ).val().replace( / /g, "" );
     233                    var isValid = wc_valorpay_form.luhnCheck( cardNum );
     234
     235                    if (cardNum === "") {
     236                        wc_valorpay_form.addErrorMessage(
     237                            $( this ),
     238                            valorpay_checkout_object.error_card
     239                        );
     240                        wc_valorpay_form.validCard = false;
     241                    } else if ( ! isValid) {
     242                        wc_valorpay_form.addErrorMessage(
     243                            $( this ),
     244                            valorpay_checkout_object.invalid_card
     245                        );
     246                        wc_valorpay_form.validCard = false;
     247                    } else {
     248                        wc_valorpay_form.removeErrorMessage( $( this ) );
     249                        wc_valorpay_form.validCard = true;
     250                        wc_valorpay_form.binLookUp();
     251                    }
     252                }
     253            );
     254            $( "body" ).on(
     255                "focus",
     256                this.cardNumberInput,
     257                function () {
     258                    if ( ! $( this ).val()) {
     259                        wc_valorpay_form.removeErrorMessage( $( this ) );
     260                    }
     261                }
     262            );
     263        },
     264        /**
     265         * Validate card expiry field.
     266         */
     267        validateCardExpiry: function () {
     268            $( "body" ).on(
     269                "blur",
     270                this.cardExpiryInput,
     271                function () {
     272                    var expiry = $( this ).val().replace( / /g, "" );
     273                    if (expiry === "") {
     274                        wc_valorpay_form.addErrorMessage(
     275                            $( this ),
     276                            valorpay_checkout_object.invalid_expiry
     277                        );
     278                        wc_valorpay_form.validCardExpiry = false;
     279                    } else {
     280                        var parts = expiry.split( "/" );
     281                        var month = parseInt( parts[0], 10 );
     282                        var year  = parseInt( parts[1], 10 );
     283                        if (year < 100) {
     284                            year += 2000;
     285                        }
     286                        if ( ! wc_valorpay_form.checkCardExpiry( month, year )) {
     287                            wc_valorpay_form.addErrorMessage(
     288                                $( this ),
     289                                valorpay_checkout_object.expiry_card
     290                            );
     291                            wc_valorpay_form.validCardExpiry = false;
     292                        } else {
     293                            wc_valorpay_form.removeErrorMessage( $( this ) );
     294                            wc_valorpay_form.validCardExpiry = true;
     295                        }
     296                    }
     297                }
     298            );
     299
     300            $( "body" ).on(
     301                "focus",
     302                this.cardExpiryInput,
     303                function () {
     304                    wc_valorpay_form.removeErrorMessage( $( this ) );
     305                }
     306            );
     307        },
     308        /**
     309         * Validate card CVV field.
     310         */
     311        validateCardCvv: function () {
     312            $( "body" ).on(
     313                "blur",
     314                this.cardCvvInput,
     315                function () {
     316                    var cvcNum = $( this ).val().trim();
     317                    if (cvcNum === "") {
     318                        wc_valorpay_form.addErrorMessage(
     319                            $( this ),
     320                            valorpay_checkout_object.error_cvv
     321                        );
     322                        wc_valorpay_form.validCvc = false;
     323                    } else if (cvcNum.length != 3 && cvcNum.length != 4) {
     324                        wc_valorpay_form.addErrorMessage(
     325                            $( this ),
     326                            valorpay_checkout_object.invalid_cvv
     327                        );
     328                        wc_valorpay_form.validCvc = false;
     329                    } else {
     330                        wc_valorpay_form.removeErrorMessage( $( this ) );
     331                        wc_valorpay_form.validCvc = true;
     332                    }
     333                }
     334            );
     335            $( "body" ).on(
     336                "focus",
     337                this.cardCvvInput,
     338                function () {
     339                    wc_valorpay_form.removeErrorMessage( $( this ) );
     340                }
     341            );
     342        },
     343        /**
     344         * Validate field on place order
     345         */
     346        valorPayPlaceOrder: function (event) {
     347            var cardNumb  = $( wc_valorpay_form.cardNumberInput ).val();
     348            const isNewCard = $( "#wc-wc_valorpay-payment-token-new" );
     349            if (isNewCard.length && ! isNewCard.is( ":checked" )) {
     350                var avsErrorIsValidSave = wc_valorpay_form.avsValidation();
     351                if (avsErrorIsValidSave) {
     352                    wc_valorpay_form.scrollToValorForm();
    180353                    return false;
    181                 }
    182             }
    183  
    184             if (cardNumb === "") {
    185                 $('input[name="wc_valorpay-card-number"]').trigger("blur");
    186             } else {
    187                 $('input[name="wc_valorpay-card-number"]').trigger("blur");
    188                 $('input[name="wc_valorpay-card-expiry"]').trigger("blur");
    189                 $('input[name="wc_valorpay-card-cvc"]').trigger("blur");
    190             }
    191             if (validcard === false) {
    192                 $("html, body").animate({
    193                         scrollTop: $("#wc-wc_valorpay-cc-form").offset().top,
    194                     },
    195                     1000
    196                 );
    197                 return false;
    198             }
    199             if (validcardexpiry === false) {
    200                 $("html, body").animate({
    201                         scrollTop: $("#wc-wc_valorpay-cc-form").offset().top,
    202                     },
    203                     1000
    204                 );
    205                 return false;
    206             }
    207             if (validcvc === false) {
    208                 $("html, body").animate({
    209                         scrollTop: $("#wc-wc_valorpay-cc-form").offset().top,
    210                     },
    211                     1000
    212                 );
    213                 return false;
    214             }
    215             if (cardNumb !== "") {
    216                 var avserrorIsValid = addAVSErrors();
    217                
    218                 if (avserrorIsValid) {
    219            
    220                     return true;
    221                 } else {
    222                     return false;
    223                 }
    224             }
    225         }
    226     );
    227  
    228  
    229  
    230     function validateCardExpiry(month, year) {
    231         var currentTime = new Date();
    232         var expiry = new Date(year, month, 1);
    233         if (expiry < currentTime) {
    234             return false;
    235         }
    236         return true;
    237     }
    238  
    239     function addAVSErrors() {
    240         var hasError = false;
    241  
    242         $('input[name="valorpay_avs_zip"] + span.error').remove();
    243         $('input[name="valorpay_avs_street"] + span.error').remove();
    244  
    245         if ($('input[name="valorpay_avs_zip"]').val() === "") {
    246             $('input[name="valorpay_avs_zip"]').after(
    247                 '<span class="error" style="color:red;">' +
    248                 valorpay_checkout_object.avs_zip_error +
    249                 "</span>"
    250             );
    251             hasError = true;
    252         } else if ($('input[name="valorpay_avs_zip"]').val().length < 4) {
    253             $('input[name="valorpay_avs_zip"]').after(
    254                 '<span class="error" style="color:red;">' +
    255                 valorpay_checkout_object.invalid_avs_zip_error + "</span>"
    256             );
    257             hasError = true;
    258         }
    259  
    260         if ($('input[name="valorpay_avs_street"]').val() === "") {
    261             $('input[name="valorpay_avs_street"]').after(
    262                 '<span class="error" style="color:red;">' +
    263                 valorpay_checkout_object.avs_street_error +
    264                 "</span>"
    265             );
    266             hasError = true;
    267         }
    268  
    269         $('input[name="valorpay_avs_zip"]').focus(function() {
    270             $('input[name="valorpay_avs_zip"] + span.error').remove();
    271         });
    272  
    273         $('input[name="valorpay_avs_street"]').focus(function() {
    274             $('input[name="valorpay_avs_street"] + span.error').remove();
    275         });
    276  
    277         return !hasError;
    278     }
    279   });
    280 
    281  
    282 })(jQuery);
     354                }
     355                return true;
     356            }
     357            if (cardNumb === "") {
     358                $( wc_valorpay_form.cardNumberInput ).trigger( "blur" );
     359            } else {
     360                $( wc_valorpay_form.cardNumberInput ).trigger( "blur" );
     361                $( wc_valorpay_form.cardExpiryInput ).trigger( "blur" );
     362                $( wc_valorpay_form.cardCvvInput ).trigger( "blur" );
     363            }
     364            if (wc_valorpay_form.validCard === false) {
     365                wc_valorpay_form.scrollToValorForm();
     366                return false;
     367            }
     368            if (wc_valorpay_form.validCardExpiry === false) {
     369                wc_valorpay_form.scrollToValorForm();
     370                return false;
     371            }
     372            if (wc_valorpay_form.validCvc === false) {
     373                wc_valorpay_form.scrollToValorForm();
     374                return false;
     375            }
     376
     377            if (cardNumb !== "") {
     378                var avsErrorIsValid = wc_valorpay_form.avsValidation();
     379                if (avsErrorIsValid) {
     380                    wc_valorpay_form.scrollToValorForm();
     381                    return false;
     382                }
     383                return true;
     384            }
     385        },
     386        /**
     387         * Validate Address Verification Service
     388         */
     389        avsValidation: function () {
     390            var hasError = false;
     391            if ($( 'input[name="valorpay_avs_zip"]' ).length) {
     392                wc_valorpay_form.removeErrorMessage(
     393                    $( 'input[name="valorpay_avs_zip"]' )
     394                );
     395                if ($( 'input[name="valorpay_avs_zip"]' ).val() === "") {
     396                        wc_valorpay_form.addErrorMessage(
     397                            $( 'input[name="valorpay_avs_zip"]' ),
     398                            valorpay_checkout_object.avs_zip_error
     399                        );
     400                        hasError = true;
     401                } else if ($( 'input[name="valorpay_avs_zip"]' ).val().length < 4) {
     402                    wc_valorpay_form.addErrorMessage(
     403                        $( 'input[name="valorpay_avs_zip"]' ),
     404                        valorpay_checkout_object.invalid_avs_zip_error
     405                    );
     406                    hasError = true;
     407                }
     408                $( 'input[name="valorpay_avs_zip"]' ).focus(
     409                    function () {
     410                        wc_valorpay_form.removeErrorMessage(
     411                            $( 'input[name="valorpay_avs_zip"]' )
     412                        );
     413                    }
     414                );
     415            }
     416
     417            if ($( 'input[name="valorpay_avs_street"]' ).length) {
     418                wc_valorpay_form.removeErrorMessage(
     419                    $( 'input[name="valorpay_avs_street"]' )
     420                );
     421                if ($( 'input[name="valorpay_avs_street"]' ).val() === "") {
     422                    wc_valorpay_form.addErrorMessage(
     423                        $( 'input[name="valorpay_avs_street"]' ),
     424                        valorpay_checkout_object.avs_street_error
     425                    );
     426                    hasError = true;
     427                }
     428                $( 'input[name="valorpay_avs_street"]' ).focus(
     429                    function () {
     430                        wc_valorpay_form.removeErrorMessage(
     431                            $( 'input[name="valorpay_avs_street"]' )
     432                        );
     433                    }
     434                );
     435            }
     436
     437            return hasError;
     438        },
     439        /**
     440         * Check if the card expiry.
     441         *
     442         * @param {number} month Card month
     443         * @param {number} year Card year
     444         * @return {boolean}
     445         */
     446        checkCardExpiry: function (month, year) {
     447            var currentTime = new Date();
     448            var expiry      = new Date( year, month, 1 );
     449            if (expiry < currentTime) {
     450                return false;
     451            }
     452            return true;
     453        },
     454        /**
     455         * Luhn check.
     456         *
     457         * @param {string} num Card number
     458         * @return {boolean}
     459         */
     460        luhnCheck: function (num) {
     461            var digit, digits, odd, sum, _i, _len;
     462            odd    = true;
     463            sum    = 0;
     464            digits = (num + "").split( "" ).reverse();
     465            for (_i = 0, _len = digits.length; _i < _len; _i++) {
     466                digit = digits[_i];
     467                digit = parseInt( digit, 10 );
     468                if ((odd = ! odd)) {
     469                    digit *= 2;
     470                }
     471                if (digit > 9) {
     472                    digit -= 9;
     473                }
     474                sum += digit;
     475            }
     476            return sum % 10 === 0.0;
     477        },
     478        /**
     479         * Scroll to payment form.
     480         */
     481        scrollToValorForm: function () {
     482            $( "html, body" ).animate(
     483                {
     484                    scrollTop: $( "#wc-wc_valorpay-cc-form" ).offset().top,
     485                },
     486                1000
     487            );
     488        },
     489    };
     490    $( document ).ready(
     491        function () {
     492            // Initialize the wc_test_form object.
     493            wc_valorpay_form.init();
     494        }
     495    );
     496})( jQuery );
  • valorpos/tags/7.4.0/wc-valorpay.php

    r2960359 r2980555  
    1616 * Plugin URI:        https://valorpaytech.com
    1717 * Description:       Adds the Valor Payment Gateway to WooCommerce.
    18  * Version:           7.3.1
     18 * Version:           7.4.0
    1919 * Author:            Valor Paytech LLC
    2020 * Author URI:        https://valorpaytech.com
     
    3737 * Rename this for your plugin and update it as you release new versions.
    3838 */
    39 define( 'WC_VALORPAY_VERSION', '7.3.1' );
     39define( 'WC_VALORPAY_VERSION', '7.4.0' );
    4040// Directory i.e. /home/user/public_html...
    4141define( 'WC_VALORPAY_DIR', plugin_dir_path( __FILE__ ) );
  • valorpos/trunk/README.txt

    r2960359 r2980555  
    33Tags: payment, payment gateway, credit card, valor pay, valor paytech
    44Requires at least: 5.0
    5 Tested up to: 6.2.2
     5Tested up to: 6.3.1
    66Requires PHP: 7.0
    7 Stable tag: 7.3.1
     7Stable tag: 7.4.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4141== Changelog ==
    4242
     43= 7.4.0 =
     44* Added a new configuration to toggle surcharge for debit transactions. This configuration determines whether a surcharge should be applied to debit transactions or not.
     45
    4346= 7.3.1 =
    4447* Update plugin title.
  • valorpos/trunk/admin/class-wc-valorpay-admin.php

    r2918841 r2980555  
    2222 * @package    Wc_Valorpay
    2323 * @subpackage Wc_Valorpay/admin
    24  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     24 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2525 */
    2626class Wc_Valorpay_Admin {
  • valorpos/trunk/includes/class-wc-valorpay-activator.php

    r2883367 r2980555  
    1818 * @package    Wc_Valorpay
    1919 * @subpackage Wc_Valorpay/includes
    20  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     20 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2121 */
    2222class Wc_Valorpay_Activator {
  • valorpos/trunk/includes/class-wc-valorpay-api.php

    r2918841 r2980555  
    2121 * @package    Wc_Valorpay
    2222 * @subpackage Wc_Valorpay/includes
    23  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     23 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2424 */
    2525class WC_ValorPay_API {
     
    2727     * Sandbox payment URL
    2828     */
    29     const WC_VALORPAY_SANDBOX_URL = 'https://securelinktest.valorpaytech.com:4430/';
     29    const WC_VALORPAY_SANDBOX_URL = 'https://securelink-staging.valorpaytech.com:4430/';
    3030    /**
    3131     * Live payment URL
     
    3535     * Sandbox OTP refund URL
    3636     */
    37     const WC_VALORPAY_REFUND_OTP_SANDBOX_URL = 'https://2fademo.isoaccess.com/?main_action=Manage2FA&operation=ecommRefund';
     37    const WC_VALORPAY_REFUND_OTP_SANDBOX_URL = 'https://2fa-staging.valorpaytech.com:4430/?main_action=Manage2FA&operation=ecommRefund';
    3838    /**
    3939     * Live OTP refund URL
    4040     */
    4141    const WC_VALORPAY_REFUND_OTP_URL = 'https://2fa.valorpaytech.com/?main_action=Manage2FA&operation=ecommRefund';
     42    /**
     43     * Create page token action
     44     */
     45    const WC_VALORPAY_PAGE_TOKEN_ACTION = 'clientToken';
     46    /**
     47     * Bin lookup action
     48     */
     49    const WC_VALORPAY_BIN_LOOKUP_ACTION = 'binLookup';
    4250
    4351    /**
     
    138146        $payload  = $this->get_payload( $order, $amount, 'send_otp' );
    139147        $response = $this->post_transaction( $payload, 'send_otp' );
     148        return $response;
     149    }
     150
     151    /**
     152     * Create checkout page token
     153     *
     154     * @since 7.4.0
     155     * @return object JSON response
     156     */
     157    public function create_checkout_page_token() {
     158        $payload  = array(
     159            'appid'    => $this->gateway->appid,
     160            'appkey'   => $this->gateway->appkey,
     161            'epi'      => $this->gateway->epi,
     162            'txn_type' => self::WC_VALORPAY_PAGE_TOKEN_ACTION,
     163        );
     164        $response = $this->post_transaction( wp_json_encode( $payload ) );
     165        return $response;
     166    }
     167
     168    /**
     169     * Get bin details
     170     *
     171     * @since 7.4.0
     172     *
     173     * @param string $bin_number Bin Number.
     174     * @param string $client_token Client Token.
     175     * @return object JSON response
     176     */
     177    public function bin_lookup( $bin_number, $client_token ) {
     178        $payload  = array(
     179            'client_token' => $client_token,
     180            'bin'          => $bin_number,
     181            'epi'          => $this->gateway->epi,
     182            'txn_type'     => self::WC_VALORPAY_BIN_LOOKUP_ACTION,
     183        );
     184        $response = $this->post_transaction( wp_json_encode( $payload ), 'bin_lookup' );
    140185        return $response;
    141186    }
     
    156201        $data         = array();
    157202        if ( 'sale' === $transaction_type ) {
    158             $surcharge_indicator = 0;
     203            $surcharge_indicator = ( 'yes' === $this->gateway->surcharge_indicator ) ? 1 : 0;
    159204            $custom_fee          = 0;
    160             if ( 'yes' === $this->gateway->surcharge_indicator && 0 < count( $order->get_fees() ) ) {
    161                 $surcharge_indicator = 1;
    162                 if ( 'sale' === $transaction_type ) {
     205            if ( 1 === $surcharge_indicator && 0 < count( $order->get_fees() ) ) {
     206                $cal_for_debit = ( 'D' === WC()->session->get( 'valor_card_type' ) ) && 'no' !== $this->gateway->surcharge_for_debit;
     207                if ( $cal_for_debit || ( 'D' !== WC()->session->get( 'valor_card_type' ) ) ) {
    163208                    foreach ( $order->get_fees() as $item_fee ) {
    164209                        if ( $item_fee->get_name() === $this->gateway->surcharge_label ) {
     
    170215                }
    171216            }
     217            $surcharge_data = array(
     218                'surchargeIndicator' => $surcharge_indicator,
     219                'surchargeAmount'    => $custom_fee,
     220            );
     221
    172222            $billing_first_name = wc_clean( $order->get_billing_first_name() );
    173223            $billing_last_name  = wc_clean( $order->get_billing_last_name() );
     
    189239            $valorpay_avs_zip    = ( isset( $_POST['valorpay_avs_zip'] ) && $_POST['valorpay_avs_zip'] ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) : wc_clean( substr( $billing_postcode, 0, 10 ) ); // phpcs:ignore
    190240            $valorpay_avs_street = ( isset( $_POST['valorpay_avs_street'] ) && $_POST['valorpay_avs_street'] ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) : wc_clean( $billing_address ); // phpcs:ignore
    191             $valorpay_terms = ( isset( $_POST['valorpay_terms'] ) && $_POST['valorpay_terms'] ) ? 1 : 0; // phpcs:ignore
     241            $valorpay_terms      = ( isset( $_POST['valorpay_terms'] ) && $_POST['valorpay_terms'] ) ? 1 : 0; // phpcs:ignore
    192242
    193243            $card_number = str_replace( ' ', '', ( isset( $_POST['wc_valorpay-card-number'] ) ) ? sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) : '' ); // phpcs:ignore
    194244            $data        = array(
    195                 'appid'              => $this->gateway->appid,
    196                 'appkey'             => $this->gateway->appkey,
    197                 'epi'                => $this->gateway->epi,
    198                 'txn_type'           => $this->gateway->payment_action,
    199                 'amount'             => wc_clean( $amount ),
    200                 'phone'              => $billing_phone,
    201                 'email'              => $billing_email,
    202                 'uid'                => $order_number,
    203                 'tax_amount'         => number_format( $tax_amount, '2', '.', '' ),
    204                 'ip'                 => $ip_address,
    205                 'surchargeIndicator' => $surcharge_indicator,
    206                 'surchargeAmount'    => $custom_fee,
    207                 'address1'           => $valorpay_avs_street,
    208                 'address2'           => wc_clean( $billing_address2 ),
    209                 'city'               => wc_clean( substr( $billing_city, 0, 40 ) ),
    210                 'state'              => wc_clean( substr( $billing_state, 0, 40 ) ),
    211                 'zip'                => $valorpay_avs_zip,
    212                 'billing_country'    => wc_clean( substr( $billing_country, 0, 60 ) ),
    213                 'shipping_country'   => wc_clean( substr( $shipping_country, 0, 60 ) ),
    214                 'status'             => 'Y',
    215                 'terms_checked'      => $valorpay_terms,
    216             );
     245                'appid'            => $this->gateway->appid,
     246                'appkey'           => $this->gateway->appkey,
     247                'epi'              => $this->gateway->epi,
     248                'txn_type'         => $this->gateway->payment_action,
     249                'amount'           => wc_clean( $amount ),
     250                'phone'            => $billing_phone,
     251                'email'            => $billing_email,
     252                'uid'              => $order_number,
     253                'tax_amount'       => number_format( $tax_amount, '2', '.', '' ),
     254                'ip'               => $ip_address,
     255                'address1'         => $valorpay_avs_street,
     256                'address2'         => wc_clean( $billing_address2 ),
     257                'city'             => wc_clean( substr( $billing_city, 0, 40 ) ),
     258                'state'            => wc_clean( substr( $billing_state, 0, 40 ) ),
     259                'zip'              => $valorpay_avs_zip,
     260                'billing_country'  => wc_clean( substr( $billing_country, 0, 60 ) ),
     261                'shipping_country' => wc_clean( substr( $shipping_country, 0, 60 ) ),
     262                'status'           => 'Y',
     263                'terms_checked'    => $valorpay_terms,
     264            ) + $surcharge_data;
    217265
    218266            if ( $card ) {
     
    287335        $response = wp_remote_post( $api_url, $args );
    288336        if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
    289             return new WP_Error( 'valorpos_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
     337            return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
    290338        }
    291339        $parsed_response = json_decode( preg_replace( '/\xEF\xBB\xBF/', '', $response['body'] ) );
    292340        if ( 'send_otp' === $transaction_type ) {
    293341            if ( ! isset( $parsed_response->error_code ) ) {
    294                 return new WP_Error( 'valorpos_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
     342                return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
    295343            }
    296344            if ( 'S00' !== $parsed_response->error_code ) {
    297345                $error_msg = sprintf( '%s', $parsed_response->error_desc );
    298                 return new WP_Error( 'valorpos_error', $error_msg );
     346                return new WP_Error( 'valorpay_error', $error_msg );
     347            }
     348        } elseif ( 'bin_lookup' === $transaction_type ) {
     349            if ( ! isset( $parsed_response->card_type ) ) {
     350                return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
    299351            }
    300352        } else {
    301353            if ( ! isset( $parsed_response->error_no ) ) {
    302                 return new WP_Error( 'valorpos_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
     354                return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );
    303355            }
    304356            if ( 'S00' !== $parsed_response->error_no ) {
    305357                $error_msg = sprintf( '%s ( %s )', $parsed_response->mesg, $parsed_response->desc );
    306                 return new WP_Error( 'valorpos_error', $error_msg );
     358                return new WP_Error( 'valorpay_error', $error_msg );
    307359            }
    308360        }
  • valorpos/trunk/includes/class-wc-valorpay-deactivator.php

    r2883367 r2980555  
    2222 * @package    Wc_Valorpay
    2323 * @subpackage Wc_Valorpay/includes
    24  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     24 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2525 */
    2626class Wc_Valorpay_Deactivator {
  • valorpos/trunk/includes/class-wc-valorpay-gateway-loader.php

    r2883367 r2980555  
    2222 * @package    Wc_Valorpay
    2323 * @subpackage Wc_Valorpay/includes
    24  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     24 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2525 */
    2626class Wc_Valorpay_Gateway_Loader {
  • valorpos/trunk/includes/class-wc-valorpay-gateway.php

    r2960359 r2980555  
    1919 * @package    Wc_Valorpay
    2020 * @subpackage Wc_Valorpay/includes
    21  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     21 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2222 * @uses WC_Payment_Gateway_CC
    2323 */
     
    9797     */
    9898    public $surcharge_flat_rate;
     99
     100    /**
     101     * Valor Pay surcharge for debit.
     102     *
     103     * @var string
     104     */
     105    public $surcharge_for_debit;
    99106
    100107    /**
     
    166173        $this->surcharge_percentage          = $this->get_option( 'surcharge_percentage' );
    167174        $this->surcharge_flat_rate           = $this->get_option( 'surcharge_flat_rate' );
     175        $this->surcharge_for_debit           = $this->get_option( 'surcharge_for_debit' );
    168176        $this->cardtypes                     = $this->get_option( 'cardtypes' );
    169177        $this->avs_type                      = $this->get_option( 'avs_type' );
     
    322330    public function validate_fields() {
    323331        try {
     332            $valorpay_avs_type = ( isset( $_POST['valorpay_avs_type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_type'] ) ) : ''; // phpcs:ignore
     333            if ( 'zip' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) {
     334                if ( ! isset( $_POST['valorpay_avs_zip'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) { // phpcs:ignore
     335                    throw new Exception( __( 'Zip Code is required.', 'wc-valorpay' ) );
     336                }
     337                if ( isset( $_POST['valorpay_avs_zip'] ) && sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) && ! preg_match( '/^([a-zA-Z0-9_-]){4,6}$/', sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) ) { // phpcs:ignore
     338                    throw new Exception( __( 'Enter a valid Zip Code.', 'wc-valorpay' ) );
     339                }
     340            }
     341            if ( 'address' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) {
     342                if ( ! isset( $_POST['valorpay_avs_street'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) { // phpcs:ignore
     343                    throw new Exception( __( 'Street No is required.', 'wc-valorpay' ) );
     344                }
     345                if ( isset( $_POST['valorpay_avs_street'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) > 25 ) { // phpcs:ignore
     346                    throw new Exception( __( 'Enter a valid Street No.', 'wc-valorpay' ) );
     347                }
     348            }
    324349            if ( isset( $_POST['wc-wc_valorpay-payment-token'] ) && 'new' !== wc_clean( $_POST['wc-wc_valorpay-payment-token'] ) ) { // phpcs:ignore
    325350                return true;
     
    526551                'default'     => 0,
    527552                'description' => __( 'Flat rate  will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $', 'wc-valorpay' ),
     553            ),
     554            'surcharge_for_debit'           => array(
     555                'title'       => __( 'Surcharge For Debit', 'wc-valorpay' ),
     556                'label'       => __( 'Enable Surcharge For Debit', 'wc-valorpay' ),
     557                'type'        => 'checkbox',
     558                'description' => __( 'Enable surcharge for debit', 'wc-valorpay' ),
     559                'default'     => 'yes',
    528560            ),
    529561            'avs_type'                      => array(
     
    704736                    $exp_date            = $exp_month . substr( $exp_year, -2 );
    705737                    $response->card_type = $valorpay_api->get_card_type( str_replace( ' ', '', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) ) ); // phpcs:ignore
    706                     $this->save_card( $response, $exp_date );
     738                    $this->save_card( $response, $exp_date, ( 'D' === WC()->session->get( 'valor_card_type' ) ) ? 1 : 0 );
    707739                }
    708740
     
    722754                );
    723755            } else {
    724                 if ( isset( $response->errors['valorpos_error'][0] ) ) {
     756                if ( isset( $response->errors['valorpay_error'][0] ) ) {
    725757                    /* translators: %s: API Error Message. */
    726                     $order->add_order_note( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpos_error'][0] ) );
     758                    $order->add_order_note( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpay_error'][0] ) );
    727759                    $this->add_failed_count_by_ip( $order );
    728760                    /* translators: %s: API Error Message. */
    729                     throw new Exception( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpos_error'][0] ) );
     761                    throw new Exception( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpay_error'][0] ) );
    730762                }
    731763                throw new Exception( __( 'Unable to process the transaction using Valor Pay, please try again.', 'wc-valorpay' ) );
     
    744776     * Save card.
    745777     *
    746      * @param Object $response Response.
     778     * @param object $response Response.
    747779     * @param string $exp_date Expiry Date.
     780     * @param int    $is_debit Is Debit Card.
    748781     * @return void
    749782     */
    750     protected function save_card( $response, $exp_date ) {
     783    protected function save_card( $response, $exp_date, $is_debit ) {
    751784        if ( $response->token ) {
    752785            $token = new WC_Payment_Token_CC();
     
    758791            $token->set_expiry_year( '20' . substr( $exp_date, -2 ) );
    759792            $token->set_user_id( get_current_user_id() );
     793            $token->add_meta_data( 'is_debit', $is_debit );
    760794            $token->save();
    761795        }
  • valorpos/trunk/includes/class-wc-valorpay-i18n.php

    r2883367 r2980555  
    2626 * @package    Wc_Valorpay
    2727 * @subpackage Wc_Valorpay/includes
    28  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     28 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2929 */
    3030class Wc_Valorpay_I18n {
  • valorpos/trunk/includes/class-wc-valorpay-loader.php

    r2883367 r2980555  
    2323 * @package    Wc_Valorpay
    2424 * @subpackage Wc_Valorpay/includes
    25  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     25 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2626 */
    2727class Wc_Valorpay_Loader {
  • valorpos/trunk/includes/class-wc-valorpay.php

    r2918841 r2980555  
    2525 * @package    Wc_Valorpay
    2626 * @subpackage Wc_Valorpay/includes
    27  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     27 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2828 */
    2929class Wc_Valorpay {
     
    197197
    198198        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts_and_styles' );
    199         $this->loader->add_action( 'woocommerce_after_checkout_validation', $plugin_public, 'valorpay_avs_checkout_validation', 10, 2 );
    200199        $this->loader->add_action( 'woocommerce_cart_calculate_fees', $plugin_public, 'valorpay_custom_surcharge' );
    201200        $this->loader->add_action( 'woocommerce_before_checkout_form', $plugin_public, 'valorpay_before_checkout_form' );
    202         $this->loader->add_action( 'woocommerce_after_checkout_form', $plugin_public, 'valorpay_checkout_script' );
     201        $this->loader->add_action( 'woocommerce_review_order_before_payment', $plugin_public, 'valorpay_update_token_card_type' );
    203202        $this->loader->add_filter( 'woocommerce_available_payment_gateways', $plugin_public, 'valorpay_disable_payment_gateway_failed_orders' );
     203        $this->loader->add_action( 'wc_ajax_valorpay_create_page_token', $plugin_public, 'valorpay_create_page_token' );
     204        $this->loader->add_action( 'wc_ajax_valorpay_bin_lookup', $plugin_public, 'valorpay_bin_lookup' );
     205        $this->loader->add_action( 'wc_ajax_valorpay_token_card_type', $plugin_public, 'valorpay_token_card_type' );
    204206
    205207    }
  • valorpos/trunk/languages/wc-valorpay.pot

    r2960359 r2980555  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Valor Pay 7.3.0\n"
    6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-valorpay\n"
     5"Project-Id-Version: Valor Pay 7.4.0\n"
     6"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/valorpos\n"
    77"Last-Translator: Valor Paytech LLC <sales@valorpaytech.com>\n"
    88"MIME-Version: 1.0\n"
    99"Content-Type: text/plain; charset=UTF-8\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "POT-Creation-Date: 2023-05-19T15:31:04+05:30\n"
    12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     11"POT-Creation-Date: 2023-10-18T08:57:12+00:00\n"
     12"PO-Revision-Date: 2023-10-18T08:57:12+00:00\n"
    1313"X-Generator: WP-CLI 2.7.1\n"
    1414"X-Domain: wc-valorpay\n"
    1515
    1616#. Plugin Name of the plugin
    17 #: includes/class-wc-valorpay-gateway.php:455
     17#: includes/class-wc-valorpay-gateway.php:480
    1818msgid "Valor Pay"
    1919msgstr ""
     
    6969
    7070#: admin/partials/wc-valorpay-admin-failure-tracker.php:18
    71 #: includes/class-wc-valorpay-gateway.php:543
     71#: includes/class-wc-valorpay-gateway.php:575
    7272msgid "Payment Failed Tracker"
    7373msgstr ""
     
    122122msgstr ""
    123123
    124 #: includes/class-wc-valorpay-api.php:289
    125 #: includes/class-wc-valorpay-api.php:294
    126 #: includes/class-wc-valorpay-api.php:302
     124#: includes/class-wc-valorpay-api.php:337
     125#: includes/class-wc-valorpay-api.php:342
     126#: includes/class-wc-valorpay-api.php:350
     127#: includes/class-wc-valorpay-api.php:354
    127128msgid "There was a problem connecting to the payment gateway."
    128129msgstr ""
    129130
    130 #: includes/class-wc-valorpay-gateway.php:143
     131#: includes/class-wc-valorpay-gateway.php:150
    131132msgid "ValorPay Plugin"
    132133msgstr ""
    133134
    134 #: includes/class-wc-valorpay-gateway.php:144
     135#: includes/class-wc-valorpay-gateway.php:151
    135136msgid "Take payments via Valorpay."
    136137msgstr ""
    137138
    138 #: includes/class-wc-valorpay-gateway.php:176
     139#: includes/class-wc-valorpay-gateway.php:184
    139140msgid "TEST MODE ENABLED. Use test card number 4111111111111111 with 999 as CVC and a future expiration date."
    140141msgstr ""
    141142
    142 #: includes/class-wc-valorpay-gateway.php:200
     143#: includes/class-wc-valorpay-gateway.php:208
    143144msgid "Unsupported currency:"
    144145msgstr ""
    145146
    146 #: includes/class-wc-valorpay-gateway.php:203
     147#: includes/class-wc-valorpay-gateway.php:211
    147148msgid "Valor Pay accepts only USD."
    148149msgstr ""
    149150
    150151#. translators: %s: Settings URL.
    151 #: includes/class-wc-valorpay-gateway.php:215
     152#: includes/class-wc-valorpay-gateway.php:223
    152153msgid "Valor Pay error: The APP ID is required.  %s"
    153154msgstr ""
    154155
    155 #: includes/class-wc-valorpay-gateway.php:216
    156 #: includes/class-wc-valorpay-gateway.php:227
    157 #: includes/class-wc-valorpay-gateway.php:236
     156#: includes/class-wc-valorpay-gateway.php:224
     157#: includes/class-wc-valorpay-gateway.php:235
     158#: includes/class-wc-valorpay-gateway.php:244
    158159msgid "Click here to update your Valor Pay settings."
    159160msgstr ""
    160161
    161162#. translators: %s: Settings URL.
    162 #: includes/class-wc-valorpay-gateway.php:226
     163#: includes/class-wc-valorpay-gateway.php:234
    163164msgid "Valor Pay error: The APP KEY is required.  %s"
    164165msgstr ""
    165166
    166167#. translators: %s: Settings URL.
    167 #: includes/class-wc-valorpay-gateway.php:235
     168#: includes/class-wc-valorpay-gateway.php:243
    168169msgid "Valor Pay error: The EPI is required.  %s"
    169170msgstr ""
    170171
    171 #: includes/class-wc-valorpay-gateway.php:332
     172#: includes/class-wc-valorpay-gateway.php:335
     173msgid "Zip Code is required."
     174msgstr ""
     175
     176#: includes/class-wc-valorpay-gateway.php:338
     177msgid "Enter a valid Zip Code."
     178msgstr ""
     179
     180#: includes/class-wc-valorpay-gateway.php:343
     181msgid "Street No is required."
     182msgstr ""
     183
     184#: includes/class-wc-valorpay-gateway.php:346
     185msgid "Enter a valid Street No."
     186msgstr ""
     187
     188#: includes/class-wc-valorpay-gateway.php:357
    172189msgid "Card number is invalid"
    173190msgstr ""
    174191
    175 #: includes/class-wc-valorpay-gateway.php:336
     192#: includes/class-wc-valorpay-gateway.php:361
    176193msgid "Not a valid card"
    177194msgstr ""
    178195
    179 #: includes/class-wc-valorpay-gateway.php:339
     196#: includes/class-wc-valorpay-gateway.php:364
    180197msgid "Card number  expired"
    181198msgstr ""
    182199
    183 #: includes/class-wc-valorpay-gateway.php:342
     200#: includes/class-wc-valorpay-gateway.php:367
    184201msgid "Card security code is invalid (only digits are allowed)"
    185202msgstr ""
    186203
    187204#. translators: 1: Terms and Conditions URL.
    188 #: includes/class-wc-valorpay-gateway.php:378
     205#: includes/class-wc-valorpay-gateway.php:403
    189206msgid "I agree to the <a href=\"%s\" target=\"_blank\">Terms and Conditions</a>"
    190207msgstr ""
    191208
    192 #: includes/class-wc-valorpay-gateway.php:409
    193 #: includes/class-wc-valorpay-gateway.php:410
     209#: includes/class-wc-valorpay-gateway.php:434
     210#: includes/class-wc-valorpay-gateway.php:435
    194211msgid "Zip Code"
    195212msgstr ""
    196213
    197 #: includes/class-wc-valorpay-gateway.php:423
    198 #: includes/class-wc-valorpay-gateway.php:424
     214#: includes/class-wc-valorpay-gateway.php:448
     215#: includes/class-wc-valorpay-gateway.php:449
    199216msgid "Street No"
    200217msgstr ""
    201218
    202 #: includes/class-wc-valorpay-gateway.php:445
     219#: includes/class-wc-valorpay-gateway.php:470
    203220msgid "Enable/Disable"
    204221msgstr ""
    205222
    206 #: includes/class-wc-valorpay-gateway.php:446
     223#: includes/class-wc-valorpay-gateway.php:471
    207224msgid "Enable Valor Pay"
    208225msgstr ""
    209226
    210 #: includes/class-wc-valorpay-gateway.php:452
     227#: includes/class-wc-valorpay-gateway.php:477
    211228msgid "Title"
    212229msgstr ""
    213230
    214 #: includes/class-wc-valorpay-gateway.php:454
     231#: includes/class-wc-valorpay-gateway.php:479
    215232msgid "This controls the title which the user sees during checkout."
    216233msgstr ""
    217234
    218 #: includes/class-wc-valorpay-gateway.php:459
     235#: includes/class-wc-valorpay-gateway.php:484
    219236msgid "Use Sandbox"
    220237msgstr ""
    221238
    222 #: includes/class-wc-valorpay-gateway.php:460
     239#: includes/class-wc-valorpay-gateway.php:485
    223240msgid "Enable sandbox mode - live payments will not be taken if enabled."
    224241msgstr ""
    225242
    226 #: includes/class-wc-valorpay-gateway.php:466
     243#: includes/class-wc-valorpay-gateway.php:491
    227244msgid "APP ID"
    228245msgstr ""
    229246
    230 #: includes/class-wc-valorpay-gateway.php:468
     247#: includes/class-wc-valorpay-gateway.php:493
    231248msgid "Please email support@valorpaytech.com to get to know about your APP ID, ( In demo mode APP ID is not needed )"
    232249msgstr ""
    233250
    234 #: includes/class-wc-valorpay-gateway.php:472
     251#: includes/class-wc-valorpay-gateway.php:497
    235252msgid "APP KEY"
    236253msgstr ""
    237254
    238 #: includes/class-wc-valorpay-gateway.php:474
     255#: includes/class-wc-valorpay-gateway.php:499
    239256msgid "Please email support@valorpaytech.com to get to know about your APP KEY, ( In demo mode APP KEY is not needed )"
    240257msgstr ""
    241258
    242 #: includes/class-wc-valorpay-gateway.php:478
     259#: includes/class-wc-valorpay-gateway.php:503
    243260msgid "EPI"
    244261msgstr ""
    245262
    246 #: includes/class-wc-valorpay-gateway.php:480
     263#: includes/class-wc-valorpay-gateway.php:505
    247264msgid "Please email support@valorpaytech.com to get to know about your EPI ID, ( In demo mode EPI ID is not needed )"
    248265msgstr ""
    249266
    250 #: includes/class-wc-valorpay-gateway.php:484
     267#: includes/class-wc-valorpay-gateway.php:509
    251268msgid "Payment Method"
    252269msgstr ""
    253270
    254 #: includes/class-wc-valorpay-gateway.php:494
     271#: includes/class-wc-valorpay-gateway.php:519
    255272msgid "Surcharge Mode"
    256273msgstr ""
    257274
    258 #: includes/class-wc-valorpay-gateway.php:495
    259 #: includes/class-wc-valorpay-gateway.php:502
     275#: includes/class-wc-valorpay-gateway.php:520
     276#: includes/class-wc-valorpay-gateway.php:527
    260277msgid "Enable Surcharge Mode"
    261278msgstr ""
    262279
    263 #: includes/class-wc-valorpay-gateway.php:497
     280#: includes/class-wc-valorpay-gateway.php:522
    264281msgid "Enable only if you want all transactions to be fall on surcharge mode, Merchant must have got an Surcharge MID inorder to work"
    265282msgstr ""
    266283
    267 #: includes/class-wc-valorpay-gateway.php:501
     284#: includes/class-wc-valorpay-gateway.php:526
    268285msgid "Surcharge Type"
    269286msgstr ""
    270287
    271 #: includes/class-wc-valorpay-gateway.php:511
    272 #: includes/class-wc-valorpay-gateway.php:512
     288#: includes/class-wc-valorpay-gateway.php:536
     289#: includes/class-wc-valorpay-gateway.php:537
    273290msgid "Surcharge Label"
    274291msgstr ""
    275292
    276 #: includes/class-wc-valorpay-gateway.php:517
     293#: includes/class-wc-valorpay-gateway.php:542
    277294msgid "Surcharge %"
    278295msgstr ""
    279296
    280 #: includes/class-wc-valorpay-gateway.php:521
     297#: includes/class-wc-valorpay-gateway.php:546
    281298msgid "Percentage will apply only on enabling on surcharge Indicator to true and Surcharge type is set fo Surcharge %"
    282299msgstr ""
    283300
    284 #: includes/class-wc-valorpay-gateway.php:524
     301#: includes/class-wc-valorpay-gateway.php:549
    285302msgid "Flat Rate $"
    286303msgstr ""
    287304
    288 #: includes/class-wc-valorpay-gateway.php:527
     305#: includes/class-wc-valorpay-gateway.php:552
    289306msgid "Flat rate  will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $"
    290307msgstr ""
    291308
    292 #: includes/class-wc-valorpay-gateway.php:530
     309#: includes/class-wc-valorpay-gateway.php:555
     310msgid "Surcharge For Debit"
     311msgstr ""
     312
     313#: includes/class-wc-valorpay-gateway.php:556
     314msgid "Enable Surcharge For Debit"
     315msgstr ""
     316
     317#: includes/class-wc-valorpay-gateway.php:558
     318msgid "Enable surcharge for debit"
     319msgstr ""
     320
     321#: includes/class-wc-valorpay-gateway.php:562
    293322msgid "AVS"
    294323msgstr ""
    295324
    296 #: includes/class-wc-valorpay-gateway.php:540
     325#: includes/class-wc-valorpay-gateway.php:572
    297326msgid "The address verification service will add a text field to the checkout page based on the above option."
    298327msgstr ""
    299328
    300 #: includes/class-wc-valorpay-gateway.php:544
     329#: includes/class-wc-valorpay-gateway.php:576
    301330msgid "Enable Protection"
    302331msgstr ""
    303332
    304333#. translators: 1: Tracker URL.
    305 #: includes/class-wc-valorpay-gateway.php:548
     334#: includes/class-wc-valorpay-gateway.php:580
    306335msgid "Disable the payment method in the checkout page for failed transactions. <a id=\"valorpay-goto-tracker\" href=\"%s\">Unblock IP</a>"
    307336msgstr ""
    308337
    309 #: includes/class-wc-valorpay-gateway.php:554
     338#: includes/class-wc-valorpay-gateway.php:586
    310339msgid "Declined Transaction Count"
    311340msgstr ""
    312341
    313 #: includes/class-wc-valorpay-gateway.php:555
     342#: includes/class-wc-valorpay-gateway.php:587
    314343msgid "Number of declined transaction count."
    315344msgstr ""
    316345
    317 #: includes/class-wc-valorpay-gateway.php:559
     346#: includes/class-wc-valorpay-gateway.php:591
    318347msgid "3"
    319348msgstr ""
    320349
    321 #: includes/class-wc-valorpay-gateway.php:560
     350#: includes/class-wc-valorpay-gateway.php:592
    322351msgid "5"
    323352msgstr ""
    324353
    325 #: includes/class-wc-valorpay-gateway.php:561
     354#: includes/class-wc-valorpay-gateway.php:593
    326355msgid "6"
    327356msgstr ""
    328357
    329 #: includes/class-wc-valorpay-gateway.php:565
     358#: includes/class-wc-valorpay-gateway.php:597
    330359msgid "Block Payment For"
    331360msgstr ""
    332361
    333 #: includes/class-wc-valorpay-gateway.php:566
     362#: includes/class-wc-valorpay-gateway.php:598
    334363msgid "Minutes to block payment gateway in checkout."
    335364msgstr ""
    336365
    337 #: includes/class-wc-valorpay-gateway.php:570
     366#: includes/class-wc-valorpay-gateway.php:602
    338367msgid "1 min"
    339368msgstr ""
    340369
    341 #: includes/class-wc-valorpay-gateway.php:571
     370#: includes/class-wc-valorpay-gateway.php:603
    342371msgid "5 min"
    343372msgstr ""
    344373
    345 #: includes/class-wc-valorpay-gateway.php:572
     374#: includes/class-wc-valorpay-gateway.php:604
    346375msgid "10 min"
    347376msgstr ""
    348377
    349 #: includes/class-wc-valorpay-gateway.php:573
     378#: includes/class-wc-valorpay-gateway.php:605
    350379msgid "1 hour"
    351380msgstr ""
    352381
    353 #: includes/class-wc-valorpay-gateway.php:574
     382#: includes/class-wc-valorpay-gateway.php:606
    354383msgid "3 hour"
    355384msgstr ""
    356385
    357 #: includes/class-wc-valorpay-gateway.php:575
     386#: includes/class-wc-valorpay-gateway.php:607
    358387msgid "5 hour"
    359388msgstr ""
    360389
    361 #: includes/class-wc-valorpay-gateway.php:576
     390#: includes/class-wc-valorpay-gateway.php:608
    362391msgid "10 hour"
    363392msgstr ""
    364393
    365 #: includes/class-wc-valorpay-gateway.php:577
     394#: includes/class-wc-valorpay-gateway.php:609
    366395msgid "1 day"
    367396msgstr ""
    368397
    369 #: includes/class-wc-valorpay-gateway.php:581
     398#: includes/class-wc-valorpay-gateway.php:613
    370399msgid "Accepted Cards"
    371400msgstr ""
    372401
    373 #: includes/class-wc-valorpay-gateway.php:585
     402#: includes/class-wc-valorpay-gateway.php:617
    374403msgid "Select the card types to accept."
    375404msgstr ""
    376405
    377406#. translators: 1: Maximum percentage.
    378 #: includes/class-wc-valorpay-gateway.php:624
     407#: includes/class-wc-valorpay-gateway.php:656
    379408msgid "Surcharge percentage cannot be more than %s"
    380409msgstr ""
    381410
    382411#. translators: 1: Maximum flat rate.
    383 #: includes/class-wc-valorpay-gateway.php:629
     412#: includes/class-wc-valorpay-gateway.php:661
    384413msgid "Surcharge flat rate cannot be more than %s"
    385414msgstr ""
    386415
    387 #: includes/class-wc-valorpay-gateway.php:674
     416#: includes/class-wc-valorpay-gateway.php:706
    388417msgid "Invalid card information."
    389418msgstr ""
    390419
    391420#. translators: 1: Error Message, 2: Amount, 3: Line Break, 4: Approval Code, 5: Line Break, 6: RRN Number.
    392 #: includes/class-wc-valorpay-gateway.php:690
     421#: includes/class-wc-valorpay-gateway.php:722
    393422msgid "Valor Pay %1$s for %2$s.%3$s <strong>Approval Code:</strong> %4$s.%5$s <strong>RRN:</strong> %6$s"
    394423msgstr ""
    395424
    396425#. translators: %s: API Error Message.
    397 #: includes/class-wc-valorpay-gateway.php:726
    398 #: includes/class-wc-valorpay-gateway.php:729
     426#: includes/class-wc-valorpay-gateway.php:758
     427#: includes/class-wc-valorpay-gateway.php:761
    399428msgid "Payment error: %s"
    400429msgstr ""
    401430
    402 #: includes/class-wc-valorpay-gateway.php:731
     431#: includes/class-wc-valorpay-gateway.php:763
    403432msgid "Unable to process the transaction using Valor Pay, please try again."
    404433msgstr ""
    405434
    406435#. translators: 1: Disable Time, 2: Unblock IP URL, 3: Customer IP.
    407 #: includes/class-wc-valorpay-gateway.php:790
     436#: includes/class-wc-valorpay-gateway.php:824
    408437msgid "Valor Pay method is disabled for %1$s. <a target=\"_blank\" href=\"%2$s\">To Unblock IP</a> %3$s"
    409438msgstr ""
    410439
    411 #: includes/class-wc-valorpay-gateway.php:853
     440#: includes/class-wc-valorpay-gateway.php:887
    412441msgid "Refund failed."
    413442msgstr ""
    414443
    415444#. translators: 1: Amount, 2: Line Break, 3: Approval code, 4: Line Break, 5: RRN Code
    416 #: includes/class-wc-valorpay-gateway.php:865
     445#: includes/class-wc-valorpay-gateway.php:899
    417446msgid "Valor Pay Refund for %1$s.%2$s <strong>Approval Code:</strong> %3$s.%4$s <strong>RRN:</strong> %5$s"
    418447msgstr ""
    419448
    420 #: public/class-wc-valorpay-public.php:80
     449#: public/class-wc-valorpay-public.php:88
    421450msgid "Please enter a card number"
    422451msgstr ""
    423452
    424 #: public/class-wc-valorpay-public.php:81
     453#: public/class-wc-valorpay-public.php:89
    425454msgid "Invalid card number"
    426455msgstr ""
    427456
    428 #: public/class-wc-valorpay-public.php:82
     457#: public/class-wc-valorpay-public.php:90
    429458msgid "Card is expired"
    430459msgstr ""
    431460
    432 #: public/class-wc-valorpay-public.php:83
     461#: public/class-wc-valorpay-public.php:91
    433462msgid "Please enter card expiry date"
    434463msgstr ""
    435464
    436 #: public/class-wc-valorpay-public.php:84
     465#: public/class-wc-valorpay-public.php:92
    437466msgid "Please enter a CVC"
    438467msgstr ""
    439468
    440 #: public/class-wc-valorpay-public.php:85
     469#: public/class-wc-valorpay-public.php:93
    441470msgid "Invalid CVC length"
    442471msgstr ""
    443472
    444 #: public/class-wc-valorpay-public.php:86
     473#: public/class-wc-valorpay-public.php:94
    445474msgid "Please enter a zip code"
    446475msgstr ""
    447476
    448 #: public/class-wc-valorpay-public.php:87
     477#: public/class-wc-valorpay-public.php:95
    449478msgid "Invalid zip code"
    450479msgstr ""
    451480
    452 #: public/class-wc-valorpay-public.php:88
     481#: public/class-wc-valorpay-public.php:96
    453482msgid "Please enter a street address"
    454483msgstr ""
    455484
    456 #: public/class-wc-valorpay-public.php:108
    457 msgid "Zip Code is required."
    458 msgstr ""
    459 
    460 #: public/class-wc-valorpay-public.php:111
    461 msgid "Enter a valid Zip Code."
    462 msgstr ""
    463 
    464 #: public/class-wc-valorpay-public.php:116
    465 msgid "Street No is required."
    466 msgstr ""
    467 
    468 #: public/class-wc-valorpay-public.php:119
    469 msgid "Enter a valid Street No."
    470 msgstr ""
     485#: public/class-wc-valorpay-public.php:97
     486msgid "Unable to process payment. Please try again."
     487msgstr ""
     488
     489#: public/class-wc-valorpay-public.php:244
     490#: public/class-wc-valorpay-public.php:272
     491#: public/class-wc-valorpay-public.php:312
     492msgid "Invalid request method."
     493msgstr ""
     494
     495#: public/class-wc-valorpay-public.php:251
     496#: public/class-wc-valorpay-public.php:282
     497msgid "Payment gateway missing."
     498msgstr ""
     499
     500#: public/class-wc-valorpay-public.php:257
     501msgid "Unable to create page token."
     502msgstr ""
     503
     504#: public/class-wc-valorpay-public.php:278
     505#: public/class-wc-valorpay-public.php:318
     506msgid "Invalid request."
     507msgstr ""
     508
     509#: public/class-wc-valorpay-public.php:299
     510msgid "Unable to lookup bin."
     511msgstr ""
     512
     513#: public/class-wc-valorpay-public.php:338
     514msgid "Unable to set card type."
     515msgstr ""
  • valorpos/trunk/public/class-wc-valorpay-public.php

    r2918841 r2980555  
    1919 * @package    Wc_Valorpay
    2020 * @subpackage Wc_Valorpay/public
    21  * @author     Valor Paytech LLC <isv@valorpaytech.com>
     21 * @author     Valor PayTech LLC <isv@valorpaytech.com>
    2222 */
    2323class Wc_Valorpay_Public {
     
    6060     * @since    1.0.0
    6161     */
     62    /**
     63     * Register the JavaScript and CSS for the public area.
     64     *
     65     * @since    1.0.0
     66     */
    6267    public function enqueue_scripts_and_styles() {
    6368        if ( is_checkout() ) {
     69            $all_payment_methods = WC()->payment_gateways()->payment_gateways();
     70            if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) {
     71                return;
     72            }
     73
    6474            wp_enqueue_style( $this->plugin_name, plugins_url( 'css/wc-valorpay-checkout.css', __FILE__ ), array(), $this->version );
    65         }
    66     }
    67 
    68     /**
    69      * Register the JavaScript for the public-facing side of the site.
    70      *
    71      * @since    1.0.0
    72      */
    73     public function valorpay_checkout_script() {
    74 
    75         wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-checkout.js', array( 'jquery' ), $this->version, false );
    76         wp_localize_script(
    77             $this->plugin_name,
    78             'valorpay_checkout_object',
    79             array(
    80                 'error_card'            => __( 'Please enter a card number', 'wc-valorpay' ),
    81                 'invalid_card'          => __( 'Invalid card number', 'wc-valorpay' ),
    82                 'expiry_card'           => __( 'Card is expired', 'wc-valorpay' ),
    83                 'invalid_expiry'        => __( 'Please enter card expiry date', 'wc-valorpay' ),
    84                 'error_cvv'             => __( 'Please enter a CVC', 'wc-valorpay' ),
    85                 'invalid_cvv'           => __( 'Invalid CVC length', 'wc-valorpay' ),
    86                 'avs_zip_error'         => __( 'Please enter a zip code', 'wc-valorpay' ),
    87                 'invalid_avs_zip_error' => __( 'Invalid zip code', 'wc-valorpay' ),
    88                 'avs_street_error'      => __( 'Please enter a street address', 'wc-valorpay' ),
    89             )
    90         );
    91 
    92     }
    93 
    94     /**
    95      * AVS checkout validation
    96      *
    97      * @since 1.0.0
    98      *
    99      * @param  array    $fields   An array of posted data.
    100      * @param  WP_Error $errors Validation errors.
    101      * @return void
    102      */
    103     public function valorpay_avs_checkout_validation( $fields, $errors ) {
    104         if ( ( isset( $fields['payment_method'] ) && 'wc_valorpay' === $fields['payment_method'] ) ) {
    105             $valorpay_avs_type = ( isset( $_POST['valorpay_avs_type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_type'] ) ) : ''; // phpcs:ignore
    106             if ( 'zip' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) {
    107                 if ( ! isset( $_POST['valorpay_avs_zip'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) { // phpcs:ignore
    108                     $errors->add( 'validation', __( 'Zip Code is required.', 'wc-valorpay' ) );
    109                 }
    110                 if ( isset( $_POST['valorpay_avs_zip'] ) && sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) && ! preg_match( '/^([a-zA-Z0-9_-]){4,6}$/', sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) ) { // phpcs:ignore
    111                     $errors->add( 'validation', __( 'Enter a valid Zip Code.', 'wc-valorpay' ) );
    112                 }
    113             }
    114             if ( 'address' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) {
    115                 if ( ! isset( $_POST['valorpay_avs_street'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) { // phpcs:ignore
    116                     $errors->add( 'validation', __( 'Street No is required.', 'wc-valorpay' ) );
    117                 }
    118                 if ( isset( $_POST['valorpay_avs_street'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) > 25 ) { // phpcs:ignore
    119                     $errors->add( 'validation', __( 'Enter a valid Street No.', 'wc-valorpay' ) );
    120                 }
    121             }
     75            wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-checkout.js', array( 'jquery' ), $this->version, false );
     76            wp_localize_script(
     77                $this->plugin_name,
     78                'valorpay_checkout_object',
     79                array(
     80                    'ajax_url'              => admin_url( 'admin-ajax.php' ),
     81                    'wc_ajax_action'        => WC_AJAX::get_endpoint( '%%endpoint_url%%' ),
     82                    'ct_ajax_action'        => 'valorpay_create_page_token',
     83                    'ct_ajax_nonce'         => wp_create_nonce( 'valorpay_create_page_token' ),
     84                    'bl_ajax_action'        => 'valorpay_bin_lookup',
     85                    'bl_ajax_nonce'         => wp_create_nonce( 'valorpay_bin_lookup' ),
     86                    'card_type_ajax_action' => 'valorpay_token_card_type',
     87                    'card_type_ajax_nonce'  => wp_create_nonce( 'valorpay_token_card_type' ),
     88                    'error_card'            => __( 'Please enter a card number', 'wc-valorpay' ),
     89                    'invalid_card'          => __( 'Invalid card number', 'wc-valorpay' ),
     90                    'expiry_card'           => __( 'Card is expired', 'wc-valorpay' ),
     91                    'invalid_expiry'        => __( 'Please enter card expiry date', 'wc-valorpay' ),
     92                    'error_cvv'             => __( 'Please enter a CVC', 'wc-valorpay' ),
     93                    'invalid_cvv'           => __( 'Invalid CVC length', 'wc-valorpay' ),
     94                    'avs_zip_error'         => __( 'Please enter a zip code', 'wc-valorpay' ),
     95                    'invalid_avs_zip_error' => __( 'Invalid zip code', 'wc-valorpay' ),
     96                    'avs_street_error'      => __( 'Please enter a street address', 'wc-valorpay' ),
     97                    'card_token_error'      => __( 'Unable to process payment. Please try again.', 'wc-valorpay' ),
     98                )
     99            );
    122100        }
    123101    }
     
    138116
    139117        if ( 'wc_valorpay' === $payment_method && 'yes' === $valorpay->surcharge_indicator && 'yes' === $valorpay->enabled ) {
     118            if ( 'D' === WC()->session->get( 'valor_card_type' ) && 'no' === $valorpay->surcharge_for_debit ) {
     119                return;
     120            }
    140121            $surcharge = 0;
    141122            if ( 'percentage' === $valorpay->surcharge_type ) {
     
    228209        }
    229210    }
     211
     212    /**
     213     * Fetch card type for the default save token.
     214     *
     215     * @since 7.4.0
     216     */
     217    public function valorpay_update_token_card_type() {
     218        $current_user_id = get_current_user_id();
     219        if ( $current_user_id ) {
     220            $token = WC_Payment_Tokens::get_customer_default_token( $current_user_id );
     221            if ( ! $token || null === $token ) {
     222                WC()->session->__unset( 'valor_card_type' );
     223            } elseif ( 'wc_valorpay' === $token->get_gateway_id() ) {
     224                $card_type = $token->get_meta( 'is_debit' ) === '1' ? 'D' : 'C';
     225                // Check if card type not same.
     226                if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) {
     227                    WC()->session->set( 'valor_card_type', $card_type );
     228                }
     229            } else {
     230                WC()->session->__unset( 'valor_card_type' );
     231            }
     232        } else {
     233            WC()->session->__unset( 'valor_card_type' );
     234        }
     235    }
     236
     237    /**
     238     * Create page token.
     239     *
     240     * @since 7.4.0
     241     */
     242    public function valorpay_create_page_token() {
     243        if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
     244            wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) );
     245        }
     246        if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_create_page_token' ) ) {
     247            wp_send_json_error( 'invalid_nonce' );
     248        }
     249        $all_payment_methods = WC()->payment_gateways()->payment_gateways();
     250        if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) {
     251            wp_send_json_error( array( 'message' => __( 'Payment gateway missing.', 'wc-valorpay' ) ) );
     252        }
     253        $valorpay     = $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ];
     254        $valorpay_api = new WC_ValorPay_API( $valorpay );
     255        $api_response = $valorpay_api->create_checkout_page_token();
     256        if ( is_wp_error( $api_response ) || ! is_object( $api_response ) || ! isset( $api_response->clientToken ) ) { // phpcs:ignore
     257            wp_send_json_error( array( 'message' => __( 'Unable to create page token.', 'wc-valorpay' ) ) );
     258        } else {
     259            wp_send_json_success( array( 'token' => $api_response->clientToken ) ); // phpcs:ignore
     260        }
     261    }
     262
     263    /**
     264     * Bin lookup.
     265     *
     266     * @since 7.4.0
     267     * @throws Exception If error.
     268     */
     269    public function valorpay_bin_lookup() {
     270        try {
     271            if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
     272                wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) );
     273            }
     274            if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_bin_lookup' ) ) {
     275                wp_send_json_error( 'invalid_nonce' );
     276            }
     277            if ( ! isset( $_REQUEST['client_token'] ) || ! isset( $_REQUEST['bin'] ) ) {
     278                wp_send_json_error( array( 'message' => __( 'Invalid request.', 'wc-valorpay' ) ) );
     279            }
     280            $all_payment_methods = WC()->payment_gateways()->payment_gateways();
     281            if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) {
     282                wp_send_json_error( array( 'message' => __( 'Payment gateway missing.', 'wc-valorpay' ) ) );
     283            }
     284            $need_update  = false;
     285            $valorpay     = $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ];
     286            $valorpay_api = new WC_ValorPay_API( $valorpay );
     287            $api_response = $valorpay_api->bin_lookup( sanitize_text_field( wp_unslash( $_REQUEST['bin'] ) ), sanitize_text_field( wp_unslash( $_REQUEST['client_token'] ) ) );
     288            if ( is_wp_error( $api_response ) ) { // phpcs:ignore
     289                throw new Exception( 'Error' );
     290            }
     291            $card_type = $api_response->card_type;
     292            // If card type same as previous value, no need to update.
     293            if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) {
     294                WC()->session->set( 'valor_card_type', $api_response->card_type );
     295                $need_update = true;
     296            }
     297            wp_send_json_success( $need_update );
     298        } catch ( Exception $ex ) {
     299            wp_send_json_error( array( 'message' => __( 'Unable to lookup bin.', 'wc-valorpay' ) ) );
     300        }
     301    }
     302
     303    /**
     304     * Get token card type.
     305     *
     306     * @since 7.4.0
     307     * @throws Exception If error.
     308     */
     309    public function valorpay_token_card_type() {
     310        try {
     311            if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
     312                wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) );
     313            }
     314            if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_token_card_type' ) ) {
     315                wp_send_json_error( 'invalid_nonce' );
     316            }
     317            if ( ! isset( $_REQUEST['token_id'] ) ) {
     318                wp_send_json_error( array( 'message' => __( 'Invalid request.', 'wc-valorpay' ) ) );
     319            }
     320            $need_update = false;
     321            $token_id    = sanitize_text_field( wp_unslash( $_REQUEST['token_id'] ) );
     322            if ( 'new' !== $token_id ) {
     323                $payment_token = WC_Payment_Tokens::get( $token_id );
     324                if ( $payment_token ) {
     325                    $card_type = $payment_token->get_meta( 'is_debit' ) === '1' ? 'D' : 'C';
     326                    // Check if the payment token exists.
     327                    if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) {
     328                        WC()->session->set( 'valor_card_type', $card_type );
     329                        $need_update = true;
     330                    }
     331                }
     332            } else {
     333                WC()->session->__unset( 'valor_card_type' );
     334                $need_update = true;
     335            }
     336            wp_send_json_success( $need_update );
     337        } catch ( Exception $ex ) {
     338            wp_send_json_error( array( 'message' => __( 'Unable to set card type.', 'wc-valorpay' ) ) );
     339        }
     340    }
    230341}
  • valorpos/trunk/public/js/wc-valorpay-checkout.js

    r2918841 r2980555  
    66 */
    77
    8 (function($) {
    9   "use strict";
    10 
    11   var validcard = false;
    12   var validcardexpiry = false;
    13   var validcvc = false;
    14   let luhnCheck = function(num) {
    15       var digit, digits, odd, sum, _i, _len;
    16       odd = true;
    17       sum = 0;
    18       digits = (num + "").split("").reverse();
    19       for (_i = 0, _len = digits.length; _i < _len; _i++) {
    20           digit = digits[_i];
    21           digit = parseInt(digit, 10);
    22           if ((odd = !odd)) {
    23               digit *= 2;
    24           }
    25           if (digit > 9) {
    26               digit -= 9;
    27           }
    28           sum += digit;
    29       }
    30       return sum % 10 === 0.0;
    31   };
    32 
    33   $(document).ready(function() {
    34       $("body").on("change", 'input[name="payment_method"]', function() {
    35           $("body").trigger("update_checkout");
    36       });
    37       $("body").on("blur", 'input[name="wc_valorpay-card-number"]', function() {
    38           if ($("#payment_method_wc_valorpay").is(":checked")) {
    39               var cardNum = $(this).val().replace(/ /g, "");
    40               var isValid = luhnCheck(cardNum);
    41 
    42               if (cardNum === "") {
    43                   $(this).addClass("error-class");
    44                   if (!$(this).next().hasClass("error-message")) {
    45                       $(
    46                           '<span class="error-message" style="color:red;">' +
    47                           valorpay_checkout_object.error_card +
    48                           "</span>"
    49                       ).insertAfter($(this));
    50                   }
    51                   $("#wc-wc_valorpay-card-number-error").remove();
    52                   validcard = false;
    53                   $(this).parent().addClass("woocommerce-invalid");
    54               } else if (!isValid) {
    55                   $(this).addClass("error-class");
    56                   if (!$(this).next().hasClass("error-message")) {
    57                       $(
    58                           '<span class="error-message" style="color:red;">' +
    59                           valorpay_checkout_object.invalid_card +
    60                           "</span>"
    61                       ).insertAfter($(this));
    62                   }
    63                   $("#wc-wc_valorpay-card-number-error").remove();
    64                   validcard = false;
    65                   $(this).parent().addClass("woocommerce-invalid");
    66               } else {
    67                   $(this).removeClass("error-class");
    68                   $(this).next(".error-message").remove();
    69                   validcard = true;
    70                   $(this).parent().removeClass("woocommerce-invalid");
    71               }
    72           }
    73       });
    74       $("body").on("focus", 'input[name="wc_valorpay-card-number"]', function() {
    75           if (!$(this).val()) {
    76               $(this).removeClass("error-class");
    77               $(this).next(".error-message").remove();
    78           }
    79       });
    80       $("body").on("blur", 'input[name="wc_valorpay-card-expiry"]', function() {
    81           if ($("#payment_method_wc_valorpay").is(":checked")) {
    82               var expiry = $(this).val().replace(/ /g, "");
    83               if (expiry === "") {
    84                   $(this).addClass("error-class");
    85                   if (!$(this).next().hasClass("error-message")) {
    86                       $(
    87                           '<span class="error-message" style="color:red;">' +
    88                           valorpay_checkout_object.invalid_expiry +
    89                           "</span>"
    90                       ).insertAfter($(this));
    91                   }
    92                   validcardexpiry = false;
    93                   $(this).parent().addClass("woocommerce-invalid");
    94               } else {
    95                   var parts = expiry.split("/");
    96                   var month = parseInt(parts[0], 10);
    97                   var year = parseInt(parts[1], 10);
    98                   if (year < 100) {
    99                       year += 2000;
    100                   }
    101                   if (!validateCardExpiry(month, year)) {
    102                       $(this).addClass("error-class");
    103                       if (!$(this).next().hasClass("error-message")) {
    104                           $(
    105                               '<span class="error-message" style="color:red;">' +
    106                               valorpay_checkout_object.expiry_card +
    107                               "</span>"
    108                           ).insertAfter($(this));
    109                       }
    110                       validcardexpiry = false;
    111                       $(this).parent().addClass("woocommerce-invalid");
    112                   } else {
    113                       $(this).removeClass("error-class");
    114                       $(this).next(".error-message").remove();
    115                       validcardexpiry = true;
    116                       $(this).parent().removeClass("woocommerce-invalid");
    117                   }
    118               }
    119           }
    120       });
    121 
    122       $("body").on("focus", 'input[name="wc_valorpay-card-expiry"]', function() {
    123           $(this).removeClass("error-class");
    124           $(this).next(".error-message").remove();
    125       });
    126       $("body").on("blur", "#wc_valorpay-card-cvc", function() {
    127           if ($("#payment_method_wc_valorpay").is(":checked")) {
    128               var cvcNum = $(this).val().trim();
    129               if (cvcNum === "") {
    130                   $(this).addClass("error-class");
    131                   if (!$(this).next().hasClass("error-message")) {
    132                       $(
    133                           '<span class="error-message" style="color:red;">' +
    134                           valorpay_checkout_object.error_cvv +
    135                           "</span>"
    136                       ).insertAfter($(this));
    137                   }
    138                   validcvc = false;
    139                   $(this).parent().addClass("woocommerce-invalid");
    140               } else if (cvcNum.length != 3 && cvcNum.length != 4) {
    141                   $(this).addClass("error-class");
    142                   if (!$(this).next().hasClass("error-message")) {
    143                       $(
    144                           '<span class="error-message" style="color:red;">' +
    145                           valorpay_checkout_object.invalid_cvv +
    146                           "</span>"
    147                       ).insertAfter($(this));
    148                   }
    149                   validcvc = false;
    150                   $(this).parent().addClass("woocommerce-invalid");
    151               } else {
    152                   $(this).removeClass("error-class");
    153                   $(this).next(".error-message").remove();
    154                   validcvc = true;
    155                   $(this).parent().removeClass("woocommerce-invalid");
    156               }
    157           }
    158       });
    159       $("body").on("focus", 'input[name="wc_valorpay-card-cvc"]', function() {
    160           $(this).removeClass("error-class");
    161           $(this).next(".error-message").remove();
    162       });
    163       $("form.woocommerce-checkout").on(
    164         "checkout_place_order_wc_valorpay",
    165         function() {
    166  
    167  
    168             var cardNumb = $('input[name="wc_valorpay-card-number"]').val();
    169             const isToken = $('#wc-wc_valorpay-payment-token-new');
    170             if (
    171                 isToken.length && !isToken.is(":checked")
    172             ) {
    173                 var avserrorIsValidsave = addAVSErrors();
    174                 // Do something if the radio button is checked
    175  
    176                 if (avserrorIsValidsave) {
    177                    
    178                     return true;
    179                 } else {
     8(function ($) {
     9    "use strict";
     10    var wc_valorpay_form = {
     11        validCard: false,
     12        validCardExpiry: false,
     13        validCvc: false,
     14        checkoutFormClass: "form.woocommerce-checkout",
     15        cardNumberInput: "#wc_valorpay-card-number",
     16        cardExpiryInput: "#wc_valorpay-card-expiry",
     17        cardCvvInput: "#wc_valorpay-card-cvc",
     18        clientTokenInit: false,
     19        clientToken: "",
     20        tokenGenerateInterval: null,
     21        tokenExpiryMin: 5,
     22        prevSelectedToken: false,
     23        /**
     24         * Initialize.
     25         */
     26        init: function () {
     27            // On payment method switch update checkout.
     28            $( document.body ).on(
     29                "change",
     30                'input[name="payment_method"]',
     31                this.updateCheckout
     32            );
     33            $( document.body ).on(
     34                "click",
     35                'input[name="wc-wc_valorpay-payment-token"]',
     36                this.surChargeCalculation
     37            );
     38            this.validateCardForm();
     39            this.createPageToken();
     40            this.startReCreatePageToken();
     41            $( wc_valorpay_form.checkoutFormClass ).on(
     42                "checkout_place_order_wc_valorpay",
     43                this.valorPayPlaceOrder
     44            );
     45        },
     46        /**
     47         * On payment gateway change update the checkout.
     48         */
     49        updateCheckout: function () {
     50            $( document.body ).trigger( "update_checkout" );
     51        },
     52        /**
     53         * On token switch
     54         */
     55        surChargeCalculation: function () {
     56            const checkedValue  = $('input[name="wc-wc_valorpay-payment-token"]:checked').val();
     57            if(wc_valorpay_form.prevSelectedToken !=  checkedValue) {
     58                if((checkedValue === 'new' && !$( wc_valorpay_form.cardNumberInput ).val()) || checkedValue !== 'new') {
     59                    wc_valorpay_form.tokenCardType(checkedValue);
     60                } else {
     61                    $( wc_valorpay_form.cardNumberInput ).trigger( "blur" );
     62                }
     63                wc_valorpay_form.prevSelectedToken = checkedValue;
     64            }
     65        },
     66        /**
     67         * Block checkout page UI.
     68         */
     69        block: function () {
     70            $( wc_valorpay_form.checkoutFormClass ).block(
     71                {
     72                    message: null,
     73                    overlayCSS: {
     74                        background: "#fff",
     75                        opacity: 0.6,
     76                    },
     77                }
     78            );
     79        },
     80        /**
     81         * Unblock checkout page UI.
     82         */
     83        unblock: function () {
     84            $( wc_valorpay_form.checkoutFormClass ).unblock();
     85        },
     86        /**
     87         * Create page or client token.
     88         */
     89        createPageToken: function () {
     90            $.ajax(
     91                {
     92                    type: "POST",
     93                    url: valorpay_checkout_object.wc_ajax_action
     94                    .toString()
     95                    .replace( "%%endpoint_url%%", valorpay_checkout_object.ct_ajax_action ),
     96                    data: {
     97                        nonce: valorpay_checkout_object.ct_ajax_nonce,
     98                    },
     99                    success: function (response) {
     100                        if (response.success) {
     101                            wc_valorpay_form.clientToken = response.data.token;
     102                        }
     103                    },
     104                }
     105            );
     106        },
     107        /**
     108         * Bin lookup.
     109         */
     110        binLookUp: function () {
     111            var cardNumber = $( wc_valorpay_form.cardNumberInput )
     112            .val()
     113            .replace( / /g, "" );
     114            $.ajax(
     115                {
     116                    type: "POST",
     117                    url: valorpay_checkout_object.wc_ajax_action
     118                    .toString()
     119                    .replace( "%%endpoint_url%%", valorpay_checkout_object.bl_ajax_action ),
     120                    data: {
     121                        nonce: valorpay_checkout_object.bl_ajax_nonce,
     122                        client_token: wc_valorpay_form.clientToken,
     123                        bin: cardNumber.substring(0, 6)
     124                    },
     125                    success: function (response) {
     126                        if (response.success && response.data) {
     127                            wc_valorpay_form.updateCheckout();
     128                        }
     129                    },
     130                }
     131            );
     132        },
     133        /**
     134         * Token card type.
     135         */
     136        tokenCardType: function (tokenId) {
     137            $.ajax(
     138                {
     139                    type: "POST",
     140                    url: valorpay_checkout_object.wc_ajax_action
     141                    .toString()
     142                    .replace( "%%endpoint_url%%", valorpay_checkout_object.card_type_ajax_action ),
     143                    data: {
     144                        nonce: valorpay_checkout_object.card_type_ajax_nonce,
     145                        token_id: tokenId,
     146                    },
     147                    success: function (response) {
     148                        if (response.success && response.data) {
     149                            wc_valorpay_form.updateCheckout();
     150                        }
     151                    },
     152                }
     153            );
     154        },
     155        /**
     156         * Recreate page token on every token expiry minutes.
     157         */
     158        startReCreatePageToken: function () {
     159            wc_valorpay_form.tokenGenerateInterval = setInterval(
     160                function () {
     161                    wc_valorpay_form.createPageToken();
     162                },
     163                wc_valorpay_form.tokenExpiryMin * 60 * 1000
     164            );
     165        },
     166        /**
     167         * Convert expiry date to MMYY format.
     168         */
     169        convertToMMYY: function (dateString) {
     170            // Remove any leading/trailing spaces.
     171            dateString = dateString.trim();
     172
     173            // Split the string into month and year parts.
     174            var parts = dateString.split( "/" );
     175            var month = parseInt( parts[0] );
     176            var year  = parseInt( parts[1] );
     177
     178            // Extract the year part based on the input format.
     179            if (year < 100) {
     180                // Format is MM/YY .
     181                year += 2000; // Assuming years below 100 are in the 21st century.
     182            }
     183
     184            // Format the month and year as MMYY .
     185            var formattedDate = ("0" + month).slice( -2 ) + ("0" + year).slice( -2 );
     186
     187            return formattedDate;
     188        },
     189        /**
     190         * Validate card checkout field.
     191         */
     192        validateCardForm: function () {
     193            this.validateCardNumber();
     194            this.validateCardExpiry();
     195            this.validateCardCvv();
     196        },
     197        /**
     198         * Add error to form field.
     199         *
     200         * @param {jQuery} currentEle The current element.
     201         * @param {string} errorMsg Error Message.
     202         */
     203        addErrorMessage: function (currentEle, errorMsg) {
     204            currentEle.addClass( "error-class" );
     205            if ( ! currentEle.next().hasClass( "error-message" )) {
     206                $(
     207                    '<span class="error-message" style="color:red;">' +
     208                    errorMsg +
     209                    "</span>"
     210                ).insertAfter( currentEle );
     211                currentEle.closest( ".form-row" ).addClass( "woocommerce-invalid" );
     212            }
     213        },
     214        /**
     215         * Remove error from the form field.
     216         *
     217         * @param {jQuery} currentEle The current element.
     218         */
     219        removeErrorMessage: function (currentEle) {
     220            currentEle.removeClass( "error-class" );
     221            currentEle.next( ".error-message" ).remove();
     222            currentEle.closest( ".form-row" ).removeClass( "woocommerce-invalid" );
     223        },
     224        /**
     225         * Validate card number field.
     226         */
     227        validateCardNumber: function () {
     228            $( "body" ).on(
     229                "blur",
     230                this.cardNumberInput,
     231                function () {
     232                    var cardNum = $( this ).val().replace( / /g, "" );
     233                    var isValid = wc_valorpay_form.luhnCheck( cardNum );
     234
     235                    if (cardNum === "") {
     236                        wc_valorpay_form.addErrorMessage(
     237                            $( this ),
     238                            valorpay_checkout_object.error_card
     239                        );
     240                        wc_valorpay_form.validCard = false;
     241                    } else if ( ! isValid) {
     242                        wc_valorpay_form.addErrorMessage(
     243                            $( this ),
     244                            valorpay_checkout_object.invalid_card
     245                        );
     246                        wc_valorpay_form.validCard = false;
     247                    } else {
     248                        wc_valorpay_form.removeErrorMessage( $( this ) );
     249                        wc_valorpay_form.validCard = true;
     250                        wc_valorpay_form.binLookUp();
     251                    }
     252                }
     253            );
     254            $( "body" ).on(
     255                "focus",
     256                this.cardNumberInput,
     257                function () {
     258                    if ( ! $( this ).val()) {
     259                        wc_valorpay_form.removeErrorMessage( $( this ) );
     260                    }
     261                }
     262            );
     263        },
     264        /**
     265         * Validate card expiry field.
     266         */
     267        validateCardExpiry: function () {
     268            $( "body" ).on(
     269                "blur",
     270                this.cardExpiryInput,
     271                function () {
     272                    var expiry = $( this ).val().replace( / /g, "" );
     273                    if (expiry === "") {
     274                        wc_valorpay_form.addErrorMessage(
     275                            $( this ),
     276                            valorpay_checkout_object.invalid_expiry
     277                        );
     278                        wc_valorpay_form.validCardExpiry = false;
     279                    } else {
     280                        var parts = expiry.split( "/" );
     281                        var month = parseInt( parts[0], 10 );
     282                        var year  = parseInt( parts[1], 10 );
     283                        if (year < 100) {
     284                            year += 2000;
     285                        }
     286                        if ( ! wc_valorpay_form.checkCardExpiry( month, year )) {
     287                            wc_valorpay_form.addErrorMessage(
     288                                $( this ),
     289                                valorpay_checkout_object.expiry_card
     290                            );
     291                            wc_valorpay_form.validCardExpiry = false;
     292                        } else {
     293                            wc_valorpay_form.removeErrorMessage( $( this ) );
     294                            wc_valorpay_form.validCardExpiry = true;
     295                        }
     296                    }
     297                }
     298            );
     299
     300            $( "body" ).on(
     301                "focus",
     302                this.cardExpiryInput,
     303                function () {
     304                    wc_valorpay_form.removeErrorMessage( $( this ) );
     305                }
     306            );
     307        },
     308        /**
     309         * Validate card CVV field.
     310         */
     311        validateCardCvv: function () {
     312            $( "body" ).on(
     313                "blur",
     314                this.cardCvvInput,
     315                function () {
     316                    var cvcNum = $( this ).val().trim();
     317                    if (cvcNum === "") {
     318                        wc_valorpay_form.addErrorMessage(
     319                            $( this ),
     320                            valorpay_checkout_object.error_cvv
     321                        );
     322                        wc_valorpay_form.validCvc = false;
     323                    } else if (cvcNum.length != 3 && cvcNum.length != 4) {
     324                        wc_valorpay_form.addErrorMessage(
     325                            $( this ),
     326                            valorpay_checkout_object.invalid_cvv
     327                        );
     328                        wc_valorpay_form.validCvc = false;
     329                    } else {
     330                        wc_valorpay_form.removeErrorMessage( $( this ) );
     331                        wc_valorpay_form.validCvc = true;
     332                    }
     333                }
     334            );
     335            $( "body" ).on(
     336                "focus",
     337                this.cardCvvInput,
     338                function () {
     339                    wc_valorpay_form.removeErrorMessage( $( this ) );
     340                }
     341            );
     342        },
     343        /**
     344         * Validate field on place order
     345         */
     346        valorPayPlaceOrder: function (event) {
     347            var cardNumb  = $( wc_valorpay_form.cardNumberInput ).val();
     348            const isNewCard = $( "#wc-wc_valorpay-payment-token-new" );
     349            if (isNewCard.length && ! isNewCard.is( ":checked" )) {
     350                var avsErrorIsValidSave = wc_valorpay_form.avsValidation();
     351                if (avsErrorIsValidSave) {
     352                    wc_valorpay_form.scrollToValorForm();
    180353                    return false;
    181                 }
    182             }
    183  
    184             if (cardNumb === "") {
    185                 $('input[name="wc_valorpay-card-number"]').trigger("blur");
    186             } else {
    187                 $('input[name="wc_valorpay-card-number"]').trigger("blur");
    188                 $('input[name="wc_valorpay-card-expiry"]').trigger("blur");
    189                 $('input[name="wc_valorpay-card-cvc"]').trigger("blur");
    190             }
    191             if (validcard === false) {
    192                 $("html, body").animate({
    193                         scrollTop: $("#wc-wc_valorpay-cc-form").offset().top,
    194                     },
    195                     1000
    196                 );
    197                 return false;
    198             }
    199             if (validcardexpiry === false) {
    200                 $("html, body").animate({
    201                         scrollTop: $("#wc-wc_valorpay-cc-form").offset().top,
    202                     },
    203                     1000
    204                 );
    205                 return false;
    206             }
    207             if (validcvc === false) {
    208                 $("html, body").animate({
    209                         scrollTop: $("#wc-wc_valorpay-cc-form").offset().top,
    210                     },
    211                     1000
    212                 );
    213                 return false;
    214             }
    215             if (cardNumb !== "") {
    216                 var avserrorIsValid = addAVSErrors();
    217                
    218                 if (avserrorIsValid) {
    219            
    220                     return true;
    221                 } else {
    222                     return false;
    223                 }
    224             }
    225         }
    226     );
    227  
    228  
    229  
    230     function validateCardExpiry(month, year) {
    231         var currentTime = new Date();
    232         var expiry = new Date(year, month, 1);
    233         if (expiry < currentTime) {
    234             return false;
    235         }
    236         return true;
    237     }
    238  
    239     function addAVSErrors() {
    240         var hasError = false;
    241  
    242         $('input[name="valorpay_avs_zip"] + span.error').remove();
    243         $('input[name="valorpay_avs_street"] + span.error').remove();
    244  
    245         if ($('input[name="valorpay_avs_zip"]').val() === "") {
    246             $('input[name="valorpay_avs_zip"]').after(
    247                 '<span class="error" style="color:red;">' +
    248                 valorpay_checkout_object.avs_zip_error +
    249                 "</span>"
    250             );
    251             hasError = true;
    252         } else if ($('input[name="valorpay_avs_zip"]').val().length < 4) {
    253             $('input[name="valorpay_avs_zip"]').after(
    254                 '<span class="error" style="color:red;">' +
    255                 valorpay_checkout_object.invalid_avs_zip_error + "</span>"
    256             );
    257             hasError = true;
    258         }
    259  
    260         if ($('input[name="valorpay_avs_street"]').val() === "") {
    261             $('input[name="valorpay_avs_street"]').after(
    262                 '<span class="error" style="color:red;">' +
    263                 valorpay_checkout_object.avs_street_error +
    264                 "</span>"
    265             );
    266             hasError = true;
    267         }
    268  
    269         $('input[name="valorpay_avs_zip"]').focus(function() {
    270             $('input[name="valorpay_avs_zip"] + span.error').remove();
    271         });
    272  
    273         $('input[name="valorpay_avs_street"]').focus(function() {
    274             $('input[name="valorpay_avs_street"] + span.error').remove();
    275         });
    276  
    277         return !hasError;
    278     }
    279   });
    280 
    281  
    282 })(jQuery);
     354                }
     355                return true;
     356            }
     357            if (cardNumb === "") {
     358                $( wc_valorpay_form.cardNumberInput ).trigger( "blur" );
     359            } else {
     360                $( wc_valorpay_form.cardNumberInput ).trigger( "blur" );
     361                $( wc_valorpay_form.cardExpiryInput ).trigger( "blur" );
     362                $( wc_valorpay_form.cardCvvInput ).trigger( "blur" );
     363            }
     364            if (wc_valorpay_form.validCard === false) {
     365                wc_valorpay_form.scrollToValorForm();
     366                return false;
     367            }
     368            if (wc_valorpay_form.validCardExpiry === false) {
     369                wc_valorpay_form.scrollToValorForm();
     370                return false;
     371            }
     372            if (wc_valorpay_form.validCvc === false) {
     373                wc_valorpay_form.scrollToValorForm();
     374                return false;
     375            }
     376
     377            if (cardNumb !== "") {
     378                var avsErrorIsValid = wc_valorpay_form.avsValidation();
     379                if (avsErrorIsValid) {
     380                    wc_valorpay_form.scrollToValorForm();
     381                    return false;
     382                }
     383                return true;
     384            }
     385        },
     386        /**
     387         * Validate Address Verification Service
     388         */
     389        avsValidation: function () {
     390            var hasError = false;
     391            if ($( 'input[name="valorpay_avs_zip"]' ).length) {
     392                wc_valorpay_form.removeErrorMessage(
     393                    $( 'input[name="valorpay_avs_zip"]' )
     394                );
     395                if ($( 'input[name="valorpay_avs_zip"]' ).val() === "") {
     396                        wc_valorpay_form.addErrorMessage(
     397                            $( 'input[name="valorpay_avs_zip"]' ),
     398                            valorpay_checkout_object.avs_zip_error
     399                        );
     400                        hasError = true;
     401                } else if ($( 'input[name="valorpay_avs_zip"]' ).val().length < 4) {
     402                    wc_valorpay_form.addErrorMessage(
     403                        $( 'input[name="valorpay_avs_zip"]' ),
     404                        valorpay_checkout_object.invalid_avs_zip_error
     405                    );
     406                    hasError = true;
     407                }
     408                $( 'input[name="valorpay_avs_zip"]' ).focus(
     409                    function () {
     410                        wc_valorpay_form.removeErrorMessage(
     411                            $( 'input[name="valorpay_avs_zip"]' )
     412                        );
     413                    }
     414                );
     415            }
     416
     417            if ($( 'input[name="valorpay_avs_street"]' ).length) {
     418                wc_valorpay_form.removeErrorMessage(
     419                    $( 'input[name="valorpay_avs_street"]' )
     420                );
     421                if ($( 'input[name="valorpay_avs_street"]' ).val() === "") {
     422                    wc_valorpay_form.addErrorMessage(
     423                        $( 'input[name="valorpay_avs_street"]' ),
     424                        valorpay_checkout_object.avs_street_error
     425                    );
     426                    hasError = true;
     427                }
     428                $( 'input[name="valorpay_avs_street"]' ).focus(
     429                    function () {
     430                        wc_valorpay_form.removeErrorMessage(
     431                            $( 'input[name="valorpay_avs_street"]' )
     432                        );
     433                    }
     434                );
     435            }
     436
     437            return hasError;
     438        },
     439        /**
     440         * Check if the card expiry.
     441         *
     442         * @param {number} month Card month
     443         * @param {number} year Card year
     444         * @return {boolean}
     445         */
     446        checkCardExpiry: function (month, year) {
     447            var currentTime = new Date();
     448            var expiry      = new Date( year, month, 1 );
     449            if (expiry < currentTime) {
     450                return false;
     451            }
     452            return true;
     453        },
     454        /**
     455         * Luhn check.
     456         *
     457         * @param {string} num Card number
     458         * @return {boolean}
     459         */
     460        luhnCheck: function (num) {
     461            var digit, digits, odd, sum, _i, _len;
     462            odd    = true;
     463            sum    = 0;
     464            digits = (num + "").split( "" ).reverse();
     465            for (_i = 0, _len = digits.length; _i < _len; _i++) {
     466                digit = digits[_i];
     467                digit = parseInt( digit, 10 );
     468                if ((odd = ! odd)) {
     469                    digit *= 2;
     470                }
     471                if (digit > 9) {
     472                    digit -= 9;
     473                }
     474                sum += digit;
     475            }
     476            return sum % 10 === 0.0;
     477        },
     478        /**
     479         * Scroll to payment form.
     480         */
     481        scrollToValorForm: function () {
     482            $( "html, body" ).animate(
     483                {
     484                    scrollTop: $( "#wc-wc_valorpay-cc-form" ).offset().top,
     485                },
     486                1000
     487            );
     488        },
     489    };
     490    $( document ).ready(
     491        function () {
     492            // Initialize the wc_test_form object.
     493            wc_valorpay_form.init();
     494        }
     495    );
     496})( jQuery );
  • valorpos/trunk/wc-valorpay.php

    r2960359 r2980555  
    1616 * Plugin URI:        https://valorpaytech.com
    1717 * Description:       Adds the Valor Payment Gateway to WooCommerce.
    18  * Version:           7.3.1
     18 * Version:           7.4.0
    1919 * Author:            Valor Paytech LLC
    2020 * Author URI:        https://valorpaytech.com
     
    3737 * Rename this for your plugin and update it as you release new versions.
    3838 */
    39 define( 'WC_VALORPAY_VERSION', '7.3.1' );
     39define( 'WC_VALORPAY_VERSION', '7.4.0' );
    4040// Directory i.e. /home/user/public_html...
    4141define( 'WC_VALORPAY_DIR', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.