Skip to content

Commit

Permalink
Merge pull request #19 from paytabscom/auth
Browse files Browse the repository at this point in the history
init auth feature
  • Loading branch information
Walaa-Elsaeed-93 authored Sep 21, 2021
2 parents 77a017c + 4834876 commit 286ea16
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
46 changes: 42 additions & 4 deletions includes/paytabs_payment_methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function __construct()

$this->order_status_success = $this->get_option('status_success');
$this->order_status_failed = $this->get_option('status_failed');
$this->trans_type = $this->get_option('trans_type');



if ($this->_code == 'valu') {
$this->valu_product_id = $this->get_option('valu_product_id');
Expand Down Expand Up @@ -202,6 +205,17 @@ public function init_form_fields()
'description' => 'Enable if you wish to hide Shipping info of the customer in PayTabs payment page.',
'default' => 'no'
),
'trans_type' => array(
'title' => __('Transaction Type', 'PayTabs'),
'label' => __('Transaction Type', 'PayTabs'),
'type' => 'select',
'description' => 'Set the transaction type to Auth or Sale',
'options' => array(
'SALE' => __( 'Sale', 'PayTabs' ),
'AUTH' => __( 'Auth', 'PayTabs' ),
),
'default' => 'SALE'
),
'status_success' => array(
'title' => __('Success Order status', 'PayTabs'),
'type' => 'select',
Expand Down Expand Up @@ -556,7 +570,13 @@ private function orderFailed($order, $message)

private function setNewStatus($order, $isSuccess)
{
if ($isSuccess) {
$transaction_type = $this->get_transaction_type($order);

if ($isSuccess && $transaction_type == "Auth") {
$configStatus = 'on-hold';
$defaultStatus = 'wc-on-hold';
}
else if ($isSuccess && transaction_type == "Sale") {
$configStatus = $this->order_status_success;
$defaultStatus = 'wc-processing';
} else {
Expand Down Expand Up @@ -649,7 +669,7 @@ private function prepareOrder($order)
$holder = new PaytabsRequestHolder();
$holder
->set01PaymentCode($this->_code, $this->allow_associated_methods)
->set02Transaction(PaytabsEnum::TRAN_TYPE_SALE, PaytabsEnum::TRAN_CLASS_ECOM)
->set02Transaction($this->trans_type, PaytabsEnum::TRAN_CLASS_ECOM)
->set03Cart($order->get_id(), $currency, $amount, $cart_desc)
->set04CustomerDetails(
$nameBilling,
Expand Down Expand Up @@ -757,7 +777,7 @@ private function prepareOrder2($order)
$holder = new PaytabsRequestHolder();
$holder
->set01PaymentCode($this->_code)
->set02Transaction(PaytabsEnum::TRAN_TYPE_SALE, PaytabsEnum::TRAN_CLASS_ECOM)
->set02Transaction($this->trans_type, PaytabsEnum::TRAN_CLASS_ECOM)
->set03Cart($order->id, $currency, $amount, $cart_desc)
->set04CustomerDetails(
$order->get_formatted_billing_full_name(),
Expand Down Expand Up @@ -835,7 +855,7 @@ private function prepareOrder_Tokenised($order, $tokenObj, $amount_to_charge = n

$holder = new PaytabsTokenHolder();
$holder
->set02Transaction(PaytabsEnum::TRAN_TYPE_SALE, PaytabsEnum::TRAN_CLASS_RECURRING)
->set02Transaction($this->trans_type, PaytabsEnum::TRAN_CLASS_RECURRING)
->set03Cart($order->get_id(), $currency, $amount, $cart_desc)
->set20Token($tran_ref, $token)
->set99PluginInfo('WooCommerce', $woocommerce->version, PAYTABS_PAYPAGE_VERSION);
Expand All @@ -855,4 +875,22 @@ private function getPaymentMethod($order)
{
return WooCommerce2 ? $order->payment_method : $order->get_payment_method();
}

private function get_transaction_type($order)
{
global $woocommerce;
$transaction_id = $order->get_transaction_id();

if (!$transaction_id)
{
return false;
}


$_paytabsApi = PaytabsApi::getInstance($this->paytabs_endpoint, $this->merchant_id, $this->merchant_key);
$transaction_type = $_paytabsApi->verify_payment($transaction_id);
$transaction_type = $transaction_type->tran_type;

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


define('PAYTABS_PAYPAGE_VERSION', '4.5.1');
define('PAYTABS_PAYPAGE_VERSION', '4.5.2');
define('PAYTABS_PAYPAGE_DIR', plugin_dir_path(__FILE__));
define('PAYTABS_PAYPAGE_ICONS_URL', plugins_url("icons/", __FILE__));
define('PAYTABS_DEBUG_FILE', WP_CONTENT_DIR . "/debug_paytabs.log");
Expand Down

0 comments on commit 286ea16

Please sign in to comment.