Plugin Directory

Changeset 3042319


Ignore:
Timestamp:
02/28/2024 06:52:06 AM (2 years ago)
Author:
abubacker
Message:

Tagging version 7.6.0 with Added support for high-performance order storage, ecommerce device identification, and subscription products with -zsh initial payment

Location:
valorpos
Files:
18 edited
1 copied

Legend:

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

    r3002583 r3042319  
    55Tested up to: 6.3.1
    66Requires PHP: 7.0
    7 Stable tag: 7.5.0
     7Stable tag: 7.6.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1818
    1919Software Systems and Payment Devices from Valor are the best around for smart hassle-free transactions. Cost-efficient and super smart. With value-added features and reliable service support to match, you’d want Valor to be your partner for growth, always.
     20
     21**WARNING:** The issue of tax price being calculated twice has been resolved in versions 7.3 and above. Please ensure that you are using version 7.3 or later to avoid encountering this problem.
    2022
    2123== Installation ==
     
    4042
    4143== Changelog ==
     44
     45= 7.6.0 =
     46* Added support for High Performance Order Storage, Ecommerce device identifier, and allowing a subscription product with a $0 initial payment has been added.
    4247
    4348= 7.5.0 =
  • valorpos/tags/7.6.0/admin/class-wc-valorpay-admin.php

    r2980555 r3042319  
    7474         * class.
    7575         */
    76         global $post;
    77 
    78             // Get admin screen id.
     76
     77        // Get admin screen id.
    7978        $screen    = get_current_screen();
    8079        $screen_id = isset( $screen->id ) ? $screen->id : '';
    8180
    82         if ( 'shop_order' === $screen_id ) {
     81        if ( in_array( $screen_id, array( 'shop_order', 'woocommerce_page_wc-orders' ), true ) ) {
    8382            // Load order .
    84             $order = wc_get_order( $post->ID );
     83            $order = wc_get_order();
    8584            // Load JS file only for valor payment method .
    86             if ( WC_ValorPay_Gateway::GATEWAY_ID === $order->get_payment_method() ) {
     85            if ( $order && WC_ValorPay_Gateway::GATEWAY_ID === $order->get_payment_method() ) {
    8786                wp_register_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-refund.js', array( 'jquery' ), $this->version, false );
    8887                wp_enqueue_script( $this->plugin_name );
  • valorpos/tags/7.6.0/admin/partials/wc-valorpay-admin-order-refund.php

    r2883367 r3042319  
    4848                    <div class="inner">
    4949                        <button id="btn-valor-otp" class="button button-primary button-large button-valor-submit"><?php echo esc_html_e( 'Submit', 'woocommerce' ); ?></button>
    50                         <button id="btn-valor-resend" class="button button-primary button-large button-valor-resend" style="display: none;"><?php echo esc_html_e( 'Resend OTP', 'woocommerce' ); ?></button>
     50                        <button id="btn-valor-resend" class="button button-primary button-large button-valor-resend" style="display: none;"><?php echo esc_html_e( 'Resend OTP', 'wc-valorpay' ); ?></button>
    5151                        <span id="valor-resend-load" class="spinner" style="display: none;"></span>
    5252                    </div>
  • valorpos/tags/7.6.0/includes/class-wc-valorpay-api.php

    r3002583 r3042319  
    4848     */
    4949    const WC_VALORPAY_BIN_LOOKUP_ACTION = 'binLookup';
     50    /**
     51     * Card token action
     52     */
     53    const WC_VALORPAY_CARD_TOKEN_ACTION = 'cardToken';
     54    /**
     55     * Ecommerce Channel ID
     56     */
     57    const WC_VALORPAY_ECOMM_CHANNEL = 'woocommerce';
    5058
    5159    /**
     
    199207        $response = $this->post_transaction( wp_json_encode( $payload ), 'bin_lookup' );
    200208        return $response;
     209    }
     210
     211    /**
     212     * Generate card token
     213     *
     214     * @since 7.6.0
     215     *
     216     * @param WC_Order $order Order Detail.
     217     * @param array    $card_detail Card detail.
     218     */
     219    public function generate_card_token( $order, $card_detail ) {
     220        $client_token_response = $this->create_checkout_page_token();
     221        if ( is_wp_error( $client_token_response ) || ! is_object( $client_token_response ) || ! isset( $client_token_response->clientToken ) ) { // phpcs:ignore
     222            $order->add_order_note( __( 'Payment error: Unable to generate client token.', 'wc-valorpay' ) );
     223            return array(
     224                'error' => __( 'Sorry, we\'re unable to create a card token right now.', 'wc-valorpay' ),
     225            );
     226        }
     227        $client_token = $client_token_response->clientToken; // phpcs:ignore
     228        $args         = array(
     229            'txn_type'     => self::WC_VALORPAY_CARD_TOKEN_ACTION,
     230            'epi'          => $this->gateway->epi,
     231            'client_token' => $client_token,
     232            'pan'          => $card_detail['card_num'],
     233            'expirydate'   => $card_detail['card_expiry'],
     234        );
     235        $request_url  = add_query_arg( $args, $this->get_valorpay_url() );
     236        $api_args     = array(
     237            'headers' => array(
     238                'Content-Type' => 'application/json',
     239            ),
     240            'method'  => 'POST',
     241            'timeout' => 70,
     242        );
     243        $api_response = wp_remote_post( $request_url, $api_args );
     244        if ( is_wp_error( $api_response ) || empty( $api_response['body'] ) ) {
     245            $order->add_order_note( __( 'Payment error: Unable to generate card token.', 'wc-valorpay' ) );
     246            return array(
     247                'error' => __( 'Sorry, we\'re unable to create a card token right now.', 'wc-valorpay' ),
     248            );
     249        }
     250        $parsed_response = json_decode( preg_replace( '/\xEF\xBB\xBF/', '', $api_response['body'] ), true );
     251        if ( ! isset( $parsed_response['cardToken'] ) ) {
     252            $order->add_order_note( __( 'Payment error: Unable to generate card token.', 'wc-valorpay' ) );
     253            return array(
     254                'error' => __( 'Sorry, we\'re unable to create a card token right now.', 'wc-valorpay' ),
     255            );
     256        }
     257        return array(
     258            'token' => $parsed_response['cardToken'],
     259        );
    201260    }
    202261
     
    277336                'status'           => 'Y',
    278337                'terms_checked'    => $valorpay_terms,
     338                'ecomm_channel'    => self::WC_VALORPAY_ECOMM_CHANNEL,
    279339            ) + $surcharge_data;
    280340
     
    306366                'epi'                => $this->gateway->epi,
    307367                'ip'                 => WC_Geolocation::get_ip_address(),
    308                 'sales_refund'       => 1,
    309368                'ref_txn_id'         => $order->get_transaction_id(),
    310                 'rrn'                => $valorpay_order_meta['rrn'],
    311369                'auth_code'          => $valorpay_order_meta['approval_code'],
    312370                'surchargeIndicator' => ( 'yes' === $this->gateway->surcharge_indicator ) ? 1 : 0,
    313371                'otp'                => $order->get_meta( '_valorpay_2fa_otp' ),
    314372                'uuid'               => $order->get_meta( '_valorpay_otp_uuid' ),
    315             );
    316             delete_post_meta( $order->get_id(), '_valorpay_2fa_otp' );
    317             delete_post_meta( $order->get_id(), '_valorpay_otp_uuid' );
     373                'ecomm_channel'      => self::WC_VALORPAY_ECOMM_CHANNEL,
     374            );
     375            $order->delete_meta_data( '_valorpay_2fa_otp' );
     376            $order->delete_meta_data( '_valorpay_otp_uuid' );
     377            $order->save();
    318378        } elseif ( 'send_otp' === $transaction_type ) {
    319379            $data = array(
     
    390450                'surchargeIndicator' => $surcharge_indicator,
    391451                'surchargeAmount'    => sprintf( '%.2f', $surcharge ),
     452                'ecomm_channel'      => self::WC_VALORPAY_ECOMM_CHANNEL,
    392453            );
    393454
  • valorpos/tags/7.6.0/includes/class-wc-valorpay-gateway-addons.php

    r3002598 r3042319  
    6161            'post_meta' => array(
    6262                '_valorpay_card_token' => array(
    63                     'value' => get_post_meta( $subscription->id, '_valorpay_card_token', true ),
     63                    'value' => $subscription->get_meta( '_valorpay_card_token', true ),
    6464                    'label' => __( 'ValorPay Card Token', 'wc-valorpay' ),
    6565                ),
    6666                '_valorpay_card_type'  => array(
    67                     'value' => get_post_meta( $subscription->id, '_valorpay_card_type', true ),
     67                    'value' => $subscription->get_meta( '_valorpay_card_type', true ),
    6868                    'label' => __( 'ValorPay Card Type', 'wc-valorpay' ),
    6969                ),
  • valorpos/tags/7.6.0/includes/class-wc-valorpay-gateway.php

    r3002583 r3042319  
    702702
    703703            $valorpay_api = new WC_ValorPay_API( $this );
     704            // Check if subscription order or if order total is zero, then add the card token to subscriptions.
     705            if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Order::order_contains_subscription( $order->get_id() ) && '0.00' === $amount ) {
     706                if ( $card ) {
     707                    $subscription_payload              = new stdClass();
     708                    $subscription_payload->token       = $card->get_token();
     709                    $subscription_payload->expiry_date = $card->get_expiry_month() . substr( $card->get_expiry_year(), -2 );
     710                    $is_debit_card                     = 'D' === WC()->session->get( 'valor_card_type' );
     711                } else {
     712                    $card_number = str_replace( ' ', '', ( isset( $_POST['wc_valorpay-card-number'] ) ) ? sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) : '' ); // phpcs:ignore
     713                    $exp_date_array = explode( '/', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-expiry'] ) ) ); // phpcs:ignore
     714                    $exp_month           = trim( $exp_date_array[0] );
     715                    $exp_year            = trim( $exp_date_array[1] );
     716                    $exp_date            = $exp_month . substr( $exp_year, -2 );
     717                    $card_detail         = array(
     718                        'card_num'    => $card_number,
     719                        'card_expiry' => $exp_date,
     720                    );
     721                    $card_token_response = $valorpay_api->generate_card_token( $order, $card_detail );
     722                    if ( isset( $card_token_response['error'] ) ) {
     723                        throw new Exception( $card_token_response['error'] );
     724                    }
     725                    $subscription_payload              = new stdClass();
     726                    $subscription_payload->token       = $card_token_response['token'];
     727                    $subscription_payload->expiry_date = $exp_month . substr( $exp_year, -2 );
     728                    $is_debit_card                     = 'D' === WC()->session->get( 'valor_card_type' );
     729                }
     730                $this->update_subscription_card_token( $order, $subscription_payload, $is_debit_card );
     731                $order->payment_complete();
     732                $order->add_order_note( __( 'Valor Pay: Card token added to subscription.', 'wc-valorpay' ) );
     733                return array(
     734                    'result'   => 'success',
     735                    'redirect' => $this->get_return_url( $order ),
     736                );
     737            }
    704738            // Call the sale or authorization API.
    705739            $response = $valorpay_api->purchase( $order, $amount, $card );
     
    728762                    $exp_year            = trim( $exp_date_array[1] );
    729763                    $exp_date            = $exp_month . substr( $exp_year, -2 );
    730                     $response->card_type = $valorpay_api->get_card_type( str_replace( ' ', '', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) ) ); // phpcs:ignore
     764                    $response->card_type = isset( $response->card_brand ) && $response->card_brand ? $response->card_brand : $valorpay_api->get_card_type( str_replace( ' ', '', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) ) ); // phpcs:ignore
    731765                    $this->save_card( $response, $exp_date, ( 'D' === WC()->session->get( 'valor_card_type' ) ) ? 1 : 0 );
    732766                }
     
    739773                    'approval_code'  => $response->approval_code,
    740774                );
    741                 add_post_meta( $order_id, '_valorpay_transaction', $tran_meta );
     775                $order->add_meta_data( '_valorpay_transaction', $tran_meta );
     776                $order->save();
    742777                $is_debit_card = 'D' === WC()->session->get( 'valor_card_type' );
    743778                if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Order::order_contains_subscription( $order->get_id() ) ) {
  • valorpos/tags/7.6.0/languages/wc-valorpay.pot

    r3002583 r3042319  
    1 # Copyright (C) 2023 Valor Paytech LLC
     1# Copyright (C) 2024 Valor Paytech LLC
    22# This file is distributed under the GPL-2.0+.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Valor Pay 7.5.0\n"
     5"Project-Id-Version: Valor Pay 7.6.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/valorpos\n"
    77"Last-Translator: Valor Paytech LLC <isv@valorpaytech.com>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-11-20T06:34:41+00:00\n"
    13 "PO-Revision-Date: 2023-11-20T06:34:41+00:00\n"
     12"POT-Creation-Date: 2024-02-20T10:51:04+05:30\n"
     13"PO-Revision-Date: 2024-02-20T10:51:04+05:30\n"
    1414"X-Generator: WP-CLI 2.7.1\n"
    1515"X-Domain: wc-valorpay\n"
     
    3333msgstr ""
    3434
    35 #: admin/class-wc-valorpay-admin.php:119
     35#: admin/class-wc-valorpay-admin.php:118
    3636msgid "Are you sure you want to remove?"
    3737msgstr ""
    3838
    39 #: admin/class-wc-valorpay-admin.php:138
     39#: admin/class-wc-valorpay-admin.php:137
    4040msgid "Settings"
    4141msgstr ""
    4242
    43 #: admin/class-wc-valorpay-admin.php:197
    44 #: admin/class-wc-valorpay-admin.php:292
     43#: admin/class-wc-valorpay-admin.php:196
     44#: admin/class-wc-valorpay-admin.php:291
    4545msgid "Invalid Request."
    4646msgstr ""
    4747
    48 #: admin/class-wc-valorpay-admin.php:207
    49 #: admin/class-wc-valorpay-admin.php:275
    50 #: admin/class-wc-valorpay-admin.php:306
     48#: admin/class-wc-valorpay-admin.php:206
     49#: admin/class-wc-valorpay-admin.php:274
     50#: admin/class-wc-valorpay-admin.php:305
    5151msgid "Error Occurred."
    5252msgstr ""
    5353
    54 #: admin/class-wc-valorpay-admin.php:242
     54#: admin/class-wc-valorpay-admin.php:241
    5555msgid "Order Id Missing."
    5656msgstr ""
    5757
    58 #: admin/class-wc-valorpay-admin.php:246
     58#: admin/class-wc-valorpay-admin.php:245
    5959msgid "Enter a valid refund amount."
    6060msgstr ""
    6161
    6262#. translators: 1: Email Address, 2: Mobile Number
    63 #: admin/class-wc-valorpay-admin.php:270
     63#: admin/class-wc-valorpay-admin.php:269
    6464msgid "OTP sent to your registered Email Address %1$s and Mobile Number %2$s"
    6565msgstr ""
    6666
    67 #: admin/class-wc-valorpay-admin.php:297
     67#: admin/class-wc-valorpay-admin.php:296
    6868msgid "Enter Valid OTP."
    6969msgstr ""
     
    123123msgstr ""
    124124
    125 #: includes/class-wc-valorpay-api.php:420
    126 #: includes/class-wc-valorpay-api.php:425
    127 #: includes/class-wc-valorpay-api.php:433
    128 #: includes/class-wc-valorpay-api.php:437
     125#: admin/partials/wc-valorpay-admin-order-refund.php:50
     126msgid "Resend OTP"
     127msgstr ""
     128
     129#: includes/class-wc-valorpay-api.php:222
     130msgid "Payment error: Unable to generate client token."
     131msgstr ""
     132
     133#: includes/class-wc-valorpay-api.php:224
     134#: includes/class-wc-valorpay-api.php:247
     135#: includes/class-wc-valorpay-api.php:254
     136msgid "Sorry, we're unable to create a card token right now."
     137msgstr ""
     138
     139#: includes/class-wc-valorpay-api.php:245
     140#: includes/class-wc-valorpay-api.php:252
     141msgid "Payment error: Unable to generate card token."
     142msgstr ""
     143
     144#: includes/class-wc-valorpay-api.php:481
     145#: includes/class-wc-valorpay-api.php:486
     146#: includes/class-wc-valorpay-api.php:494
     147#: includes/class-wc-valorpay-api.php:498
    129148msgid "There was a problem connecting to the payment gateway."
    130149msgstr ""
     
    457476msgstr ""
    458477
     478#: includes/class-wc-valorpay-gateway.php:732
     479msgid "Valor Pay: Card token added to subscription."
     480msgstr ""
     481
    459482#. translators: 1: Error Message, 2: Amount, 3: Line Break, 4: Approval Code, 5: Line Break, 6: RRN Number.
    460 #: includes/class-wc-valorpay-gateway.php:715
     483#: includes/class-wc-valorpay-gateway.php:749
    461484msgid "Valor Pay %1$s for %2$s.%3$s <strong>Approval Code:</strong> %4$s.%5$s <strong>RRN:</strong> %6$s"
    462485msgstr ""
    463486
    464487#. translators: %s: API Error Message.
    465 #: includes/class-wc-valorpay-gateway.php:755
    466 #: includes/class-wc-valorpay-gateway.php:758
     488#: includes/class-wc-valorpay-gateway.php:790
     489#: includes/class-wc-valorpay-gateway.php:793
    467490msgid "Payment error: %s"
    468491msgstr ""
    469492
    470 #: includes/class-wc-valorpay-gateway.php:760
     493#: includes/class-wc-valorpay-gateway.php:795
    471494msgid "Unable to process the transaction using Valor Pay, please try again."
    472495msgstr ""
    473496
    474497#. translators: 1: Disable Time, 2: Unblock IP URL, 3: Customer IP.
    475 #: includes/class-wc-valorpay-gateway.php:851
     498#: includes/class-wc-valorpay-gateway.php:886
    476499msgid "Valor Pay method is disabled for %1$s. <a target=\"_blank\" href=\"%2$s\">To Unblock IP</a> %3$s"
    477500msgstr ""
    478501
    479 #: includes/class-wc-valorpay-gateway.php:914
     502#: includes/class-wc-valorpay-gateway.php:949
    480503msgid "Refund failed."
    481504msgstr ""
    482505
    483506#. translators: 1: Amount, 2: Line Break, 3: Approval code, 4: Line Break, 5: RRN Code
    484 #: includes/class-wc-valorpay-gateway.php:926
     507#: includes/class-wc-valorpay-gateway.php:961
    485508msgid "Valor Pay Refund for %1$s.%2$s <strong>Approval Code:</strong> %3$s.%4$s <strong>RRN:</strong> %5$s"
    486509msgstr ""
    487510
    488 #: includes/class-wc-valorpay-gateway.php:946
     511#: includes/class-wc-valorpay-gateway.php:981
    489512msgid "You can only add a new card when placing an order."
    490513msgstr ""
     
    528551#: public/class-wc-valorpay-public.php:97
    529552msgid "Unable to process payment. Please try again."
     553msgstr ""
     554
     555#: public/class-wc-valorpay-public.php:209
     556msgid "Valor Pay is disabled due to multiple payment failures."
    530557msgstr ""
    531558
  • valorpos/tags/7.6.0/public/class-wc-valorpay-public.php

    r3002583 r3042319  
    207207                        $elapsed      = round( abs( $current_time - $failed_time ) / MINUTE_IN_SECONDS, 2 );
    208208                        if ( $elapsed <= $valorpay->disable_payment_decline_time ) {
    209                             wc_add_notice( __( 'Valor Pay is disabled due to multiple payment failures.', 'woocommerce' ), 'notice' );
     209                            wc_add_notice( __( 'Valor Pay is disabled due to multiple payment failures.', 'wc-valorpay' ), 'notice' );
    210210                            $payment_failed_tracker[ $customer_ip ]['block_payment'] = true;
    211211                        } else {
  • valorpos/tags/7.6.0/wc-valorpay.php

    r3002583 r3042319  
    1616 * Plugin URI:        https://valorpaytech.com
    1717 * Description:       Adds the Valor Payment Gateway to WooCommerce.
    18  * Version:           7.5.0
     18 * Version:           7.6.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.5.0' );
     39define( 'WC_VALORPAY_VERSION', '7.6.0' );
    4040// Directory i.e. /home/user/public_html...
    4141define( 'WC_VALORPAY_DIR', plugin_dir_path( __FILE__ ) );
     
    9090}
    9191run_wc_valorpay();
     92
     93add_action(
     94    'before_woocommerce_init',
     95    function() {
     96        if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
     97            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     98        }
     99    }
     100);
  • valorpos/trunk/README.txt

    r3002583 r3042319  
    55Tested up to: 6.3.1
    66Requires PHP: 7.0
    7 Stable tag: 7.5.0
     7Stable tag: 7.6.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1818
    1919Software Systems and Payment Devices from Valor are the best around for smart hassle-free transactions. Cost-efficient and super smart. With value-added features and reliable service support to match, you’d want Valor to be your partner for growth, always.
     20
     21**WARNING:** The issue of tax price being calculated twice has been resolved in versions 7.3 and above. Please ensure that you are using version 7.3 or later to avoid encountering this problem.
    2022
    2123== Installation ==
     
    4042
    4143== Changelog ==
     44
     45= 7.6.0 =
     46* Added support for High Performance Order Storage, Ecommerce device identifier, and allowing a subscription product with a $0 initial payment has been added.
    4247
    4348= 7.5.0 =
  • valorpos/trunk/admin/class-wc-valorpay-admin.php

    r2980555 r3042319  
    7474         * class.
    7575         */
    76         global $post;
    77 
    78             // Get admin screen id.
     76
     77        // Get admin screen id.
    7978        $screen    = get_current_screen();
    8079        $screen_id = isset( $screen->id ) ? $screen->id : '';
    8180
    82         if ( 'shop_order' === $screen_id ) {
     81        if ( in_array( $screen_id, array( 'shop_order', 'woocommerce_page_wc-orders' ), true ) ) {
    8382            // Load order .
    84             $order = wc_get_order( $post->ID );
     83            $order = wc_get_order();
    8584            // Load JS file only for valor payment method .
    86             if ( WC_ValorPay_Gateway::GATEWAY_ID === $order->get_payment_method() ) {
     85            if ( $order && WC_ValorPay_Gateway::GATEWAY_ID === $order->get_payment_method() ) {
    8786                wp_register_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-refund.js', array( 'jquery' ), $this->version, false );
    8887                wp_enqueue_script( $this->plugin_name );
  • valorpos/trunk/admin/partials/wc-valorpay-admin-order-refund.php

    r2883367 r3042319  
    4848                    <div class="inner">
    4949                        <button id="btn-valor-otp" class="button button-primary button-large button-valor-submit"><?php echo esc_html_e( 'Submit', 'woocommerce' ); ?></button>
    50                         <button id="btn-valor-resend" class="button button-primary button-large button-valor-resend" style="display: none;"><?php echo esc_html_e( 'Resend OTP', 'woocommerce' ); ?></button>
     50                        <button id="btn-valor-resend" class="button button-primary button-large button-valor-resend" style="display: none;"><?php echo esc_html_e( 'Resend OTP', 'wc-valorpay' ); ?></button>
    5151                        <span id="valor-resend-load" class="spinner" style="display: none;"></span>
    5252                    </div>
  • valorpos/trunk/includes/class-wc-valorpay-api.php

    r3002583 r3042319  
    4848     */
    4949    const WC_VALORPAY_BIN_LOOKUP_ACTION = 'binLookup';
     50    /**
     51     * Card token action
     52     */
     53    const WC_VALORPAY_CARD_TOKEN_ACTION = 'cardToken';
     54    /**
     55     * Ecommerce Channel ID
     56     */
     57    const WC_VALORPAY_ECOMM_CHANNEL = 'woocommerce';
    5058
    5159    /**
     
    199207        $response = $this->post_transaction( wp_json_encode( $payload ), 'bin_lookup' );
    200208        return $response;
     209    }
     210
     211    /**
     212     * Generate card token
     213     *
     214     * @since 7.6.0
     215     *
     216     * @param WC_Order $order Order Detail.
     217     * @param array    $card_detail Card detail.
     218     */
     219    public function generate_card_token( $order, $card_detail ) {
     220        $client_token_response = $this->create_checkout_page_token();
     221        if ( is_wp_error( $client_token_response ) || ! is_object( $client_token_response ) || ! isset( $client_token_response->clientToken ) ) { // phpcs:ignore
     222            $order->add_order_note( __( 'Payment error: Unable to generate client token.', 'wc-valorpay' ) );
     223            return array(
     224                'error' => __( 'Sorry, we\'re unable to create a card token right now.', 'wc-valorpay' ),
     225            );
     226        }
     227        $client_token = $client_token_response->clientToken; // phpcs:ignore
     228        $args         = array(
     229            'txn_type'     => self::WC_VALORPAY_CARD_TOKEN_ACTION,
     230            'epi'          => $this->gateway->epi,
     231            'client_token' => $client_token,
     232            'pan'          => $card_detail['card_num'],
     233            'expirydate'   => $card_detail['card_expiry'],
     234        );
     235        $request_url  = add_query_arg( $args, $this->get_valorpay_url() );
     236        $api_args     = array(
     237            'headers' => array(
     238                'Content-Type' => 'application/json',
     239            ),
     240            'method'  => 'POST',
     241            'timeout' => 70,
     242        );
     243        $api_response = wp_remote_post( $request_url, $api_args );
     244        if ( is_wp_error( $api_response ) || empty( $api_response['body'] ) ) {
     245            $order->add_order_note( __( 'Payment error: Unable to generate card token.', 'wc-valorpay' ) );
     246            return array(
     247                'error' => __( 'Sorry, we\'re unable to create a card token right now.', 'wc-valorpay' ),
     248            );
     249        }
     250        $parsed_response = json_decode( preg_replace( '/\xEF\xBB\xBF/', '', $api_response['body'] ), true );
     251        if ( ! isset( $parsed_response['cardToken'] ) ) {
     252            $order->add_order_note( __( 'Payment error: Unable to generate card token.', 'wc-valorpay' ) );
     253            return array(
     254                'error' => __( 'Sorry, we\'re unable to create a card token right now.', 'wc-valorpay' ),
     255            );
     256        }
     257        return array(
     258            'token' => $parsed_response['cardToken'],
     259        );
    201260    }
    202261
     
    277336                'status'           => 'Y',
    278337                'terms_checked'    => $valorpay_terms,
     338                'ecomm_channel'    => self::WC_VALORPAY_ECOMM_CHANNEL,
    279339            ) + $surcharge_data;
    280340
     
    306366                'epi'                => $this->gateway->epi,
    307367                'ip'                 => WC_Geolocation::get_ip_address(),
    308                 'sales_refund'       => 1,
    309368                'ref_txn_id'         => $order->get_transaction_id(),
    310                 'rrn'                => $valorpay_order_meta['rrn'],
    311369                'auth_code'          => $valorpay_order_meta['approval_code'],
    312370                'surchargeIndicator' => ( 'yes' === $this->gateway->surcharge_indicator ) ? 1 : 0,
    313371                'otp'                => $order->get_meta( '_valorpay_2fa_otp' ),
    314372                'uuid'               => $order->get_meta( '_valorpay_otp_uuid' ),
    315             );
    316             delete_post_meta( $order->get_id(), '_valorpay_2fa_otp' );
    317             delete_post_meta( $order->get_id(), '_valorpay_otp_uuid' );
     373                'ecomm_channel'      => self::WC_VALORPAY_ECOMM_CHANNEL,
     374            );
     375            $order->delete_meta_data( '_valorpay_2fa_otp' );
     376            $order->delete_meta_data( '_valorpay_otp_uuid' );
     377            $order->save();
    318378        } elseif ( 'send_otp' === $transaction_type ) {
    319379            $data = array(
     
    390450                'surchargeIndicator' => $surcharge_indicator,
    391451                'surchargeAmount'    => sprintf( '%.2f', $surcharge ),
     452                'ecomm_channel'      => self::WC_VALORPAY_ECOMM_CHANNEL,
    392453            );
    393454
  • valorpos/trunk/includes/class-wc-valorpay-gateway-addons.php

    r3002598 r3042319  
    6161            'post_meta' => array(
    6262                '_valorpay_card_token' => array(
    63                     'value' => get_post_meta( $subscription->id, '_valorpay_card_token', true ),
     63                    'value' => $subscription->get_meta( '_valorpay_card_token', true ),
    6464                    'label' => __( 'ValorPay Card Token', 'wc-valorpay' ),
    6565                ),
    6666                '_valorpay_card_type'  => array(
    67                     'value' => get_post_meta( $subscription->id, '_valorpay_card_type', true ),
     67                    'value' => $subscription->get_meta( '_valorpay_card_type', true ),
    6868                    'label' => __( 'ValorPay Card Type', 'wc-valorpay' ),
    6969                ),
  • valorpos/trunk/includes/class-wc-valorpay-gateway.php

    r3002583 r3042319  
    702702
    703703            $valorpay_api = new WC_ValorPay_API( $this );
     704            // Check if subscription order or if order total is zero, then add the card token to subscriptions.
     705            if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Order::order_contains_subscription( $order->get_id() ) && '0.00' === $amount ) {
     706                if ( $card ) {
     707                    $subscription_payload              = new stdClass();
     708                    $subscription_payload->token       = $card->get_token();
     709                    $subscription_payload->expiry_date = $card->get_expiry_month() . substr( $card->get_expiry_year(), -2 );
     710                    $is_debit_card                     = 'D' === WC()->session->get( 'valor_card_type' );
     711                } else {
     712                    $card_number = str_replace( ' ', '', ( isset( $_POST['wc_valorpay-card-number'] ) ) ? sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) : '' ); // phpcs:ignore
     713                    $exp_date_array = explode( '/', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-expiry'] ) ) ); // phpcs:ignore
     714                    $exp_month           = trim( $exp_date_array[0] );
     715                    $exp_year            = trim( $exp_date_array[1] );
     716                    $exp_date            = $exp_month . substr( $exp_year, -2 );
     717                    $card_detail         = array(
     718                        'card_num'    => $card_number,
     719                        'card_expiry' => $exp_date,
     720                    );
     721                    $card_token_response = $valorpay_api->generate_card_token( $order, $card_detail );
     722                    if ( isset( $card_token_response['error'] ) ) {
     723                        throw new Exception( $card_token_response['error'] );
     724                    }
     725                    $subscription_payload              = new stdClass();
     726                    $subscription_payload->token       = $card_token_response['token'];
     727                    $subscription_payload->expiry_date = $exp_month . substr( $exp_year, -2 );
     728                    $is_debit_card                     = 'D' === WC()->session->get( 'valor_card_type' );
     729                }
     730                $this->update_subscription_card_token( $order, $subscription_payload, $is_debit_card );
     731                $order->payment_complete();
     732                $order->add_order_note( __( 'Valor Pay: Card token added to subscription.', 'wc-valorpay' ) );
     733                return array(
     734                    'result'   => 'success',
     735                    'redirect' => $this->get_return_url( $order ),
     736                );
     737            }
    704738            // Call the sale or authorization API.
    705739            $response = $valorpay_api->purchase( $order, $amount, $card );
     
    728762                    $exp_year            = trim( $exp_date_array[1] );
    729763                    $exp_date            = $exp_month . substr( $exp_year, -2 );
    730                     $response->card_type = $valorpay_api->get_card_type( str_replace( ' ', '', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) ) ); // phpcs:ignore
     764                    $response->card_type = isset( $response->card_brand ) && $response->card_brand ? $response->card_brand : $valorpay_api->get_card_type( str_replace( ' ', '', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) ) ); // phpcs:ignore
    731765                    $this->save_card( $response, $exp_date, ( 'D' === WC()->session->get( 'valor_card_type' ) ) ? 1 : 0 );
    732766                }
     
    739773                    'approval_code'  => $response->approval_code,
    740774                );
    741                 add_post_meta( $order_id, '_valorpay_transaction', $tran_meta );
     775                $order->add_meta_data( '_valorpay_transaction', $tran_meta );
     776                $order->save();
    742777                $is_debit_card = 'D' === WC()->session->get( 'valor_card_type' );
    743778                if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Order::order_contains_subscription( $order->get_id() ) ) {
  • valorpos/trunk/languages/wc-valorpay.pot

    r3002583 r3042319  
    1 # Copyright (C) 2023 Valor Paytech LLC
     1# Copyright (C) 2024 Valor Paytech LLC
    22# This file is distributed under the GPL-2.0+.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Valor Pay 7.5.0\n"
     5"Project-Id-Version: Valor Pay 7.6.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/valorpos\n"
    77"Last-Translator: Valor Paytech LLC <isv@valorpaytech.com>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-11-20T06:34:41+00:00\n"
    13 "PO-Revision-Date: 2023-11-20T06:34:41+00:00\n"
     12"POT-Creation-Date: 2024-02-20T10:51:04+05:30\n"
     13"PO-Revision-Date: 2024-02-20T10:51:04+05:30\n"
    1414"X-Generator: WP-CLI 2.7.1\n"
    1515"X-Domain: wc-valorpay\n"
     
    3333msgstr ""
    3434
    35 #: admin/class-wc-valorpay-admin.php:119
     35#: admin/class-wc-valorpay-admin.php:118
    3636msgid "Are you sure you want to remove?"
    3737msgstr ""
    3838
    39 #: admin/class-wc-valorpay-admin.php:138
     39#: admin/class-wc-valorpay-admin.php:137
    4040msgid "Settings"
    4141msgstr ""
    4242
    43 #: admin/class-wc-valorpay-admin.php:197
    44 #: admin/class-wc-valorpay-admin.php:292
     43#: admin/class-wc-valorpay-admin.php:196
     44#: admin/class-wc-valorpay-admin.php:291
    4545msgid "Invalid Request."
    4646msgstr ""
    4747
    48 #: admin/class-wc-valorpay-admin.php:207
    49 #: admin/class-wc-valorpay-admin.php:275
    50 #: admin/class-wc-valorpay-admin.php:306
     48#: admin/class-wc-valorpay-admin.php:206
     49#: admin/class-wc-valorpay-admin.php:274
     50#: admin/class-wc-valorpay-admin.php:305
    5151msgid "Error Occurred."
    5252msgstr ""
    5353
    54 #: admin/class-wc-valorpay-admin.php:242
     54#: admin/class-wc-valorpay-admin.php:241
    5555msgid "Order Id Missing."
    5656msgstr ""
    5757
    58 #: admin/class-wc-valorpay-admin.php:246
     58#: admin/class-wc-valorpay-admin.php:245
    5959msgid "Enter a valid refund amount."
    6060msgstr ""
    6161
    6262#. translators: 1: Email Address, 2: Mobile Number
    63 #: admin/class-wc-valorpay-admin.php:270
     63#: admin/class-wc-valorpay-admin.php:269
    6464msgid "OTP sent to your registered Email Address %1$s and Mobile Number %2$s"
    6565msgstr ""
    6666
    67 #: admin/class-wc-valorpay-admin.php:297
     67#: admin/class-wc-valorpay-admin.php:296
    6868msgid "Enter Valid OTP."
    6969msgstr ""
     
    123123msgstr ""
    124124
    125 #: includes/class-wc-valorpay-api.php:420
    126 #: includes/class-wc-valorpay-api.php:425
    127 #: includes/class-wc-valorpay-api.php:433
    128 #: includes/class-wc-valorpay-api.php:437
     125#: admin/partials/wc-valorpay-admin-order-refund.php:50
     126msgid "Resend OTP"
     127msgstr ""
     128
     129#: includes/class-wc-valorpay-api.php:222
     130msgid "Payment error: Unable to generate client token."
     131msgstr ""
     132
     133#: includes/class-wc-valorpay-api.php:224
     134#: includes/class-wc-valorpay-api.php:247
     135#: includes/class-wc-valorpay-api.php:254
     136msgid "Sorry, we're unable to create a card token right now."
     137msgstr ""
     138
     139#: includes/class-wc-valorpay-api.php:245
     140#: includes/class-wc-valorpay-api.php:252
     141msgid "Payment error: Unable to generate card token."
     142msgstr ""
     143
     144#: includes/class-wc-valorpay-api.php:481
     145#: includes/class-wc-valorpay-api.php:486
     146#: includes/class-wc-valorpay-api.php:494
     147#: includes/class-wc-valorpay-api.php:498
    129148msgid "There was a problem connecting to the payment gateway."
    130149msgstr ""
     
    457476msgstr ""
    458477
     478#: includes/class-wc-valorpay-gateway.php:732
     479msgid "Valor Pay: Card token added to subscription."
     480msgstr ""
     481
    459482#. translators: 1: Error Message, 2: Amount, 3: Line Break, 4: Approval Code, 5: Line Break, 6: RRN Number.
    460 #: includes/class-wc-valorpay-gateway.php:715
     483#: includes/class-wc-valorpay-gateway.php:749
    461484msgid "Valor Pay %1$s for %2$s.%3$s <strong>Approval Code:</strong> %4$s.%5$s <strong>RRN:</strong> %6$s"
    462485msgstr ""
    463486
    464487#. translators: %s: API Error Message.
    465 #: includes/class-wc-valorpay-gateway.php:755
    466 #: includes/class-wc-valorpay-gateway.php:758
     488#: includes/class-wc-valorpay-gateway.php:790
     489#: includes/class-wc-valorpay-gateway.php:793
    467490msgid "Payment error: %s"
    468491msgstr ""
    469492
    470 #: includes/class-wc-valorpay-gateway.php:760
     493#: includes/class-wc-valorpay-gateway.php:795
    471494msgid "Unable to process the transaction using Valor Pay, please try again."
    472495msgstr ""
    473496
    474497#. translators: 1: Disable Time, 2: Unblock IP URL, 3: Customer IP.
    475 #: includes/class-wc-valorpay-gateway.php:851
     498#: includes/class-wc-valorpay-gateway.php:886
    476499msgid "Valor Pay method is disabled for %1$s. <a target=\"_blank\" href=\"%2$s\">To Unblock IP</a> %3$s"
    477500msgstr ""
    478501
    479 #: includes/class-wc-valorpay-gateway.php:914
     502#: includes/class-wc-valorpay-gateway.php:949
    480503msgid "Refund failed."
    481504msgstr ""
    482505
    483506#. translators: 1: Amount, 2: Line Break, 3: Approval code, 4: Line Break, 5: RRN Code
    484 #: includes/class-wc-valorpay-gateway.php:926
     507#: includes/class-wc-valorpay-gateway.php:961
    485508msgid "Valor Pay Refund for %1$s.%2$s <strong>Approval Code:</strong> %3$s.%4$s <strong>RRN:</strong> %5$s"
    486509msgstr ""
    487510
    488 #: includes/class-wc-valorpay-gateway.php:946
     511#: includes/class-wc-valorpay-gateway.php:981
    489512msgid "You can only add a new card when placing an order."
    490513msgstr ""
     
    528551#: public/class-wc-valorpay-public.php:97
    529552msgid "Unable to process payment. Please try again."
     553msgstr ""
     554
     555#: public/class-wc-valorpay-public.php:209
     556msgid "Valor Pay is disabled due to multiple payment failures."
    530557msgstr ""
    531558
  • valorpos/trunk/public/class-wc-valorpay-public.php

    r3002583 r3042319  
    207207                        $elapsed      = round( abs( $current_time - $failed_time ) / MINUTE_IN_SECONDS, 2 );
    208208                        if ( $elapsed <= $valorpay->disable_payment_decline_time ) {
    209                             wc_add_notice( __( 'Valor Pay is disabled due to multiple payment failures.', 'woocommerce' ), 'notice' );
     209                            wc_add_notice( __( 'Valor Pay is disabled due to multiple payment failures.', 'wc-valorpay' ), 'notice' );
    210210                            $payment_failed_tracker[ $customer_ip ]['block_payment'] = true;
    211211                        } else {
  • valorpos/trunk/wc-valorpay.php

    r3002583 r3042319  
    1616 * Plugin URI:        https://valorpaytech.com
    1717 * Description:       Adds the Valor Payment Gateway to WooCommerce.
    18  * Version:           7.5.0
     18 * Version:           7.6.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.5.0' );
     39define( 'WC_VALORPAY_VERSION', '7.6.0' );
    4040// Directory i.e. /home/user/public_html...
    4141define( 'WC_VALORPAY_DIR', plugin_dir_path( __FILE__ ) );
     
    9090}
    9191run_wc_valorpay();
     92
     93add_action(
     94    'before_woocommerce_init',
     95    function() {
     96        if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
     97            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     98        }
     99    }
     100);
Note: See TracChangeset for help on using the changeset viewer.