Skip to content

Commit

Permalink
Alt currency (#64)
Browse files Browse the repository at this point in the history
* Adding alternative currency feature

* Update SDK
  • Loading branch information
MAboyadak authored Nov 24, 2023
1 parent 3621b1d commit 6fea84d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
28 changes: 23 additions & 5 deletions includes/paytabs_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

/**
* PayTabs v2 PHP SDK
* Version: 2.14.0
* Version: 2.15.0
* PHP >= 7.0.0
*/

define('PAYTABS_SDK_VERSION', '2.14.0');
define('PAYTABS_SDK_VERSION', '2.15.0');

define('PAYTABS_DEBUG_FILE_NAME', 'debug_paytabs.log');
define('PAYTABS_DEBUG_SEVERITY', ['Info', 'Warning', 'Error']);
Expand Down Expand Up @@ -737,6 +737,11 @@ class PaytabsRequestHolder extends PaytabsBasicHolder
*/
private $config_id;

/**
* alt_currency
*/
private $alt_currency;

//

/**
Expand All @@ -750,7 +755,8 @@ public function pt_build()
$all,
$this->hide_shipping,
$this->framed,
$this->config_id
$this->config_id,
$this->alt_currency
);

return $all;
Expand Down Expand Up @@ -781,16 +787,28 @@ public function set09Framed(bool $on = false, $redirect_target = 'iframe')

public function set11ThemeConfigId($config_id)
{
$config_id = (int) trim($config_id);
$config_id = (int) trim($config_id ?? "");

if (isset($config_id) && (is_int($config_id) && $config_id > 0)) {
if (is_int($config_id) && $config_id > 0) {
$this->config_id = [
'config_id' => $config_id
];
}

return $this;
}

public function set12AltCurrency($alt_currency)
{
$alt_currency = trim($alt_currency ?? "");

if (!empty($alt_currency)) {
$this->alt_currency = [
'alt_currency' => $alt_currency
];
}
return $this;
}
}


Expand Down
48 changes: 44 additions & 4 deletions includes/paytabs_payment_methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class WC_Gateway_Paytabs extends WC_Payment_Gateway
// Select the PayPage to use
private $theme_config_id;

// Alt currency
private $alt_currency_enable;
private $alt_currency;

//

const PT_HANDLED = '_pt_handled';
Expand Down Expand Up @@ -104,6 +108,9 @@ public function __construct()

$this->theme_config_id = $this->get_option('theme_config_id', '');

$this->alt_currency_enable = $this->get_option('alt_currency_enable', "no") == 'yes';
$this->alt_currency = $this->get_option('alt_currency', '');

// This action hook saves the settings
add_action("woocommerce_update_options_payment_gateways_{$this->id}", array($this, 'process_admin_options'));

Expand Down Expand Up @@ -342,6 +349,20 @@ public function init_form_fields()
'description' => "Config id of the theme/payment page (if any) you want to open, You may find it in <strong>Dashboard > Developers > PayPage Settings (Themes)</strong>",
'default' => '',
'required' => false
),
'alt_currency_enable' => array(
'title' => __('Enable alternative currency', 'PayTabs'),
'type' => 'checkbox',
'description' => "Display alternative currency equivalent in the payment page.",
'default' => "no",
'required' => false
),
'alt_currency' => array(
'title' => __('Alternative currency', 'PayTabs'),
'type' => 'text',
'description' => 'The alternative currency to be shown in the payment page, e.g. "USD", "AED, "SAR"',
'default' => '',
'required' => false
)
);

Expand Down Expand Up @@ -1515,8 +1536,13 @@ private function prepareOrder($order, $isTokenize = false)
->set08Lang($lang)
->set09Framed($this->is_frammed_page, 'top')
->set10Tokenise($tokenise)
->set11ThemeConfigId($this->theme_config_id)
->set99PluginInfo('WooCommerce', $woocommerce->version, PAYTABS_PAYPAGE_VERSION);
->set11ThemeConfigId($this->theme_config_id);

if ($this->alt_currency_enable) {
$holder->set12AltCurrency($this->getAltCurrency());
}

$holder->set99PluginInfo('WooCommerce', $woocommerce->version, PAYTABS_PAYPAGE_VERSION);

if ($this->_code == 'valu') {
// $holder->set20ValuParams($this->valu_product_id, 0);
Expand Down Expand Up @@ -1629,8 +1655,13 @@ private function prepareOrder2($order, $isTokenize = false)
->set08Lang($lang)
->set09Framed($this->is_frammed_page, 'top')
->set10Tokenise($tokenise)
->set11ThemeConfigId($this->theme_config_id)
->set99PluginInfo('WooCommerce', $woocommerce->version, PAYTABS_PAYPAGE_VERSION);
->set11ThemeConfigId($this->theme_config_id);

if ($this->alt_currency_enable) {
$holder->set12AltCurrency($this->getAltCurrency());
}

$holder->set99PluginInfo('WooCommerce', $woocommerce->version, PAYTABS_PAYPAGE_VERSION);

if ($this->_code == 'valu') {
// $holder->set20ValuParams($this->valu_product_id, 0);
Expand Down Expand Up @@ -1706,4 +1737,13 @@ private function getPaymentMethod($order)
{
return WooCommerce2 ? $order->payment_method : $order->get_payment_method();
}

private function getAltCurrency()
{
/*
/ any logic needed in the future
*/

return $this->alt_currency;
}
}
4 changes: 2 additions & 2 deletions paytabs-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin URI: https://paytabs.com/
* Description: PayTabs is a <strong>3rd party payment gateway</strong>. Ideal payment solutions for your internet business.
* Version: 4.19.0
* Version: 4.20.0
* Requires PHP: 7.0
* Author: PayTabs
* Author URI: [email protected]
Expand All @@ -20,7 +20,7 @@
}


define('PAYTABS_PAYPAGE_VERSION', '4.19.0');
define('PAYTABS_PAYPAGE_VERSION', '4.20.0');
define('PAYTABS_PAYPAGE_DIR', plugin_dir_path(__FILE__));
define('PAYTABS_PAYPAGE_ICONS_URL', plugins_url("icons/", __FILE__));
define('PAYTABS_PAYPAGE_IMAGES_URL', plugins_url("images/", __FILE__));
Expand Down

0 comments on commit 6fea84d

Please sign in to comment.