Skip to content

Commit 53e54e1

Browse files
committed
added js luhn checker
1 parent 52cecae commit 53e54e1

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

wc-payneteasy.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
/**
33
* Plugin Name: Payment system PAYNETEASY
44
* Description: Allows you to use Payment system PAYNETEASY with the WooCommerce plugin.
5-
* Version: 1.0.4
5+
* Version: 1.0.0
66
* Author: Payneteasy
77
* Author URI: https:#payneteasy.com/
88
* Text Domain: wc-payneteasy
99
* Domain Path: /languages/
10-
* Requires PHP: 7.4+
10+
* Requires PHP: 7.4
1111
*
1212
* @package Payneteasy
13-
* @version 1.0.4
13+
* @version 1.0.3
1414
*/
1515

1616
if (!defined('ABSPATH')) exit; # Exit if accessed directly
@@ -159,6 +159,14 @@ private static function form_cell(?array $cell, string $class): string {
159159
private static function form_row(array $cell1, ?array $cell2): string
160160
{ return '<div class="form-row">'.self::form_cell($cell1, 'first').self::form_cell($cell2, 'last').'</div>'; }
161161

162+
private static function js_luhn_checker(): string {
163+
return '<script>function checkLuhn(ccnS) {
164+
let sum = 0; const parity = (ccnS.length) % 2;
165+
for (let i = 0; i < ccnS.length; i += 1) { let digit = Number(ccnS[i]); if (i % 2 === parity) { digit *= 2;
166+
if (digit > 9) { digit -= 9; } } sum += digit; }
167+
document.getElementById("place_order").disabled = Number(sum % 10) !== 0; }</script>';
168+
}
169+
162170
# отображение описания платежной системы PAYNET при оформлении заказа
163171
public function payment_fields(): void {
164172
if (!empty($this->description))
@@ -168,8 +176,9 @@ public function payment_fields(): void {
168176
do_action('woocommerce_credit_card_form_start', $this->id);
169177

170178
echo $this->api->is_direct()
171-
? self::form_row(
172-
['Card Number', 'credit_card_number', 'cc-number'],
179+
? self::js_luhn_checker()
180+
.self::form_row(
181+
['Card Number', 'credit_card_number', 'cc-number', 'onkeyup="checkLuhn(this.value)"'],
173182
['Printed name', 'card_printed_name', 'cc-name', 'placeholder="Printed name"'])
174183
.self::form_row(
175184
['Expiry month', 'expire_month', 'off', 'minlength="2" maxlength="2" placeholder="MM" style="max-width:50%"'],

0 commit comments

Comments
 (0)