Skip to content

Commit

Permalink
Airtel TZ payment method is added
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kashukov committed Jan 8, 2025
1 parent 9896ee2 commit f1cdae2
Show file tree
Hide file tree
Showing 33 changed files with 521 additions and 167 deletions.
117 changes: 68 additions & 49 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.49
1.5.51
Binary file added readme_images/airtel_tz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme_images/payment_methods.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed readme_images/payments_methods.png
Binary file not shown.
2 changes: 1 addition & 1 deletion unlimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Unlimit Payments
* Plugin URI: https://github.com/cardpay/woocommerce-plugin
* Description: Unlimit WooCommerce plugin allows merchants to make payments, installment payments and refunds.
* Version: 1.5.49
* Version: 1.5.51
* Author: Unlimit
* Author URI: https://www.unlimit.com
* Text Domain: woocommerce-unlimit
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.addEventListener('load', function () {
setupPaymentForm('woocommerce_woo-unlimit-airteltz_woocommerce_unlimit_airteltz_');
});
31 changes: 31 additions & 0 deletions wp-content/plugins/unlimit/assets/js/airteltz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const AIRTELTZ_PHONE = '#ul-airteltz-phone';

(function ($) {
'use strict';

$(function () {
$('form.checkout').on('checkout_place_order_woo-unlimit-airteltz', function () {
return validatePhoneNumber(
AIRTELTZ_PHONE,
'#ul-airteltz-phone-error',
'#ul-airteltz-phone-error-second',
/^\+255\d{9}$/,
13,
13,
);
});
});
}(jQuery));

function validateUlAirteltzInput() {
autoFillCountryCode(jQuery(AIRTELTZ_PHONE), '+255');

setTimeout(validatePhoneNumber(
AIRTELTZ_PHONE,
'#ul-airteltz-phone-error',
'#ul-airteltz-phone-error-second',
/^\+255\d{9}$/,
13,
13,
), 1);
}
58 changes: 21 additions & 37 deletions wp-content/plugins/unlimit/assets/js/mbway.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
(function ($) {
'use strict';

$(function () {
$('form.checkout').on('checkout_place_order_woo-unlimit-mbway', function () {
return validateUlMbwayPhone();
});
'use strict';

$(function () {
jQuery('form.checkout').on('checkout_place_order_woo-unlimit-mbway', function () {
return validatePhoneNumber(
'#ul-mbway-phone',
'#ul-mbway-phone-error',
'#ul-mbway-phone-error-second',
/^\+?351\d{9}$|^(?!.*[a-zA-Z])\d{9}$/,
12,
13,
);
});
});
}(jQuery));

function validateUlMbwayInput() {
setTimeout(validateUlMbwayPhone(), 1);
}

const validateUlMbwayPhone = function () {
var phoneField = jQuery('#ul-mbway-phone');
var phoneErrField = jQuery('#ul-mbway-phone-error');
var phoneErrFieldSecond = jQuery('#ul-mbway-phone-error-second');

phoneField.val(phoneField.val().replace(/[^+\d]/g, ''));

var numbersOnly = phoneField.val().trim();
var phonePattern = /^\+?351\d{9}$|^(?!.*[a-zA-Z])\d{9}$/;

if (numbersOnly === '') {
phoneErrField.hide();
phoneErrFieldSecond.show();
phoneField.addClass(UL_ERROR_CLASS);
return false;
}

if (!numbersOnly.match(phonePattern)) {
phoneErrFieldSecond.hide();
phoneErrField.show();
phoneField.addClass(UL_ERROR_CLASS);
return false;
}

phoneField.removeClass(UL_ERROR_CLASS);
phoneErrField.hide();
phoneErrFieldSecond.hide();
return true;
setTimeout(validatePhoneNumber(
'#ul-mbway-phone',
'#ul-mbway-phone-error',
'#ul-mbway-phone-error-second',
/^\+?351\d{9}$|^(?!.*[a-zA-Z])\d{9}$/,
12,
13,
), 1);
}
46 changes: 46 additions & 0 deletions wp-content/plugins/unlimit/assets/js/phone-validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function autoFillCountryCode(phoneField, countryCode) {
const value = phoneField.val().trim().replace(/\s+/g, '');

if (value === "+") {
phoneField.val(countryCode);
} else if (value.startsWith(countryCode)) {
console.debug('Value starts with the correct country code');
} else if (value.startsWith(countryCode.slice(1))) {
phoneField.val('+' + value);
} else if (value.startsWith('+')) {
phoneField.val(countryCode + value.slice(value.indexOf(countryCode.slice(1))));
} else {
phoneField.val(countryCode + value);
}
}

function validatePhoneNumber(phoneFieldSelector, phoneErrFieldSelector, phoneErrFieldSecondSelector, phonePattern, minLength, maxLength) {
const phoneField = jQuery(phoneFieldSelector);
const phoneErrField = jQuery(phoneErrFieldSelector);
const phoneErrFieldSecond = jQuery(phoneErrFieldSecondSelector);

phoneField.val(phoneField.val().replace(/[^+\d]/g, '').trim());
const phoneNumber = phoneField.val();

const showError = (errorField) => {
phoneErrField.hide();
phoneErrFieldSecond.hide();
errorField.show();
phoneField.addClass(UL_ERROR_CLASS);
};

if (phoneNumber === '') {
showError(phoneErrFieldSecond);
return false;
}

if (phoneNumber.length < minLength || phoneNumber.length > maxLength || !phonePattern.test(phoneNumber)) {
showError(phoneErrField);
return false;
}

phoneField.removeClass(UL_ERROR_CLASS);
phoneErrField.hide();
phoneErrFieldSecond.hide();
return true;
}
7 changes: 5 additions & 2 deletions wp-content/plugins/unlimit/assets/js/unlimit-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const unlimitIframeProcessor = {
iframePadding: 80,
spinner: '.woocommerce-checkout-payment, .woocommerce-checkout-review-order-table',
beforeSubmit: function () {
unlimitFormCheckout.addClass('processing');
jQuery(this.spinner).block({
message: null,
overlayCSS: {
Expand All @@ -83,6 +84,7 @@ const unlimitIframeProcessor = {
const isMbway = jQuery('#payment_method_woo-unlimit-mbway').is(':checked');
const isMultibanco = jQuery('#payment_method_woo-unlimit-multibanco').is(':checked');
const isOxxo = jQuery('#payment_method_woo-unlimit-oxxo').is(':checked');
const isAirteltz = jQuery('#payment_method_woo-unlimit-airteltz').is(':checked');
const isPaypal = jQuery('#payment_method_woo-unlimit-paypal').is(':checked');
const isSpei = jQuery('#payment_method_woo-unlimit-spei').is(':checked');
const isSepa = jQuery('#payment_method_woo-unlimit-sepa').is(':checked');
Expand All @@ -92,6 +94,7 @@ const unlimitIframeProcessor = {
(isMbway && !unlimitIframePaymentMethods.includes('mbway')) ||
(isMultibanco && !unlimitIframePaymentMethods.includes('multibanco')) ||
(isOxxo && !unlimitIframePaymentMethods.includes('oxxo')) ||
(isAirteltz && !unlimitIframePaymentMethods.includes('airteltz')) ||
(isPaypal && !unlimitIframePaymentMethods.includes('paypal')) ||
(isSpei && !unlimitIframePaymentMethods.includes('spei')) ||
(isSepa && !unlimitIframePaymentMethods.includes('sepa'))
Expand All @@ -100,7 +103,7 @@ const unlimitIframeProcessor = {
return;
}

if (!isMbway && !isCreditCard && !isMultibanco && !isOxxo && !isPaypal && !isSpei && !isSepa && unlimitIframeProcessor.oldEvents !== false) {
if (!isMbway && !isCreditCard && !isAirteltz && !isMultibanco && !isOxxo && !isPaypal && !isSpei && !isSepa && unlimitIframeProcessor.oldEvents !== false) {
unlimitFormCheckout.unbind('submit');
const events = unlimitIframeProcessor.oldEvents;
for (const type in events) {
Expand All @@ -115,7 +118,7 @@ const unlimitIframeProcessor = {
unlimitIframeProcessor.oldEvents = false;
return;
}
if ((isMbway || isCreditCard || isMultibanco || isOxxo || isPaypal || isSpei || isSepa) && unlimitIframeProcessor.oldEvents === false) {
if ((isMbway || isCreditCard || isAirteltz || isMultibanco || isOxxo || isPaypal || isSpei || isSepa) && unlimitIframeProcessor.oldEvents === false) {
unlimitIframeProcessor.oldEvents = unlimitFormCheckout.data('events',
'submit');
unlimitFormCheckout.unbind('submit').submit(function (event) {
Expand Down
Binary file modified wp-content/plugins/unlimit/i18n/languages/unlimit-es.mo
Binary file not shown.
16 changes: 16 additions & 0 deletions wp-content/plugins/unlimit/i18n/languages/unlimit-es.po
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,19 @@ msgstr "Tu tarjeta ha sido eliminada."

msgid "Save the card that will be entered next"
msgstr "Guarde la tarjeta que se ingresará a continuación"

msgid "Airtel TZ phone number"
msgstr "Número de teléfono Airtel TZ"


msgid "Please fill out an Airtel TZ phone number"
msgstr "Por favor, complete un número de teléfono Airtel TZ"


msgid "Airtel TZ phone number is invalid"
msgstr "El número de teléfono Airtel TZ no es válido"


msgid "Airtel TZ payment method"
msgstr "Método de pago Airtel TZ"

Binary file modified wp-content/plugins/unlimit/i18n/languages/unlimit-pt.mo
Binary file not shown.
15 changes: 15 additions & 0 deletions wp-content/plugins/unlimit/i18n/languages/unlimit-pt.po
Original file line number Diff line number Diff line change
Expand Up @@ -810,3 +810,18 @@ msgstr "Seu cartão foi excluído."

msgid "Save the card that will be entered next"
msgstr "Salve o cartão que será inserido a seguir"

msgid "Airtel TZ phone number"
msgstr "Número de telefone Airtel TZ"


msgid "Please fill out an Airtel TZ phone number"
msgstr "Por favor, preencha um número de telefone Airtel TZ"


msgid "Airtel TZ phone number is invalid"
msgstr "O número de telefone Airtel TZ é inválido"


msgid "Airtel TZ payment method"
msgstr "Método de pagamento Airtel TZ"
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private function update_token() {
*/
public function set_payment_gateway( $methods = null ) {
$methods[] = WC_Unlimit_Constants::BANKCARD_GATEWAY;
$methods[] = WC_Unlimit_Constants::AIRTELTZ_GATEWAY;
$methods[] = WC_Unlimit_Constants::APAY_GATEWAY;
$methods[] = WC_Unlimit_Constants::BOLETO_GATEWAY;
$methods[] = WC_Unlimit_Constants::GPAY_GATEWAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
defined( 'ABSPATH' ) || exit;

class WC_Unlimit_Constants {
public const VERSION = '1.5.49';
public const VERSION = '1.5.51';

public const API_UL_BASE_URL = 'https://cardpay.com/api';
public const API_UL_SANDBOX_URL = 'https://sandbox.cardpay.com/api';

public const BANKCARD_GATEWAY = 'WC_Unlimit_Custom_Gateway';
public const AIRTELTZ_GATEWAY = 'WC_Unlimit_Airteltz_Gateway';
public const APAY_GATEWAY = 'WC_Unlimit_Apay_Gateway';

public const BOLETO_GATEWAY = 'WC_Unlimit_Ticket_Gateway';
public const PIX_GATEWAY = 'WC_Unlimit_Pix_Gateway';
public const PAYPAL_GATEWAY = 'WC_Unlimit_Paypal_Gateway';
Expand All @@ -23,6 +23,7 @@ class WC_Unlimit_Constants {

public const PAYMENT_GATEWAYS = [
self::BANKCARD_GATEWAY,
self::AIRTELTZ_GATEWAY,
self::APAY_GATEWAY,
self::BOLETO_GATEWAY,
self::GPAY_GATEWAY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public function logger_enabled() {
case 'woo-unlimit-oxxo':
$logger_enabled = get_option( 'woocommerce_unlimit_oxxo_log_to_file' );
break;
case 'woo-unlimit-airteltz':
$logger_enabled = get_option( 'woocommerce_unlimit_airteltz_log_to_file' );
break;
default:
$logger_enabled = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function get_common_api_request() {
],
'merchant_order' => [
'id' => $order_id,
'description' => "Order #$order_id",
'description' => "Order $order_id",
'shipping_address' => [
'country' => $customer->get_shipping_country(),
'state' => $customer->get_shipping_state(),
Expand Down Expand Up @@ -197,7 +197,7 @@ private function get_items() {
foreach ( $this->order->get_items() as $item ) {
$items[] = [
'name' => $item->get_name(),
'description' => 'Item #' . $item->get_id(),
'description' => "Item #{$item->get_id()}",
'count' => $item->get_quantity(),
'price' => $item->get_total()
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Automattic\WooCommerce\Admin\Overrides\Order;

require_once __DIR__ . '/WC_Unlimit_Alt_Module.php';

defined( 'ABSPATH' ) || exit;

class WC_Unlimit_Module_Airteltz extends WC_Unlimit_Alt_Module {

/**
* @param WC_Unlimit_Gateway_Abstract $payment Payment
* @param Order $order
* @param array $post_fields
*
* @throws Exception
*/
public function __construct( $payment, $order, $post_fields ) {
parent::__construct( $payment, $order, $post_fields, 'AIRTELTZS', 'airteltz' );

$this->api_request['ewallet_account']['id'] = $this->post_fields['cardpay_airteltz']['phone_number'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require_once __DIR__ . '/rest-client/WC_Unlimit_Rest_Client_Abstract.php';
require_once __DIR__ . '/rest-client/WC_Unlimit_Rest_Client.php';
require_once __DIR__ . '/../../../payments/form_fields/WC_Unlimit_Admin_Airteltz_Fields.php';
require_once __DIR__ . '/../../../payments/form_fields/WC_Unlimit_Admin_Apay_Fields.php';
require_once __DIR__ . '/../../../payments/form_fields/WC_Unlimit_Admin_BankCard_Fields.php';
require_once __DIR__ . '/../../../payments/form_fields/WC_Unlimit_Admin_Boleto_Fields.php';
Expand Down Expand Up @@ -350,6 +351,10 @@ public static function get_option_name_prefix( $payment_gateway_id ) {
$prefix = WC_Unlimit_Admin_Oxxo_Fields::FIELDNAME_PREFIX;
break;

case WC_Unlimit_Airteltz_Gateway::GATEWAY_ID:
$prefix = WC_Unlimit_Admin_Airteltz_Fields::FIELDNAME_PREFIX;
break;

default:
throw new WC_Unlimit_Exception( 'Invalid payment gateway id provided' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public function ul_rule_approved( $order, $used_gateway ) {
}
break;

case WC_Unlimit_Constants::AIRTELTZ_GATEWAY:
case WC_Unlimit_Constants::APAY_GATEWAY:
case WC_Unlimit_Constants::BOLETO_GATEWAY:
case WC_Unlimit_Constants::PAYPAL_GATEWAY:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

defined( 'ABSPATH' ) || exit;

require_once __DIR__ . '/form_fields/WC_Unlimit_Admin_Airteltz_Fields.php';
require_once __DIR__ . '/hooks/WC_Unlimit_Hook_Airteltz.php';
require_once __DIR__ . '/../module/preference/WC_Unlimit_Module_Airteltz.php';
require_once __DIR__ . '/WC_Unlimit_Alt_Gateway.php';

/**
* Unlimit Airteltz payment method
*/
class WC_Unlimit_Airteltz_Gateway extends WC_Unlimit_Alt_Gateway {

const GATEWAY_ID = 'woo-unlimit-airteltz';
const SHORT_GATEWAY_ID = 'airteltz';

public function __construct() {
$this->id = self::GATEWAY_ID;

parent::__construct(
self::GATEWAY_ID,
self::SHORT_GATEWAY_ID,
'Airtel TZ',
new WC_Unlimit_Admin_Airteltz_Fields(),
new WC_Unlimit_Hook_Airteltz( $this )
);
}

/**
* @throws Exception
*/
public function get_module( $order, $post_fields ) {
return new WC_Unlimit_Module_Airteltz( $this, $order, $post_fields );
}

/**
* @return string
*/
public static function get_id() {
return self::GATEWAY_ID;
}
}
Loading

0 comments on commit f1cdae2

Please sign in to comment.