Changeset 2980555
- Timestamp:
- 10/18/2023 09:19:27 AM (2 years ago)
- Location:
- valorpos
- Files:
-
- 28 edited
- 1 copied
-
tags/7.4.0 (copied) (copied from valorpos/trunk)
-
tags/7.4.0/README.txt (modified) (2 diffs)
-
tags/7.4.0/admin/class-wc-valorpay-admin.php (modified) (1 diff)
-
tags/7.4.0/includes/class-wc-valorpay-activator.php (modified) (1 diff)
-
tags/7.4.0/includes/class-wc-valorpay-api.php (modified) (8 diffs)
-
tags/7.4.0/includes/class-wc-valorpay-deactivator.php (modified) (1 diff)
-
tags/7.4.0/includes/class-wc-valorpay-gateway-loader.php (modified) (1 diff)
-
tags/7.4.0/includes/class-wc-valorpay-gateway.php (modified) (9 diffs)
-
tags/7.4.0/includes/class-wc-valorpay-i18n.php (modified) (1 diff)
-
tags/7.4.0/includes/class-wc-valorpay-loader.php (modified) (1 diff)
-
tags/7.4.0/includes/class-wc-valorpay.php (modified) (2 diffs)
-
tags/7.4.0/languages/wc-valorpay.pot (modified) (3 diffs)
-
tags/7.4.0/public/class-wc-valorpay-public.php (modified) (4 diffs)
-
tags/7.4.0/public/js/wc-valorpay-checkout.js (modified) (1 diff)
-
tags/7.4.0/wc-valorpay.php (modified) (2 diffs)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/admin/class-wc-valorpay-admin.php (modified) (1 diff)
-
trunk/includes/class-wc-valorpay-activator.php (modified) (1 diff)
-
trunk/includes/class-wc-valorpay-api.php (modified) (8 diffs)
-
trunk/includes/class-wc-valorpay-deactivator.php (modified) (1 diff)
-
trunk/includes/class-wc-valorpay-gateway-loader.php (modified) (1 diff)
-
trunk/includes/class-wc-valorpay-gateway.php (modified) (9 diffs)
-
trunk/includes/class-wc-valorpay-i18n.php (modified) (1 diff)
-
trunk/includes/class-wc-valorpay-loader.php (modified) (1 diff)
-
trunk/includes/class-wc-valorpay.php (modified) (2 diffs)
-
trunk/languages/wc-valorpay.pot (modified) (3 diffs)
-
trunk/public/class-wc-valorpay-public.php (modified) (4 diffs)
-
trunk/public/js/wc-valorpay-checkout.js (modified) (1 diff)
-
trunk/wc-valorpay.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
valorpos/tags/7.4.0/README.txt
r2960359 r2980555 3 3 Tags: payment, payment gateway, credit card, valor pay, valor paytech 4 4 Requires at least: 5.0 5 Tested up to: 6. 2.25 Tested up to: 6.3.1 6 6 Requires PHP: 7.0 7 Stable tag: 7. 3.17 Stable tag: 7.4.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 41 41 == Changelog == 42 42 43 = 7.4.0 = 44 * Added a new configuration to toggle surcharge for debit transactions. This configuration determines whether a surcharge should be applied to debit transactions or not. 45 43 46 = 7.3.1 = 44 47 * Update plugin title. -
valorpos/tags/7.4.0/admin/class-wc-valorpay-admin.php
r2918841 r2980555 22 22 * @package Wc_Valorpay 23 23 * @subpackage Wc_Valorpay/admin 24 * @author Valor Pay tech LLC <isv@valorpaytech.com>24 * @author Valor PayTech LLC <isv@valorpaytech.com> 25 25 */ 26 26 class Wc_Valorpay_Admin { -
valorpos/tags/7.4.0/includes/class-wc-valorpay-activator.php
r2883367 r2980555 18 18 * @package Wc_Valorpay 19 19 * @subpackage Wc_Valorpay/includes 20 * @author Valor Pay tech LLC <isv@valorpaytech.com>20 * @author Valor PayTech LLC <isv@valorpaytech.com> 21 21 */ 22 22 class Wc_Valorpay_Activator { -
valorpos/tags/7.4.0/includes/class-wc-valorpay-api.php
r2918841 r2980555 21 21 * @package Wc_Valorpay 22 22 * @subpackage Wc_Valorpay/includes 23 * @author Valor Pay tech LLC <isv@valorpaytech.com>23 * @author Valor PayTech LLC <isv@valorpaytech.com> 24 24 */ 25 25 class WC_ValorPay_API { … … 27 27 * Sandbox payment URL 28 28 */ 29 const WC_VALORPAY_SANDBOX_URL = 'https://securelink test.valorpaytech.com:4430/';29 const WC_VALORPAY_SANDBOX_URL = 'https://securelink-staging.valorpaytech.com:4430/'; 30 30 /** 31 31 * Live payment URL … … 35 35 * Sandbox OTP refund URL 36 36 */ 37 const WC_VALORPAY_REFUND_OTP_SANDBOX_URL = 'https://2fa demo.isoaccess.com/?main_action=Manage2FA&operation=ecommRefund';37 const WC_VALORPAY_REFUND_OTP_SANDBOX_URL = 'https://2fa-staging.valorpaytech.com:4430/?main_action=Manage2FA&operation=ecommRefund'; 38 38 /** 39 39 * Live OTP refund URL 40 40 */ 41 41 const WC_VALORPAY_REFUND_OTP_URL = 'https://2fa.valorpaytech.com/?main_action=Manage2FA&operation=ecommRefund'; 42 /** 43 * Create page token action 44 */ 45 const WC_VALORPAY_PAGE_TOKEN_ACTION = 'clientToken'; 46 /** 47 * Bin lookup action 48 */ 49 const WC_VALORPAY_BIN_LOOKUP_ACTION = 'binLookup'; 42 50 43 51 /** … … 138 146 $payload = $this->get_payload( $order, $amount, 'send_otp' ); 139 147 $response = $this->post_transaction( $payload, 'send_otp' ); 148 return $response; 149 } 150 151 /** 152 * Create checkout page token 153 * 154 * @since 7.4.0 155 * @return object JSON response 156 */ 157 public function create_checkout_page_token() { 158 $payload = array( 159 'appid' => $this->gateway->appid, 160 'appkey' => $this->gateway->appkey, 161 'epi' => $this->gateway->epi, 162 'txn_type' => self::WC_VALORPAY_PAGE_TOKEN_ACTION, 163 ); 164 $response = $this->post_transaction( wp_json_encode( $payload ) ); 165 return $response; 166 } 167 168 /** 169 * Get bin details 170 * 171 * @since 7.4.0 172 * 173 * @param string $bin_number Bin Number. 174 * @param string $client_token Client Token. 175 * @return object JSON response 176 */ 177 public function bin_lookup( $bin_number, $client_token ) { 178 $payload = array( 179 'client_token' => $client_token, 180 'bin' => $bin_number, 181 'epi' => $this->gateway->epi, 182 'txn_type' => self::WC_VALORPAY_BIN_LOOKUP_ACTION, 183 ); 184 $response = $this->post_transaction( wp_json_encode( $payload ), 'bin_lookup' ); 140 185 return $response; 141 186 } … … 156 201 $data = array(); 157 202 if ( 'sale' === $transaction_type ) { 158 $surcharge_indicator = 0;203 $surcharge_indicator = ( 'yes' === $this->gateway->surcharge_indicator ) ? 1 : 0; 159 204 $custom_fee = 0; 160 if ( 'yes' === $this->gateway->surcharge_indicator && 0 < count( $order->get_fees() ) ) {161 $ surcharge_indicator = 1;162 if ( 'sale' === $transaction_type) {205 if ( 1 === $surcharge_indicator && 0 < count( $order->get_fees() ) ) { 206 $cal_for_debit = ( 'D' === WC()->session->get( 'valor_card_type' ) ) && 'no' !== $this->gateway->surcharge_for_debit; 207 if ( $cal_for_debit || ( 'D' !== WC()->session->get( 'valor_card_type' ) ) ) { 163 208 foreach ( $order->get_fees() as $item_fee ) { 164 209 if ( $item_fee->get_name() === $this->gateway->surcharge_label ) { … … 170 215 } 171 216 } 217 $surcharge_data = array( 218 'surchargeIndicator' => $surcharge_indicator, 219 'surchargeAmount' => $custom_fee, 220 ); 221 172 222 $billing_first_name = wc_clean( $order->get_billing_first_name() ); 173 223 $billing_last_name = wc_clean( $order->get_billing_last_name() ); … … 189 239 $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 190 240 $valorpay_avs_street = ( isset( $_POST['valorpay_avs_street'] ) && $_POST['valorpay_avs_street'] ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) : wc_clean( $billing_address ); // phpcs:ignore 191 $valorpay_terms = ( isset( $_POST['valorpay_terms'] ) && $_POST['valorpay_terms'] ) ? 1 : 0; // phpcs:ignore241 $valorpay_terms = ( isset( $_POST['valorpay_terms'] ) && $_POST['valorpay_terms'] ) ? 1 : 0; // phpcs:ignore 192 242 193 243 $card_number = str_replace( ' ', '', ( isset( $_POST['wc_valorpay-card-number'] ) ) ? sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) : '' ); // phpcs:ignore 194 244 $data = array( 195 'appid' => $this->gateway->appid, 196 'appkey' => $this->gateway->appkey, 197 'epi' => $this->gateway->epi, 198 'txn_type' => $this->gateway->payment_action, 199 'amount' => wc_clean( $amount ), 200 'phone' => $billing_phone, 201 'email' => $billing_email, 202 'uid' => $order_number, 203 'tax_amount' => number_format( $tax_amount, '2', '.', '' ), 204 'ip' => $ip_address, 205 'surchargeIndicator' => $surcharge_indicator, 206 'surchargeAmount' => $custom_fee, 207 'address1' => $valorpay_avs_street, 208 'address2' => wc_clean( $billing_address2 ), 209 'city' => wc_clean( substr( $billing_city, 0, 40 ) ), 210 'state' => wc_clean( substr( $billing_state, 0, 40 ) ), 211 'zip' => $valorpay_avs_zip, 212 'billing_country' => wc_clean( substr( $billing_country, 0, 60 ) ), 213 'shipping_country' => wc_clean( substr( $shipping_country, 0, 60 ) ), 214 'status' => 'Y', 215 'terms_checked' => $valorpay_terms, 216 ); 245 'appid' => $this->gateway->appid, 246 'appkey' => $this->gateway->appkey, 247 'epi' => $this->gateway->epi, 248 'txn_type' => $this->gateway->payment_action, 249 'amount' => wc_clean( $amount ), 250 'phone' => $billing_phone, 251 'email' => $billing_email, 252 'uid' => $order_number, 253 'tax_amount' => number_format( $tax_amount, '2', '.', '' ), 254 'ip' => $ip_address, 255 'address1' => $valorpay_avs_street, 256 'address2' => wc_clean( $billing_address2 ), 257 'city' => wc_clean( substr( $billing_city, 0, 40 ) ), 258 'state' => wc_clean( substr( $billing_state, 0, 40 ) ), 259 'zip' => $valorpay_avs_zip, 260 'billing_country' => wc_clean( substr( $billing_country, 0, 60 ) ), 261 'shipping_country' => wc_clean( substr( $shipping_country, 0, 60 ) ), 262 'status' => 'Y', 263 'terms_checked' => $valorpay_terms, 264 ) + $surcharge_data; 217 265 218 266 if ( $card ) { … … 287 335 $response = wp_remote_post( $api_url, $args ); 288 336 if ( is_wp_error( $response ) || empty( $response['body'] ) ) { 289 return new WP_Error( 'valorp os_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );337 return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) ); 290 338 } 291 339 $parsed_response = json_decode( preg_replace( '/\xEF\xBB\xBF/', '', $response['body'] ) ); 292 340 if ( 'send_otp' === $transaction_type ) { 293 341 if ( ! isset( $parsed_response->error_code ) ) { 294 return new WP_Error( 'valorp os_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );342 return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) ); 295 343 } 296 344 if ( 'S00' !== $parsed_response->error_code ) { 297 345 $error_msg = sprintf( '%s', $parsed_response->error_desc ); 298 return new WP_Error( 'valorpos_error', $error_msg ); 346 return new WP_Error( 'valorpay_error', $error_msg ); 347 } 348 } elseif ( 'bin_lookup' === $transaction_type ) { 349 if ( ! isset( $parsed_response->card_type ) ) { 350 return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) ); 299 351 } 300 352 } else { 301 353 if ( ! isset( $parsed_response->error_no ) ) { 302 return new WP_Error( 'valorp os_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );354 return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) ); 303 355 } 304 356 if ( 'S00' !== $parsed_response->error_no ) { 305 357 $error_msg = sprintf( '%s ( %s )', $parsed_response->mesg, $parsed_response->desc ); 306 return new WP_Error( 'valorp os_error', $error_msg );358 return new WP_Error( 'valorpay_error', $error_msg ); 307 359 } 308 360 } -
valorpos/tags/7.4.0/includes/class-wc-valorpay-deactivator.php
r2883367 r2980555 22 22 * @package Wc_Valorpay 23 23 * @subpackage Wc_Valorpay/includes 24 * @author Valor Pay tech LLC <isv@valorpaytech.com>24 * @author Valor PayTech LLC <isv@valorpaytech.com> 25 25 */ 26 26 class Wc_Valorpay_Deactivator { -
valorpos/tags/7.4.0/includes/class-wc-valorpay-gateway-loader.php
r2883367 r2980555 22 22 * @package Wc_Valorpay 23 23 * @subpackage Wc_Valorpay/includes 24 * @author Valor Pay tech LLC <isv@valorpaytech.com>24 * @author Valor PayTech LLC <isv@valorpaytech.com> 25 25 */ 26 26 class Wc_Valorpay_Gateway_Loader { -
valorpos/tags/7.4.0/includes/class-wc-valorpay-gateway.php
r2960359 r2980555 19 19 * @package Wc_Valorpay 20 20 * @subpackage Wc_Valorpay/includes 21 * @author Valor Pay tech LLC <isv@valorpaytech.com>21 * @author Valor PayTech LLC <isv@valorpaytech.com> 22 22 * @uses WC_Payment_Gateway_CC 23 23 */ … … 97 97 */ 98 98 public $surcharge_flat_rate; 99 100 /** 101 * Valor Pay surcharge for debit. 102 * 103 * @var string 104 */ 105 public $surcharge_for_debit; 99 106 100 107 /** … … 166 173 $this->surcharge_percentage = $this->get_option( 'surcharge_percentage' ); 167 174 $this->surcharge_flat_rate = $this->get_option( 'surcharge_flat_rate' ); 175 $this->surcharge_for_debit = $this->get_option( 'surcharge_for_debit' ); 168 176 $this->cardtypes = $this->get_option( 'cardtypes' ); 169 177 $this->avs_type = $this->get_option( 'avs_type' ); … … 322 330 public function validate_fields() { 323 331 try { 332 $valorpay_avs_type = ( isset( $_POST['valorpay_avs_type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_type'] ) ) : ''; // phpcs:ignore 333 if ( 'zip' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) { 334 if ( ! isset( $_POST['valorpay_avs_zip'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) { // phpcs:ignore 335 throw new Exception( __( 'Zip Code is required.', 'wc-valorpay' ) ); 336 } 337 if ( isset( $_POST['valorpay_avs_zip'] ) && sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) && ! preg_match( '/^([a-zA-Z0-9_-]){4,6}$/', sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) ) { // phpcs:ignore 338 throw new Exception( __( 'Enter a valid Zip Code.', 'wc-valorpay' ) ); 339 } 340 } 341 if ( 'address' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) { 342 if ( ! isset( $_POST['valorpay_avs_street'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) { // phpcs:ignore 343 throw new Exception( __( 'Street No is required.', 'wc-valorpay' ) ); 344 } 345 if ( isset( $_POST['valorpay_avs_street'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) > 25 ) { // phpcs:ignore 346 throw new Exception( __( 'Enter a valid Street No.', 'wc-valorpay' ) ); 347 } 348 } 324 349 if ( isset( $_POST['wc-wc_valorpay-payment-token'] ) && 'new' !== wc_clean( $_POST['wc-wc_valorpay-payment-token'] ) ) { // phpcs:ignore 325 350 return true; … … 526 551 'default' => 0, 527 552 'description' => __( 'Flat rate will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $', 'wc-valorpay' ), 553 ), 554 'surcharge_for_debit' => array( 555 'title' => __( 'Surcharge For Debit', 'wc-valorpay' ), 556 'label' => __( 'Enable Surcharge For Debit', 'wc-valorpay' ), 557 'type' => 'checkbox', 558 'description' => __( 'Enable surcharge for debit', 'wc-valorpay' ), 559 'default' => 'yes', 528 560 ), 529 561 'avs_type' => array( … … 704 736 $exp_date = $exp_month . substr( $exp_year, -2 ); 705 737 $response->card_type = $valorpay_api->get_card_type( str_replace( ' ', '', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) ) ); // phpcs:ignore 706 $this->save_card( $response, $exp_date );738 $this->save_card( $response, $exp_date, ( 'D' === WC()->session->get( 'valor_card_type' ) ) ? 1 : 0 ); 707 739 } 708 740 … … 722 754 ); 723 755 } else { 724 if ( isset( $response->errors['valorp os_error'][0] ) ) {756 if ( isset( $response->errors['valorpay_error'][0] ) ) { 725 757 /* translators: %s: API Error Message. */ 726 $order->add_order_note( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorp os_error'][0] ) );758 $order->add_order_note( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpay_error'][0] ) ); 727 759 $this->add_failed_count_by_ip( $order ); 728 760 /* translators: %s: API Error Message. */ 729 throw new Exception( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorp os_error'][0] ) );761 throw new Exception( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpay_error'][0] ) ); 730 762 } 731 763 throw new Exception( __( 'Unable to process the transaction using Valor Pay, please try again.', 'wc-valorpay' ) ); … … 744 776 * Save card. 745 777 * 746 * @param Object $response Response.778 * @param object $response Response. 747 779 * @param string $exp_date Expiry Date. 780 * @param int $is_debit Is Debit Card. 748 781 * @return void 749 782 */ 750 protected function save_card( $response, $exp_date ) {783 protected function save_card( $response, $exp_date, $is_debit ) { 751 784 if ( $response->token ) { 752 785 $token = new WC_Payment_Token_CC(); … … 758 791 $token->set_expiry_year( '20' . substr( $exp_date, -2 ) ); 759 792 $token->set_user_id( get_current_user_id() ); 793 $token->add_meta_data( 'is_debit', $is_debit ); 760 794 $token->save(); 761 795 } -
valorpos/tags/7.4.0/includes/class-wc-valorpay-i18n.php
r2883367 r2980555 26 26 * @package Wc_Valorpay 27 27 * @subpackage Wc_Valorpay/includes 28 * @author Valor Pay tech LLC <isv@valorpaytech.com>28 * @author Valor PayTech LLC <isv@valorpaytech.com> 29 29 */ 30 30 class Wc_Valorpay_I18n { -
valorpos/tags/7.4.0/includes/class-wc-valorpay-loader.php
r2883367 r2980555 23 23 * @package Wc_Valorpay 24 24 * @subpackage Wc_Valorpay/includes 25 * @author Valor Pay tech LLC <isv@valorpaytech.com>25 * @author Valor PayTech LLC <isv@valorpaytech.com> 26 26 */ 27 27 class Wc_Valorpay_Loader { -
valorpos/tags/7.4.0/includes/class-wc-valorpay.php
r2918841 r2980555 25 25 * @package Wc_Valorpay 26 26 * @subpackage Wc_Valorpay/includes 27 * @author Valor Pay tech LLC <isv@valorpaytech.com>27 * @author Valor PayTech LLC <isv@valorpaytech.com> 28 28 */ 29 29 class Wc_Valorpay { … … 197 197 198 198 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts_and_styles' ); 199 $this->loader->add_action( 'woocommerce_after_checkout_validation', $plugin_public, 'valorpay_avs_checkout_validation', 10, 2 );200 199 $this->loader->add_action( 'woocommerce_cart_calculate_fees', $plugin_public, 'valorpay_custom_surcharge' ); 201 200 $this->loader->add_action( 'woocommerce_before_checkout_form', $plugin_public, 'valorpay_before_checkout_form' ); 202 $this->loader->add_action( 'woocommerce_ after_checkout_form', $plugin_public, 'valorpay_checkout_script' );201 $this->loader->add_action( 'woocommerce_review_order_before_payment', $plugin_public, 'valorpay_update_token_card_type' ); 203 202 $this->loader->add_filter( 'woocommerce_available_payment_gateways', $plugin_public, 'valorpay_disable_payment_gateway_failed_orders' ); 203 $this->loader->add_action( 'wc_ajax_valorpay_create_page_token', $plugin_public, 'valorpay_create_page_token' ); 204 $this->loader->add_action( 'wc_ajax_valorpay_bin_lookup', $plugin_public, 'valorpay_bin_lookup' ); 205 $this->loader->add_action( 'wc_ajax_valorpay_token_card_type', $plugin_public, 'valorpay_token_card_type' ); 204 206 205 207 } -
valorpos/tags/7.4.0/languages/wc-valorpay.pot
r2960359 r2980555 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Valor Pay 7. 3.0\n"6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/ wc-valorpay\n"5 "Project-Id-Version: Valor Pay 7.4.0\n" 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/valorpos\n" 7 7 "Last-Translator: Valor Paytech LLC <sales@valorpaytech.com>\n" 8 8 "MIME-Version: 1.0\n" 9 9 "Content-Type: text/plain; charset=UTF-8\n" 10 10 "Content-Transfer-Encoding: 8bit\n" 11 "POT-Creation-Date: 2023- 05-19T15:31:04+05:30\n"12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"11 "POT-Creation-Date: 2023-10-18T08:57:12+00:00\n" 12 "PO-Revision-Date: 2023-10-18T08:57:12+00:00\n" 13 13 "X-Generator: WP-CLI 2.7.1\n" 14 14 "X-Domain: wc-valorpay\n" 15 15 16 16 #. Plugin Name of the plugin 17 #: includes/class-wc-valorpay-gateway.php:4 5517 #: includes/class-wc-valorpay-gateway.php:480 18 18 msgid "Valor Pay" 19 19 msgstr "" … … 69 69 70 70 #: admin/partials/wc-valorpay-admin-failure-tracker.php:18 71 #: includes/class-wc-valorpay-gateway.php:5 4371 #: includes/class-wc-valorpay-gateway.php:575 72 72 msgid "Payment Failed Tracker" 73 73 msgstr "" … … 122 122 msgstr "" 123 123 124 #: includes/class-wc-valorpay-api.php:289 125 #: includes/class-wc-valorpay-api.php:294 126 #: includes/class-wc-valorpay-api.php:302 124 #: includes/class-wc-valorpay-api.php:337 125 #: includes/class-wc-valorpay-api.php:342 126 #: includes/class-wc-valorpay-api.php:350 127 #: includes/class-wc-valorpay-api.php:354 127 128 msgid "There was a problem connecting to the payment gateway." 128 129 msgstr "" 129 130 130 #: includes/class-wc-valorpay-gateway.php:1 43131 #: includes/class-wc-valorpay-gateway.php:150 131 132 msgid "ValorPay Plugin" 132 133 msgstr "" 133 134 134 #: includes/class-wc-valorpay-gateway.php:1 44135 #: includes/class-wc-valorpay-gateway.php:151 135 136 msgid "Take payments via Valorpay." 136 137 msgstr "" 137 138 138 #: includes/class-wc-valorpay-gateway.php:1 76139 #: includes/class-wc-valorpay-gateway.php:184 139 140 msgid "TEST MODE ENABLED. Use test card number 4111111111111111 with 999 as CVC and a future expiration date." 140 141 msgstr "" 141 142 142 #: includes/class-wc-valorpay-gateway.php:20 0143 #: includes/class-wc-valorpay-gateway.php:208 143 144 msgid "Unsupported currency:" 144 145 msgstr "" 145 146 146 #: includes/class-wc-valorpay-gateway.php:2 03147 #: includes/class-wc-valorpay-gateway.php:211 147 148 msgid "Valor Pay accepts only USD." 148 149 msgstr "" 149 150 150 151 #. translators: %s: Settings URL. 151 #: includes/class-wc-valorpay-gateway.php:2 15152 #: includes/class-wc-valorpay-gateway.php:223 152 153 msgid "Valor Pay error: The APP ID is required. %s" 153 154 msgstr "" 154 155 155 #: includes/class-wc-valorpay-gateway.php:2 16156 #: includes/class-wc-valorpay-gateway.php:2 27157 #: includes/class-wc-valorpay-gateway.php:2 36156 #: includes/class-wc-valorpay-gateway.php:224 157 #: includes/class-wc-valorpay-gateway.php:235 158 #: includes/class-wc-valorpay-gateway.php:244 158 159 msgid "Click here to update your Valor Pay settings." 159 160 msgstr "" 160 161 161 162 #. translators: %s: Settings URL. 162 #: includes/class-wc-valorpay-gateway.php:2 26163 #: includes/class-wc-valorpay-gateway.php:234 163 164 msgid "Valor Pay error: The APP KEY is required. %s" 164 165 msgstr "" 165 166 166 167 #. translators: %s: Settings URL. 167 #: includes/class-wc-valorpay-gateway.php:2 35168 #: includes/class-wc-valorpay-gateway.php:243 168 169 msgid "Valor Pay error: The EPI is required. %s" 169 170 msgstr "" 170 171 171 #: includes/class-wc-valorpay-gateway.php:332 172 #: includes/class-wc-valorpay-gateway.php:335 173 msgid "Zip Code is required." 174 msgstr "" 175 176 #: includes/class-wc-valorpay-gateway.php:338 177 msgid "Enter a valid Zip Code." 178 msgstr "" 179 180 #: includes/class-wc-valorpay-gateway.php:343 181 msgid "Street No is required." 182 msgstr "" 183 184 #: includes/class-wc-valorpay-gateway.php:346 185 msgid "Enter a valid Street No." 186 msgstr "" 187 188 #: includes/class-wc-valorpay-gateway.php:357 172 189 msgid "Card number is invalid" 173 190 msgstr "" 174 191 175 #: includes/class-wc-valorpay-gateway.php:3 36192 #: includes/class-wc-valorpay-gateway.php:361 176 193 msgid "Not a valid card" 177 194 msgstr "" 178 195 179 #: includes/class-wc-valorpay-gateway.php:3 39196 #: includes/class-wc-valorpay-gateway.php:364 180 197 msgid "Card number expired" 181 198 msgstr "" 182 199 183 #: includes/class-wc-valorpay-gateway.php:3 42200 #: includes/class-wc-valorpay-gateway.php:367 184 201 msgid "Card security code is invalid (only digits are allowed)" 185 202 msgstr "" 186 203 187 204 #. translators: 1: Terms and Conditions URL. 188 #: includes/class-wc-valorpay-gateway.php: 378205 #: includes/class-wc-valorpay-gateway.php:403 189 206 msgid "I agree to the <a href=\"%s\" target=\"_blank\">Terms and Conditions</a>" 190 207 msgstr "" 191 208 192 #: includes/class-wc-valorpay-gateway.php:4 09193 #: includes/class-wc-valorpay-gateway.php:4 10209 #: includes/class-wc-valorpay-gateway.php:434 210 #: includes/class-wc-valorpay-gateway.php:435 194 211 msgid "Zip Code" 195 212 msgstr "" 196 213 197 #: includes/class-wc-valorpay-gateway.php:4 23198 #: includes/class-wc-valorpay-gateway.php:4 24214 #: includes/class-wc-valorpay-gateway.php:448 215 #: includes/class-wc-valorpay-gateway.php:449 199 216 msgid "Street No" 200 217 msgstr "" 201 218 202 #: includes/class-wc-valorpay-gateway.php:4 45219 #: includes/class-wc-valorpay-gateway.php:470 203 220 msgid "Enable/Disable" 204 221 msgstr "" 205 222 206 #: includes/class-wc-valorpay-gateway.php:4 46223 #: includes/class-wc-valorpay-gateway.php:471 207 224 msgid "Enable Valor Pay" 208 225 msgstr "" 209 226 210 #: includes/class-wc-valorpay-gateway.php:4 52227 #: includes/class-wc-valorpay-gateway.php:477 211 228 msgid "Title" 212 229 msgstr "" 213 230 214 #: includes/class-wc-valorpay-gateway.php:4 54231 #: includes/class-wc-valorpay-gateway.php:479 215 232 msgid "This controls the title which the user sees during checkout." 216 233 msgstr "" 217 234 218 #: includes/class-wc-valorpay-gateway.php:4 59235 #: includes/class-wc-valorpay-gateway.php:484 219 236 msgid "Use Sandbox" 220 237 msgstr "" 221 238 222 #: includes/class-wc-valorpay-gateway.php:4 60239 #: includes/class-wc-valorpay-gateway.php:485 223 240 msgid "Enable sandbox mode - live payments will not be taken if enabled." 224 241 msgstr "" 225 242 226 #: includes/class-wc-valorpay-gateway.php:4 66243 #: includes/class-wc-valorpay-gateway.php:491 227 244 msgid "APP ID" 228 245 msgstr "" 229 246 230 #: includes/class-wc-valorpay-gateway.php:4 68247 #: includes/class-wc-valorpay-gateway.php:493 231 248 msgid "Please email support@valorpaytech.com to get to know about your APP ID, ( In demo mode APP ID is not needed )" 232 249 msgstr "" 233 250 234 #: includes/class-wc-valorpay-gateway.php:4 72251 #: includes/class-wc-valorpay-gateway.php:497 235 252 msgid "APP KEY" 236 253 msgstr "" 237 254 238 #: includes/class-wc-valorpay-gateway.php:4 74255 #: includes/class-wc-valorpay-gateway.php:499 239 256 msgid "Please email support@valorpaytech.com to get to know about your APP KEY, ( In demo mode APP KEY is not needed )" 240 257 msgstr "" 241 258 242 #: includes/class-wc-valorpay-gateway.php: 478259 #: includes/class-wc-valorpay-gateway.php:503 243 260 msgid "EPI" 244 261 msgstr "" 245 262 246 #: includes/class-wc-valorpay-gateway.php: 480263 #: includes/class-wc-valorpay-gateway.php:505 247 264 msgid "Please email support@valorpaytech.com to get to know about your EPI ID, ( In demo mode EPI ID is not needed )" 248 265 msgstr "" 249 266 250 #: includes/class-wc-valorpay-gateway.php: 484267 #: includes/class-wc-valorpay-gateway.php:509 251 268 msgid "Payment Method" 252 269 msgstr "" 253 270 254 #: includes/class-wc-valorpay-gateway.php: 494271 #: includes/class-wc-valorpay-gateway.php:519 255 272 msgid "Surcharge Mode" 256 273 msgstr "" 257 274 258 #: includes/class-wc-valorpay-gateway.php: 495259 #: includes/class-wc-valorpay-gateway.php:5 02275 #: includes/class-wc-valorpay-gateway.php:520 276 #: includes/class-wc-valorpay-gateway.php:527 260 277 msgid "Enable Surcharge Mode" 261 278 msgstr "" 262 279 263 #: includes/class-wc-valorpay-gateway.php: 497280 #: includes/class-wc-valorpay-gateway.php:522 264 281 msgid "Enable only if you want all transactions to be fall on surcharge mode, Merchant must have got an Surcharge MID inorder to work" 265 282 msgstr "" 266 283 267 #: includes/class-wc-valorpay-gateway.php:5 01284 #: includes/class-wc-valorpay-gateway.php:526 268 285 msgid "Surcharge Type" 269 286 msgstr "" 270 287 271 #: includes/class-wc-valorpay-gateway.php:5 11272 #: includes/class-wc-valorpay-gateway.php:5 12288 #: includes/class-wc-valorpay-gateway.php:536 289 #: includes/class-wc-valorpay-gateway.php:537 273 290 msgid "Surcharge Label" 274 291 msgstr "" 275 292 276 #: includes/class-wc-valorpay-gateway.php:5 17293 #: includes/class-wc-valorpay-gateway.php:542 277 294 msgid "Surcharge %" 278 295 msgstr "" 279 296 280 #: includes/class-wc-valorpay-gateway.php:5 21297 #: includes/class-wc-valorpay-gateway.php:546 281 298 msgid "Percentage will apply only on enabling on surcharge Indicator to true and Surcharge type is set fo Surcharge %" 282 299 msgstr "" 283 300 284 #: includes/class-wc-valorpay-gateway.php:5 24301 #: includes/class-wc-valorpay-gateway.php:549 285 302 msgid "Flat Rate $" 286 303 msgstr "" 287 304 288 #: includes/class-wc-valorpay-gateway.php:5 27305 #: includes/class-wc-valorpay-gateway.php:552 289 306 msgid "Flat rate will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $" 290 307 msgstr "" 291 308 292 #: includes/class-wc-valorpay-gateway.php:530 309 #: includes/class-wc-valorpay-gateway.php:555 310 msgid "Surcharge For Debit" 311 msgstr "" 312 313 #: includes/class-wc-valorpay-gateway.php:556 314 msgid "Enable Surcharge For Debit" 315 msgstr "" 316 317 #: includes/class-wc-valorpay-gateway.php:558 318 msgid "Enable surcharge for debit" 319 msgstr "" 320 321 #: includes/class-wc-valorpay-gateway.php:562 293 322 msgid "AVS" 294 323 msgstr "" 295 324 296 #: includes/class-wc-valorpay-gateway.php:5 40325 #: includes/class-wc-valorpay-gateway.php:572 297 326 msgid "The address verification service will add a text field to the checkout page based on the above option." 298 327 msgstr "" 299 328 300 #: includes/class-wc-valorpay-gateway.php:5 44329 #: includes/class-wc-valorpay-gateway.php:576 301 330 msgid "Enable Protection" 302 331 msgstr "" 303 332 304 333 #. translators: 1: Tracker URL. 305 #: includes/class-wc-valorpay-gateway.php:5 48334 #: includes/class-wc-valorpay-gateway.php:580 306 335 msgid "Disable the payment method in the checkout page for failed transactions. <a id=\"valorpay-goto-tracker\" href=\"%s\">Unblock IP</a>" 307 336 msgstr "" 308 337 309 #: includes/class-wc-valorpay-gateway.php:5 54338 #: includes/class-wc-valorpay-gateway.php:586 310 339 msgid "Declined Transaction Count" 311 340 msgstr "" 312 341 313 #: includes/class-wc-valorpay-gateway.php:5 55342 #: includes/class-wc-valorpay-gateway.php:587 314 343 msgid "Number of declined transaction count." 315 344 msgstr "" 316 345 317 #: includes/class-wc-valorpay-gateway.php:5 59346 #: includes/class-wc-valorpay-gateway.php:591 318 347 msgid "3" 319 348 msgstr "" 320 349 321 #: includes/class-wc-valorpay-gateway.php:5 60350 #: includes/class-wc-valorpay-gateway.php:592 322 351 msgid "5" 323 352 msgstr "" 324 353 325 #: includes/class-wc-valorpay-gateway.php:5 61354 #: includes/class-wc-valorpay-gateway.php:593 326 355 msgid "6" 327 356 msgstr "" 328 357 329 #: includes/class-wc-valorpay-gateway.php:5 65358 #: includes/class-wc-valorpay-gateway.php:597 330 359 msgid "Block Payment For" 331 360 msgstr "" 332 361 333 #: includes/class-wc-valorpay-gateway.php:5 66362 #: includes/class-wc-valorpay-gateway.php:598 334 363 msgid "Minutes to block payment gateway in checkout." 335 364 msgstr "" 336 365 337 #: includes/class-wc-valorpay-gateway.php: 570366 #: includes/class-wc-valorpay-gateway.php:602 338 367 msgid "1 min" 339 368 msgstr "" 340 369 341 #: includes/class-wc-valorpay-gateway.php: 571370 #: includes/class-wc-valorpay-gateway.php:603 342 371 msgid "5 min" 343 372 msgstr "" 344 373 345 #: includes/class-wc-valorpay-gateway.php: 572374 #: includes/class-wc-valorpay-gateway.php:604 346 375 msgid "10 min" 347 376 msgstr "" 348 377 349 #: includes/class-wc-valorpay-gateway.php: 573378 #: includes/class-wc-valorpay-gateway.php:605 350 379 msgid "1 hour" 351 380 msgstr "" 352 381 353 #: includes/class-wc-valorpay-gateway.php: 574382 #: includes/class-wc-valorpay-gateway.php:606 354 383 msgid "3 hour" 355 384 msgstr "" 356 385 357 #: includes/class-wc-valorpay-gateway.php: 575386 #: includes/class-wc-valorpay-gateway.php:607 358 387 msgid "5 hour" 359 388 msgstr "" 360 389 361 #: includes/class-wc-valorpay-gateway.php: 576390 #: includes/class-wc-valorpay-gateway.php:608 362 391 msgid "10 hour" 363 392 msgstr "" 364 393 365 #: includes/class-wc-valorpay-gateway.php: 577394 #: includes/class-wc-valorpay-gateway.php:609 366 395 msgid "1 day" 367 396 msgstr "" 368 397 369 #: includes/class-wc-valorpay-gateway.php: 581398 #: includes/class-wc-valorpay-gateway.php:613 370 399 msgid "Accepted Cards" 371 400 msgstr "" 372 401 373 #: includes/class-wc-valorpay-gateway.php: 585402 #: includes/class-wc-valorpay-gateway.php:617 374 403 msgid "Select the card types to accept." 375 404 msgstr "" 376 405 377 406 #. translators: 1: Maximum percentage. 378 #: includes/class-wc-valorpay-gateway.php:6 24407 #: includes/class-wc-valorpay-gateway.php:656 379 408 msgid "Surcharge percentage cannot be more than %s" 380 409 msgstr "" 381 410 382 411 #. translators: 1: Maximum flat rate. 383 #: includes/class-wc-valorpay-gateway.php:6 29412 #: includes/class-wc-valorpay-gateway.php:661 384 413 msgid "Surcharge flat rate cannot be more than %s" 385 414 msgstr "" 386 415 387 #: includes/class-wc-valorpay-gateway.php: 674416 #: includes/class-wc-valorpay-gateway.php:706 388 417 msgid "Invalid card information." 389 418 msgstr "" 390 419 391 420 #. translators: 1: Error Message, 2: Amount, 3: Line Break, 4: Approval Code, 5: Line Break, 6: RRN Number. 392 #: includes/class-wc-valorpay-gateway.php: 690421 #: includes/class-wc-valorpay-gateway.php:722 393 422 msgid "Valor Pay %1$s for %2$s.%3$s <strong>Approval Code:</strong> %4$s.%5$s <strong>RRN:</strong> %6$s" 394 423 msgstr "" 395 424 396 425 #. translators: %s: API Error Message. 397 #: includes/class-wc-valorpay-gateway.php:7 26398 #: includes/class-wc-valorpay-gateway.php:7 29426 #: includes/class-wc-valorpay-gateway.php:758 427 #: includes/class-wc-valorpay-gateway.php:761 399 428 msgid "Payment error: %s" 400 429 msgstr "" 401 430 402 #: includes/class-wc-valorpay-gateway.php:7 31431 #: includes/class-wc-valorpay-gateway.php:763 403 432 msgid "Unable to process the transaction using Valor Pay, please try again." 404 433 msgstr "" 405 434 406 435 #. translators: 1: Disable Time, 2: Unblock IP URL, 3: Customer IP. 407 #: includes/class-wc-valorpay-gateway.php: 790436 #: includes/class-wc-valorpay-gateway.php:824 408 437 msgid "Valor Pay method is disabled for %1$s. <a target=\"_blank\" href=\"%2$s\">To Unblock IP</a> %3$s" 409 438 msgstr "" 410 439 411 #: includes/class-wc-valorpay-gateway.php:8 53440 #: includes/class-wc-valorpay-gateway.php:887 412 441 msgid "Refund failed." 413 442 msgstr "" 414 443 415 444 #. translators: 1: Amount, 2: Line Break, 3: Approval code, 4: Line Break, 5: RRN Code 416 #: includes/class-wc-valorpay-gateway.php:8 65445 #: includes/class-wc-valorpay-gateway.php:899 417 446 msgid "Valor Pay Refund for %1$s.%2$s <strong>Approval Code:</strong> %3$s.%4$s <strong>RRN:</strong> %5$s" 418 447 msgstr "" 419 448 420 #: public/class-wc-valorpay-public.php:8 0449 #: public/class-wc-valorpay-public.php:88 421 450 msgid "Please enter a card number" 422 451 msgstr "" 423 452 424 #: public/class-wc-valorpay-public.php:8 1453 #: public/class-wc-valorpay-public.php:89 425 454 msgid "Invalid card number" 426 455 msgstr "" 427 456 428 #: public/class-wc-valorpay-public.php: 82457 #: public/class-wc-valorpay-public.php:90 429 458 msgid "Card is expired" 430 459 msgstr "" 431 460 432 #: public/class-wc-valorpay-public.php: 83461 #: public/class-wc-valorpay-public.php:91 433 462 msgid "Please enter card expiry date" 434 463 msgstr "" 435 464 436 #: public/class-wc-valorpay-public.php: 84465 #: public/class-wc-valorpay-public.php:92 437 466 msgid "Please enter a CVC" 438 467 msgstr "" 439 468 440 #: public/class-wc-valorpay-public.php: 85469 #: public/class-wc-valorpay-public.php:93 441 470 msgid "Invalid CVC length" 442 471 msgstr "" 443 472 444 #: public/class-wc-valorpay-public.php: 86473 #: public/class-wc-valorpay-public.php:94 445 474 msgid "Please enter a zip code" 446 475 msgstr "" 447 476 448 #: public/class-wc-valorpay-public.php: 87477 #: public/class-wc-valorpay-public.php:95 449 478 msgid "Invalid zip code" 450 479 msgstr "" 451 480 452 #: public/class-wc-valorpay-public.php: 88481 #: public/class-wc-valorpay-public.php:96 453 482 msgid "Please enter a street address" 454 483 msgstr "" 455 484 456 #: public/class-wc-valorpay-public.php:108 457 msgid "Zip Code is required." 458 msgstr "" 459 460 #: public/class-wc-valorpay-public.php:111 461 msgid "Enter a valid Zip Code." 462 msgstr "" 463 464 #: public/class-wc-valorpay-public.php:116 465 msgid "Street No is required." 466 msgstr "" 467 468 #: public/class-wc-valorpay-public.php:119 469 msgid "Enter a valid Street No." 470 msgstr "" 485 #: public/class-wc-valorpay-public.php:97 486 msgid "Unable to process payment. Please try again." 487 msgstr "" 488 489 #: public/class-wc-valorpay-public.php:244 490 #: public/class-wc-valorpay-public.php:272 491 #: public/class-wc-valorpay-public.php:312 492 msgid "Invalid request method." 493 msgstr "" 494 495 #: public/class-wc-valorpay-public.php:251 496 #: public/class-wc-valorpay-public.php:282 497 msgid "Payment gateway missing." 498 msgstr "" 499 500 #: public/class-wc-valorpay-public.php:257 501 msgid "Unable to create page token." 502 msgstr "" 503 504 #: public/class-wc-valorpay-public.php:278 505 #: public/class-wc-valorpay-public.php:318 506 msgid "Invalid request." 507 msgstr "" 508 509 #: public/class-wc-valorpay-public.php:299 510 msgid "Unable to lookup bin." 511 msgstr "" 512 513 #: public/class-wc-valorpay-public.php:338 514 msgid "Unable to set card type." 515 msgstr "" -
valorpos/tags/7.4.0/public/class-wc-valorpay-public.php
r2918841 r2980555 19 19 * @package Wc_Valorpay 20 20 * @subpackage Wc_Valorpay/public 21 * @author Valor Pay tech LLC <isv@valorpaytech.com>21 * @author Valor PayTech LLC <isv@valorpaytech.com> 22 22 */ 23 23 class Wc_Valorpay_Public { … … 60 60 * @since 1.0.0 61 61 */ 62 /** 63 * Register the JavaScript and CSS for the public area. 64 * 65 * @since 1.0.0 66 */ 62 67 public function enqueue_scripts_and_styles() { 63 68 if ( is_checkout() ) { 69 $all_payment_methods = WC()->payment_gateways()->payment_gateways(); 70 if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) { 71 return; 72 } 73 64 74 wp_enqueue_style( $this->plugin_name, plugins_url( 'css/wc-valorpay-checkout.css', __FILE__ ), array(), $this->version ); 65 } 66 } 67 68 /** 69 * Register the JavaScript for the public-facing side of the site. 70 * 71 * @since 1.0.0 72 */ 73 public function valorpay_checkout_script() { 74 75 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-checkout.js', array( 'jquery' ), $this->version, false ); 76 wp_localize_script( 77 $this->plugin_name, 78 'valorpay_checkout_object', 79 array( 80 'error_card' => __( 'Please enter a card number', 'wc-valorpay' ), 81 'invalid_card' => __( 'Invalid card number', 'wc-valorpay' ), 82 'expiry_card' => __( 'Card is expired', 'wc-valorpay' ), 83 'invalid_expiry' => __( 'Please enter card expiry date', 'wc-valorpay' ), 84 'error_cvv' => __( 'Please enter a CVC', 'wc-valorpay' ), 85 'invalid_cvv' => __( 'Invalid CVC length', 'wc-valorpay' ), 86 'avs_zip_error' => __( 'Please enter a zip code', 'wc-valorpay' ), 87 'invalid_avs_zip_error' => __( 'Invalid zip code', 'wc-valorpay' ), 88 'avs_street_error' => __( 'Please enter a street address', 'wc-valorpay' ), 89 ) 90 ); 91 92 } 93 94 /** 95 * AVS checkout validation 96 * 97 * @since 1.0.0 98 * 99 * @param array $fields An array of posted data. 100 * @param WP_Error $errors Validation errors. 101 * @return void 102 */ 103 public function valorpay_avs_checkout_validation( $fields, $errors ) { 104 if ( ( isset( $fields['payment_method'] ) && 'wc_valorpay' === $fields['payment_method'] ) ) { 105 $valorpay_avs_type = ( isset( $_POST['valorpay_avs_type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_type'] ) ) : ''; // phpcs:ignore 106 if ( 'zip' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) { 107 if ( ! isset( $_POST['valorpay_avs_zip'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) { // phpcs:ignore 108 $errors->add( 'validation', __( 'Zip Code is required.', 'wc-valorpay' ) ); 109 } 110 if ( isset( $_POST['valorpay_avs_zip'] ) && sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) && ! preg_match( '/^([a-zA-Z0-9_-]){4,6}$/', sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) ) { // phpcs:ignore 111 $errors->add( 'validation', __( 'Enter a valid Zip Code.', 'wc-valorpay' ) ); 112 } 113 } 114 if ( 'address' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) { 115 if ( ! isset( $_POST['valorpay_avs_street'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) { // phpcs:ignore 116 $errors->add( 'validation', __( 'Street No is required.', 'wc-valorpay' ) ); 117 } 118 if ( isset( $_POST['valorpay_avs_street'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) > 25 ) { // phpcs:ignore 119 $errors->add( 'validation', __( 'Enter a valid Street No.', 'wc-valorpay' ) ); 120 } 121 } 75 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-checkout.js', array( 'jquery' ), $this->version, false ); 76 wp_localize_script( 77 $this->plugin_name, 78 'valorpay_checkout_object', 79 array( 80 'ajax_url' => admin_url( 'admin-ajax.php' ), 81 'wc_ajax_action' => WC_AJAX::get_endpoint( '%%endpoint_url%%' ), 82 'ct_ajax_action' => 'valorpay_create_page_token', 83 'ct_ajax_nonce' => wp_create_nonce( 'valorpay_create_page_token' ), 84 'bl_ajax_action' => 'valorpay_bin_lookup', 85 'bl_ajax_nonce' => wp_create_nonce( 'valorpay_bin_lookup' ), 86 'card_type_ajax_action' => 'valorpay_token_card_type', 87 'card_type_ajax_nonce' => wp_create_nonce( 'valorpay_token_card_type' ), 88 'error_card' => __( 'Please enter a card number', 'wc-valorpay' ), 89 'invalid_card' => __( 'Invalid card number', 'wc-valorpay' ), 90 'expiry_card' => __( 'Card is expired', 'wc-valorpay' ), 91 'invalid_expiry' => __( 'Please enter card expiry date', 'wc-valorpay' ), 92 'error_cvv' => __( 'Please enter a CVC', 'wc-valorpay' ), 93 'invalid_cvv' => __( 'Invalid CVC length', 'wc-valorpay' ), 94 'avs_zip_error' => __( 'Please enter a zip code', 'wc-valorpay' ), 95 'invalid_avs_zip_error' => __( 'Invalid zip code', 'wc-valorpay' ), 96 'avs_street_error' => __( 'Please enter a street address', 'wc-valorpay' ), 97 'card_token_error' => __( 'Unable to process payment. Please try again.', 'wc-valorpay' ), 98 ) 99 ); 122 100 } 123 101 } … … 138 116 139 117 if ( 'wc_valorpay' === $payment_method && 'yes' === $valorpay->surcharge_indicator && 'yes' === $valorpay->enabled ) { 118 if ( 'D' === WC()->session->get( 'valor_card_type' ) && 'no' === $valorpay->surcharge_for_debit ) { 119 return; 120 } 140 121 $surcharge = 0; 141 122 if ( 'percentage' === $valorpay->surcharge_type ) { … … 228 209 } 229 210 } 211 212 /** 213 * Fetch card type for the default save token. 214 * 215 * @since 7.4.0 216 */ 217 public function valorpay_update_token_card_type() { 218 $current_user_id = get_current_user_id(); 219 if ( $current_user_id ) { 220 $token = WC_Payment_Tokens::get_customer_default_token( $current_user_id ); 221 if ( ! $token || null === $token ) { 222 WC()->session->__unset( 'valor_card_type' ); 223 } elseif ( 'wc_valorpay' === $token->get_gateway_id() ) { 224 $card_type = $token->get_meta( 'is_debit' ) === '1' ? 'D' : 'C'; 225 // Check if card type not same. 226 if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) { 227 WC()->session->set( 'valor_card_type', $card_type ); 228 } 229 } else { 230 WC()->session->__unset( 'valor_card_type' ); 231 } 232 } else { 233 WC()->session->__unset( 'valor_card_type' ); 234 } 235 } 236 237 /** 238 * Create page token. 239 * 240 * @since 7.4.0 241 */ 242 public function valorpay_create_page_token() { 243 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { 244 wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) ); 245 } 246 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_create_page_token' ) ) { 247 wp_send_json_error( 'invalid_nonce' ); 248 } 249 $all_payment_methods = WC()->payment_gateways()->payment_gateways(); 250 if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) { 251 wp_send_json_error( array( 'message' => __( 'Payment gateway missing.', 'wc-valorpay' ) ) ); 252 } 253 $valorpay = $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ]; 254 $valorpay_api = new WC_ValorPay_API( $valorpay ); 255 $api_response = $valorpay_api->create_checkout_page_token(); 256 if ( is_wp_error( $api_response ) || ! is_object( $api_response ) || ! isset( $api_response->clientToken ) ) { // phpcs:ignore 257 wp_send_json_error( array( 'message' => __( 'Unable to create page token.', 'wc-valorpay' ) ) ); 258 } else { 259 wp_send_json_success( array( 'token' => $api_response->clientToken ) ); // phpcs:ignore 260 } 261 } 262 263 /** 264 * Bin lookup. 265 * 266 * @since 7.4.0 267 * @throws Exception If error. 268 */ 269 public function valorpay_bin_lookup() { 270 try { 271 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { 272 wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) ); 273 } 274 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_bin_lookup' ) ) { 275 wp_send_json_error( 'invalid_nonce' ); 276 } 277 if ( ! isset( $_REQUEST['client_token'] ) || ! isset( $_REQUEST['bin'] ) ) { 278 wp_send_json_error( array( 'message' => __( 'Invalid request.', 'wc-valorpay' ) ) ); 279 } 280 $all_payment_methods = WC()->payment_gateways()->payment_gateways(); 281 if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) { 282 wp_send_json_error( array( 'message' => __( 'Payment gateway missing.', 'wc-valorpay' ) ) ); 283 } 284 $need_update = false; 285 $valorpay = $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ]; 286 $valorpay_api = new WC_ValorPay_API( $valorpay ); 287 $api_response = $valorpay_api->bin_lookup( sanitize_text_field( wp_unslash( $_REQUEST['bin'] ) ), sanitize_text_field( wp_unslash( $_REQUEST['client_token'] ) ) ); 288 if ( is_wp_error( $api_response ) ) { // phpcs:ignore 289 throw new Exception( 'Error' ); 290 } 291 $card_type = $api_response->card_type; 292 // If card type same as previous value, no need to update. 293 if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) { 294 WC()->session->set( 'valor_card_type', $api_response->card_type ); 295 $need_update = true; 296 } 297 wp_send_json_success( $need_update ); 298 } catch ( Exception $ex ) { 299 wp_send_json_error( array( 'message' => __( 'Unable to lookup bin.', 'wc-valorpay' ) ) ); 300 } 301 } 302 303 /** 304 * Get token card type. 305 * 306 * @since 7.4.0 307 * @throws Exception If error. 308 */ 309 public function valorpay_token_card_type() { 310 try { 311 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { 312 wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) ); 313 } 314 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_token_card_type' ) ) { 315 wp_send_json_error( 'invalid_nonce' ); 316 } 317 if ( ! isset( $_REQUEST['token_id'] ) ) { 318 wp_send_json_error( array( 'message' => __( 'Invalid request.', 'wc-valorpay' ) ) ); 319 } 320 $need_update = false; 321 $token_id = sanitize_text_field( wp_unslash( $_REQUEST['token_id'] ) ); 322 if ( 'new' !== $token_id ) { 323 $payment_token = WC_Payment_Tokens::get( $token_id ); 324 if ( $payment_token ) { 325 $card_type = $payment_token->get_meta( 'is_debit' ) === '1' ? 'D' : 'C'; 326 // Check if the payment token exists. 327 if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) { 328 WC()->session->set( 'valor_card_type', $card_type ); 329 $need_update = true; 330 } 331 } 332 } else { 333 WC()->session->__unset( 'valor_card_type' ); 334 $need_update = true; 335 } 336 wp_send_json_success( $need_update ); 337 } catch ( Exception $ex ) { 338 wp_send_json_error( array( 'message' => __( 'Unable to set card type.', 'wc-valorpay' ) ) ); 339 } 340 } 230 341 } -
valorpos/tags/7.4.0/public/js/wc-valorpay-checkout.js
r2918841 r2980555 6 6 */ 7 7 8 (function($) { 9 "use strict"; 10 11 var validcard = false; 12 var validcardexpiry = false; 13 var validcvc = false; 14 let luhnCheck = function(num) { 15 var digit, digits, odd, sum, _i, _len; 16 odd = true; 17 sum = 0; 18 digits = (num + "").split("").reverse(); 19 for (_i = 0, _len = digits.length; _i < _len; _i++) { 20 digit = digits[_i]; 21 digit = parseInt(digit, 10); 22 if ((odd = !odd)) { 23 digit *= 2; 24 } 25 if (digit > 9) { 26 digit -= 9; 27 } 28 sum += digit; 29 } 30 return sum % 10 === 0.0; 31 }; 32 33 $(document).ready(function() { 34 $("body").on("change", 'input[name="payment_method"]', function() { 35 $("body").trigger("update_checkout"); 36 }); 37 $("body").on("blur", 'input[name="wc_valorpay-card-number"]', function() { 38 if ($("#payment_method_wc_valorpay").is(":checked")) { 39 var cardNum = $(this).val().replace(/ /g, ""); 40 var isValid = luhnCheck(cardNum); 41 42 if (cardNum === "") { 43 $(this).addClass("error-class"); 44 if (!$(this).next().hasClass("error-message")) { 45 $( 46 '<span class="error-message" style="color:red;">' + 47 valorpay_checkout_object.error_card + 48 "</span>" 49 ).insertAfter($(this)); 50 } 51 $("#wc-wc_valorpay-card-number-error").remove(); 52 validcard = false; 53 $(this).parent().addClass("woocommerce-invalid"); 54 } else if (!isValid) { 55 $(this).addClass("error-class"); 56 if (!$(this).next().hasClass("error-message")) { 57 $( 58 '<span class="error-message" style="color:red;">' + 59 valorpay_checkout_object.invalid_card + 60 "</span>" 61 ).insertAfter($(this)); 62 } 63 $("#wc-wc_valorpay-card-number-error").remove(); 64 validcard = false; 65 $(this).parent().addClass("woocommerce-invalid"); 66 } else { 67 $(this).removeClass("error-class"); 68 $(this).next(".error-message").remove(); 69 validcard = true; 70 $(this).parent().removeClass("woocommerce-invalid"); 71 } 72 } 73 }); 74 $("body").on("focus", 'input[name="wc_valorpay-card-number"]', function() { 75 if (!$(this).val()) { 76 $(this).removeClass("error-class"); 77 $(this).next(".error-message").remove(); 78 } 79 }); 80 $("body").on("blur", 'input[name="wc_valorpay-card-expiry"]', function() { 81 if ($("#payment_method_wc_valorpay").is(":checked")) { 82 var expiry = $(this).val().replace(/ /g, ""); 83 if (expiry === "") { 84 $(this).addClass("error-class"); 85 if (!$(this).next().hasClass("error-message")) { 86 $( 87 '<span class="error-message" style="color:red;">' + 88 valorpay_checkout_object.invalid_expiry + 89 "</span>" 90 ).insertAfter($(this)); 91 } 92 validcardexpiry = false; 93 $(this).parent().addClass("woocommerce-invalid"); 94 } else { 95 var parts = expiry.split("/"); 96 var month = parseInt(parts[0], 10); 97 var year = parseInt(parts[1], 10); 98 if (year < 100) { 99 year += 2000; 100 } 101 if (!validateCardExpiry(month, year)) { 102 $(this).addClass("error-class"); 103 if (!$(this).next().hasClass("error-message")) { 104 $( 105 '<span class="error-message" style="color:red;">' + 106 valorpay_checkout_object.expiry_card + 107 "</span>" 108 ).insertAfter($(this)); 109 } 110 validcardexpiry = false; 111 $(this).parent().addClass("woocommerce-invalid"); 112 } else { 113 $(this).removeClass("error-class"); 114 $(this).next(".error-message").remove(); 115 validcardexpiry = true; 116 $(this).parent().removeClass("woocommerce-invalid"); 117 } 118 } 119 } 120 }); 121 122 $("body").on("focus", 'input[name="wc_valorpay-card-expiry"]', function() { 123 $(this).removeClass("error-class"); 124 $(this).next(".error-message").remove(); 125 }); 126 $("body").on("blur", "#wc_valorpay-card-cvc", function() { 127 if ($("#payment_method_wc_valorpay").is(":checked")) { 128 var cvcNum = $(this).val().trim(); 129 if (cvcNum === "") { 130 $(this).addClass("error-class"); 131 if (!$(this).next().hasClass("error-message")) { 132 $( 133 '<span class="error-message" style="color:red;">' + 134 valorpay_checkout_object.error_cvv + 135 "</span>" 136 ).insertAfter($(this)); 137 } 138 validcvc = false; 139 $(this).parent().addClass("woocommerce-invalid"); 140 } else if (cvcNum.length != 3 && cvcNum.length != 4) { 141 $(this).addClass("error-class"); 142 if (!$(this).next().hasClass("error-message")) { 143 $( 144 '<span class="error-message" style="color:red;">' + 145 valorpay_checkout_object.invalid_cvv + 146 "</span>" 147 ).insertAfter($(this)); 148 } 149 validcvc = false; 150 $(this).parent().addClass("woocommerce-invalid"); 151 } else { 152 $(this).removeClass("error-class"); 153 $(this).next(".error-message").remove(); 154 validcvc = true; 155 $(this).parent().removeClass("woocommerce-invalid"); 156 } 157 } 158 }); 159 $("body").on("focus", 'input[name="wc_valorpay-card-cvc"]', function() { 160 $(this).removeClass("error-class"); 161 $(this).next(".error-message").remove(); 162 }); 163 $("form.woocommerce-checkout").on( 164 "checkout_place_order_wc_valorpay", 165 function() { 166 167 168 var cardNumb = $('input[name="wc_valorpay-card-number"]').val(); 169 const isToken = $('#wc-wc_valorpay-payment-token-new'); 170 if ( 171 isToken.length && !isToken.is(":checked") 172 ) { 173 var avserrorIsValidsave = addAVSErrors(); 174 // Do something if the radio button is checked 175 176 if (avserrorIsValidsave) { 177 178 return true; 179 } else { 8 (function ($) { 9 "use strict"; 10 var wc_valorpay_form = { 11 validCard: false, 12 validCardExpiry: false, 13 validCvc: false, 14 checkoutFormClass: "form.woocommerce-checkout", 15 cardNumberInput: "#wc_valorpay-card-number", 16 cardExpiryInput: "#wc_valorpay-card-expiry", 17 cardCvvInput: "#wc_valorpay-card-cvc", 18 clientTokenInit: false, 19 clientToken: "", 20 tokenGenerateInterval: null, 21 tokenExpiryMin: 5, 22 prevSelectedToken: false, 23 /** 24 * Initialize. 25 */ 26 init: function () { 27 // On payment method switch update checkout. 28 $( document.body ).on( 29 "change", 30 'input[name="payment_method"]', 31 this.updateCheckout 32 ); 33 $( document.body ).on( 34 "click", 35 'input[name="wc-wc_valorpay-payment-token"]', 36 this.surChargeCalculation 37 ); 38 this.validateCardForm(); 39 this.createPageToken(); 40 this.startReCreatePageToken(); 41 $( wc_valorpay_form.checkoutFormClass ).on( 42 "checkout_place_order_wc_valorpay", 43 this.valorPayPlaceOrder 44 ); 45 }, 46 /** 47 * On payment gateway change update the checkout. 48 */ 49 updateCheckout: function () { 50 $( document.body ).trigger( "update_checkout" ); 51 }, 52 /** 53 * On token switch 54 */ 55 surChargeCalculation: function () { 56 const checkedValue = $('input[name="wc-wc_valorpay-payment-token"]:checked').val(); 57 if(wc_valorpay_form.prevSelectedToken != checkedValue) { 58 if((checkedValue === 'new' && !$( wc_valorpay_form.cardNumberInput ).val()) || checkedValue !== 'new') { 59 wc_valorpay_form.tokenCardType(checkedValue); 60 } else { 61 $( wc_valorpay_form.cardNumberInput ).trigger( "blur" ); 62 } 63 wc_valorpay_form.prevSelectedToken = checkedValue; 64 } 65 }, 66 /** 67 * Block checkout page UI. 68 */ 69 block: function () { 70 $( wc_valorpay_form.checkoutFormClass ).block( 71 { 72 message: null, 73 overlayCSS: { 74 background: "#fff", 75 opacity: 0.6, 76 }, 77 } 78 ); 79 }, 80 /** 81 * Unblock checkout page UI. 82 */ 83 unblock: function () { 84 $( wc_valorpay_form.checkoutFormClass ).unblock(); 85 }, 86 /** 87 * Create page or client token. 88 */ 89 createPageToken: function () { 90 $.ajax( 91 { 92 type: "POST", 93 url: valorpay_checkout_object.wc_ajax_action 94 .toString() 95 .replace( "%%endpoint_url%%", valorpay_checkout_object.ct_ajax_action ), 96 data: { 97 nonce: valorpay_checkout_object.ct_ajax_nonce, 98 }, 99 success: function (response) { 100 if (response.success) { 101 wc_valorpay_form.clientToken = response.data.token; 102 } 103 }, 104 } 105 ); 106 }, 107 /** 108 * Bin lookup. 109 */ 110 binLookUp: function () { 111 var cardNumber = $( wc_valorpay_form.cardNumberInput ) 112 .val() 113 .replace( / /g, "" ); 114 $.ajax( 115 { 116 type: "POST", 117 url: valorpay_checkout_object.wc_ajax_action 118 .toString() 119 .replace( "%%endpoint_url%%", valorpay_checkout_object.bl_ajax_action ), 120 data: { 121 nonce: valorpay_checkout_object.bl_ajax_nonce, 122 client_token: wc_valorpay_form.clientToken, 123 bin: cardNumber.substring(0, 6) 124 }, 125 success: function (response) { 126 if (response.success && response.data) { 127 wc_valorpay_form.updateCheckout(); 128 } 129 }, 130 } 131 ); 132 }, 133 /** 134 * Token card type. 135 */ 136 tokenCardType: function (tokenId) { 137 $.ajax( 138 { 139 type: "POST", 140 url: valorpay_checkout_object.wc_ajax_action 141 .toString() 142 .replace( "%%endpoint_url%%", valorpay_checkout_object.card_type_ajax_action ), 143 data: { 144 nonce: valorpay_checkout_object.card_type_ajax_nonce, 145 token_id: tokenId, 146 }, 147 success: function (response) { 148 if (response.success && response.data) { 149 wc_valorpay_form.updateCheckout(); 150 } 151 }, 152 } 153 ); 154 }, 155 /** 156 * Recreate page token on every token expiry minutes. 157 */ 158 startReCreatePageToken: function () { 159 wc_valorpay_form.tokenGenerateInterval = setInterval( 160 function () { 161 wc_valorpay_form.createPageToken(); 162 }, 163 wc_valorpay_form.tokenExpiryMin * 60 * 1000 164 ); 165 }, 166 /** 167 * Convert expiry date to MMYY format. 168 */ 169 convertToMMYY: function (dateString) { 170 // Remove any leading/trailing spaces. 171 dateString = dateString.trim(); 172 173 // Split the string into month and year parts. 174 var parts = dateString.split( "/" ); 175 var month = parseInt( parts[0] ); 176 var year = parseInt( parts[1] ); 177 178 // Extract the year part based on the input format. 179 if (year < 100) { 180 // Format is MM/YY . 181 year += 2000; // Assuming years below 100 are in the 21st century. 182 } 183 184 // Format the month and year as MMYY . 185 var formattedDate = ("0" + month).slice( -2 ) + ("0" + year).slice( -2 ); 186 187 return formattedDate; 188 }, 189 /** 190 * Validate card checkout field. 191 */ 192 validateCardForm: function () { 193 this.validateCardNumber(); 194 this.validateCardExpiry(); 195 this.validateCardCvv(); 196 }, 197 /** 198 * Add error to form field. 199 * 200 * @param {jQuery} currentEle The current element. 201 * @param {string} errorMsg Error Message. 202 */ 203 addErrorMessage: function (currentEle, errorMsg) { 204 currentEle.addClass( "error-class" ); 205 if ( ! currentEle.next().hasClass( "error-message" )) { 206 $( 207 '<span class="error-message" style="color:red;">' + 208 errorMsg + 209 "</span>" 210 ).insertAfter( currentEle ); 211 currentEle.closest( ".form-row" ).addClass( "woocommerce-invalid" ); 212 } 213 }, 214 /** 215 * Remove error from the form field. 216 * 217 * @param {jQuery} currentEle The current element. 218 */ 219 removeErrorMessage: function (currentEle) { 220 currentEle.removeClass( "error-class" ); 221 currentEle.next( ".error-message" ).remove(); 222 currentEle.closest( ".form-row" ).removeClass( "woocommerce-invalid" ); 223 }, 224 /** 225 * Validate card number field. 226 */ 227 validateCardNumber: function () { 228 $( "body" ).on( 229 "blur", 230 this.cardNumberInput, 231 function () { 232 var cardNum = $( this ).val().replace( / /g, "" ); 233 var isValid = wc_valorpay_form.luhnCheck( cardNum ); 234 235 if (cardNum === "") { 236 wc_valorpay_form.addErrorMessage( 237 $( this ), 238 valorpay_checkout_object.error_card 239 ); 240 wc_valorpay_form.validCard = false; 241 } else if ( ! isValid) { 242 wc_valorpay_form.addErrorMessage( 243 $( this ), 244 valorpay_checkout_object.invalid_card 245 ); 246 wc_valorpay_form.validCard = false; 247 } else { 248 wc_valorpay_form.removeErrorMessage( $( this ) ); 249 wc_valorpay_form.validCard = true; 250 wc_valorpay_form.binLookUp(); 251 } 252 } 253 ); 254 $( "body" ).on( 255 "focus", 256 this.cardNumberInput, 257 function () { 258 if ( ! $( this ).val()) { 259 wc_valorpay_form.removeErrorMessage( $( this ) ); 260 } 261 } 262 ); 263 }, 264 /** 265 * Validate card expiry field. 266 */ 267 validateCardExpiry: function () { 268 $( "body" ).on( 269 "blur", 270 this.cardExpiryInput, 271 function () { 272 var expiry = $( this ).val().replace( / /g, "" ); 273 if (expiry === "") { 274 wc_valorpay_form.addErrorMessage( 275 $( this ), 276 valorpay_checkout_object.invalid_expiry 277 ); 278 wc_valorpay_form.validCardExpiry = false; 279 } else { 280 var parts = expiry.split( "/" ); 281 var month = parseInt( parts[0], 10 ); 282 var year = parseInt( parts[1], 10 ); 283 if (year < 100) { 284 year += 2000; 285 } 286 if ( ! wc_valorpay_form.checkCardExpiry( month, year )) { 287 wc_valorpay_form.addErrorMessage( 288 $( this ), 289 valorpay_checkout_object.expiry_card 290 ); 291 wc_valorpay_form.validCardExpiry = false; 292 } else { 293 wc_valorpay_form.removeErrorMessage( $( this ) ); 294 wc_valorpay_form.validCardExpiry = true; 295 } 296 } 297 } 298 ); 299 300 $( "body" ).on( 301 "focus", 302 this.cardExpiryInput, 303 function () { 304 wc_valorpay_form.removeErrorMessage( $( this ) ); 305 } 306 ); 307 }, 308 /** 309 * Validate card CVV field. 310 */ 311 validateCardCvv: function () { 312 $( "body" ).on( 313 "blur", 314 this.cardCvvInput, 315 function () { 316 var cvcNum = $( this ).val().trim(); 317 if (cvcNum === "") { 318 wc_valorpay_form.addErrorMessage( 319 $( this ), 320 valorpay_checkout_object.error_cvv 321 ); 322 wc_valorpay_form.validCvc = false; 323 } else if (cvcNum.length != 3 && cvcNum.length != 4) { 324 wc_valorpay_form.addErrorMessage( 325 $( this ), 326 valorpay_checkout_object.invalid_cvv 327 ); 328 wc_valorpay_form.validCvc = false; 329 } else { 330 wc_valorpay_form.removeErrorMessage( $( this ) ); 331 wc_valorpay_form.validCvc = true; 332 } 333 } 334 ); 335 $( "body" ).on( 336 "focus", 337 this.cardCvvInput, 338 function () { 339 wc_valorpay_form.removeErrorMessage( $( this ) ); 340 } 341 ); 342 }, 343 /** 344 * Validate field on place order 345 */ 346 valorPayPlaceOrder: function (event) { 347 var cardNumb = $( wc_valorpay_form.cardNumberInput ).val(); 348 const isNewCard = $( "#wc-wc_valorpay-payment-token-new" ); 349 if (isNewCard.length && ! isNewCard.is( ":checked" )) { 350 var avsErrorIsValidSave = wc_valorpay_form.avsValidation(); 351 if (avsErrorIsValidSave) { 352 wc_valorpay_form.scrollToValorForm(); 180 353 return false; 181 } 182 } 183 184 if (cardNumb === "") { 185 $('input[name="wc_valorpay-card-number"]').trigger("blur"); 186 } else { 187 $('input[name="wc_valorpay-card-number"]').trigger("blur"); 188 $('input[name="wc_valorpay-card-expiry"]').trigger("blur"); 189 $('input[name="wc_valorpay-card-cvc"]').trigger("blur"); 190 } 191 if (validcard === false) { 192 $("html, body").animate({ 193 scrollTop: $("#wc-wc_valorpay-cc-form").offset().top, 194 }, 195 1000 196 ); 197 return false; 198 } 199 if (validcardexpiry === false) { 200 $("html, body").animate({ 201 scrollTop: $("#wc-wc_valorpay-cc-form").offset().top, 202 }, 203 1000 204 ); 205 return false; 206 } 207 if (validcvc === false) { 208 $("html, body").animate({ 209 scrollTop: $("#wc-wc_valorpay-cc-form").offset().top, 210 }, 211 1000 212 ); 213 return false; 214 } 215 if (cardNumb !== "") { 216 var avserrorIsValid = addAVSErrors(); 217 218 if (avserrorIsValid) { 219 220 return true; 221 } else { 222 return false; 223 } 224 } 225 } 226 ); 227 228 229 230 function validateCardExpiry(month, year) { 231 var currentTime = new Date(); 232 var expiry = new Date(year, month, 1); 233 if (expiry < currentTime) { 234 return false; 235 } 236 return true; 237 } 238 239 function addAVSErrors() { 240 var hasError = false; 241 242 $('input[name="valorpay_avs_zip"] + span.error').remove(); 243 $('input[name="valorpay_avs_street"] + span.error').remove(); 244 245 if ($('input[name="valorpay_avs_zip"]').val() === "") { 246 $('input[name="valorpay_avs_zip"]').after( 247 '<span class="error" style="color:red;">' + 248 valorpay_checkout_object.avs_zip_error + 249 "</span>" 250 ); 251 hasError = true; 252 } else if ($('input[name="valorpay_avs_zip"]').val().length < 4) { 253 $('input[name="valorpay_avs_zip"]').after( 254 '<span class="error" style="color:red;">' + 255 valorpay_checkout_object.invalid_avs_zip_error + "</span>" 256 ); 257 hasError = true; 258 } 259 260 if ($('input[name="valorpay_avs_street"]').val() === "") { 261 $('input[name="valorpay_avs_street"]').after( 262 '<span class="error" style="color:red;">' + 263 valorpay_checkout_object.avs_street_error + 264 "</span>" 265 ); 266 hasError = true; 267 } 268 269 $('input[name="valorpay_avs_zip"]').focus(function() { 270 $('input[name="valorpay_avs_zip"] + span.error').remove(); 271 }); 272 273 $('input[name="valorpay_avs_street"]').focus(function() { 274 $('input[name="valorpay_avs_street"] + span.error').remove(); 275 }); 276 277 return !hasError; 278 } 279 }); 280 281 282 })(jQuery); 354 } 355 return true; 356 } 357 if (cardNumb === "") { 358 $( wc_valorpay_form.cardNumberInput ).trigger( "blur" ); 359 } else { 360 $( wc_valorpay_form.cardNumberInput ).trigger( "blur" ); 361 $( wc_valorpay_form.cardExpiryInput ).trigger( "blur" ); 362 $( wc_valorpay_form.cardCvvInput ).trigger( "blur" ); 363 } 364 if (wc_valorpay_form.validCard === false) { 365 wc_valorpay_form.scrollToValorForm(); 366 return false; 367 } 368 if (wc_valorpay_form.validCardExpiry === false) { 369 wc_valorpay_form.scrollToValorForm(); 370 return false; 371 } 372 if (wc_valorpay_form.validCvc === false) { 373 wc_valorpay_form.scrollToValorForm(); 374 return false; 375 } 376 377 if (cardNumb !== "") { 378 var avsErrorIsValid = wc_valorpay_form.avsValidation(); 379 if (avsErrorIsValid) { 380 wc_valorpay_form.scrollToValorForm(); 381 return false; 382 } 383 return true; 384 } 385 }, 386 /** 387 * Validate Address Verification Service 388 */ 389 avsValidation: function () { 390 var hasError = false; 391 if ($( 'input[name="valorpay_avs_zip"]' ).length) { 392 wc_valorpay_form.removeErrorMessage( 393 $( 'input[name="valorpay_avs_zip"]' ) 394 ); 395 if ($( 'input[name="valorpay_avs_zip"]' ).val() === "") { 396 wc_valorpay_form.addErrorMessage( 397 $( 'input[name="valorpay_avs_zip"]' ), 398 valorpay_checkout_object.avs_zip_error 399 ); 400 hasError = true; 401 } else if ($( 'input[name="valorpay_avs_zip"]' ).val().length < 4) { 402 wc_valorpay_form.addErrorMessage( 403 $( 'input[name="valorpay_avs_zip"]' ), 404 valorpay_checkout_object.invalid_avs_zip_error 405 ); 406 hasError = true; 407 } 408 $( 'input[name="valorpay_avs_zip"]' ).focus( 409 function () { 410 wc_valorpay_form.removeErrorMessage( 411 $( 'input[name="valorpay_avs_zip"]' ) 412 ); 413 } 414 ); 415 } 416 417 if ($( 'input[name="valorpay_avs_street"]' ).length) { 418 wc_valorpay_form.removeErrorMessage( 419 $( 'input[name="valorpay_avs_street"]' ) 420 ); 421 if ($( 'input[name="valorpay_avs_street"]' ).val() === "") { 422 wc_valorpay_form.addErrorMessage( 423 $( 'input[name="valorpay_avs_street"]' ), 424 valorpay_checkout_object.avs_street_error 425 ); 426 hasError = true; 427 } 428 $( 'input[name="valorpay_avs_street"]' ).focus( 429 function () { 430 wc_valorpay_form.removeErrorMessage( 431 $( 'input[name="valorpay_avs_street"]' ) 432 ); 433 } 434 ); 435 } 436 437 return hasError; 438 }, 439 /** 440 * Check if the card expiry. 441 * 442 * @param {number} month Card month 443 * @param {number} year Card year 444 * @return {boolean} 445 */ 446 checkCardExpiry: function (month, year) { 447 var currentTime = new Date(); 448 var expiry = new Date( year, month, 1 ); 449 if (expiry < currentTime) { 450 return false; 451 } 452 return true; 453 }, 454 /** 455 * Luhn check. 456 * 457 * @param {string} num Card number 458 * @return {boolean} 459 */ 460 luhnCheck: function (num) { 461 var digit, digits, odd, sum, _i, _len; 462 odd = true; 463 sum = 0; 464 digits = (num + "").split( "" ).reverse(); 465 for (_i = 0, _len = digits.length; _i < _len; _i++) { 466 digit = digits[_i]; 467 digit = parseInt( digit, 10 ); 468 if ((odd = ! odd)) { 469 digit *= 2; 470 } 471 if (digit > 9) { 472 digit -= 9; 473 } 474 sum += digit; 475 } 476 return sum % 10 === 0.0; 477 }, 478 /** 479 * Scroll to payment form. 480 */ 481 scrollToValorForm: function () { 482 $( "html, body" ).animate( 483 { 484 scrollTop: $( "#wc-wc_valorpay-cc-form" ).offset().top, 485 }, 486 1000 487 ); 488 }, 489 }; 490 $( document ).ready( 491 function () { 492 // Initialize the wc_test_form object. 493 wc_valorpay_form.init(); 494 } 495 ); 496 })( jQuery ); -
valorpos/tags/7.4.0/wc-valorpay.php
r2960359 r2980555 16 16 * Plugin URI: https://valorpaytech.com 17 17 * Description: Adds the Valor Payment Gateway to WooCommerce. 18 * Version: 7. 3.118 * Version: 7.4.0 19 19 * Author: Valor Paytech LLC 20 20 * Author URI: https://valorpaytech.com … … 37 37 * Rename this for your plugin and update it as you release new versions. 38 38 */ 39 define( 'WC_VALORPAY_VERSION', '7. 3.1' );39 define( 'WC_VALORPAY_VERSION', '7.4.0' ); 40 40 // Directory i.e. /home/user/public_html... 41 41 define( 'WC_VALORPAY_DIR', plugin_dir_path( __FILE__ ) ); -
valorpos/trunk/README.txt
r2960359 r2980555 3 3 Tags: payment, payment gateway, credit card, valor pay, valor paytech 4 4 Requires at least: 5.0 5 Tested up to: 6. 2.25 Tested up to: 6.3.1 6 6 Requires PHP: 7.0 7 Stable tag: 7. 3.17 Stable tag: 7.4.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 41 41 == Changelog == 42 42 43 = 7.4.0 = 44 * Added a new configuration to toggle surcharge for debit transactions. This configuration determines whether a surcharge should be applied to debit transactions or not. 45 43 46 = 7.3.1 = 44 47 * Update plugin title. -
valorpos/trunk/admin/class-wc-valorpay-admin.php
r2918841 r2980555 22 22 * @package Wc_Valorpay 23 23 * @subpackage Wc_Valorpay/admin 24 * @author Valor Pay tech LLC <isv@valorpaytech.com>24 * @author Valor PayTech LLC <isv@valorpaytech.com> 25 25 */ 26 26 class Wc_Valorpay_Admin { -
valorpos/trunk/includes/class-wc-valorpay-activator.php
r2883367 r2980555 18 18 * @package Wc_Valorpay 19 19 * @subpackage Wc_Valorpay/includes 20 * @author Valor Pay tech LLC <isv@valorpaytech.com>20 * @author Valor PayTech LLC <isv@valorpaytech.com> 21 21 */ 22 22 class Wc_Valorpay_Activator { -
valorpos/trunk/includes/class-wc-valorpay-api.php
r2918841 r2980555 21 21 * @package Wc_Valorpay 22 22 * @subpackage Wc_Valorpay/includes 23 * @author Valor Pay tech LLC <isv@valorpaytech.com>23 * @author Valor PayTech LLC <isv@valorpaytech.com> 24 24 */ 25 25 class WC_ValorPay_API { … … 27 27 * Sandbox payment URL 28 28 */ 29 const WC_VALORPAY_SANDBOX_URL = 'https://securelink test.valorpaytech.com:4430/';29 const WC_VALORPAY_SANDBOX_URL = 'https://securelink-staging.valorpaytech.com:4430/'; 30 30 /** 31 31 * Live payment URL … … 35 35 * Sandbox OTP refund URL 36 36 */ 37 const WC_VALORPAY_REFUND_OTP_SANDBOX_URL = 'https://2fa demo.isoaccess.com/?main_action=Manage2FA&operation=ecommRefund';37 const WC_VALORPAY_REFUND_OTP_SANDBOX_URL = 'https://2fa-staging.valorpaytech.com:4430/?main_action=Manage2FA&operation=ecommRefund'; 38 38 /** 39 39 * Live OTP refund URL 40 40 */ 41 41 const WC_VALORPAY_REFUND_OTP_URL = 'https://2fa.valorpaytech.com/?main_action=Manage2FA&operation=ecommRefund'; 42 /** 43 * Create page token action 44 */ 45 const WC_VALORPAY_PAGE_TOKEN_ACTION = 'clientToken'; 46 /** 47 * Bin lookup action 48 */ 49 const WC_VALORPAY_BIN_LOOKUP_ACTION = 'binLookup'; 42 50 43 51 /** … … 138 146 $payload = $this->get_payload( $order, $amount, 'send_otp' ); 139 147 $response = $this->post_transaction( $payload, 'send_otp' ); 148 return $response; 149 } 150 151 /** 152 * Create checkout page token 153 * 154 * @since 7.4.0 155 * @return object JSON response 156 */ 157 public function create_checkout_page_token() { 158 $payload = array( 159 'appid' => $this->gateway->appid, 160 'appkey' => $this->gateway->appkey, 161 'epi' => $this->gateway->epi, 162 'txn_type' => self::WC_VALORPAY_PAGE_TOKEN_ACTION, 163 ); 164 $response = $this->post_transaction( wp_json_encode( $payload ) ); 165 return $response; 166 } 167 168 /** 169 * Get bin details 170 * 171 * @since 7.4.0 172 * 173 * @param string $bin_number Bin Number. 174 * @param string $client_token Client Token. 175 * @return object JSON response 176 */ 177 public function bin_lookup( $bin_number, $client_token ) { 178 $payload = array( 179 'client_token' => $client_token, 180 'bin' => $bin_number, 181 'epi' => $this->gateway->epi, 182 'txn_type' => self::WC_VALORPAY_BIN_LOOKUP_ACTION, 183 ); 184 $response = $this->post_transaction( wp_json_encode( $payload ), 'bin_lookup' ); 140 185 return $response; 141 186 } … … 156 201 $data = array(); 157 202 if ( 'sale' === $transaction_type ) { 158 $surcharge_indicator = 0;203 $surcharge_indicator = ( 'yes' === $this->gateway->surcharge_indicator ) ? 1 : 0; 159 204 $custom_fee = 0; 160 if ( 'yes' === $this->gateway->surcharge_indicator && 0 < count( $order->get_fees() ) ) {161 $ surcharge_indicator = 1;162 if ( 'sale' === $transaction_type) {205 if ( 1 === $surcharge_indicator && 0 < count( $order->get_fees() ) ) { 206 $cal_for_debit = ( 'D' === WC()->session->get( 'valor_card_type' ) ) && 'no' !== $this->gateway->surcharge_for_debit; 207 if ( $cal_for_debit || ( 'D' !== WC()->session->get( 'valor_card_type' ) ) ) { 163 208 foreach ( $order->get_fees() as $item_fee ) { 164 209 if ( $item_fee->get_name() === $this->gateway->surcharge_label ) { … … 170 215 } 171 216 } 217 $surcharge_data = array( 218 'surchargeIndicator' => $surcharge_indicator, 219 'surchargeAmount' => $custom_fee, 220 ); 221 172 222 $billing_first_name = wc_clean( $order->get_billing_first_name() ); 173 223 $billing_last_name = wc_clean( $order->get_billing_last_name() ); … … 189 239 $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 190 240 $valorpay_avs_street = ( isset( $_POST['valorpay_avs_street'] ) && $_POST['valorpay_avs_street'] ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) : wc_clean( $billing_address ); // phpcs:ignore 191 $valorpay_terms = ( isset( $_POST['valorpay_terms'] ) && $_POST['valorpay_terms'] ) ? 1 : 0; // phpcs:ignore241 $valorpay_terms = ( isset( $_POST['valorpay_terms'] ) && $_POST['valorpay_terms'] ) ? 1 : 0; // phpcs:ignore 192 242 193 243 $card_number = str_replace( ' ', '', ( isset( $_POST['wc_valorpay-card-number'] ) ) ? sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) : '' ); // phpcs:ignore 194 244 $data = array( 195 'appid' => $this->gateway->appid, 196 'appkey' => $this->gateway->appkey, 197 'epi' => $this->gateway->epi, 198 'txn_type' => $this->gateway->payment_action, 199 'amount' => wc_clean( $amount ), 200 'phone' => $billing_phone, 201 'email' => $billing_email, 202 'uid' => $order_number, 203 'tax_amount' => number_format( $tax_amount, '2', '.', '' ), 204 'ip' => $ip_address, 205 'surchargeIndicator' => $surcharge_indicator, 206 'surchargeAmount' => $custom_fee, 207 'address1' => $valorpay_avs_street, 208 'address2' => wc_clean( $billing_address2 ), 209 'city' => wc_clean( substr( $billing_city, 0, 40 ) ), 210 'state' => wc_clean( substr( $billing_state, 0, 40 ) ), 211 'zip' => $valorpay_avs_zip, 212 'billing_country' => wc_clean( substr( $billing_country, 0, 60 ) ), 213 'shipping_country' => wc_clean( substr( $shipping_country, 0, 60 ) ), 214 'status' => 'Y', 215 'terms_checked' => $valorpay_terms, 216 ); 245 'appid' => $this->gateway->appid, 246 'appkey' => $this->gateway->appkey, 247 'epi' => $this->gateway->epi, 248 'txn_type' => $this->gateway->payment_action, 249 'amount' => wc_clean( $amount ), 250 'phone' => $billing_phone, 251 'email' => $billing_email, 252 'uid' => $order_number, 253 'tax_amount' => number_format( $tax_amount, '2', '.', '' ), 254 'ip' => $ip_address, 255 'address1' => $valorpay_avs_street, 256 'address2' => wc_clean( $billing_address2 ), 257 'city' => wc_clean( substr( $billing_city, 0, 40 ) ), 258 'state' => wc_clean( substr( $billing_state, 0, 40 ) ), 259 'zip' => $valorpay_avs_zip, 260 'billing_country' => wc_clean( substr( $billing_country, 0, 60 ) ), 261 'shipping_country' => wc_clean( substr( $shipping_country, 0, 60 ) ), 262 'status' => 'Y', 263 'terms_checked' => $valorpay_terms, 264 ) + $surcharge_data; 217 265 218 266 if ( $card ) { … … 287 335 $response = wp_remote_post( $api_url, $args ); 288 336 if ( is_wp_error( $response ) || empty( $response['body'] ) ) { 289 return new WP_Error( 'valorp os_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );337 return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) ); 290 338 } 291 339 $parsed_response = json_decode( preg_replace( '/\xEF\xBB\xBF/', '', $response['body'] ) ); 292 340 if ( 'send_otp' === $transaction_type ) { 293 341 if ( ! isset( $parsed_response->error_code ) ) { 294 return new WP_Error( 'valorp os_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );342 return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) ); 295 343 } 296 344 if ( 'S00' !== $parsed_response->error_code ) { 297 345 $error_msg = sprintf( '%s', $parsed_response->error_desc ); 298 return new WP_Error( 'valorpos_error', $error_msg ); 346 return new WP_Error( 'valorpay_error', $error_msg ); 347 } 348 } elseif ( 'bin_lookup' === $transaction_type ) { 349 if ( ! isset( $parsed_response->card_type ) ) { 350 return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) ); 299 351 } 300 352 } else { 301 353 if ( ! isset( $parsed_response->error_no ) ) { 302 return new WP_Error( 'valorp os_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) );354 return new WP_Error( 'valorpay_error', __( 'There was a problem connecting to the payment gateway.', 'wc-valorpay' ) ); 303 355 } 304 356 if ( 'S00' !== $parsed_response->error_no ) { 305 357 $error_msg = sprintf( '%s ( %s )', $parsed_response->mesg, $parsed_response->desc ); 306 return new WP_Error( 'valorp os_error', $error_msg );358 return new WP_Error( 'valorpay_error', $error_msg ); 307 359 } 308 360 } -
valorpos/trunk/includes/class-wc-valorpay-deactivator.php
r2883367 r2980555 22 22 * @package Wc_Valorpay 23 23 * @subpackage Wc_Valorpay/includes 24 * @author Valor Pay tech LLC <isv@valorpaytech.com>24 * @author Valor PayTech LLC <isv@valorpaytech.com> 25 25 */ 26 26 class Wc_Valorpay_Deactivator { -
valorpos/trunk/includes/class-wc-valorpay-gateway-loader.php
r2883367 r2980555 22 22 * @package Wc_Valorpay 23 23 * @subpackage Wc_Valorpay/includes 24 * @author Valor Pay tech LLC <isv@valorpaytech.com>24 * @author Valor PayTech LLC <isv@valorpaytech.com> 25 25 */ 26 26 class Wc_Valorpay_Gateway_Loader { -
valorpos/trunk/includes/class-wc-valorpay-gateway.php
r2960359 r2980555 19 19 * @package Wc_Valorpay 20 20 * @subpackage Wc_Valorpay/includes 21 * @author Valor Pay tech LLC <isv@valorpaytech.com>21 * @author Valor PayTech LLC <isv@valorpaytech.com> 22 22 * @uses WC_Payment_Gateway_CC 23 23 */ … … 97 97 */ 98 98 public $surcharge_flat_rate; 99 100 /** 101 * Valor Pay surcharge for debit. 102 * 103 * @var string 104 */ 105 public $surcharge_for_debit; 99 106 100 107 /** … … 166 173 $this->surcharge_percentage = $this->get_option( 'surcharge_percentage' ); 167 174 $this->surcharge_flat_rate = $this->get_option( 'surcharge_flat_rate' ); 175 $this->surcharge_for_debit = $this->get_option( 'surcharge_for_debit' ); 168 176 $this->cardtypes = $this->get_option( 'cardtypes' ); 169 177 $this->avs_type = $this->get_option( 'avs_type' ); … … 322 330 public function validate_fields() { 323 331 try { 332 $valorpay_avs_type = ( isset( $_POST['valorpay_avs_type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_type'] ) ) : ''; // phpcs:ignore 333 if ( 'zip' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) { 334 if ( ! isset( $_POST['valorpay_avs_zip'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) { // phpcs:ignore 335 throw new Exception( __( 'Zip Code is required.', 'wc-valorpay' ) ); 336 } 337 if ( isset( $_POST['valorpay_avs_zip'] ) && sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) && ! preg_match( '/^([a-zA-Z0-9_-]){4,6}$/', sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) ) { // phpcs:ignore 338 throw new Exception( __( 'Enter a valid Zip Code.', 'wc-valorpay' ) ); 339 } 340 } 341 if ( 'address' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) { 342 if ( ! isset( $_POST['valorpay_avs_street'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) { // phpcs:ignore 343 throw new Exception( __( 'Street No is required.', 'wc-valorpay' ) ); 344 } 345 if ( isset( $_POST['valorpay_avs_street'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) > 25 ) { // phpcs:ignore 346 throw new Exception( __( 'Enter a valid Street No.', 'wc-valorpay' ) ); 347 } 348 } 324 349 if ( isset( $_POST['wc-wc_valorpay-payment-token'] ) && 'new' !== wc_clean( $_POST['wc-wc_valorpay-payment-token'] ) ) { // phpcs:ignore 325 350 return true; … … 526 551 'default' => 0, 527 552 'description' => __( 'Flat rate will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $', 'wc-valorpay' ), 553 ), 554 'surcharge_for_debit' => array( 555 'title' => __( 'Surcharge For Debit', 'wc-valorpay' ), 556 'label' => __( 'Enable Surcharge For Debit', 'wc-valorpay' ), 557 'type' => 'checkbox', 558 'description' => __( 'Enable surcharge for debit', 'wc-valorpay' ), 559 'default' => 'yes', 528 560 ), 529 561 'avs_type' => array( … … 704 736 $exp_date = $exp_month . substr( $exp_year, -2 ); 705 737 $response->card_type = $valorpay_api->get_card_type( str_replace( ' ', '', sanitize_text_field( wp_unslash( $_POST['wc_valorpay-card-number'] ) ) ) ); // phpcs:ignore 706 $this->save_card( $response, $exp_date );738 $this->save_card( $response, $exp_date, ( 'D' === WC()->session->get( 'valor_card_type' ) ) ? 1 : 0 ); 707 739 } 708 740 … … 722 754 ); 723 755 } else { 724 if ( isset( $response->errors['valorp os_error'][0] ) ) {756 if ( isset( $response->errors['valorpay_error'][0] ) ) { 725 757 /* translators: %s: API Error Message. */ 726 $order->add_order_note( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorp os_error'][0] ) );758 $order->add_order_note( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpay_error'][0] ) ); 727 759 $this->add_failed_count_by_ip( $order ); 728 760 /* translators: %s: API Error Message. */ 729 throw new Exception( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorp os_error'][0] ) );761 throw new Exception( sprintf( __( 'Payment error: %s', 'wc-valorpay' ), $response->errors['valorpay_error'][0] ) ); 730 762 } 731 763 throw new Exception( __( 'Unable to process the transaction using Valor Pay, please try again.', 'wc-valorpay' ) ); … … 744 776 * Save card. 745 777 * 746 * @param Object $response Response.778 * @param object $response Response. 747 779 * @param string $exp_date Expiry Date. 780 * @param int $is_debit Is Debit Card. 748 781 * @return void 749 782 */ 750 protected function save_card( $response, $exp_date ) {783 protected function save_card( $response, $exp_date, $is_debit ) { 751 784 if ( $response->token ) { 752 785 $token = new WC_Payment_Token_CC(); … … 758 791 $token->set_expiry_year( '20' . substr( $exp_date, -2 ) ); 759 792 $token->set_user_id( get_current_user_id() ); 793 $token->add_meta_data( 'is_debit', $is_debit ); 760 794 $token->save(); 761 795 } -
valorpos/trunk/includes/class-wc-valorpay-i18n.php
r2883367 r2980555 26 26 * @package Wc_Valorpay 27 27 * @subpackage Wc_Valorpay/includes 28 * @author Valor Pay tech LLC <isv@valorpaytech.com>28 * @author Valor PayTech LLC <isv@valorpaytech.com> 29 29 */ 30 30 class Wc_Valorpay_I18n { -
valorpos/trunk/includes/class-wc-valorpay-loader.php
r2883367 r2980555 23 23 * @package Wc_Valorpay 24 24 * @subpackage Wc_Valorpay/includes 25 * @author Valor Pay tech LLC <isv@valorpaytech.com>25 * @author Valor PayTech LLC <isv@valorpaytech.com> 26 26 */ 27 27 class Wc_Valorpay_Loader { -
valorpos/trunk/includes/class-wc-valorpay.php
r2918841 r2980555 25 25 * @package Wc_Valorpay 26 26 * @subpackage Wc_Valorpay/includes 27 * @author Valor Pay tech LLC <isv@valorpaytech.com>27 * @author Valor PayTech LLC <isv@valorpaytech.com> 28 28 */ 29 29 class Wc_Valorpay { … … 197 197 198 198 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts_and_styles' ); 199 $this->loader->add_action( 'woocommerce_after_checkout_validation', $plugin_public, 'valorpay_avs_checkout_validation', 10, 2 );200 199 $this->loader->add_action( 'woocommerce_cart_calculate_fees', $plugin_public, 'valorpay_custom_surcharge' ); 201 200 $this->loader->add_action( 'woocommerce_before_checkout_form', $plugin_public, 'valorpay_before_checkout_form' ); 202 $this->loader->add_action( 'woocommerce_ after_checkout_form', $plugin_public, 'valorpay_checkout_script' );201 $this->loader->add_action( 'woocommerce_review_order_before_payment', $plugin_public, 'valorpay_update_token_card_type' ); 203 202 $this->loader->add_filter( 'woocommerce_available_payment_gateways', $plugin_public, 'valorpay_disable_payment_gateway_failed_orders' ); 203 $this->loader->add_action( 'wc_ajax_valorpay_create_page_token', $plugin_public, 'valorpay_create_page_token' ); 204 $this->loader->add_action( 'wc_ajax_valorpay_bin_lookup', $plugin_public, 'valorpay_bin_lookup' ); 205 $this->loader->add_action( 'wc_ajax_valorpay_token_card_type', $plugin_public, 'valorpay_token_card_type' ); 204 206 205 207 } -
valorpos/trunk/languages/wc-valorpay.pot
r2960359 r2980555 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Valor Pay 7. 3.0\n"6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/ wc-valorpay\n"5 "Project-Id-Version: Valor Pay 7.4.0\n" 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/valorpos\n" 7 7 "Last-Translator: Valor Paytech LLC <sales@valorpaytech.com>\n" 8 8 "MIME-Version: 1.0\n" 9 9 "Content-Type: text/plain; charset=UTF-8\n" 10 10 "Content-Transfer-Encoding: 8bit\n" 11 "POT-Creation-Date: 2023- 05-19T15:31:04+05:30\n"12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"11 "POT-Creation-Date: 2023-10-18T08:57:12+00:00\n" 12 "PO-Revision-Date: 2023-10-18T08:57:12+00:00\n" 13 13 "X-Generator: WP-CLI 2.7.1\n" 14 14 "X-Domain: wc-valorpay\n" 15 15 16 16 #. Plugin Name of the plugin 17 #: includes/class-wc-valorpay-gateway.php:4 5517 #: includes/class-wc-valorpay-gateway.php:480 18 18 msgid "Valor Pay" 19 19 msgstr "" … … 69 69 70 70 #: admin/partials/wc-valorpay-admin-failure-tracker.php:18 71 #: includes/class-wc-valorpay-gateway.php:5 4371 #: includes/class-wc-valorpay-gateway.php:575 72 72 msgid "Payment Failed Tracker" 73 73 msgstr "" … … 122 122 msgstr "" 123 123 124 #: includes/class-wc-valorpay-api.php:289 125 #: includes/class-wc-valorpay-api.php:294 126 #: includes/class-wc-valorpay-api.php:302 124 #: includes/class-wc-valorpay-api.php:337 125 #: includes/class-wc-valorpay-api.php:342 126 #: includes/class-wc-valorpay-api.php:350 127 #: includes/class-wc-valorpay-api.php:354 127 128 msgid "There was a problem connecting to the payment gateway." 128 129 msgstr "" 129 130 130 #: includes/class-wc-valorpay-gateway.php:1 43131 #: includes/class-wc-valorpay-gateway.php:150 131 132 msgid "ValorPay Plugin" 132 133 msgstr "" 133 134 134 #: includes/class-wc-valorpay-gateway.php:1 44135 #: includes/class-wc-valorpay-gateway.php:151 135 136 msgid "Take payments via Valorpay." 136 137 msgstr "" 137 138 138 #: includes/class-wc-valorpay-gateway.php:1 76139 #: includes/class-wc-valorpay-gateway.php:184 139 140 msgid "TEST MODE ENABLED. Use test card number 4111111111111111 with 999 as CVC and a future expiration date." 140 141 msgstr "" 141 142 142 #: includes/class-wc-valorpay-gateway.php:20 0143 #: includes/class-wc-valorpay-gateway.php:208 143 144 msgid "Unsupported currency:" 144 145 msgstr "" 145 146 146 #: includes/class-wc-valorpay-gateway.php:2 03147 #: includes/class-wc-valorpay-gateway.php:211 147 148 msgid "Valor Pay accepts only USD." 148 149 msgstr "" 149 150 150 151 #. translators: %s: Settings URL. 151 #: includes/class-wc-valorpay-gateway.php:2 15152 #: includes/class-wc-valorpay-gateway.php:223 152 153 msgid "Valor Pay error: The APP ID is required. %s" 153 154 msgstr "" 154 155 155 #: includes/class-wc-valorpay-gateway.php:2 16156 #: includes/class-wc-valorpay-gateway.php:2 27157 #: includes/class-wc-valorpay-gateway.php:2 36156 #: includes/class-wc-valorpay-gateway.php:224 157 #: includes/class-wc-valorpay-gateway.php:235 158 #: includes/class-wc-valorpay-gateway.php:244 158 159 msgid "Click here to update your Valor Pay settings." 159 160 msgstr "" 160 161 161 162 #. translators: %s: Settings URL. 162 #: includes/class-wc-valorpay-gateway.php:2 26163 #: includes/class-wc-valorpay-gateway.php:234 163 164 msgid "Valor Pay error: The APP KEY is required. %s" 164 165 msgstr "" 165 166 166 167 #. translators: %s: Settings URL. 167 #: includes/class-wc-valorpay-gateway.php:2 35168 #: includes/class-wc-valorpay-gateway.php:243 168 169 msgid "Valor Pay error: The EPI is required. %s" 169 170 msgstr "" 170 171 171 #: includes/class-wc-valorpay-gateway.php:332 172 #: includes/class-wc-valorpay-gateway.php:335 173 msgid "Zip Code is required." 174 msgstr "" 175 176 #: includes/class-wc-valorpay-gateway.php:338 177 msgid "Enter a valid Zip Code." 178 msgstr "" 179 180 #: includes/class-wc-valorpay-gateway.php:343 181 msgid "Street No is required." 182 msgstr "" 183 184 #: includes/class-wc-valorpay-gateway.php:346 185 msgid "Enter a valid Street No." 186 msgstr "" 187 188 #: includes/class-wc-valorpay-gateway.php:357 172 189 msgid "Card number is invalid" 173 190 msgstr "" 174 191 175 #: includes/class-wc-valorpay-gateway.php:3 36192 #: includes/class-wc-valorpay-gateway.php:361 176 193 msgid "Not a valid card" 177 194 msgstr "" 178 195 179 #: includes/class-wc-valorpay-gateway.php:3 39196 #: includes/class-wc-valorpay-gateway.php:364 180 197 msgid "Card number expired" 181 198 msgstr "" 182 199 183 #: includes/class-wc-valorpay-gateway.php:3 42200 #: includes/class-wc-valorpay-gateway.php:367 184 201 msgid "Card security code is invalid (only digits are allowed)" 185 202 msgstr "" 186 203 187 204 #. translators: 1: Terms and Conditions URL. 188 #: includes/class-wc-valorpay-gateway.php: 378205 #: includes/class-wc-valorpay-gateway.php:403 189 206 msgid "I agree to the <a href=\"%s\" target=\"_blank\">Terms and Conditions</a>" 190 207 msgstr "" 191 208 192 #: includes/class-wc-valorpay-gateway.php:4 09193 #: includes/class-wc-valorpay-gateway.php:4 10209 #: includes/class-wc-valorpay-gateway.php:434 210 #: includes/class-wc-valorpay-gateway.php:435 194 211 msgid "Zip Code" 195 212 msgstr "" 196 213 197 #: includes/class-wc-valorpay-gateway.php:4 23198 #: includes/class-wc-valorpay-gateway.php:4 24214 #: includes/class-wc-valorpay-gateway.php:448 215 #: includes/class-wc-valorpay-gateway.php:449 199 216 msgid "Street No" 200 217 msgstr "" 201 218 202 #: includes/class-wc-valorpay-gateway.php:4 45219 #: includes/class-wc-valorpay-gateway.php:470 203 220 msgid "Enable/Disable" 204 221 msgstr "" 205 222 206 #: includes/class-wc-valorpay-gateway.php:4 46223 #: includes/class-wc-valorpay-gateway.php:471 207 224 msgid "Enable Valor Pay" 208 225 msgstr "" 209 226 210 #: includes/class-wc-valorpay-gateway.php:4 52227 #: includes/class-wc-valorpay-gateway.php:477 211 228 msgid "Title" 212 229 msgstr "" 213 230 214 #: includes/class-wc-valorpay-gateway.php:4 54231 #: includes/class-wc-valorpay-gateway.php:479 215 232 msgid "This controls the title which the user sees during checkout." 216 233 msgstr "" 217 234 218 #: includes/class-wc-valorpay-gateway.php:4 59235 #: includes/class-wc-valorpay-gateway.php:484 219 236 msgid "Use Sandbox" 220 237 msgstr "" 221 238 222 #: includes/class-wc-valorpay-gateway.php:4 60239 #: includes/class-wc-valorpay-gateway.php:485 223 240 msgid "Enable sandbox mode - live payments will not be taken if enabled." 224 241 msgstr "" 225 242 226 #: includes/class-wc-valorpay-gateway.php:4 66243 #: includes/class-wc-valorpay-gateway.php:491 227 244 msgid "APP ID" 228 245 msgstr "" 229 246 230 #: includes/class-wc-valorpay-gateway.php:4 68247 #: includes/class-wc-valorpay-gateway.php:493 231 248 msgid "Please email support@valorpaytech.com to get to know about your APP ID, ( In demo mode APP ID is not needed )" 232 249 msgstr "" 233 250 234 #: includes/class-wc-valorpay-gateway.php:4 72251 #: includes/class-wc-valorpay-gateway.php:497 235 252 msgid "APP KEY" 236 253 msgstr "" 237 254 238 #: includes/class-wc-valorpay-gateway.php:4 74255 #: includes/class-wc-valorpay-gateway.php:499 239 256 msgid "Please email support@valorpaytech.com to get to know about your APP KEY, ( In demo mode APP KEY is not needed )" 240 257 msgstr "" 241 258 242 #: includes/class-wc-valorpay-gateway.php: 478259 #: includes/class-wc-valorpay-gateway.php:503 243 260 msgid "EPI" 244 261 msgstr "" 245 262 246 #: includes/class-wc-valorpay-gateway.php: 480263 #: includes/class-wc-valorpay-gateway.php:505 247 264 msgid "Please email support@valorpaytech.com to get to know about your EPI ID, ( In demo mode EPI ID is not needed )" 248 265 msgstr "" 249 266 250 #: includes/class-wc-valorpay-gateway.php: 484267 #: includes/class-wc-valorpay-gateway.php:509 251 268 msgid "Payment Method" 252 269 msgstr "" 253 270 254 #: includes/class-wc-valorpay-gateway.php: 494271 #: includes/class-wc-valorpay-gateway.php:519 255 272 msgid "Surcharge Mode" 256 273 msgstr "" 257 274 258 #: includes/class-wc-valorpay-gateway.php: 495259 #: includes/class-wc-valorpay-gateway.php:5 02275 #: includes/class-wc-valorpay-gateway.php:520 276 #: includes/class-wc-valorpay-gateway.php:527 260 277 msgid "Enable Surcharge Mode" 261 278 msgstr "" 262 279 263 #: includes/class-wc-valorpay-gateway.php: 497280 #: includes/class-wc-valorpay-gateway.php:522 264 281 msgid "Enable only if you want all transactions to be fall on surcharge mode, Merchant must have got an Surcharge MID inorder to work" 265 282 msgstr "" 266 283 267 #: includes/class-wc-valorpay-gateway.php:5 01284 #: includes/class-wc-valorpay-gateway.php:526 268 285 msgid "Surcharge Type" 269 286 msgstr "" 270 287 271 #: includes/class-wc-valorpay-gateway.php:5 11272 #: includes/class-wc-valorpay-gateway.php:5 12288 #: includes/class-wc-valorpay-gateway.php:536 289 #: includes/class-wc-valorpay-gateway.php:537 273 290 msgid "Surcharge Label" 274 291 msgstr "" 275 292 276 #: includes/class-wc-valorpay-gateway.php:5 17293 #: includes/class-wc-valorpay-gateway.php:542 277 294 msgid "Surcharge %" 278 295 msgstr "" 279 296 280 #: includes/class-wc-valorpay-gateway.php:5 21297 #: includes/class-wc-valorpay-gateway.php:546 281 298 msgid "Percentage will apply only on enabling on surcharge Indicator to true and Surcharge type is set fo Surcharge %" 282 299 msgstr "" 283 300 284 #: includes/class-wc-valorpay-gateway.php:5 24301 #: includes/class-wc-valorpay-gateway.php:549 285 302 msgid "Flat Rate $" 286 303 msgstr "" 287 304 288 #: includes/class-wc-valorpay-gateway.php:5 27305 #: includes/class-wc-valorpay-gateway.php:552 289 306 msgid "Flat rate will apply only on if Enable surcharge mode is true and Surcharge type is set to Flat Rate $" 290 307 msgstr "" 291 308 292 #: includes/class-wc-valorpay-gateway.php:530 309 #: includes/class-wc-valorpay-gateway.php:555 310 msgid "Surcharge For Debit" 311 msgstr "" 312 313 #: includes/class-wc-valorpay-gateway.php:556 314 msgid "Enable Surcharge For Debit" 315 msgstr "" 316 317 #: includes/class-wc-valorpay-gateway.php:558 318 msgid "Enable surcharge for debit" 319 msgstr "" 320 321 #: includes/class-wc-valorpay-gateway.php:562 293 322 msgid "AVS" 294 323 msgstr "" 295 324 296 #: includes/class-wc-valorpay-gateway.php:5 40325 #: includes/class-wc-valorpay-gateway.php:572 297 326 msgid "The address verification service will add a text field to the checkout page based on the above option." 298 327 msgstr "" 299 328 300 #: includes/class-wc-valorpay-gateway.php:5 44329 #: includes/class-wc-valorpay-gateway.php:576 301 330 msgid "Enable Protection" 302 331 msgstr "" 303 332 304 333 #. translators: 1: Tracker URL. 305 #: includes/class-wc-valorpay-gateway.php:5 48334 #: includes/class-wc-valorpay-gateway.php:580 306 335 msgid "Disable the payment method in the checkout page for failed transactions. <a id=\"valorpay-goto-tracker\" href=\"%s\">Unblock IP</a>" 307 336 msgstr "" 308 337 309 #: includes/class-wc-valorpay-gateway.php:5 54338 #: includes/class-wc-valorpay-gateway.php:586 310 339 msgid "Declined Transaction Count" 311 340 msgstr "" 312 341 313 #: includes/class-wc-valorpay-gateway.php:5 55342 #: includes/class-wc-valorpay-gateway.php:587 314 343 msgid "Number of declined transaction count." 315 344 msgstr "" 316 345 317 #: includes/class-wc-valorpay-gateway.php:5 59346 #: includes/class-wc-valorpay-gateway.php:591 318 347 msgid "3" 319 348 msgstr "" 320 349 321 #: includes/class-wc-valorpay-gateway.php:5 60350 #: includes/class-wc-valorpay-gateway.php:592 322 351 msgid "5" 323 352 msgstr "" 324 353 325 #: includes/class-wc-valorpay-gateway.php:5 61354 #: includes/class-wc-valorpay-gateway.php:593 326 355 msgid "6" 327 356 msgstr "" 328 357 329 #: includes/class-wc-valorpay-gateway.php:5 65358 #: includes/class-wc-valorpay-gateway.php:597 330 359 msgid "Block Payment For" 331 360 msgstr "" 332 361 333 #: includes/class-wc-valorpay-gateway.php:5 66362 #: includes/class-wc-valorpay-gateway.php:598 334 363 msgid "Minutes to block payment gateway in checkout." 335 364 msgstr "" 336 365 337 #: includes/class-wc-valorpay-gateway.php: 570366 #: includes/class-wc-valorpay-gateway.php:602 338 367 msgid "1 min" 339 368 msgstr "" 340 369 341 #: includes/class-wc-valorpay-gateway.php: 571370 #: includes/class-wc-valorpay-gateway.php:603 342 371 msgid "5 min" 343 372 msgstr "" 344 373 345 #: includes/class-wc-valorpay-gateway.php: 572374 #: includes/class-wc-valorpay-gateway.php:604 346 375 msgid "10 min" 347 376 msgstr "" 348 377 349 #: includes/class-wc-valorpay-gateway.php: 573378 #: includes/class-wc-valorpay-gateway.php:605 350 379 msgid "1 hour" 351 380 msgstr "" 352 381 353 #: includes/class-wc-valorpay-gateway.php: 574382 #: includes/class-wc-valorpay-gateway.php:606 354 383 msgid "3 hour" 355 384 msgstr "" 356 385 357 #: includes/class-wc-valorpay-gateway.php: 575386 #: includes/class-wc-valorpay-gateway.php:607 358 387 msgid "5 hour" 359 388 msgstr "" 360 389 361 #: includes/class-wc-valorpay-gateway.php: 576390 #: includes/class-wc-valorpay-gateway.php:608 362 391 msgid "10 hour" 363 392 msgstr "" 364 393 365 #: includes/class-wc-valorpay-gateway.php: 577394 #: includes/class-wc-valorpay-gateway.php:609 366 395 msgid "1 day" 367 396 msgstr "" 368 397 369 #: includes/class-wc-valorpay-gateway.php: 581398 #: includes/class-wc-valorpay-gateway.php:613 370 399 msgid "Accepted Cards" 371 400 msgstr "" 372 401 373 #: includes/class-wc-valorpay-gateway.php: 585402 #: includes/class-wc-valorpay-gateway.php:617 374 403 msgid "Select the card types to accept." 375 404 msgstr "" 376 405 377 406 #. translators: 1: Maximum percentage. 378 #: includes/class-wc-valorpay-gateway.php:6 24407 #: includes/class-wc-valorpay-gateway.php:656 379 408 msgid "Surcharge percentage cannot be more than %s" 380 409 msgstr "" 381 410 382 411 #. translators: 1: Maximum flat rate. 383 #: includes/class-wc-valorpay-gateway.php:6 29412 #: includes/class-wc-valorpay-gateway.php:661 384 413 msgid "Surcharge flat rate cannot be more than %s" 385 414 msgstr "" 386 415 387 #: includes/class-wc-valorpay-gateway.php: 674416 #: includes/class-wc-valorpay-gateway.php:706 388 417 msgid "Invalid card information." 389 418 msgstr "" 390 419 391 420 #. translators: 1: Error Message, 2: Amount, 3: Line Break, 4: Approval Code, 5: Line Break, 6: RRN Number. 392 #: includes/class-wc-valorpay-gateway.php: 690421 #: includes/class-wc-valorpay-gateway.php:722 393 422 msgid "Valor Pay %1$s for %2$s.%3$s <strong>Approval Code:</strong> %4$s.%5$s <strong>RRN:</strong> %6$s" 394 423 msgstr "" 395 424 396 425 #. translators: %s: API Error Message. 397 #: includes/class-wc-valorpay-gateway.php:7 26398 #: includes/class-wc-valorpay-gateway.php:7 29426 #: includes/class-wc-valorpay-gateway.php:758 427 #: includes/class-wc-valorpay-gateway.php:761 399 428 msgid "Payment error: %s" 400 429 msgstr "" 401 430 402 #: includes/class-wc-valorpay-gateway.php:7 31431 #: includes/class-wc-valorpay-gateway.php:763 403 432 msgid "Unable to process the transaction using Valor Pay, please try again." 404 433 msgstr "" 405 434 406 435 #. translators: 1: Disable Time, 2: Unblock IP URL, 3: Customer IP. 407 #: includes/class-wc-valorpay-gateway.php: 790436 #: includes/class-wc-valorpay-gateway.php:824 408 437 msgid "Valor Pay method is disabled for %1$s. <a target=\"_blank\" href=\"%2$s\">To Unblock IP</a> %3$s" 409 438 msgstr "" 410 439 411 #: includes/class-wc-valorpay-gateway.php:8 53440 #: includes/class-wc-valorpay-gateway.php:887 412 441 msgid "Refund failed." 413 442 msgstr "" 414 443 415 444 #. translators: 1: Amount, 2: Line Break, 3: Approval code, 4: Line Break, 5: RRN Code 416 #: includes/class-wc-valorpay-gateway.php:8 65445 #: includes/class-wc-valorpay-gateway.php:899 417 446 msgid "Valor Pay Refund for %1$s.%2$s <strong>Approval Code:</strong> %3$s.%4$s <strong>RRN:</strong> %5$s" 418 447 msgstr "" 419 448 420 #: public/class-wc-valorpay-public.php:8 0449 #: public/class-wc-valorpay-public.php:88 421 450 msgid "Please enter a card number" 422 451 msgstr "" 423 452 424 #: public/class-wc-valorpay-public.php:8 1453 #: public/class-wc-valorpay-public.php:89 425 454 msgid "Invalid card number" 426 455 msgstr "" 427 456 428 #: public/class-wc-valorpay-public.php: 82457 #: public/class-wc-valorpay-public.php:90 429 458 msgid "Card is expired" 430 459 msgstr "" 431 460 432 #: public/class-wc-valorpay-public.php: 83461 #: public/class-wc-valorpay-public.php:91 433 462 msgid "Please enter card expiry date" 434 463 msgstr "" 435 464 436 #: public/class-wc-valorpay-public.php: 84465 #: public/class-wc-valorpay-public.php:92 437 466 msgid "Please enter a CVC" 438 467 msgstr "" 439 468 440 #: public/class-wc-valorpay-public.php: 85469 #: public/class-wc-valorpay-public.php:93 441 470 msgid "Invalid CVC length" 442 471 msgstr "" 443 472 444 #: public/class-wc-valorpay-public.php: 86473 #: public/class-wc-valorpay-public.php:94 445 474 msgid "Please enter a zip code" 446 475 msgstr "" 447 476 448 #: public/class-wc-valorpay-public.php: 87477 #: public/class-wc-valorpay-public.php:95 449 478 msgid "Invalid zip code" 450 479 msgstr "" 451 480 452 #: public/class-wc-valorpay-public.php: 88481 #: public/class-wc-valorpay-public.php:96 453 482 msgid "Please enter a street address" 454 483 msgstr "" 455 484 456 #: public/class-wc-valorpay-public.php:108 457 msgid "Zip Code is required." 458 msgstr "" 459 460 #: public/class-wc-valorpay-public.php:111 461 msgid "Enter a valid Zip Code." 462 msgstr "" 463 464 #: public/class-wc-valorpay-public.php:116 465 msgid "Street No is required." 466 msgstr "" 467 468 #: public/class-wc-valorpay-public.php:119 469 msgid "Enter a valid Street No." 470 msgstr "" 485 #: public/class-wc-valorpay-public.php:97 486 msgid "Unable to process payment. Please try again." 487 msgstr "" 488 489 #: public/class-wc-valorpay-public.php:244 490 #: public/class-wc-valorpay-public.php:272 491 #: public/class-wc-valorpay-public.php:312 492 msgid "Invalid request method." 493 msgstr "" 494 495 #: public/class-wc-valorpay-public.php:251 496 #: public/class-wc-valorpay-public.php:282 497 msgid "Payment gateway missing." 498 msgstr "" 499 500 #: public/class-wc-valorpay-public.php:257 501 msgid "Unable to create page token." 502 msgstr "" 503 504 #: public/class-wc-valorpay-public.php:278 505 #: public/class-wc-valorpay-public.php:318 506 msgid "Invalid request." 507 msgstr "" 508 509 #: public/class-wc-valorpay-public.php:299 510 msgid "Unable to lookup bin." 511 msgstr "" 512 513 #: public/class-wc-valorpay-public.php:338 514 msgid "Unable to set card type." 515 msgstr "" -
valorpos/trunk/public/class-wc-valorpay-public.php
r2918841 r2980555 19 19 * @package Wc_Valorpay 20 20 * @subpackage Wc_Valorpay/public 21 * @author Valor Pay tech LLC <isv@valorpaytech.com>21 * @author Valor PayTech LLC <isv@valorpaytech.com> 22 22 */ 23 23 class Wc_Valorpay_Public { … … 60 60 * @since 1.0.0 61 61 */ 62 /** 63 * Register the JavaScript and CSS for the public area. 64 * 65 * @since 1.0.0 66 */ 62 67 public function enqueue_scripts_and_styles() { 63 68 if ( is_checkout() ) { 69 $all_payment_methods = WC()->payment_gateways()->payment_gateways(); 70 if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) { 71 return; 72 } 73 64 74 wp_enqueue_style( $this->plugin_name, plugins_url( 'css/wc-valorpay-checkout.css', __FILE__ ), array(), $this->version ); 65 } 66 } 67 68 /** 69 * Register the JavaScript for the public-facing side of the site. 70 * 71 * @since 1.0.0 72 */ 73 public function valorpay_checkout_script() { 74 75 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-checkout.js', array( 'jquery' ), $this->version, false ); 76 wp_localize_script( 77 $this->plugin_name, 78 'valorpay_checkout_object', 79 array( 80 'error_card' => __( 'Please enter a card number', 'wc-valorpay' ), 81 'invalid_card' => __( 'Invalid card number', 'wc-valorpay' ), 82 'expiry_card' => __( 'Card is expired', 'wc-valorpay' ), 83 'invalid_expiry' => __( 'Please enter card expiry date', 'wc-valorpay' ), 84 'error_cvv' => __( 'Please enter a CVC', 'wc-valorpay' ), 85 'invalid_cvv' => __( 'Invalid CVC length', 'wc-valorpay' ), 86 'avs_zip_error' => __( 'Please enter a zip code', 'wc-valorpay' ), 87 'invalid_avs_zip_error' => __( 'Invalid zip code', 'wc-valorpay' ), 88 'avs_street_error' => __( 'Please enter a street address', 'wc-valorpay' ), 89 ) 90 ); 91 92 } 93 94 /** 95 * AVS checkout validation 96 * 97 * @since 1.0.0 98 * 99 * @param array $fields An array of posted data. 100 * @param WP_Error $errors Validation errors. 101 * @return void 102 */ 103 public function valorpay_avs_checkout_validation( $fields, $errors ) { 104 if ( ( isset( $fields['payment_method'] ) && 'wc_valorpay' === $fields['payment_method'] ) ) { 105 $valorpay_avs_type = ( isset( $_POST['valorpay_avs_type'] ) ) ? sanitize_text_field( wp_unslash( $_POST['valorpay_avs_type'] ) ) : ''; // phpcs:ignore 106 if ( 'zip' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) { 107 if ( ! isset( $_POST['valorpay_avs_zip'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) { // phpcs:ignore 108 $errors->add( 'validation', __( 'Zip Code is required.', 'wc-valorpay' ) ); 109 } 110 if ( isset( $_POST['valorpay_avs_zip'] ) && sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) && ! preg_match( '/^([a-zA-Z0-9_-]){4,6}$/', sanitize_text_field( wp_unslash( $_POST['valorpay_avs_zip'] ) ) ) ) { // phpcs:ignore 111 $errors->add( 'validation', __( 'Enter a valid Zip Code.', 'wc-valorpay' ) ); 112 } 113 } 114 if ( 'address' === $valorpay_avs_type || 'zipandaddress' === $valorpay_avs_type ) { 115 if ( ! isset( $_POST['valorpay_avs_street'] ) || ! sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) { // phpcs:ignore 116 $errors->add( 'validation', __( 'Street No is required.', 'wc-valorpay' ) ); 117 } 118 if ( isset( $_POST['valorpay_avs_street'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['valorpay_avs_street'] ) ) ) > 25 ) { // phpcs:ignore 119 $errors->add( 'validation', __( 'Enter a valid Street No.', 'wc-valorpay' ) ); 120 } 121 } 75 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-valorpay-checkout.js', array( 'jquery' ), $this->version, false ); 76 wp_localize_script( 77 $this->plugin_name, 78 'valorpay_checkout_object', 79 array( 80 'ajax_url' => admin_url( 'admin-ajax.php' ), 81 'wc_ajax_action' => WC_AJAX::get_endpoint( '%%endpoint_url%%' ), 82 'ct_ajax_action' => 'valorpay_create_page_token', 83 'ct_ajax_nonce' => wp_create_nonce( 'valorpay_create_page_token' ), 84 'bl_ajax_action' => 'valorpay_bin_lookup', 85 'bl_ajax_nonce' => wp_create_nonce( 'valorpay_bin_lookup' ), 86 'card_type_ajax_action' => 'valorpay_token_card_type', 87 'card_type_ajax_nonce' => wp_create_nonce( 'valorpay_token_card_type' ), 88 'error_card' => __( 'Please enter a card number', 'wc-valorpay' ), 89 'invalid_card' => __( 'Invalid card number', 'wc-valorpay' ), 90 'expiry_card' => __( 'Card is expired', 'wc-valorpay' ), 91 'invalid_expiry' => __( 'Please enter card expiry date', 'wc-valorpay' ), 92 'error_cvv' => __( 'Please enter a CVC', 'wc-valorpay' ), 93 'invalid_cvv' => __( 'Invalid CVC length', 'wc-valorpay' ), 94 'avs_zip_error' => __( 'Please enter a zip code', 'wc-valorpay' ), 95 'invalid_avs_zip_error' => __( 'Invalid zip code', 'wc-valorpay' ), 96 'avs_street_error' => __( 'Please enter a street address', 'wc-valorpay' ), 97 'card_token_error' => __( 'Unable to process payment. Please try again.', 'wc-valorpay' ), 98 ) 99 ); 122 100 } 123 101 } … … 138 116 139 117 if ( 'wc_valorpay' === $payment_method && 'yes' === $valorpay->surcharge_indicator && 'yes' === $valorpay->enabled ) { 118 if ( 'D' === WC()->session->get( 'valor_card_type' ) && 'no' === $valorpay->surcharge_for_debit ) { 119 return; 120 } 140 121 $surcharge = 0; 141 122 if ( 'percentage' === $valorpay->surcharge_type ) { … … 228 209 } 229 210 } 211 212 /** 213 * Fetch card type for the default save token. 214 * 215 * @since 7.4.0 216 */ 217 public function valorpay_update_token_card_type() { 218 $current_user_id = get_current_user_id(); 219 if ( $current_user_id ) { 220 $token = WC_Payment_Tokens::get_customer_default_token( $current_user_id ); 221 if ( ! $token || null === $token ) { 222 WC()->session->__unset( 'valor_card_type' ); 223 } elseif ( 'wc_valorpay' === $token->get_gateway_id() ) { 224 $card_type = $token->get_meta( 'is_debit' ) === '1' ? 'D' : 'C'; 225 // Check if card type not same. 226 if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) { 227 WC()->session->set( 'valor_card_type', $card_type ); 228 } 229 } else { 230 WC()->session->__unset( 'valor_card_type' ); 231 } 232 } else { 233 WC()->session->__unset( 'valor_card_type' ); 234 } 235 } 236 237 /** 238 * Create page token. 239 * 240 * @since 7.4.0 241 */ 242 public function valorpay_create_page_token() { 243 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { 244 wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) ); 245 } 246 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_create_page_token' ) ) { 247 wp_send_json_error( 'invalid_nonce' ); 248 } 249 $all_payment_methods = WC()->payment_gateways()->payment_gateways(); 250 if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) { 251 wp_send_json_error( array( 'message' => __( 'Payment gateway missing.', 'wc-valorpay' ) ) ); 252 } 253 $valorpay = $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ]; 254 $valorpay_api = new WC_ValorPay_API( $valorpay ); 255 $api_response = $valorpay_api->create_checkout_page_token(); 256 if ( is_wp_error( $api_response ) || ! is_object( $api_response ) || ! isset( $api_response->clientToken ) ) { // phpcs:ignore 257 wp_send_json_error( array( 'message' => __( 'Unable to create page token.', 'wc-valorpay' ) ) ); 258 } else { 259 wp_send_json_success( array( 'token' => $api_response->clientToken ) ); // phpcs:ignore 260 } 261 } 262 263 /** 264 * Bin lookup. 265 * 266 * @since 7.4.0 267 * @throws Exception If error. 268 */ 269 public function valorpay_bin_lookup() { 270 try { 271 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { 272 wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) ); 273 } 274 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_bin_lookup' ) ) { 275 wp_send_json_error( 'invalid_nonce' ); 276 } 277 if ( ! isset( $_REQUEST['client_token'] ) || ! isset( $_REQUEST['bin'] ) ) { 278 wp_send_json_error( array( 'message' => __( 'Invalid request.', 'wc-valorpay' ) ) ); 279 } 280 $all_payment_methods = WC()->payment_gateways()->payment_gateways(); 281 if ( ! isset( $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ] ) ) { 282 wp_send_json_error( array( 'message' => __( 'Payment gateway missing.', 'wc-valorpay' ) ) ); 283 } 284 $need_update = false; 285 $valorpay = $all_payment_methods[ WC_ValorPay_Gateway::GATEWAY_ID ]; 286 $valorpay_api = new WC_ValorPay_API( $valorpay ); 287 $api_response = $valorpay_api->bin_lookup( sanitize_text_field( wp_unslash( $_REQUEST['bin'] ) ), sanitize_text_field( wp_unslash( $_REQUEST['client_token'] ) ) ); 288 if ( is_wp_error( $api_response ) ) { // phpcs:ignore 289 throw new Exception( 'Error' ); 290 } 291 $card_type = $api_response->card_type; 292 // If card type same as previous value, no need to update. 293 if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) { 294 WC()->session->set( 'valor_card_type', $api_response->card_type ); 295 $need_update = true; 296 } 297 wp_send_json_success( $need_update ); 298 } catch ( Exception $ex ) { 299 wp_send_json_error( array( 'message' => __( 'Unable to lookup bin.', 'wc-valorpay' ) ) ); 300 } 301 } 302 303 /** 304 * Get token card type. 305 * 306 * @since 7.4.0 307 * @throws Exception If error. 308 */ 309 public function valorpay_token_card_type() { 310 try { 311 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { 312 wp_send_json_error( array( 'message' => __( 'Invalid request method.', 'wc-valorpay' ) ) ); 313 } 314 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'valorpay_token_card_type' ) ) { 315 wp_send_json_error( 'invalid_nonce' ); 316 } 317 if ( ! isset( $_REQUEST['token_id'] ) ) { 318 wp_send_json_error( array( 'message' => __( 'Invalid request.', 'wc-valorpay' ) ) ); 319 } 320 $need_update = false; 321 $token_id = sanitize_text_field( wp_unslash( $_REQUEST['token_id'] ) ); 322 if ( 'new' !== $token_id ) { 323 $payment_token = WC_Payment_Tokens::get( $token_id ); 324 if ( $payment_token ) { 325 $card_type = $payment_token->get_meta( 'is_debit' ) === '1' ? 'D' : 'C'; 326 // Check if the payment token exists. 327 if ( WC()->session->get( 'valor_card_type' ) !== $card_type ) { 328 WC()->session->set( 'valor_card_type', $card_type ); 329 $need_update = true; 330 } 331 } 332 } else { 333 WC()->session->__unset( 'valor_card_type' ); 334 $need_update = true; 335 } 336 wp_send_json_success( $need_update ); 337 } catch ( Exception $ex ) { 338 wp_send_json_error( array( 'message' => __( 'Unable to set card type.', 'wc-valorpay' ) ) ); 339 } 340 } 230 341 } -
valorpos/trunk/public/js/wc-valorpay-checkout.js
r2918841 r2980555 6 6 */ 7 7 8 (function($) { 9 "use strict"; 10 11 var validcard = false; 12 var validcardexpiry = false; 13 var validcvc = false; 14 let luhnCheck = function(num) { 15 var digit, digits, odd, sum, _i, _len; 16 odd = true; 17 sum = 0; 18 digits = (num + "").split("").reverse(); 19 for (_i = 0, _len = digits.length; _i < _len; _i++) { 20 digit = digits[_i]; 21 digit = parseInt(digit, 10); 22 if ((odd = !odd)) { 23 digit *= 2; 24 } 25 if (digit > 9) { 26 digit -= 9; 27 } 28 sum += digit; 29 } 30 return sum % 10 === 0.0; 31 }; 32 33 $(document).ready(function() { 34 $("body").on("change", 'input[name="payment_method"]', function() { 35 $("body").trigger("update_checkout"); 36 }); 37 $("body").on("blur", 'input[name="wc_valorpay-card-number"]', function() { 38 if ($("#payment_method_wc_valorpay").is(":checked")) { 39 var cardNum = $(this).val().replace(/ /g, ""); 40 var isValid = luhnCheck(cardNum); 41 42 if (cardNum === "") { 43 $(this).addClass("error-class"); 44 if (!$(this).next().hasClass("error-message")) { 45 $( 46 '<span class="error-message" style="color:red;">' + 47 valorpay_checkout_object.error_card + 48 "</span>" 49 ).insertAfter($(this)); 50 } 51 $("#wc-wc_valorpay-card-number-error").remove(); 52 validcard = false; 53 $(this).parent().addClass("woocommerce-invalid"); 54 } else if (!isValid) { 55 $(this).addClass("error-class"); 56 if (!$(this).next().hasClass("error-message")) { 57 $( 58 '<span class="error-message" style="color:red;">' + 59 valorpay_checkout_object.invalid_card + 60 "</span>" 61 ).insertAfter($(this)); 62 } 63 $("#wc-wc_valorpay-card-number-error").remove(); 64 validcard = false; 65 $(this).parent().addClass("woocommerce-invalid"); 66 } else { 67 $(this).removeClass("error-class"); 68 $(this).next(".error-message").remove(); 69 validcard = true; 70 $(this).parent().removeClass("woocommerce-invalid"); 71 } 72 } 73 }); 74 $("body").on("focus", 'input[name="wc_valorpay-card-number"]', function() { 75 if (!$(this).val()) { 76 $(this).removeClass("error-class"); 77 $(this).next(".error-message").remove(); 78 } 79 }); 80 $("body").on("blur", 'input[name="wc_valorpay-card-expiry"]', function() { 81 if ($("#payment_method_wc_valorpay").is(":checked")) { 82 var expiry = $(this).val().replace(/ /g, ""); 83 if (expiry === "") { 84 $(this).addClass("error-class"); 85 if (!$(this).next().hasClass("error-message")) { 86 $( 87 '<span class="error-message" style="color:red;">' + 88 valorpay_checkout_object.invalid_expiry + 89 "</span>" 90 ).insertAfter($(this)); 91 } 92 validcardexpiry = false; 93 $(this).parent().addClass("woocommerce-invalid"); 94 } else { 95 var parts = expiry.split("/"); 96 var month = parseInt(parts[0], 10); 97 var year = parseInt(parts[1], 10); 98 if (year < 100) { 99 year += 2000; 100 } 101 if (!validateCardExpiry(month, year)) { 102 $(this).addClass("error-class"); 103 if (!$(this).next().hasClass("error-message")) { 104 $( 105 '<span class="error-message" style="color:red;">' + 106 valorpay_checkout_object.expiry_card + 107 "</span>" 108 ).insertAfter($(this)); 109 } 110 validcardexpiry = false; 111 $(this).parent().addClass("woocommerce-invalid"); 112 } else { 113 $(this).removeClass("error-class"); 114 $(this).next(".error-message").remove(); 115 validcardexpiry = true; 116 $(this).parent().removeClass("woocommerce-invalid"); 117 } 118 } 119 } 120 }); 121 122 $("body").on("focus", 'input[name="wc_valorpay-card-expiry"]', function() { 123 $(this).removeClass("error-class"); 124 $(this).next(".error-message").remove(); 125 }); 126 $("body").on("blur", "#wc_valorpay-card-cvc", function() { 127 if ($("#payment_method_wc_valorpay").is(":checked")) { 128 var cvcNum = $(this).val().trim(); 129 if (cvcNum === "") { 130 $(this).addClass("error-class"); 131 if (!$(this).next().hasClass("error-message")) { 132 $( 133 '<span class="error-message" style="color:red;">' + 134 valorpay_checkout_object.error_cvv + 135 "</span>" 136 ).insertAfter($(this)); 137 } 138 validcvc = false; 139 $(this).parent().addClass("woocommerce-invalid"); 140 } else if (cvcNum.length != 3 && cvcNum.length != 4) { 141 $(this).addClass("error-class"); 142 if (!$(this).next().hasClass("error-message")) { 143 $( 144 '<span class="error-message" style="color:red;">' + 145 valorpay_checkout_object.invalid_cvv + 146 "</span>" 147 ).insertAfter($(this)); 148 } 149 validcvc = false; 150 $(this).parent().addClass("woocommerce-invalid"); 151 } else { 152 $(this).removeClass("error-class"); 153 $(this).next(".error-message").remove(); 154 validcvc = true; 155 $(this).parent().removeClass("woocommerce-invalid"); 156 } 157 } 158 }); 159 $("body").on("focus", 'input[name="wc_valorpay-card-cvc"]', function() { 160 $(this).removeClass("error-class"); 161 $(this).next(".error-message").remove(); 162 }); 163 $("form.woocommerce-checkout").on( 164 "checkout_place_order_wc_valorpay", 165 function() { 166 167 168 var cardNumb = $('input[name="wc_valorpay-card-number"]').val(); 169 const isToken = $('#wc-wc_valorpay-payment-token-new'); 170 if ( 171 isToken.length && !isToken.is(":checked") 172 ) { 173 var avserrorIsValidsave = addAVSErrors(); 174 // Do something if the radio button is checked 175 176 if (avserrorIsValidsave) { 177 178 return true; 179 } else { 8 (function ($) { 9 "use strict"; 10 var wc_valorpay_form = { 11 validCard: false, 12 validCardExpiry: false, 13 validCvc: false, 14 checkoutFormClass: "form.woocommerce-checkout", 15 cardNumberInput: "#wc_valorpay-card-number", 16 cardExpiryInput: "#wc_valorpay-card-expiry", 17 cardCvvInput: "#wc_valorpay-card-cvc", 18 clientTokenInit: false, 19 clientToken: "", 20 tokenGenerateInterval: null, 21 tokenExpiryMin: 5, 22 prevSelectedToken: false, 23 /** 24 * Initialize. 25 */ 26 init: function () { 27 // On payment method switch update checkout. 28 $( document.body ).on( 29 "change", 30 'input[name="payment_method"]', 31 this.updateCheckout 32 ); 33 $( document.body ).on( 34 "click", 35 'input[name="wc-wc_valorpay-payment-token"]', 36 this.surChargeCalculation 37 ); 38 this.validateCardForm(); 39 this.createPageToken(); 40 this.startReCreatePageToken(); 41 $( wc_valorpay_form.checkoutFormClass ).on( 42 "checkout_place_order_wc_valorpay", 43 this.valorPayPlaceOrder 44 ); 45 }, 46 /** 47 * On payment gateway change update the checkout. 48 */ 49 updateCheckout: function () { 50 $( document.body ).trigger( "update_checkout" ); 51 }, 52 /** 53 * On token switch 54 */ 55 surChargeCalculation: function () { 56 const checkedValue = $('input[name="wc-wc_valorpay-payment-token"]:checked').val(); 57 if(wc_valorpay_form.prevSelectedToken != checkedValue) { 58 if((checkedValue === 'new' && !$( wc_valorpay_form.cardNumberInput ).val()) || checkedValue !== 'new') { 59 wc_valorpay_form.tokenCardType(checkedValue); 60 } else { 61 $( wc_valorpay_form.cardNumberInput ).trigger( "blur" ); 62 } 63 wc_valorpay_form.prevSelectedToken = checkedValue; 64 } 65 }, 66 /** 67 * Block checkout page UI. 68 */ 69 block: function () { 70 $( wc_valorpay_form.checkoutFormClass ).block( 71 { 72 message: null, 73 overlayCSS: { 74 background: "#fff", 75 opacity: 0.6, 76 }, 77 } 78 ); 79 }, 80 /** 81 * Unblock checkout page UI. 82 */ 83 unblock: function () { 84 $( wc_valorpay_form.checkoutFormClass ).unblock(); 85 }, 86 /** 87 * Create page or client token. 88 */ 89 createPageToken: function () { 90 $.ajax( 91 { 92 type: "POST", 93 url: valorpay_checkout_object.wc_ajax_action 94 .toString() 95 .replace( "%%endpoint_url%%", valorpay_checkout_object.ct_ajax_action ), 96 data: { 97 nonce: valorpay_checkout_object.ct_ajax_nonce, 98 }, 99 success: function (response) { 100 if (response.success) { 101 wc_valorpay_form.clientToken = response.data.token; 102 } 103 }, 104 } 105 ); 106 }, 107 /** 108 * Bin lookup. 109 */ 110 binLookUp: function () { 111 var cardNumber = $( wc_valorpay_form.cardNumberInput ) 112 .val() 113 .replace( / /g, "" ); 114 $.ajax( 115 { 116 type: "POST", 117 url: valorpay_checkout_object.wc_ajax_action 118 .toString() 119 .replace( "%%endpoint_url%%", valorpay_checkout_object.bl_ajax_action ), 120 data: { 121 nonce: valorpay_checkout_object.bl_ajax_nonce, 122 client_token: wc_valorpay_form.clientToken, 123 bin: cardNumber.substring(0, 6) 124 }, 125 success: function (response) { 126 if (response.success && response.data) { 127 wc_valorpay_form.updateCheckout(); 128 } 129 }, 130 } 131 ); 132 }, 133 /** 134 * Token card type. 135 */ 136 tokenCardType: function (tokenId) { 137 $.ajax( 138 { 139 type: "POST", 140 url: valorpay_checkout_object.wc_ajax_action 141 .toString() 142 .replace( "%%endpoint_url%%", valorpay_checkout_object.card_type_ajax_action ), 143 data: { 144 nonce: valorpay_checkout_object.card_type_ajax_nonce, 145 token_id: tokenId, 146 }, 147 success: function (response) { 148 if (response.success && response.data) { 149 wc_valorpay_form.updateCheckout(); 150 } 151 }, 152 } 153 ); 154 }, 155 /** 156 * Recreate page token on every token expiry minutes. 157 */ 158 startReCreatePageToken: function () { 159 wc_valorpay_form.tokenGenerateInterval = setInterval( 160 function () { 161 wc_valorpay_form.createPageToken(); 162 }, 163 wc_valorpay_form.tokenExpiryMin * 60 * 1000 164 ); 165 }, 166 /** 167 * Convert expiry date to MMYY format. 168 */ 169 convertToMMYY: function (dateString) { 170 // Remove any leading/trailing spaces. 171 dateString = dateString.trim(); 172 173 // Split the string into month and year parts. 174 var parts = dateString.split( "/" ); 175 var month = parseInt( parts[0] ); 176 var year = parseInt( parts[1] ); 177 178 // Extract the year part based on the input format. 179 if (year < 100) { 180 // Format is MM/YY . 181 year += 2000; // Assuming years below 100 are in the 21st century. 182 } 183 184 // Format the month and year as MMYY . 185 var formattedDate = ("0" + month).slice( -2 ) + ("0" + year).slice( -2 ); 186 187 return formattedDate; 188 }, 189 /** 190 * Validate card checkout field. 191 */ 192 validateCardForm: function () { 193 this.validateCardNumber(); 194 this.validateCardExpiry(); 195 this.validateCardCvv(); 196 }, 197 /** 198 * Add error to form field. 199 * 200 * @param {jQuery} currentEle The current element. 201 * @param {string} errorMsg Error Message. 202 */ 203 addErrorMessage: function (currentEle, errorMsg) { 204 currentEle.addClass( "error-class" ); 205 if ( ! currentEle.next().hasClass( "error-message" )) { 206 $( 207 '<span class="error-message" style="color:red;">' + 208 errorMsg + 209 "</span>" 210 ).insertAfter( currentEle ); 211 currentEle.closest( ".form-row" ).addClass( "woocommerce-invalid" ); 212 } 213 }, 214 /** 215 * Remove error from the form field. 216 * 217 * @param {jQuery} currentEle The current element. 218 */ 219 removeErrorMessage: function (currentEle) { 220 currentEle.removeClass( "error-class" ); 221 currentEle.next( ".error-message" ).remove(); 222 currentEle.closest( ".form-row" ).removeClass( "woocommerce-invalid" ); 223 }, 224 /** 225 * Validate card number field. 226 */ 227 validateCardNumber: function () { 228 $( "body" ).on( 229 "blur", 230 this.cardNumberInput, 231 function () { 232 var cardNum = $( this ).val().replace( / /g, "" ); 233 var isValid = wc_valorpay_form.luhnCheck( cardNum ); 234 235 if (cardNum === "") { 236 wc_valorpay_form.addErrorMessage( 237 $( this ), 238 valorpay_checkout_object.error_card 239 ); 240 wc_valorpay_form.validCard = false; 241 } else if ( ! isValid) { 242 wc_valorpay_form.addErrorMessage( 243 $( this ), 244 valorpay_checkout_object.invalid_card 245 ); 246 wc_valorpay_form.validCard = false; 247 } else { 248 wc_valorpay_form.removeErrorMessage( $( this ) ); 249 wc_valorpay_form.validCard = true; 250 wc_valorpay_form.binLookUp(); 251 } 252 } 253 ); 254 $( "body" ).on( 255 "focus", 256 this.cardNumberInput, 257 function () { 258 if ( ! $( this ).val()) { 259 wc_valorpay_form.removeErrorMessage( $( this ) ); 260 } 261 } 262 ); 263 }, 264 /** 265 * Validate card expiry field. 266 */ 267 validateCardExpiry: function () { 268 $( "body" ).on( 269 "blur", 270 this.cardExpiryInput, 271 function () { 272 var expiry = $( this ).val().replace( / /g, "" ); 273 if (expiry === "") { 274 wc_valorpay_form.addErrorMessage( 275 $( this ), 276 valorpay_checkout_object.invalid_expiry 277 ); 278 wc_valorpay_form.validCardExpiry = false; 279 } else { 280 var parts = expiry.split( "/" ); 281 var month = parseInt( parts[0], 10 ); 282 var year = parseInt( parts[1], 10 ); 283 if (year < 100) { 284 year += 2000; 285 } 286 if ( ! wc_valorpay_form.checkCardExpiry( month, year )) { 287 wc_valorpay_form.addErrorMessage( 288 $( this ), 289 valorpay_checkout_object.expiry_card 290 ); 291 wc_valorpay_form.validCardExpiry = false; 292 } else { 293 wc_valorpay_form.removeErrorMessage( $( this ) ); 294 wc_valorpay_form.validCardExpiry = true; 295 } 296 } 297 } 298 ); 299 300 $( "body" ).on( 301 "focus", 302 this.cardExpiryInput, 303 function () { 304 wc_valorpay_form.removeErrorMessage( $( this ) ); 305 } 306 ); 307 }, 308 /** 309 * Validate card CVV field. 310 */ 311 validateCardCvv: function () { 312 $( "body" ).on( 313 "blur", 314 this.cardCvvInput, 315 function () { 316 var cvcNum = $( this ).val().trim(); 317 if (cvcNum === "") { 318 wc_valorpay_form.addErrorMessage( 319 $( this ), 320 valorpay_checkout_object.error_cvv 321 ); 322 wc_valorpay_form.validCvc = false; 323 } else if (cvcNum.length != 3 && cvcNum.length != 4) { 324 wc_valorpay_form.addErrorMessage( 325 $( this ), 326 valorpay_checkout_object.invalid_cvv 327 ); 328 wc_valorpay_form.validCvc = false; 329 } else { 330 wc_valorpay_form.removeErrorMessage( $( this ) ); 331 wc_valorpay_form.validCvc = true; 332 } 333 } 334 ); 335 $( "body" ).on( 336 "focus", 337 this.cardCvvInput, 338 function () { 339 wc_valorpay_form.removeErrorMessage( $( this ) ); 340 } 341 ); 342 }, 343 /** 344 * Validate field on place order 345 */ 346 valorPayPlaceOrder: function (event) { 347 var cardNumb = $( wc_valorpay_form.cardNumberInput ).val(); 348 const isNewCard = $( "#wc-wc_valorpay-payment-token-new" ); 349 if (isNewCard.length && ! isNewCard.is( ":checked" )) { 350 var avsErrorIsValidSave = wc_valorpay_form.avsValidation(); 351 if (avsErrorIsValidSave) { 352 wc_valorpay_form.scrollToValorForm(); 180 353 return false; 181 } 182 } 183 184 if (cardNumb === "") { 185 $('input[name="wc_valorpay-card-number"]').trigger("blur"); 186 } else { 187 $('input[name="wc_valorpay-card-number"]').trigger("blur"); 188 $('input[name="wc_valorpay-card-expiry"]').trigger("blur"); 189 $('input[name="wc_valorpay-card-cvc"]').trigger("blur"); 190 } 191 if (validcard === false) { 192 $("html, body").animate({ 193 scrollTop: $("#wc-wc_valorpay-cc-form").offset().top, 194 }, 195 1000 196 ); 197 return false; 198 } 199 if (validcardexpiry === false) { 200 $("html, body").animate({ 201 scrollTop: $("#wc-wc_valorpay-cc-form").offset().top, 202 }, 203 1000 204 ); 205 return false; 206 } 207 if (validcvc === false) { 208 $("html, body").animate({ 209 scrollTop: $("#wc-wc_valorpay-cc-form").offset().top, 210 }, 211 1000 212 ); 213 return false; 214 } 215 if (cardNumb !== "") { 216 var avserrorIsValid = addAVSErrors(); 217 218 if (avserrorIsValid) { 219 220 return true; 221 } else { 222 return false; 223 } 224 } 225 } 226 ); 227 228 229 230 function validateCardExpiry(month, year) { 231 var currentTime = new Date(); 232 var expiry = new Date(year, month, 1); 233 if (expiry < currentTime) { 234 return false; 235 } 236 return true; 237 } 238 239 function addAVSErrors() { 240 var hasError = false; 241 242 $('input[name="valorpay_avs_zip"] + span.error').remove(); 243 $('input[name="valorpay_avs_street"] + span.error').remove(); 244 245 if ($('input[name="valorpay_avs_zip"]').val() === "") { 246 $('input[name="valorpay_avs_zip"]').after( 247 '<span class="error" style="color:red;">' + 248 valorpay_checkout_object.avs_zip_error + 249 "</span>" 250 ); 251 hasError = true; 252 } else if ($('input[name="valorpay_avs_zip"]').val().length < 4) { 253 $('input[name="valorpay_avs_zip"]').after( 254 '<span class="error" style="color:red;">' + 255 valorpay_checkout_object.invalid_avs_zip_error + "</span>" 256 ); 257 hasError = true; 258 } 259 260 if ($('input[name="valorpay_avs_street"]').val() === "") { 261 $('input[name="valorpay_avs_street"]').after( 262 '<span class="error" style="color:red;">' + 263 valorpay_checkout_object.avs_street_error + 264 "</span>" 265 ); 266 hasError = true; 267 } 268 269 $('input[name="valorpay_avs_zip"]').focus(function() { 270 $('input[name="valorpay_avs_zip"] + span.error').remove(); 271 }); 272 273 $('input[name="valorpay_avs_street"]').focus(function() { 274 $('input[name="valorpay_avs_street"] + span.error').remove(); 275 }); 276 277 return !hasError; 278 } 279 }); 280 281 282 })(jQuery); 354 } 355 return true; 356 } 357 if (cardNumb === "") { 358 $( wc_valorpay_form.cardNumberInput ).trigger( "blur" ); 359 } else { 360 $( wc_valorpay_form.cardNumberInput ).trigger( "blur" ); 361 $( wc_valorpay_form.cardExpiryInput ).trigger( "blur" ); 362 $( wc_valorpay_form.cardCvvInput ).trigger( "blur" ); 363 } 364 if (wc_valorpay_form.validCard === false) { 365 wc_valorpay_form.scrollToValorForm(); 366 return false; 367 } 368 if (wc_valorpay_form.validCardExpiry === false) { 369 wc_valorpay_form.scrollToValorForm(); 370 return false; 371 } 372 if (wc_valorpay_form.validCvc === false) { 373 wc_valorpay_form.scrollToValorForm(); 374 return false; 375 } 376 377 if (cardNumb !== "") { 378 var avsErrorIsValid = wc_valorpay_form.avsValidation(); 379 if (avsErrorIsValid) { 380 wc_valorpay_form.scrollToValorForm(); 381 return false; 382 } 383 return true; 384 } 385 }, 386 /** 387 * Validate Address Verification Service 388 */ 389 avsValidation: function () { 390 var hasError = false; 391 if ($( 'input[name="valorpay_avs_zip"]' ).length) { 392 wc_valorpay_form.removeErrorMessage( 393 $( 'input[name="valorpay_avs_zip"]' ) 394 ); 395 if ($( 'input[name="valorpay_avs_zip"]' ).val() === "") { 396 wc_valorpay_form.addErrorMessage( 397 $( 'input[name="valorpay_avs_zip"]' ), 398 valorpay_checkout_object.avs_zip_error 399 ); 400 hasError = true; 401 } else if ($( 'input[name="valorpay_avs_zip"]' ).val().length < 4) { 402 wc_valorpay_form.addErrorMessage( 403 $( 'input[name="valorpay_avs_zip"]' ), 404 valorpay_checkout_object.invalid_avs_zip_error 405 ); 406 hasError = true; 407 } 408 $( 'input[name="valorpay_avs_zip"]' ).focus( 409 function () { 410 wc_valorpay_form.removeErrorMessage( 411 $( 'input[name="valorpay_avs_zip"]' ) 412 ); 413 } 414 ); 415 } 416 417 if ($( 'input[name="valorpay_avs_street"]' ).length) { 418 wc_valorpay_form.removeErrorMessage( 419 $( 'input[name="valorpay_avs_street"]' ) 420 ); 421 if ($( 'input[name="valorpay_avs_street"]' ).val() === "") { 422 wc_valorpay_form.addErrorMessage( 423 $( 'input[name="valorpay_avs_street"]' ), 424 valorpay_checkout_object.avs_street_error 425 ); 426 hasError = true; 427 } 428 $( 'input[name="valorpay_avs_street"]' ).focus( 429 function () { 430 wc_valorpay_form.removeErrorMessage( 431 $( 'input[name="valorpay_avs_street"]' ) 432 ); 433 } 434 ); 435 } 436 437 return hasError; 438 }, 439 /** 440 * Check if the card expiry. 441 * 442 * @param {number} month Card month 443 * @param {number} year Card year 444 * @return {boolean} 445 */ 446 checkCardExpiry: function (month, year) { 447 var currentTime = new Date(); 448 var expiry = new Date( year, month, 1 ); 449 if (expiry < currentTime) { 450 return false; 451 } 452 return true; 453 }, 454 /** 455 * Luhn check. 456 * 457 * @param {string} num Card number 458 * @return {boolean} 459 */ 460 luhnCheck: function (num) { 461 var digit, digits, odd, sum, _i, _len; 462 odd = true; 463 sum = 0; 464 digits = (num + "").split( "" ).reverse(); 465 for (_i = 0, _len = digits.length; _i < _len; _i++) { 466 digit = digits[_i]; 467 digit = parseInt( digit, 10 ); 468 if ((odd = ! odd)) { 469 digit *= 2; 470 } 471 if (digit > 9) { 472 digit -= 9; 473 } 474 sum += digit; 475 } 476 return sum % 10 === 0.0; 477 }, 478 /** 479 * Scroll to payment form. 480 */ 481 scrollToValorForm: function () { 482 $( "html, body" ).animate( 483 { 484 scrollTop: $( "#wc-wc_valorpay-cc-form" ).offset().top, 485 }, 486 1000 487 ); 488 }, 489 }; 490 $( document ).ready( 491 function () { 492 // Initialize the wc_test_form object. 493 wc_valorpay_form.init(); 494 } 495 ); 496 })( jQuery ); -
valorpos/trunk/wc-valorpay.php
r2960359 r2980555 16 16 * Plugin URI: https://valorpaytech.com 17 17 * Description: Adds the Valor Payment Gateway to WooCommerce. 18 * Version: 7. 3.118 * Version: 7.4.0 19 19 * Author: Valor Paytech LLC 20 20 * Author URI: https://valorpaytech.com … … 37 37 * Rename this for your plugin and update it as you release new versions. 38 38 */ 39 define( 'WC_VALORPAY_VERSION', '7. 3.1' );39 define( 'WC_VALORPAY_VERSION', '7.4.0' ); 40 40 // Directory i.e. /home/user/public_html... 41 41 define( 'WC_VALORPAY_DIR', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset
for help on using the changeset viewer.