From 1d3eb872b22efadabc0ae3a14a96cd6142976d27 Mon Sep 17 00:00:00 2001 From: wajih Date: Thu, 30 Apr 2020 09:49:41 +0400 Subject: [PATCH] Bug fix: Virtual product has no Shipping address --- includes/paytabs_api.php | 8 ++++++ includes/paytabs_payment_methods.php | 40 ++++++++++++++++------------ paytabs-paypage.php | 4 +-- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/includes/paytabs_api.php b/includes/paytabs_api.php index 03361c2..b8db56e 100644 --- a/includes/paytabs_api.php +++ b/includes/paytabs_api.php @@ -563,6 +563,14 @@ public static function countryGetiso3($iso_2) return $iso_3; } + + public static function getNonEmpty(...$vars) + { + foreach ($vars as $var) { + if (!empty($var)) return $var; + } + return false; + } } diff --git a/includes/paytabs_payment_methods.php b/includes/paytabs_payment_methods.php index e04d62a..724ec03 100644 --- a/includes/paytabs_payment_methods.php +++ b/includes/paytabs_payment_methods.php @@ -319,6 +319,9 @@ private function prepareOrder($order) $stateShipping = $order->get_shipping_city(); } + $addressBilling = trim($order->get_billing_address_1() . ' ' . $order->get_billing_address_2()); + $addressShipping = trim($order->get_shipping_address_1() . ' ' . $order->get_shipping_address_2()); + $lang_code = get_locale(); $lang = ($lang_code == 'ar' || substr($lang_code, 0, 3) == 'ar_') ? 'Arabic' : 'English'; @@ -342,15 +345,15 @@ private function prepareOrder($order) 'state' => $stateBilling, 'city' => $order->get_billing_city(), 'postal_code' => $postalCodeBilling, - 'billing_address' => $order->get_billing_address_1() . ' ' . $order->get_billing_address_2(), + 'billing_address' => $addressBilling, - 'shipping_firstname' => $order->get_shipping_first_name(), - 'shipping_lastname' => $order->get_shipping_last_name(), - 'country_shipping' => $countryShipping, - 'state_shipping' => $stateShipping, - 'city_shipping' => $order->get_shipping_city(), - 'postal_code_shipping' => $postalCodeShipping, - 'address_shipping' => $order->get_shipping_address_1() . ' ' . $order->get_shipping_address_2(), + 'shipping_firstname' => PaytabsHelper::getNonEmpty($order->get_shipping_first_name(), $order->get_billing_first_name()), + 'shipping_lastname' => PaytabsHelper::getNonEmpty($order->get_billing_last_name(), $order->get_shipping_last_name()), + 'country_shipping' => PaytabsHelper::getNonEmpty($countryShipping, $countryBilling), + 'state_shipping' => PaytabsHelper::getNonEmpty($stateShipping, $stateBilling), + 'city_shipping' => PaytabsHelper::getNonEmpty($order->get_shipping_city(), $order->get_billing_city()), + 'postal_code_shipping' => ($postalCodeShipping == '11111') ? $postalCodeBilling : $postalCodeShipping, + 'address_shipping' => PaytabsHelper::getNonEmpty($addressShipping, $addressBilling), 'reference_no' => $order->get_id(), 'cms_with_version' => "WooCommerce {$woocommerce->version}", @@ -428,6 +431,9 @@ private function prepareOrder2($order) $stateShipping = $order->shipping_city; } + $addressBilling = trim($order->billing_address_1 . ' ' . $order->billing_address_2); + $addressShipping = trim($order->shipping_address_1 . ' ' . $order->shipping_address_2); + $lang_code = get_locale(); $lang = ($lang_code == 'ar' || substr($lang_code, 0, 3) == 'ar_') ? 'Arabic' : 'English'; @@ -451,15 +457,15 @@ private function prepareOrder2($order) 'state' => $stateBilling, 'city' => $order->billing_city, 'postal_code' => $postalCodeBilling, - 'billing_address' => $order->billing_address_1 . ' ' . $order->billing_address_2, - - 'shipping_firstname' => $order->shipping_first_name, - 'shipping_lastname' => $order->shipping_last_name, - 'country_shipping' => $countryShipping, - 'state_shipping' => $stateShipping, - 'city_shipping' => $order->shipping_city, - 'postal_code_shipping' => $postalCodeShipping, - 'address_shipping' => $order->shipping_address_1 . ' ' . $order->shipping_address_2, + 'billing_address' => $addressBilling, + + 'shipping_firstname' => PaytabsHelper::getNonEmpty($order->shipping_first_name, $order->billing_first_name), + 'shipping_lastname' => PaytabsHelper::getNonEmpty($order->shipping_last_name, $order->billing_last_name), + 'country_shipping' => PaytabsHelper::getNonEmpty($countryShipping, $countryBilling), + 'state_shipping' => PaytabsHelper::getNonEmpty($stateShipping, $stateBilling), + 'city_shipping' => PaytabsHelper::getNonEmpty($order->shipping_city, $order->billing_city), + 'postal_code_shipping' => ($postalCodeShipping == '11111') ? $postalCodeBilling : $postalCodeShipping, + 'address_shipping' => PaytabsHelper::getNonEmpty($addressShipping, $addressBilling), 'reference_no' => $order->id, 'cms_with_version' => "WooCommerce {$woocommerce->version}", diff --git a/paytabs-paypage.php b/paytabs-paypage.php index cf9e796..d6ae4e1 100644 --- a/paytabs-paypage.php +++ b/paytabs-paypage.php @@ -8,7 +8,7 @@ * Plugin Name: PayTabs - WooCommerce Payment Gateway * Plugin URI: https://paytabs.com/ * Description: PayTabs is a 3rd party payment gateway. Ideal payment solutions for your internet business. - * Version: 3.1.4 + * Version: 3.1.5 * Author: PayTabs * Author URI: https://paytabs.com/ * Revision Date : 19/April/2020 @@ -21,7 +21,7 @@ //load plugin function when woocommerce loaded add_action('plugins_loaded', 'woocommerce_paytabs_init', 0); -define('PAYTABS_PAYPAGE_VERSION', '3.1.4'); +define('PAYTABS_PAYPAGE_VERSION', '3.1.5'); define('PAYTABS_PAYPAGE_DIR', plugin_dir_path(__FILE__)); define('PAYTABS_PAYPAGE_ICONS_URL', plugins_url("icons/", __FILE__)); $PAYTABS_PAYPAGE_METHODS = [