Skip to content

Commit

Permalink
Bugs relating to latest WooCommerce plugin + minor default text rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Sameer Ababneh committed Apr 21, 2021
1 parent a9a5826 commit fe946dd
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 91 deletions.
Expand Up @@ -23,7 +23,7 @@ public function __construct()
$this->description = PointCheckout_Card_Config::getInstance()->getDescription();
$this->paymentService = PointCheckout_Card_Payment::getInstance();
$this->config = PointCheckout_Card_Config::getInstance();
$this->icon = plugin_dir_url(__FILE__) . '../assets/images/mc-visa-network-logos.png';
$this->icon = plugin_dir_url(__FILE__) . '../assets/images/mc-visa-network-logos.png';

if ( !$this->config->isLiveMode() ) {
$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. You can use test cards only. ' .
Expand Down Expand Up @@ -61,13 +61,15 @@ public function is_available()
$valid = true;
if ($this->config->isSpecificUserRoles()) {
$valid = false;
$user_id = WC()->customer->get_id();
$user = new WP_User($user_id);
if (!empty($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $user_role) {
foreach ($this->config->getSpecificUserRoles() as $role) {
if ($role == $user_role) {
$valid = true;
if(WC()->customer != null) {
$user_id = WC()->customer->get_id();
$user = new WP_User($user_id);
if (!empty($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $user_role) {
foreach ($this->config->getSpecificUserRoles() as $role) {
if ($role == $user_role) {
$valid = true;
}
}
}
}
Expand All @@ -76,12 +78,14 @@ public function is_available()

if ($valid && $this->config->isSpecificCountries()) {
$valid = false;
$billingCountry = WC()->customer->get_billing_country();
if(WC()->customer != null) {
$billingCountry = WC()->customer->get_billing_country();

if (!$billingCountry == null) {
foreach ($this->config->getSpecificCountries() as $country) {
if ($country == $billingCountry) {
$valid = true;
if (!$billingCountry == null) {
foreach ($this->config->getSpecificCountries() as $country) {
if ($country == $billingCountry) {
$valid = true;
}
}
}
}
Expand Down Expand Up @@ -185,11 +189,11 @@ function init_form_fields()
'type' => 'select',
'options' => $staging_enabled ? array(
'1' => __('Live', 'pointcheckout_card'),
'0' => __('Test', 'pointcheckout_card'),
'0' => __('Testing', 'pointcheckout_card'),
'2' => __('Staging', 'pointcheckout_card'),
) : array(
'1' => 'Live',
'0' => 'Test',
'1' => __('Live', 'pointcheckout_card'),
'0' => __('Testing', 'pointcheckout_card'),
),
'default' => '0',
'desc_tip' => true,
Expand Down
4 changes: 2 additions & 2 deletions pointcheckout_payment_card/includes/lib/class-pc-config.php
Expand Up @@ -4,8 +4,8 @@ class PointCheckout_Card_Config extends PointCheckout_Card_Parent
{

private static $instance;
private $api_Secret;
private $api_Key;
private $api_secret;
private $api_key;
private $Mode;
private $orderPlacement;
private $allowSpecific;
Expand Down
@@ -1,5 +1,5 @@
<?php
define("PC_EXT_VERSION", "WooCommerce-Card-2.0.3");
define("PC_EXT_VERSION", "WooCommerce-Card-2.0.4");

class PointCheckout_Card_Payment extends PointCheckout_Card_Parent
{
Expand Down Expand Up @@ -127,7 +127,7 @@ public function getPaymentRequestForm()
$this->pcOrder->clearSessionCurrentOrder();
$form = '<form style="display:none" name="frm_pointcheckout_card_payment" id="frm_pointcheckout_card_payment" method="GET" action="' . $actionUrl . '">';
$form .= '<input type="submit">';

return array(
'form' => $form,
'response' => $response
Expand All @@ -137,7 +137,7 @@ public function getPaymentRequestForm()

public function postCheckout($paymentRequestParams)
{
return $this->pcUtils->apiCall("/", $paymentRequestParams);
return $this->pcUtils->apiCall("", $paymentRequestParams);
}


Expand Down
Expand Up @@ -10,18 +10,27 @@ class WC_Gateway_PointCheckout_Rewards extends PointCheckout_Rewards_Parent
public function __construct()
{
$this->has_fields = false;
$this->icon = apply_filters('woocommerce_POINTCHECKOUT_icon', 'https://www.pointcheckout.com/en/image/logo.png');
if (is_admin()) {
$this->has_fields = true;
$this->init_form_fields();
$this->init_settings();
}

// Define user set variables
$this->method_title = __('PointCheckout', 'woocommerce');
$this->method_title = __('PointCheckout Rewards Pay', 'woocommerce');
$this->title = 'PointCheckout';
$this->description = 'Pay using your loyalty points with PointCheckout';
$this->paymentService = PointCheckout_Rewards_Payment::getInstance();
$this->config = PointCheckout_Rewards_Config::getInstance();
$this->description = $this->config->getDescription();
$this->icon = apply_filters('woocommerce_POINTCHECKOUT_icon', 'https://www.pointcheckout.com/en/image/logo.png');

if ( !$this->config->isLiveMode() ) {
$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED.' .
'See the <a href="%s" target="_blank">PointCheckout WooCommerce Guide</a> for more details.', 'woocommerce' ),
'https://docs.pointcheckout.com/guides/woocommerce' );
$this->description = trim( $this->description );
}

// Actions
add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));
Expand All @@ -36,7 +45,7 @@ function process_admin_options()
{
$result = parent::process_admin_options();
$settings = $this->settings;
$settings['enabled'] = isset($settings['enabled']) ? $settings['enabled'] : 0;
$settings['enabled'] = isset($settings['enabled']) ? $settings['enabled'] : 'no';

update_option('woocommerce_pointcheckout_rewards_settings', apply_filters('woocommerce_settings_api_sanitized_fields_pointcheckout_rewards', $settings));
return $result;
Expand All @@ -52,13 +61,15 @@ public function is_available()
$valid = true;
if ($this->config->isSpecificUserRoles()) {
$valid = false;
$user_id = WC()->customer->get_id();
$user = new WP_User($user_id);
if (!empty($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $user_role) {
foreach ($this->config->getSpecificUserRoles() as $role) {
if ($role == $user_role) {
$valid = true;
if(WC()->customer != null) {
$user_id = WC()->customer->get_id();
$user = new WP_User($user_id);
if (!empty($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $user_role) {
foreach ($this->config->getSpecificUserRoles() as $role) {
if ($role == $user_role) {
$valid = true;
}
}
}
}
Expand All @@ -67,12 +78,14 @@ public function is_available()

if ($valid && $this->config->isSpecificCountries()) {
$valid = false;
$billingCountry = WC()->customer->get_billing_country();
if(WC()->customer != null) {
$billingCountry = WC()->customer->get_billing_country();

if (!$billingCountry == null) {
foreach ($this->config->getSpecificCountries() as $country) {
if ($country == $billingCountry) {
$valid = true;
if (!$billingCountry == null) {
foreach ($this->config->getSpecificCountries() as $country) {
if ($country == $billingCountry) {
$valid = true;
}
}
}
}
Expand Down Expand Up @@ -102,8 +115,8 @@ function payment_scripts()
public function admin_options()
{
?>
<h3><?php _e('PointCheckout', 'pointcheckout_rewards'); ?></h3>
<p><?php _e('Please fill in the below section to start accepting payments on your site! You can find all the required information in your <a href="https://www.pointcheckout.com/" target="_blank">PointCheckout website</a>.', 'pointcheckout_rewards'); ?></p>
<h3><?php _e('PointCheckout Rewards Payment', 'pointcheckout_rewards'); ?></h3>
<p><?php _e('Please fill in the below section to start accepting payments on your site via PointCheckout! Learn more at <a href="https://docs.pointcheckout.com/" target="_blank">PointCheckout</a>." target="_blank">PointCheckout website</a>.', 'pointcheckout_rewards'); ?></p>


<table class="form-table">
Expand All @@ -114,23 +127,23 @@ public function admin_options()
<script>
jQuery(document).ready(function() {
jQuery('[name=save]').click(function() {
if (!jQuery('#woocommerce_pointcheckout_rewards_Api_Key').val()) {
alert('Please enter your Api Key!');
if (!jQuery('#woocommerce_pointcheckout_rewards_api_key').val()) {
alert('API key not configured');
return false;
}
if (!jQuery('#woocommerce_pointcheckout_rewards_Api_Secret').val()) {
alert('Please enter your Api Secret!');
if (!jQuery('#woocommerce_pointcheckout_rewards_api_secret').val()) {
alert('API secret not configured');
return false;
}
if (jQuery('#woocommerce_pointcheckout_rewards_allow_specific').val() == 1) {
if (!jQuery('#woocommerce_pointcheckout_rewards_specific_countries').val()) {
alert('You select to specifiy for applicable countries but you did not select any!');
alert('You enabled PointCheckout for specific countries but you did not select any');
return false;
}
}
if (jQuery('#woocommerce_pointcheckout_rewards_allow_user_specific').val() == 1) {
if (!jQuery('#woocommerce_pointcheckout_rewards_specific_user_roles').val()) {
alert('You select to specifiy for applicable user roles but you did not select any!');
alert('You enabled PointCheckout for speficic user roles but you did not select any');
return false;
}
}
Expand All @@ -153,15 +166,11 @@ function init_form_fields()
{
$staging_enabled = false;
$this->form_fields = array(
'enabled' => array(
'enabled' => array(
'title' => __('Enable/Disable', 'pointcheckout_rewards'),
'type' => 'select',
'label' => __('Enable the PointCheckout gateway', 'pointcheckout_rewards'),
'default' => '0',
'options' => array(
'1' => __('Enabled', 'pointcheckout_rewards'),
'0' => __('Disabled', 'pointcheckout_rewards'),
)
'type' => 'checkbox',
'label' => __('Enable rewards payments via PointCheckout', 'pointcheckout_rewards'),
'default' => 'no'
),
'description' => array(
'title' => __('Description', 'pointcheckout_rewards'),
Expand All @@ -173,29 +182,29 @@ function init_form_fields()
'title' => __('Mode', 'pointcheckout_rewards'),
'type' => 'select',
'options' => $staging_enabled ? array(
'1' => __('live', 'pointcheckout_rewards'),
'0' => __('testing', 'pointcheckout_rewards'),
'1' => __('Live', 'pointcheckout_rewards'),
'0' => __('Testing', 'pointcheckout_rewards'),
'2' => __('Staging', 'pointcheckout_rewards'),
) : array(
'1' => __('live', 'pointcheckout_rewards'),
'0' => __('testing', 'pointcheckout_rewards'),
'1' => __('Live', 'pointcheckout_rewards'),
'0' => __('Testing', 'pointcheckout_rewards'),
),
'default' => '0',
'desc_tip' => true,
'description' => sprintf(__('Logs additional information. <br>Log file path: %s', 'pointcheckout_rewards'), 'Your admin panel -> WooCommerce -> System Status -> Logs'),
'placeholder' => '',
'class' => 'wc-enhanced-select',
),
'Api_Key' => array(
'title' => __('Api Key', 'pointcheckout_rewards'),
'api_key' => array(
'title' => __('API Key', 'pointcheckout_rewards'),
'type' => 'text',
'description' => __('Your Api Key, you can find in your PointCheckout account settings.', 'pointcheckout_rewards'),
'default' => '',
'desc_tip' => true,
'placeholder' => ''
),
'Api_Secret' => array(
'title' => __('Api Secret', 'pointcheckout_rewards'),
'api_secret' => array(
'title' => __('API Secret', 'pointcheckout_rewards'),
'type' => 'text',
'description' => __('Your Api Secret, you can find in your PointCheckout account settings.', 'pointcheckout_rewards'),
'default' => '',
Expand Down
28 changes: 13 additions & 15 deletions pointcheckout_payment_rewards/includes/lib/class-pc-config.php
Expand Up @@ -6,25 +6,26 @@ class PointCheckout_Rewards_Config extends PointCheckout_Rewards_Parent
{

private static $instance;
private $Api_Secret;
private $Api_Key;
private $api_secret;
private $api_key;
private $Mode;
private $orderPlacement;
private $allowSpecific;
private $specific_countries;
private $allowUserSpecific;
private $specific_uesr_roles;
private $new_order_status;
public $description;


public function __construct()
{
parent::__construct();
$this->language = $this->_getShoppingCartConfig('language');
$this->enabled = $this->_getShoppingCartConfig('enabled');
$this->Api_Key = $this->_getShoppingCartConfig('Api_Key');
$this->api_key = $this->_getShoppingCartConfig('api_key');
$this->command = $this->_getShoppingCartConfig('command');
$this->Api_Secret = $this->_getShoppingCartConfig('Api_Secret');
$this->api_secret = $this->_getShoppingCartConfig('api_secret');
$this->Mode = $this->_getShoppingCartConfig('mode');
$this->orderPlacement = $this->_getShoppingCartConfig('order_placement');
$this->allowSpecific = $this->_getShoppingCartConfig('allow_specific');
Expand Down Expand Up @@ -55,8 +56,6 @@ public function getLanguage()
return 'en';
}



public function getEnabled()
{
return $this->enabled;
Expand All @@ -67,17 +66,11 @@ public function getMode()
return $this->Mode;
}





public function getSuccessOrderStatusId()
{
return $this->successOrderStatusId;
}



public function isActive()
{
if ($this->active) {
Expand Down Expand Up @@ -137,17 +130,17 @@ public function orderPlacementIsOnSuccess()

public function isEnabled()
{
return $this->enabled == 1 ? true : false;
return $this->enabled === 'yes';
}

public function getApiKey()
{
return $this->Api_Key;
return $this->api_key;
}

public function getApiSecret()
{
return $this->Api_Secret;
return $this->api_secret;
}

public function isLiveMode()
Expand All @@ -159,4 +152,9 @@ public function isStagingMode()
{
return $this->Mode == 2 ? true : false;
}

public function getDescription()
{
return $this->description;
}
}
Expand Up @@ -3,8 +3,7 @@
class PointCheckout_Rewards_Parent extends WC_Payment_Gateway
{
public $id = 'pointcheckout_rewards';
public function __construct()
{
public function __construct() {
// NO INTITALIZATION REQuIRED
}
}
Expand Down
@@ -1,5 +1,5 @@
<?php
define("PC_EXT_VERSION", "WooCommerce-Card-2.0.3");
define("PC_EXT_VERSION", "WooCommerce-Rewards-2.0.4");


class PointCheckout_Rewards_Payment extends PointCheckout_Rewards_Parent
Expand Down

0 comments on commit fe946dd

Please sign in to comment.