Skip to content

Commit

Permalink
Payment blocks (#75)
Browse files Browse the repository at this point in the history
* Add support to WC blocks

* Support Blocks for all methods

* Add a notice for the managed form option

* Emit some warning

* Remove Fawry (#76)

* Update the SDK version
  • Loading branch information
MAboyadak authored Mar 20, 2024
1 parent ed2d83f commit 2db8929
Show file tree
Hide file tree
Showing 12 changed files with 19,038 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode/*
node_modules
1 change: 1 addition & 0 deletions assets/js/frontend/blocks.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-html-entities', 'wp-i18n'), 'version' => 'fa804360790c00d8fbe1');
1 change: 1 addition & 0 deletions assets/js/frontend/blocks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 108 additions & 0 deletions includes/blocks/class-wc-paytabs-payments-blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;

/**
* Dummy Payments Blocks integration
*
* @since 1.0.3
*/
final class WC_Gateway_Paytabs_Blocks_Support extends AbstractPaymentMethodType
{
/**
* Payment method name/id/slug.
*
* @var string
*/
public $gateways = [];
public $id = "paytabs_blocks";

protected $name = 'paytabs_blocks';

/**
* Initializes the payment method type.
*/
public function initialize()
{
$this->gateways = $this->get_gateways();
}

public function get_gateways()
{
$gateways = WC()->payment_gateways->payment_gateways();
$enabled_gateways = [];

foreach ($gateways as $gateway) {
if (str_starts_with($gateway->id, "paytabs_") && $gateway->enabled == "yes") {
$enabled_gateways[$gateway->id] = $gateway;
}
}
return $enabled_gateways;
}

/**
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
*
* @return boolean
*/
public function is_active()
{
return true; // $this->gateway->is_available();
}

/**
* Returns an array of scripts/handles to be registered for this payment method.
*
* @return array
*/
public function get_payment_method_script_handles()
{
$script_path = 'assets/js/frontend/blocks.js';
$script_asset_path = PAYTABS_PAYPAGE_DIR . 'assets/js/frontend/blocks.asset.php';
$script_asset = file_exists($script_asset_path)
? require($script_asset_path)
: array(
'dependencies' => array(),
'version' => '1.2.0'
);
$script_url = PAYTABS_PAYPAGE_URL . $script_path;

wp_register_script(
$this->id,
$script_url,
$script_asset['dependencies'],
$script_asset['version'],
true
);

if (function_exists('wp_set_script_translations')) {
// wp_set_script_translations( 'wc-dummy-payments-blocks', 'woocommerce-gateway-dummy', WC_Dummy_Payments::plugin_abspath() . 'languages/' );
}

return [$this->id];
}

/**
* Returns an array of key=>value pairs of data made available to the payment methods script.
*
* @return array
*/
public function get_payment_method_data()
{
$data = [];

foreach ($this->gateways as $gateway) {
$gateWayData = [
'name' => $gateway->id,
'title' => $gateway->title,
'supports' => array_filter($gateway->supports, [$gateway, 'supports']),
'icon' => $gateway->getIcon(),
'description' => $gateway->description,
];

$key = "blocks";
$data[$key][] = $gateWayData;
}
return $data;
}
}
6 changes: 3 additions & 3 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.20.1
* Version: 2.21.0
* PHP >= 7.0.0
*/

define('PAYTABS_SDK_VERSION', '2.20.1');
define('PAYTABS_SDK_VERSION', '2.21.0');

define('PAYTABS_DEBUG_FILE_NAME', 'debug_paytabs.log');
define('PAYTABS_DEBUG_SEVERITY', ['Info', 'Warning', 'Error']);
Expand Down Expand Up @@ -1283,7 +1283,7 @@ class PaytabsApi
'5' => ['name' => 'mada', 'title' => 'PayTabs - mada', 'currencies' => ['SAR'], 'groups' => [PaytabsApi::GROUP_TOKENIZE, PaytabsApi::GROUP_CARDS, PaytabsApi::GROUP_AUTH_CAPTURE, PaytabsApi::GROUP_IFRAME, PaytabsApi::GROUP_REFUND]],
'6' => ['name' => 'creditcard', 'title' => 'PayTabs - CreditCard', 'currencies' => null, 'groups' => [PaytabsApi::GROUP_TOKENIZE, PaytabsApi::GROUP_CARDS, PaytabsApi::GROUP_CARDS_INTERNATIONAL, PaytabsApi::GROUP_AUTH_CAPTURE, PaytabsApi::GROUP_IFRAME, PaytabsApi::GROUP_REFUND]],
'7' => ['name' => 'sadad', 'title' => 'PayTabs - Sadad', 'currencies' => ['SAR'], 'groups' => [PaytabsApi::GROUP_IFRAME, PaytabsApi::GROUP_PENDING]],
'8' => ['name' => 'fawry', 'title' => 'PayTabs - @Fawry', 'currencies' => ['EGP'], 'groups' => [PaytabsApi::GROUP_IFRAME, PaytabsApi::GROUP_REFUND, PaytabsApi::GROUP_PENDING]],
// '8' => ['name' => 'fawry', 'title' => 'PayTabs - @Fawry', 'currencies' => ['EGP'], 'groups' => [PaytabsApi::GROUP_IFRAME, PaytabsApi::GROUP_REFUND, PaytabsApi::GROUP_PENDING]],
'9' => ['name' => 'knet', 'title' => 'PayTabs - KnPay', 'currencies' => ['KWD'], 'groups' => [PaytabsApi::GROUP_CARDS, PaytabsApi::GROUP_REFUND]],
'10' => ['name' => 'amex', 'title' => 'PayTabs - Amex', 'currencies' => ['AED', 'SAR', 'USD'], 'groups' => [PaytabsApi::GROUP_TOKENIZE, PaytabsApi::GROUP_CARDS, PaytabsApi::GROUP_CARDS_INTERNATIONAL, PaytabsApi::GROUP_AUTH_CAPTURE, PaytabsApi::GROUP_IFRAME, PaytabsApi::GROUP_REFUND]],
'11' => ['name' => 'valu', 'title' => 'PayTabs - valU', 'currencies' => ['EGP'], 'groups' => [PaytabsApi::GROUP_IFRAME, PaytabsApi::GROUP_REFUND]],
Expand Down
6 changes: 3 additions & 3 deletions includes/paytabs_gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ class WC_Gateway_Paytabs_Sadad extends WC_Gateway_Paytabs
protected $_description = 'PayTabs - Sadad payment method';
}

class WC_Gateway_Paytabs_Fawry extends WC_Gateway_Paytabs
/*class WC_Gateway_Paytabs_Fawry extends WC_Gateway_Paytabs
{
protected $_code = 'fawry';
protected $_title = 'PayTabs - @Fawry';
protected $_description = 'PayTabs - @Fawry payment method';
}
}*/

class WC_Gateway_Paytabs_Knpay extends WC_Gateway_Paytabs
{
Expand Down Expand Up @@ -255,4 +255,4 @@ class WC_Gateway_Paytabs_AmanInstallments extends WC_Gateway_Paytabs
protected $_description = 'PayTabs - Aman installments payment method';

protected $_icon = "amaninstallments.svg";
}
}
40 changes: 38 additions & 2 deletions includes/paytabs_payment_methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,42 @@ class WC_Gateway_Paytabs extends WC_Payment_Gateway
//
protected $_paytabsApi;

// Fields

private $paytabs_endpoint;
private $merchant_id;
private $merchant_key;
private $client_key;

private $trans_type;

private $_is_card_method;
private $allow_associated_methods;
private $_support_tokenise;
private $_support_auth_capture;
private $_support_iframe;
private $payment_form;
private $is_frammed_page;
private $is_managed_form;

private $hide_shipping;

private $order_status_success;
private $order_status_failed;
private $order_status_auth_success;
private $failed_send_note;

private $valu_widget_enable;
private $valu_widget_static_content;
private $valu_widget_phone_number;
private $valu_widget_price_threshold;

private $enable_tokenise;
private $tokenise_param;
private $token_id_param;

private $ipn_enable;

// Select the PayPage to use
private $theme_config_id;

Expand Down Expand Up @@ -153,7 +189,7 @@ public function __construct()
* example: stcpay.png, applepay.png ...
* @return string
*/
private function getIcon()
public function getIcon()
{
$icon_name = $this->_icon ?? "{$this->_code}.png";

Expand Down Expand Up @@ -252,7 +288,7 @@ public function init_form_fields()
'title' => __('Payment form type', 'PayTabs'),
'type' => 'select',
'options' => $redirect_modes,
'description' => __("Hosted form on PayTabs server is the secure solution of choice, While iFrame provides better customer experience (https strongly advised)", 'PayTabs'),
'description' => __("Hosted form on PayTabs server is the secure solution of choice, While iFrame provides better customer experience (https strongly advised), <br><strong>Managed form option</strong> is not yet supported by the new blocks mode", 'PayTabs'),
'default' => 'redirect',
'desc_tip' => false,
];
Expand Down
Loading

0 comments on commit 2db8929

Please sign in to comment.