Plugin Directory

Changeset 2918841


Ignore:
Timestamp:
05/30/2023 07:28:55 AM (3 years ago)
Author:
abubacker
Message:

Added validation to card fields & Tax amount separated from sub total

Location:
valorpos
Files:
14 edited
5 copied

Legend:

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

    r2897749 r2918841  
    33Tags: payment, payment gateway, credit card, valor pay, valor paytech
    44Requires at least: 5.0
    5 Tested up to: 6.1.1
     5Tested up to: 6.2.2
    66Requires PHP: 7.0
    7 Stable tag: 7.2.1
     7Stable tag: 7.3.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4141== Changelog ==
    4242
     43= 7.3.0 =
     44* Added validation to card fields & Tax amount separated from sub total.
     45
    4346= 7.2.1 =
    4447* Change event listener selector for payment method.
  • valorpos/tags/7.3.0/admin/class-wc-valorpay-admin.php

    r2883367 r2918841  
    308308    }
    309309
     310
    310311}
  • valorpos/tags/7.3.0/includes/class-wc-valorpay-api.php

    r2887504 r2918841  
    170170                }
    171171            }
    172 
    173172            $billing_first_name = wc_clean( $order->get_billing_first_name() );
    174173            $billing_last_name  = wc_clean( $order->get_billing_last_name() );
     
    186185            $billing_email       = wc_clean( $order->get_billing_email() );
    187186            $tax_amount          = wc_clean( $order->get_total_tax() );
     187            $amount              = $amount - $tax_amount;
    188188            $ip_address          = wc_clean( $order->get_customer_ip_address() );
    189189            $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
     
    201201                'email'              => $billing_email,
    202202                'uid'                => $order_number,
    203                 'tax'                => number_format( $tax_amount, '2', '.', '' ),
     203                'tax_amount'         => number_format( $tax_amount, '2', '.', '' ),
    204204                'ip'                 => $ip_address,
    205205                'surchargeIndicator' => $surcharge_indicator,
  • valorpos/tags/7.3.0/includes/class-wc-valorpay-gateway.php

    r2887504 r2918841  
    266266        $this->valorpay_acknowledgement_form();
    267267    }
     268    /**
     269     * Luhn check.
     270     *
     271     * @since 7.3.0
     272     * @param  string $account_number Account Number.
     273     * @return object
     274     */
     275    public function luhn_check( $account_number ) {
     276        for ( $sum = 0, $i = 0, $ix = strlen( $account_number ); $i < $ix - 1; $i++ ) {
     277            $weight = substr( $account_number, $ix - ( $i + 2 ), 1 ) * ( 2 - ( $i % 2 ) );
     278            $sum   += $weight < 10 ? $weight : $weight - 9;
     279
     280        }
     281        if ( 0 !== $sum ) {
     282            return ( (int) substr( $account_number, $ix - 1 ) ) === ( ( 10 - $sum % 10 ) % 10 );
     283        } else {
     284            return false;
     285        }
     286    }
     287    /**
     288     * Get card information.
     289     *
     290     * @since 7.3.0
     291     * @return object
     292     */
     293    private function get_posted_card() {
     294        $card_number    = isset( $_POST['wc_valorpay-card-number'] ) ? wc_clean( $_POST['wc_valorpay-card-number'] ) : ''; // phpcs:ignore
     295        $card_cvc       = isset( $_POST['wc_valorpay-card-cvc'] ) ? wc_clean( $_POST['wc_valorpay-card-cvc'] ) : ''; // phpcs:ignore
     296        $card_expiry    = isset( $_POST['wc_valorpay-card-expiry'] ) ? wc_clean( $_POST['wc_valorpay-card-expiry'] ) : ''; // phpcs:ignore
     297        $card_number    = str_replace( array( ' ', '-' ), '', $card_number );
     298        $card_expiry    = array_map( 'trim', explode( '/', $card_expiry ) );
     299        $card_exp_month = str_pad( $card_expiry[0], 2, '0', STR_PAD_LEFT );
     300        $card_exp_year  = isset( $card_expiry[1] ) ? $card_expiry[1] : '';
     301        if ( 2 === strlen( $card_exp_year ) ) {
     302            $card_exp_year += 2000;
     303        }
     304        return (object) array(
     305            'number'    => $card_number,
     306            'type'      => '',
     307            'cvc'       => $card_cvc,
     308            'exp_month' => $card_exp_month,
     309            'exp_year'  => $card_exp_year,
     310        );
     311    }
     312
     313    /**
     314     * Validate frontend fields.
     315     *
     316     * Validate payment fields on the frontend.
     317     *
     318     * @since 7.3.0
     319     * @throws \Exception If the card information is invalid.
     320     * @return bool
     321     */
     322    public function validate_fields() {
     323        try {
     324            if ( isset( $_POST['wc-wc_valorpay-payment-token'] ) && 'new' !== wc_clean( $_POST['wc-wc_valorpay-payment-token'] ) ) { // phpcs:ignore
     325                return true;
     326            }
     327            $card          = $this->get_posted_card();
     328            $current_year  = gmdate( 'Y' );
     329            $current_month = gmdate( 'n' );
     330
     331            if ( empty( $card->number ) || ! ctype_digit( $card->number ) || strlen( $card->number ) < 12 || strlen( $card->number ) > 19 ) {
     332                throw new Exception( __( 'Card number is invalid', 'wc-valorpay' ) );
     333            }
     334
     335            if ( ! ( $this->luhn_check( $card->number ) ) ) {
     336                throw new Exception( __( 'Not a valid card', 'wc-valorpay' ) );
     337            }
     338            if ( empty( $card->exp_month ) || empty( $card->exp_year ) || ! ctype_digit( $card->exp_month ) || ! ctype_digit( $card->exp_year ) || $card->exp_month > 12 || $card->exp_month < 1 || $card->exp_year < $current_year || ( $card->exp_year === $current_year && $card->exp_month < $current_month ) ) {
     339                throw new Exception( __( 'Card number  expired', 'wc-valorpay' ) );
     340            }
     341            if ( ! ctype_digit( $card->cvc ) ) {
     342                throw new Exception( __( 'Card security code is invalid (only digits are allowed)', 'wc-valorpay' ) );
     343            }
     344
     345            return true;
     346        } catch ( Exception $e ) {
     347            wc_add_notice( $e->getMessage(), 'error' );
     348            return false;
     349        }
     350    }
    268351
    269352    /**
     
    519602     *
    520603     * @since 1.0.0
     604     */
     605    public function add_card_field_id() {
     606
     607        $fields['card-number-field']['label_class'] .= ' woocommerce-input-wrapper';
     608        $fields['card-number-field']['class'][]      = 'form-row-wide';
     609        $fields['card-number-field']['id']           = 'wc-valorpay-card-field';
     610        return $fields;
     611    }
     612
     613    /**
     614     * Surcharge admin validation.
     615     *
     616     * @since 7.2.0
    521617     */
    522618    public function process_admin_options() {
     
    780876    }
    781877
     878
     879
     880
    782881}
     882
     883
     884
     885
  • valorpos/tags/7.3.0/includes/class-wc-valorpay.php

    r2883367 r2918841  
    202202        $this->loader->add_action( 'woocommerce_after_checkout_form', $plugin_public, 'valorpay_checkout_script' );
    203203        $this->loader->add_filter( 'woocommerce_available_payment_gateways', $plugin_public, 'valorpay_disable_payment_gateway_failed_orders' );
     204
    204205    }
    205206
     
    245246
    246247}
     248
  • valorpos/tags/7.3.0/languages/wc-valorpay.pot

    r2897749 r2918841  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Valor Pay 7.2.1\n"
     5"Project-Id-Version: Valor Pay 7.3.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-valorpay\n"
    77"Last-Translator: Valor Paytech LLC <sales@valorpaytech.com>\n"
     
    99"Content-Type: text/plain; charset=UTF-8\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "POT-Creation-Date: 2023-03-27T15:16:11+05:30\n"
     11"POT-Creation-Date: 2023-05-19T15:31:04+05:30\n"
    1212"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1313"X-Generator: WP-CLI 2.7.1\n"
     
    1515
    1616#. Plugin Name of the plugin
    17 #: includes/class-wc-valorpay-gateway.php:372
     17#: includes/class-wc-valorpay-gateway.php:455
    1818msgid "Valor Pay"
    1919msgstr ""
     
    6969
    7070#: admin/partials/wc-valorpay-admin-failure-tracker.php:18
    71 #: includes/class-wc-valorpay-gateway.php:460
     71#: includes/class-wc-valorpay-gateway.php:543
    7272msgid "Payment Failed Tracker"
    7373msgstr ""
     
    169169msgstr ""
    170170
     171#: includes/class-wc-valorpay-gateway.php:332
     172msgid "Card number is invalid"
     173msgstr ""
     174
     175#: includes/class-wc-valorpay-gateway.php:336
     176msgid "Not a valid card"
     177msgstr ""
     178
     179#: includes/class-wc-valorpay-gateway.php:339
     180msgid "Card number  expired"
     181msgstr ""
     182
     183#: includes/class-wc-valorpay-gateway.php:342
     184msgid "Card security code is invalid (only digits are allowed)"
     185msgstr ""
     186
    171187#. translators: 1: Terms and Conditions URL.
    172 #: includes/class-wc-valorpay-gateway.php:295
     188#: includes/class-wc-valorpay-gateway.php:378
    173189msgid "I agree to the <a href=\"%s\" target=\"_blank\">Terms and Conditions</a>"
    174190msgstr ""
    175191
    176 #: includes/class-wc-valorpay-gateway.php:326
    177 #: includes/class-wc-valorpay-gateway.php:327
     192#: includes/class-wc-valorpay-gateway.php:409
     193#: includes/class-wc-valorpay-gateway.php:410
    178194msgid "Zip Code"
    179195msgstr ""
    180196
    181 #: includes/class-wc-valorpay-gateway.php:340
    182 #: includes/class-wc-valorpay-gateway.php:341
     197#: includes/class-wc-valorpay-gateway.php:423
     198#: includes/class-wc-valorpay-gateway.php:424
    183199msgid "Street No"
    184200msgstr ""
    185201
    186 #: includes/class-wc-valorpay-gateway.php:362
     202#: includes/class-wc-valorpay-gateway.php:445
    187203msgid "Enable/Disable"
    188204msgstr ""
    189205
    190 #: includes/class-wc-valorpay-gateway.php:363
     206#: includes/class-wc-valorpay-gateway.php:446
    191207msgid "Enable Valor Pay"
    192208msgstr ""
    193209
    194 #: includes/class-wc-valorpay-gateway.php:369
     210#: includes/class-wc-valorpay-gateway.php:452
    195211msgid "Title"
    196212msgstr ""
    197213
    198 #: includes/class-wc-valorpay-gateway.php:371
     214#: includes/class-wc-valorpay-gateway.php:454
    199215msgid "This controls the title which the user sees during checkout."
    200216msgstr ""
    201217
    202 #: includes/class-wc-valorpay-gateway.php:376
     218#: includes/class-wc-valorpay-gateway.php:459
    203219msgid "Use Sandbox"
    204220msgstr ""
    205221
    206 #: includes/class-wc-valorpay-gateway.php:377
     222#: includes/class-wc-valorpay-gateway.php:460
    207223msgid "Enable sandbox mode - live payments will not be taken if enabled."
    208224msgstr ""
    209225
    210 #: includes/class-wc-valorpay-gateway.php:383
     226#: includes/class-wc-valorpay-gateway.php:466
    211227msgid "APP ID"
    212228msgstr ""
    213229
    214 #: includes/class-wc-valorpay-gateway.php:385
     230#: includes/class-wc-valorpay-gateway.php:468
    215231msgid "Please email support@valorpaytech.com to get to know about your APP ID, ( In demo mode APP ID is not needed )"
    216232msgstr ""
    217233
    218 #: includes/class-wc-valorpay-gateway.php:389
     234#: includes/class-wc-valorpay-gateway.php:472
    219235msgid "APP KEY"
    220236msgstr ""
    221237
    222 #: includes/class-wc-valorpay-gateway.php:391
     238#: includes/class-wc-valorpay-gateway.php:474
    223239msgid "Please email support@valorpaytech.com to get to know about your APP KEY, ( In demo mode APP KEY is not needed )"
    224240msgstr ""
    225241
    226 #: includes/class-wc-valorpay-gateway.php:395
     242#: includes/class-wc-valorpay-gateway.php:478
    227243msgid "EPI"
    228244msgstr ""
    229245
    230 #: includes/class-wc-valorpay-gateway.php:397
     246#: includes/class-wc-valorpay-gateway.php:480
    231247msgid "Please email support@valorpaytech.com to get to know about your EPI ID, ( In demo mode EPI ID is not needed )"
    232248msgstr ""
    233249
    234 #: includes/class-wc-valorpay-gateway.php:401
     250#: includes/class-wc-valorpay-gateway.php:484
    235251msgid "Payment Method"
    236252msgstr ""
    237253
    238 #: includes/class-wc-valorpay-gateway.php:411
     254#: includes/class-wc-valorpay-gateway.php:494
    239255msgid "Surcharge Mode"
    240256msgstr ""
    241257
    242 #: includes/class-wc-valorpay-gateway.php:412
    243 #: includes/class-wc-valorpay-gateway.php:419
     258#: includes/class-wc-valorpay-gateway.php:495
     259#: includes/class-wc-valorpay-gateway.php:502
    244260msgid "Enable Surcharge Mode"
    245261msgstr ""
    246262
    247 #: includes/class-wc-valorpay-gateway.php:414
     263#: includes/class-wc-valorpay-gateway.php:497
    248264msgid "Enable only if you want all transactions to be fall on surcharge mode, Merchant must have got an Surcharge MID inorder to work"
    249265msgstr ""
    250266
    251 #: includes/class-wc-valorpay-gateway.php:418
     267#: includes/class-wc-valorpay-gateway.php:501
    252268msgid "Surcharge Type"
    253269msgstr ""
    254270
    255 #: includes/class-wc-valorpay-gateway.php:428
    256 #: includes/class-wc-valorpay-gateway.php:429
     271#: includes/class-wc-valorpay-gateway.php:511
     272#: includes/class-wc-valorpay-gateway.php:512
    257273msgid "Surcharge Label"
    258274msgstr ""
    259275
    260 #: includes/class-wc-valorpay-gateway.php:434
     276#: includes/class-wc-valorpay-gateway.php:517
    261277msgid "Surcharge %"
    262278msgstr ""
    263279
    264 #: includes/class-wc-valorpay-gateway.php:438
     280#: includes/class-wc-valorpay-gateway.php:521
    265281msgid "Percentage will apply only on enabling on surcharge Indicator to true and Surcharge type is set fo Surcharge %"
    266282msgstr ""
    267283
    268 #: includes/class-wc-valorpay-gateway.php:441
     284#: includes/class-wc-valorpay-gateway.php:524
    269285msgid "Flat Rate $"
    270286msgstr ""
    271287
    272 #: includes/class-wc-valorpay-gateway.php:444
     288#: includes/class-wc-valorpay-gateway.php:527
    273289msgid "Flat rate  will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $"
    274290msgstr ""
    275291
    276 #: includes/class-wc-valorpay-gateway.php:447
     292#: includes/class-wc-valorpay-gateway.php:530
    277293msgid "AVS"
    278294msgstr ""
    279295
    280 #: includes/class-wc-valorpay-gateway.php:457
     296#: includes/class-wc-valorpay-gateway.php:540
    281297msgid "The address verification service will add a text field to the checkout page based on the above option."
    282298msgstr ""
    283299
    284 #: includes/class-wc-valorpay-gateway.php:461
     300#: includes/class-wc-valorpay-gateway.php:544
    285301msgid "Enable Protection"
    286302msgstr ""
    287303
    288304#. translators: 1: Tracker URL.
    289 #: includes/class-wc-valorpay-gateway.php:465
     305#: includes/class-wc-valorpay-gateway.php:548
    290306msgid "Disable the payment method in the checkout page for failed transactions. <a id=\"valorpay-goto-tracker\" href=\"%s\">Unblock IP</a>"
    291307msgstr ""
    292308
    293 #: includes/class-wc-valorpay-gateway.php:471
     309#: includes/class-wc-valorpay-gateway.php:554
    294310msgid "Declined Transaction Count"
    295311msgstr ""
    296312
    297 #: includes/class-wc-valorpay-gateway.php:472
     313#: includes/class-wc-valorpay-gateway.php:555
    298314msgid "Number of declined transaction count."
    299315msgstr ""
    300316
    301 #: includes/class-wc-valorpay-gateway.php:476
     317#: includes/class-wc-valorpay-gateway.php:559
    302318msgid "3"
    303319msgstr ""
    304320
    305 #: includes/class-wc-valorpay-gateway.php:477
     321#: includes/class-wc-valorpay-gateway.php:560
    306322msgid "5"
    307323msgstr ""
    308324
    309 #: includes/class-wc-valorpay-gateway.php:478
     325#: includes/class-wc-valorpay-gateway.php:561
    310326msgid "6"
    311327msgstr ""
    312328
    313 #: includes/class-wc-valorpay-gateway.php:482
     329#: includes/class-wc-valorpay-gateway.php:565
    314330msgid "Block Payment For"
    315331msgstr ""
    316332
    317 #: includes/class-wc-valorpay-gateway.php:483
     333#: includes/class-wc-valorpay-gateway.php:566
    318334msgid "Minutes to block payment gateway in checkout."
    319335msgstr ""
    320336
    321 #: includes/class-wc-valorpay-gateway.php:487
     337#: includes/class-wc-valorpay-gateway.php:570
    322338msgid "1 min"
    323339msgstr ""
    324340
    325 #: includes/class-wc-valorpay-gateway.php:488
     341#: includes/class-wc-valorpay-gateway.php:571
    326342msgid "5 min"
    327343msgstr ""
    328344
    329 #: includes/class-wc-valorpay-gateway.php:489
     345#: includes/class-wc-valorpay-gateway.php:572
    330346msgid "10 min"
    331347msgstr ""
    332348
    333 #: includes/class-wc-valorpay-gateway.php:490
     349#: includes/class-wc-valorpay-gateway.php:573
    334350msgid "1 hour"
    335351msgstr ""
    336352
    337 #: includes/class-wc-valorpay-gateway.php:491
     353#: includes/class-wc-valorpay-gateway.php:574
    338354msgid "3 hour"
    339355msgstr ""
    340356
    341 #: includes/class-wc-valorpay-gateway.php:492
     357#: includes/class-wc-valorpay-gateway.php:575
    342358msgid "5 hour"
    343359msgstr ""
    344360
    345 #: includes/class-wc-valorpay-gateway.php:493
     361#: includes/class-wc-valorpay-gateway.php:576
    346362msgid "10 hour"
    347363msgstr ""
    348364
    349 #: includes/class-wc-valorpay-gateway.php:494
     365#: includes/class-wc-valorpay-gateway.php:577
    350366msgid "1 day"
    351367msgstr ""
    352368
    353 #: includes/class-wc-valorpay-gateway.php:498
     369#: includes/class-wc-valorpay-gateway.php:581
    354370msgid "Accepted Cards"
    355371msgstr ""
    356372
    357 #: includes/class-wc-valorpay-gateway.php:502
     373#: includes/class-wc-valorpay-gateway.php:585
    358374msgid "Select the card types to accept."
    359375msgstr ""
    360376
    361377#. translators: 1: Maximum percentage.
    362 #: includes/class-wc-valorpay-gateway.php:528
     378#: includes/class-wc-valorpay-gateway.php:624
    363379msgid "Surcharge percentage cannot be more than %s"
    364380msgstr ""
    365381
    366382#. translators: 1: Maximum flat rate.
    367 #: includes/class-wc-valorpay-gateway.php:533
     383#: includes/class-wc-valorpay-gateway.php:629
    368384msgid "Surcharge flat rate cannot be more than %s"
    369385msgstr ""
    370386
    371 #: includes/class-wc-valorpay-gateway.php:578
     387#: includes/class-wc-valorpay-gateway.php:674
    372388msgid "Invalid card information."
    373389msgstr ""
    374390
    375391#. translators: 1: Error Message, 2: Amount, 3: Line Break, 4: Approval Code, 5: Line Break, 6: RRN Number.
    376 #: includes/class-wc-valorpay-gateway.php:594
     392#: includes/class-wc-valorpay-gateway.php:690
    377393msgid "Valor Pay %1$s for %2$s.%3$s <strong>Approval Code:</strong> %4$s.%5$s <strong>RRN:</strong> %6$s"
    378394msgstr ""
    379395
    380396#. translators: %s: API Error Message.
    381 #: includes/class-wc-valorpay-gateway.php:630
    382 #: includes/class-wc-valorpay-gateway.php:633
     397#: includes/class-wc-valorpay-gateway.php:726
     398#: includes/class-wc-valorpay-gateway.php:729
    383399msgid "Payment error: %s"
    384400msgstr ""
    385401
    386 #: includes/class-wc-valorpay-gateway.php:635
     402#: includes/class-wc-valorpay-gateway.php:731
    387403msgid "Unable to process the transaction using Valor Pay, please try again."
    388404msgstr ""
    389405
    390406#. translators: 1: Disable Time, 2: Unblock IP URL, 3: Customer IP.
    391 #: includes/class-wc-valorpay-gateway.php:694
     407#: includes/class-wc-valorpay-gateway.php:790
    392408msgid "Valor Pay method is disabled for %1$s. <a target=\"_blank\" href=\"%2$s\">To Unblock IP</a> %3$s"
    393409msgstr ""
    394410
    395 #: includes/class-wc-valorpay-gateway.php:757
     411#: includes/class-wc-valorpay-gateway.php:853
    396412msgid "Refund failed."
    397413msgstr ""
    398414
    399415#. translators: 1: Amount, 2: Line Break, 3: Approval code, 4: Line Break, 5: RRN Code
    400 #: includes/class-wc-valorpay-gateway.php:769
     416#: includes/class-wc-valorpay-gateway.php:865
    401417msgid "Valor Pay Refund for %1$s.%2$s <strong>Approval Code:</strong> %3$s.%4$s <strong>RRN:</strong> %5$s"
    402418msgstr ""
    403419
    404 #: public/class-wc-valorpay-public.php:93
     420#: public/class-wc-valorpay-public.php:80
     421msgid "Please enter a card number"
     422msgstr ""
     423
     424#: public/class-wc-valorpay-public.php:81
     425msgid "Invalid card number"
     426msgstr ""
     427
     428#: public/class-wc-valorpay-public.php:82
     429msgid "Card is expired"
     430msgstr ""
     431
     432#: public/class-wc-valorpay-public.php:83
     433msgid "Please enter card expiry date"
     434msgstr ""
     435
     436#: public/class-wc-valorpay-public.php:84
     437msgid "Please enter a CVC"
     438msgstr ""
     439
     440#: public/class-wc-valorpay-public.php:85
     441msgid "Invalid CVC length"
     442msgstr ""
     443
     444#: public/class-wc-valorpay-public.php:86
     445msgid "Please enter a zip code"
     446msgstr ""
     447
     448#: public/class-wc-valorpay-public.php:87
     449msgid "Invalid zip code"
     450msgstr ""
     451
     452#: public/class-wc-valorpay-public.php:88
     453msgid "Please enter a street address"
     454msgstr ""
     455
     456#: public/class-wc-valorpay-public.php:108
    405457msgid "Zip Code is required."
    406458msgstr ""
    407459
    408 #: public/class-wc-valorpay-public.php:96
     460#: public/class-wc-valorpay-public.php:111
    409461msgid "Enter a valid Zip Code."
    410462msgstr ""
    411463
    412 #: public/class-wc-valorpay-public.php:101
     464#: public/class-wc-valorpay-public.php:116
    413465msgid "Street No is required."
    414466msgstr ""
    415467
    416 #: public/class-wc-valorpay-public.php:104
     468#: public/class-wc-valorpay-public.php:119
    417469msgid "Enter a valid Street No."
    418470msgstr ""
  • valorpos/tags/7.3.0/public/class-wc-valorpay-public.php

    r2887504 r2918841  
    7474
    7575        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        );
    7691
    7792    }
  • valorpos/tags/7.3.0/public/js/wc-valorpay-checkout.js

    r2897749 r2918841  
    66 */
    77
    8 (function( $ ) {
    9     'use strict';
    10 
    11     $( 'body' ).on(
    12         'change',
    13         'input[name="payment_method"]',
    14         function(){
    15             $( 'body' ).trigger( 'update_checkout' );
    16         }
    17     );
    18 
    19 })( jQuery );
     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 {
     180                    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);
  • valorpos/tags/7.3.0/wc-valorpay.php

    r2897749 r2918841  
    1616 * Plugin URI:        https://valorpaytech.com
    1717 * Description:       Adds the Valor Payment Gateway to WooCommerce.
    18  * Version:           7.2.1
     18 * Version:           7.3.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.2.1' );
     39define( 'WC_VALORPAY_VERSION', '7.3.0' );
    4040// Directory i.e. /home/user/public_html...
    4141define( 'WC_VALORPAY_DIR', plugin_dir_path( __FILE__ ) );
  • valorpos/trunk/README.txt

    r2897749 r2918841  
    33Tags: payment, payment gateway, credit card, valor pay, valor paytech
    44Requires at least: 5.0
    5 Tested up to: 6.1.1
     5Tested up to: 6.2.2
    66Requires PHP: 7.0
    7 Stable tag: 7.2.1
     7Stable tag: 7.3.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4141== Changelog ==
    4242
     43= 7.3.0 =
     44* Added validation to card fields & Tax amount separated from sub total.
     45
    4346= 7.2.1 =
    4447* Change event listener selector for payment method.
  • valorpos/trunk/admin/class-wc-valorpay-admin.php

    r2883367 r2918841  
    308308    }
    309309
     310
    310311}
  • valorpos/trunk/includes/class-wc-valorpay-api.php

    r2887504 r2918841  
    170170                }
    171171            }
    172 
    173172            $billing_first_name = wc_clean( $order->get_billing_first_name() );
    174173            $billing_last_name  = wc_clean( $order->get_billing_last_name() );
     
    186185            $billing_email       = wc_clean( $order->get_billing_email() );
    187186            $tax_amount          = wc_clean( $order->get_total_tax() );
     187            $amount              = $amount - $tax_amount;
    188188            $ip_address          = wc_clean( $order->get_customer_ip_address() );
    189189            $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
     
    201201                'email'              => $billing_email,
    202202                'uid'                => $order_number,
    203                 'tax'                => number_format( $tax_amount, '2', '.', '' ),
     203                'tax_amount'         => number_format( $tax_amount, '2', '.', '' ),
    204204                'ip'                 => $ip_address,
    205205                'surchargeIndicator' => $surcharge_indicator,
  • valorpos/trunk/includes/class-wc-valorpay-gateway.php

    r2887504 r2918841  
    266266        $this->valorpay_acknowledgement_form();
    267267    }
     268    /**
     269     * Luhn check.
     270     *
     271     * @since 7.3.0
     272     * @param  string $account_number Account Number.
     273     * @return object
     274     */
     275    public function luhn_check( $account_number ) {
     276        for ( $sum = 0, $i = 0, $ix = strlen( $account_number ); $i < $ix - 1; $i++ ) {
     277            $weight = substr( $account_number, $ix - ( $i + 2 ), 1 ) * ( 2 - ( $i % 2 ) );
     278            $sum   += $weight < 10 ? $weight : $weight - 9;
     279
     280        }
     281        if ( 0 !== $sum ) {
     282            return ( (int) substr( $account_number, $ix - 1 ) ) === ( ( 10 - $sum % 10 ) % 10 );
     283        } else {
     284            return false;
     285        }
     286    }
     287    /**
     288     * Get card information.
     289     *
     290     * @since 7.3.0
     291     * @return object
     292     */
     293    private function get_posted_card() {
     294        $card_number    = isset( $_POST['wc_valorpay-card-number'] ) ? wc_clean( $_POST['wc_valorpay-card-number'] ) : ''; // phpcs:ignore
     295        $card_cvc       = isset( $_POST['wc_valorpay-card-cvc'] ) ? wc_clean( $_POST['wc_valorpay-card-cvc'] ) : ''; // phpcs:ignore
     296        $card_expiry    = isset( $_POST['wc_valorpay-card-expiry'] ) ? wc_clean( $_POST['wc_valorpay-card-expiry'] ) : ''; // phpcs:ignore
     297        $card_number    = str_replace( array( ' ', '-' ), '', $card_number );
     298        $card_expiry    = array_map( 'trim', explode( '/', $card_expiry ) );
     299        $card_exp_month = str_pad( $card_expiry[0], 2, '0', STR_PAD_LEFT );
     300        $card_exp_year  = isset( $card_expiry[1] ) ? $card_expiry[1] : '';
     301        if ( 2 === strlen( $card_exp_year ) ) {
     302            $card_exp_year += 2000;
     303        }
     304        return (object) array(
     305            'number'    => $card_number,
     306            'type'      => '',
     307            'cvc'       => $card_cvc,
     308            'exp_month' => $card_exp_month,
     309            'exp_year'  => $card_exp_year,
     310        );
     311    }
     312
     313    /**
     314     * Validate frontend fields.
     315     *
     316     * Validate payment fields on the frontend.
     317     *
     318     * @since 7.3.0
     319     * @throws \Exception If the card information is invalid.
     320     * @return bool
     321     */
     322    public function validate_fields() {
     323        try {
     324            if ( isset( $_POST['wc-wc_valorpay-payment-token'] ) && 'new' !== wc_clean( $_POST['wc-wc_valorpay-payment-token'] ) ) { // phpcs:ignore
     325                return true;
     326            }
     327            $card          = $this->get_posted_card();
     328            $current_year  = gmdate( 'Y' );
     329            $current_month = gmdate( 'n' );
     330
     331            if ( empty( $card->number ) || ! ctype_digit( $card->number ) || strlen( $card->number ) < 12 || strlen( $card->number ) > 19 ) {
     332                throw new Exception( __( 'Card number is invalid', 'wc-valorpay' ) );
     333            }
     334
     335            if ( ! ( $this->luhn_check( $card->number ) ) ) {
     336                throw new Exception( __( 'Not a valid card', 'wc-valorpay' ) );
     337            }
     338            if ( empty( $card->exp_month ) || empty( $card->exp_year ) || ! ctype_digit( $card->exp_month ) || ! ctype_digit( $card->exp_year ) || $card->exp_month > 12 || $card->exp_month < 1 || $card->exp_year < $current_year || ( $card->exp_year === $current_year && $card->exp_month < $current_month ) ) {
     339                throw new Exception( __( 'Card number  expired', 'wc-valorpay' ) );
     340            }
     341            if ( ! ctype_digit( $card->cvc ) ) {
     342                throw new Exception( __( 'Card security code is invalid (only digits are allowed)', 'wc-valorpay' ) );
     343            }
     344
     345            return true;
     346        } catch ( Exception $e ) {
     347            wc_add_notice( $e->getMessage(), 'error' );
     348            return false;
     349        }
     350    }
    268351
    269352    /**
     
    519602     *
    520603     * @since 1.0.0
     604     */
     605    public function add_card_field_id() {
     606
     607        $fields['card-number-field']['label_class'] .= ' woocommerce-input-wrapper';
     608        $fields['card-number-field']['class'][]      = 'form-row-wide';
     609        $fields['card-number-field']['id']           = 'wc-valorpay-card-field';
     610        return $fields;
     611    }
     612
     613    /**
     614     * Surcharge admin validation.
     615     *
     616     * @since 7.2.0
    521617     */
    522618    public function process_admin_options() {
     
    780876    }
    781877
     878
     879
     880
    782881}
     882
     883
     884
     885
  • valorpos/trunk/includes/class-wc-valorpay.php

    r2883367 r2918841  
    202202        $this->loader->add_action( 'woocommerce_after_checkout_form', $plugin_public, 'valorpay_checkout_script' );
    203203        $this->loader->add_filter( 'woocommerce_available_payment_gateways', $plugin_public, 'valorpay_disable_payment_gateway_failed_orders' );
     204
    204205    }
    205206
     
    245246
    246247}
     248
  • valorpos/trunk/languages/wc-valorpay.pot

    r2897749 r2918841  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Valor Pay 7.2.1\n"
     5"Project-Id-Version: Valor Pay 7.3.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-valorpay\n"
    77"Last-Translator: Valor Paytech LLC <sales@valorpaytech.com>\n"
     
    99"Content-Type: text/plain; charset=UTF-8\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "POT-Creation-Date: 2023-03-27T15:16:11+05:30\n"
     11"POT-Creation-Date: 2023-05-19T15:31:04+05:30\n"
    1212"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1313"X-Generator: WP-CLI 2.7.1\n"
     
    1515
    1616#. Plugin Name of the plugin
    17 #: includes/class-wc-valorpay-gateway.php:372
     17#: includes/class-wc-valorpay-gateway.php:455
    1818msgid "Valor Pay"
    1919msgstr ""
     
    6969
    7070#: admin/partials/wc-valorpay-admin-failure-tracker.php:18
    71 #: includes/class-wc-valorpay-gateway.php:460
     71#: includes/class-wc-valorpay-gateway.php:543
    7272msgid "Payment Failed Tracker"
    7373msgstr ""
     
    169169msgstr ""
    170170
     171#: includes/class-wc-valorpay-gateway.php:332
     172msgid "Card number is invalid"
     173msgstr ""
     174
     175#: includes/class-wc-valorpay-gateway.php:336
     176msgid "Not a valid card"
     177msgstr ""
     178
     179#: includes/class-wc-valorpay-gateway.php:339
     180msgid "Card number  expired"
     181msgstr ""
     182
     183#: includes/class-wc-valorpay-gateway.php:342
     184msgid "Card security code is invalid (only digits are allowed)"
     185msgstr ""
     186
    171187#. translators: 1: Terms and Conditions URL.
    172 #: includes/class-wc-valorpay-gateway.php:295
     188#: includes/class-wc-valorpay-gateway.php:378
    173189msgid "I agree to the <a href=\"%s\" target=\"_blank\">Terms and Conditions</a>"
    174190msgstr ""
    175191
    176 #: includes/class-wc-valorpay-gateway.php:326
    177 #: includes/class-wc-valorpay-gateway.php:327
     192#: includes/class-wc-valorpay-gateway.php:409
     193#: includes/class-wc-valorpay-gateway.php:410
    178194msgid "Zip Code"
    179195msgstr ""
    180196
    181 #: includes/class-wc-valorpay-gateway.php:340
    182 #: includes/class-wc-valorpay-gateway.php:341
     197#: includes/class-wc-valorpay-gateway.php:423
     198#: includes/class-wc-valorpay-gateway.php:424
    183199msgid "Street No"
    184200msgstr ""
    185201
    186 #: includes/class-wc-valorpay-gateway.php:362
     202#: includes/class-wc-valorpay-gateway.php:445
    187203msgid "Enable/Disable"
    188204msgstr ""
    189205
    190 #: includes/class-wc-valorpay-gateway.php:363
     206#: includes/class-wc-valorpay-gateway.php:446
    191207msgid "Enable Valor Pay"
    192208msgstr ""
    193209
    194 #: includes/class-wc-valorpay-gateway.php:369
     210#: includes/class-wc-valorpay-gateway.php:452
    195211msgid "Title"
    196212msgstr ""
    197213
    198 #: includes/class-wc-valorpay-gateway.php:371
     214#: includes/class-wc-valorpay-gateway.php:454
    199215msgid "This controls the title which the user sees during checkout."
    200216msgstr ""
    201217
    202 #: includes/class-wc-valorpay-gateway.php:376
     218#: includes/class-wc-valorpay-gateway.php:459
    203219msgid "Use Sandbox"
    204220msgstr ""
    205221
    206 #: includes/class-wc-valorpay-gateway.php:377
     222#: includes/class-wc-valorpay-gateway.php:460
    207223msgid "Enable sandbox mode - live payments will not be taken if enabled."
    208224msgstr ""
    209225
    210 #: includes/class-wc-valorpay-gateway.php:383
     226#: includes/class-wc-valorpay-gateway.php:466
    211227msgid "APP ID"
    212228msgstr ""
    213229
    214 #: includes/class-wc-valorpay-gateway.php:385
     230#: includes/class-wc-valorpay-gateway.php:468
    215231msgid "Please email support@valorpaytech.com to get to know about your APP ID, ( In demo mode APP ID is not needed )"
    216232msgstr ""
    217233
    218 #: includes/class-wc-valorpay-gateway.php:389
     234#: includes/class-wc-valorpay-gateway.php:472
    219235msgid "APP KEY"
    220236msgstr ""
    221237
    222 #: includes/class-wc-valorpay-gateway.php:391
     238#: includes/class-wc-valorpay-gateway.php:474
    223239msgid "Please email support@valorpaytech.com to get to know about your APP KEY, ( In demo mode APP KEY is not needed )"
    224240msgstr ""
    225241
    226 #: includes/class-wc-valorpay-gateway.php:395
     242#: includes/class-wc-valorpay-gateway.php:478
    227243msgid "EPI"
    228244msgstr ""
    229245
    230 #: includes/class-wc-valorpay-gateway.php:397
     246#: includes/class-wc-valorpay-gateway.php:480
    231247msgid "Please email support@valorpaytech.com to get to know about your EPI ID, ( In demo mode EPI ID is not needed )"
    232248msgstr ""
    233249
    234 #: includes/class-wc-valorpay-gateway.php:401
     250#: includes/class-wc-valorpay-gateway.php:484
    235251msgid "Payment Method"
    236252msgstr ""
    237253
    238 #: includes/class-wc-valorpay-gateway.php:411
     254#: includes/class-wc-valorpay-gateway.php:494
    239255msgid "Surcharge Mode"
    240256msgstr ""
    241257
    242 #: includes/class-wc-valorpay-gateway.php:412
    243 #: includes/class-wc-valorpay-gateway.php:419
     258#: includes/class-wc-valorpay-gateway.php:495
     259#: includes/class-wc-valorpay-gateway.php:502
    244260msgid "Enable Surcharge Mode"
    245261msgstr ""
    246262
    247 #: includes/class-wc-valorpay-gateway.php:414
     263#: includes/class-wc-valorpay-gateway.php:497
    248264msgid "Enable only if you want all transactions to be fall on surcharge mode, Merchant must have got an Surcharge MID inorder to work"
    249265msgstr ""
    250266
    251 #: includes/class-wc-valorpay-gateway.php:418
     267#: includes/class-wc-valorpay-gateway.php:501
    252268msgid "Surcharge Type"
    253269msgstr ""
    254270
    255 #: includes/class-wc-valorpay-gateway.php:428
    256 #: includes/class-wc-valorpay-gateway.php:429
     271#: includes/class-wc-valorpay-gateway.php:511
     272#: includes/class-wc-valorpay-gateway.php:512
    257273msgid "Surcharge Label"
    258274msgstr ""
    259275
    260 #: includes/class-wc-valorpay-gateway.php:434
     276#: includes/class-wc-valorpay-gateway.php:517
    261277msgid "Surcharge %"
    262278msgstr ""
    263279
    264 #: includes/class-wc-valorpay-gateway.php:438
     280#: includes/class-wc-valorpay-gateway.php:521
    265281msgid "Percentage will apply only on enabling on surcharge Indicator to true and Surcharge type is set fo Surcharge %"
    266282msgstr ""
    267283
    268 #: includes/class-wc-valorpay-gateway.php:441
     284#: includes/class-wc-valorpay-gateway.php:524
    269285msgid "Flat Rate $"
    270286msgstr ""
    271287
    272 #: includes/class-wc-valorpay-gateway.php:444
     288#: includes/class-wc-valorpay-gateway.php:527
    273289msgid "Flat rate  will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $"
    274290msgstr ""
    275291
    276 #: includes/class-wc-valorpay-gateway.php:447
     292#: includes/class-wc-valorpay-gateway.php:530
    277293msgid "AVS"
    278294msgstr ""
    279295
    280 #: includes/class-wc-valorpay-gateway.php:457
     296#: includes/class-wc-valorpay-gateway.php:540
    281297msgid "The address verification service will add a text field to the checkout page based on the above option."
    282298msgstr ""
    283299
    284 #: includes/class-wc-valorpay-gateway.php:461
     300#: includes/class-wc-valorpay-gateway.php:544
    285301msgid "Enable Protection"
    286302msgstr ""
    287303
    288304#. translators: 1: Tracker URL.
    289 #: includes/class-wc-valorpay-gateway.php:465
     305#: includes/class-wc-valorpay-gateway.php:548
    290306msgid "Disable the payment method in the checkout page for failed transactions. <a id=\"valorpay-goto-tracker\" href=\"%s\">Unblock IP</a>"
    291307msgstr ""
    292308
    293 #: includes/class-wc-valorpay-gateway.php:471
     309#: includes/class-wc-valorpay-gateway.php:554
    294310msgid "Declined Transaction Count"
    295311msgstr ""
    296312
    297 #: includes/class-wc-valorpay-gateway.php:472
     313#: includes/class-wc-valorpay-gateway.php:555
    298314msgid "Number of declined transaction count."
    299315msgstr ""
    300316
    301 #: includes/class-wc-valorpay-gateway.php:476
     317#: includes/class-wc-valorpay-gateway.php:559
    302318msgid "3"
    303319msgstr ""
    304320
    305 #: includes/class-wc-valorpay-gateway.php:477
     321#: includes/class-wc-valorpay-gateway.php:560
    306322msgid "5"
    307323msgstr ""
    308324
    309 #: includes/class-wc-valorpay-gateway.php:478
     325#: includes/class-wc-valorpay-gateway.php:561
    310326msgid "6"
    311327msgstr ""
    312328
    313 #: includes/class-wc-valorpay-gateway.php:482
     329#: includes/class-wc-valorpay-gateway.php:565
    314330msgid "Block Payment For"
    315331msgstr ""
    316332
    317 #: includes/class-wc-valorpay-gateway.php:483
     333#: includes/class-wc-valorpay-gateway.php:566
    318334msgid "Minutes to block payment gateway in checkout."
    319335msgstr ""
    320336
    321 #: includes/class-wc-valorpay-gateway.php:487
     337#: includes/class-wc-valorpay-gateway.php:570
    322338msgid "1 min"
    323339msgstr ""
    324340
    325 #: includes/class-wc-valorpay-gateway.php:488
     341#: includes/class-wc-valorpay-gateway.php:571
    326342msgid "5 min"
    327343msgstr ""
    328344
    329 #: includes/class-wc-valorpay-gateway.php:489
     345#: includes/class-wc-valorpay-gateway.php:572
    330346msgid "10 min"
    331347msgstr ""
    332348
    333 #: includes/class-wc-valorpay-gateway.php:490
     349#: includes/class-wc-valorpay-gateway.php:573
    334350msgid "1 hour"
    335351msgstr ""
    336352
    337 #: includes/class-wc-valorpay-gateway.php:491
     353#: includes/class-wc-valorpay-gateway.php:574
    338354msgid "3 hour"
    339355msgstr ""
    340356
    341 #: includes/class-wc-valorpay-gateway.php:492
     357#: includes/class-wc-valorpay-gateway.php:575
    342358msgid "5 hour"
    343359msgstr ""
    344360
    345 #: includes/class-wc-valorpay-gateway.php:493
     361#: includes/class-wc-valorpay-gateway.php:576
    346362msgid "10 hour"
    347363msgstr ""
    348364
    349 #: includes/class-wc-valorpay-gateway.php:494
     365#: includes/class-wc-valorpay-gateway.php:577
    350366msgid "1 day"
    351367msgstr ""
    352368
    353 #: includes/class-wc-valorpay-gateway.php:498
     369#: includes/class-wc-valorpay-gateway.php:581
    354370msgid "Accepted Cards"
    355371msgstr ""
    356372
    357 #: includes/class-wc-valorpay-gateway.php:502
     373#: includes/class-wc-valorpay-gateway.php:585
    358374msgid "Select the card types to accept."
    359375msgstr ""
    360376
    361377#. translators: 1: Maximum percentage.
    362 #: includes/class-wc-valorpay-gateway.php:528
     378#: includes/class-wc-valorpay-gateway.php:624
    363379msgid "Surcharge percentage cannot be more than %s"
    364380msgstr ""
    365381
    366382#. translators: 1: Maximum flat rate.
    367 #: includes/class-wc-valorpay-gateway.php:533
     383#: includes/class-wc-valorpay-gateway.php:629
    368384msgid "Surcharge flat rate cannot be more than %s"
    369385msgstr ""
    370386
    371 #: includes/class-wc-valorpay-gateway.php:578
     387#: includes/class-wc-valorpay-gateway.php:674
    372388msgid "Invalid card information."
    373389msgstr ""
    374390
    375391#. translators: 1: Error Message, 2: Amount, 3: Line Break, 4: Approval Code, 5: Line Break, 6: RRN Number.
    376 #: includes/class-wc-valorpay-gateway.php:594
     392#: includes/class-wc-valorpay-gateway.php:690
    377393msgid "Valor Pay %1$s for %2$s.%3$s <strong>Approval Code:</strong> %4$s.%5$s <strong>RRN:</strong> %6$s"
    378394msgstr ""
    379395
    380396#. translators: %s: API Error Message.
    381 #: includes/class-wc-valorpay-gateway.php:630
    382 #: includes/class-wc-valorpay-gateway.php:633
     397#: includes/class-wc-valorpay-gateway.php:726
     398#: includes/class-wc-valorpay-gateway.php:729
    383399msgid "Payment error: %s"
    384400msgstr ""
    385401
    386 #: includes/class-wc-valorpay-gateway.php:635
     402#: includes/class-wc-valorpay-gateway.php:731
    387403msgid "Unable to process the transaction using Valor Pay, please try again."
    388404msgstr ""
    389405
    390406#. translators: 1: Disable Time, 2: Unblock IP URL, 3: Customer IP.
    391 #: includes/class-wc-valorpay-gateway.php:694
     407#: includes/class-wc-valorpay-gateway.php:790
    392408msgid "Valor Pay method is disabled for %1$s. <a target=\"_blank\" href=\"%2$s\">To Unblock IP</a> %3$s"
    393409msgstr ""
    394410
    395 #: includes/class-wc-valorpay-gateway.php:757
     411#: includes/class-wc-valorpay-gateway.php:853
    396412msgid "Refund failed."
    397413msgstr ""
    398414
    399415#. translators: 1: Amount, 2: Line Break, 3: Approval code, 4: Line Break, 5: RRN Code
    400 #: includes/class-wc-valorpay-gateway.php:769
     416#: includes/class-wc-valorpay-gateway.php:865
    401417msgid "Valor Pay Refund for %1$s.%2$s <strong>Approval Code:</strong> %3$s.%4$s <strong>RRN:</strong> %5$s"
    402418msgstr ""
    403419
    404 #: public/class-wc-valorpay-public.php:93
     420#: public/class-wc-valorpay-public.php:80
     421msgid "Please enter a card number"
     422msgstr ""
     423
     424#: public/class-wc-valorpay-public.php:81
     425msgid "Invalid card number"
     426msgstr ""
     427
     428#: public/class-wc-valorpay-public.php:82
     429msgid "Card is expired"
     430msgstr ""
     431
     432#: public/class-wc-valorpay-public.php:83
     433msgid "Please enter card expiry date"
     434msgstr ""
     435
     436#: public/class-wc-valorpay-public.php:84
     437msgid "Please enter a CVC"
     438msgstr ""
     439
     440#: public/class-wc-valorpay-public.php:85
     441msgid "Invalid CVC length"
     442msgstr ""
     443
     444#: public/class-wc-valorpay-public.php:86
     445msgid "Please enter a zip code"
     446msgstr ""
     447
     448#: public/class-wc-valorpay-public.php:87
     449msgid "Invalid zip code"
     450msgstr ""
     451
     452#: public/class-wc-valorpay-public.php:88
     453msgid "Please enter a street address"
     454msgstr ""
     455
     456#: public/class-wc-valorpay-public.php:108
    405457msgid "Zip Code is required."
    406458msgstr ""
    407459
    408 #: public/class-wc-valorpay-public.php:96
     460#: public/class-wc-valorpay-public.php:111
    409461msgid "Enter a valid Zip Code."
    410462msgstr ""
    411463
    412 #: public/class-wc-valorpay-public.php:101
     464#: public/class-wc-valorpay-public.php:116
    413465msgid "Street No is required."
    414466msgstr ""
    415467
    416 #: public/class-wc-valorpay-public.php:104
     468#: public/class-wc-valorpay-public.php:119
    417469msgid "Enter a valid Street No."
    418470msgstr ""
  • valorpos/trunk/public/class-wc-valorpay-public.php

    r2887504 r2918841  
    7474
    7575        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        );
    7691
    7792    }
  • valorpos/trunk/public/js/wc-valorpay-checkout.js

    r2897749 r2918841  
    66 */
    77
    8 (function( $ ) {
    9     'use strict';
    10 
    11     $( 'body' ).on(
    12         'change',
    13         'input[name="payment_method"]',
    14         function(){
    15             $( 'body' ).trigger( 'update_checkout' );
    16         }
    17     );
    18 
    19 })( jQuery );
     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 {
     180                    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);
  • valorpos/trunk/wc-valorpay.php

    r2897749 r2918841  
    1616 * Plugin URI:        https://valorpaytech.com
    1717 * Description:       Adds the Valor Payment Gateway to WooCommerce.
    18  * Version:           7.2.1
     18 * Version:           7.3.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.2.1' );
     39define( 'WC_VALORPAY_VERSION', '7.3.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.