Skip to content

Commit

Permalink
Merge branch 'gitlab-master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Mason authored and Mason committed Oct 1, 2020
2 parents f6c2604 + 9a02b12 commit bca4cfd
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 29 deletions.
30 changes: 2 additions & 28 deletions src/includes/class-paymentwall-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
*/
class Paymentwall_Gateway extends Paymentwall_Abstract {

const PAYMENTWALL_METHOD = 'paymentwall';
const USER_ID_GEOLOCATION = 'user101';
const CACHED_DATA_TIME_TO_LIVE = 300;

public $id = 'paymentwall';
public $id = self::PAYMENTWALL_METHOD;
public $has_fields = true;

public function __construct() {
Expand All @@ -34,7 +35,6 @@ public function __construct() {
add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));
add_action('woocommerce_api_' . $this->id . '_gateway', array($this, 'handle_action'));

add_action('woocommerce_review_order_before_payment', array($this, 'html_payment_system'));
add_action('woocommerce_checkout_update_order_meta', array($this,'update_payment_system_order_meta'));
add_filter('woocommerce_order_get_payment_method_title', array($this,'get_payment_method_title'), 10, 2 );
add_filter('woocommerce_get_order_item_totals', array($this,'update_payment_title_by_selected_method'), 10, 3);
Expand Down Expand Up @@ -458,32 +458,6 @@ public function prepare_payment_methods_from_api_response($response) {
return $methods;
}

public function html_payment_system() {
$paymentMethods = $this->get_local_payment_methods();
if (is_array($paymentMethods) && !empty($paymentMethods)) {
echo '<ul class="wc_payment_methods payment_methods methods paymentwall-method">';
foreach ($paymentMethods as $gateway) {
$dataPaymentSystem = array(
'id' => $gateway['id'],
'name' => $gateway['name']
);
?>
<li class="wc_payment_method payment_method_paymentwall_ps">
<input id="payment_method_<?php echo esc_attr( $gateway['id'] ); ?>" type="radio" class="input-radio pw_payment_system" name="payment_method" data-payment-system='<?php echo json_encode($dataPaymentSystem); ?>' value="paymentwall" />
<label for="payment_method_<?php echo esc_attr( $gateway['id'] ); ?>">
<?php echo $gateway['name']; ?> <img alt="<?php echo $gateway['name']; ?>" src="<?php echo $gateway['img_url'];?>">
</label>
</li>
<?php
}
echo '</ul>';
?>
<input id="pw_gateway" type="hidden" class="hidden" name="pw_payment_system" value=""/>
<style>li.wc_payment_method.payment_method_paymentwall{ display: none } .wc_payment_methods:not(.paymentwall-method){ margin-top: 1rem; } </style>
<?php
}
}

/**
* Update payment system to order
*/
Expand Down
83 changes: 82 additions & 1 deletion src/paymentwall-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin Name: Paymentwall for WooCommerce
* Plugin URI: https://www.paymentwall.com/en/documentation/WooCommerce/1409
* Description: Official Paymentwall module for WordPress WooCommerce.
* Version: 1.7.1
* Version: 1.7.2
* Author: The Paymentwall Team
* Author URI: http://www.paymentwall.com/
* Text Domain: paymentwall-for-woocommerce
Expand Down Expand Up @@ -149,3 +149,84 @@ function start_session() {
session_start();
}
}

add_filter('woocommerce_available_payment_gateways', 'addPaymentwallGateway', 99, 2);
function addPaymentwallGateway($availableGateways){

if (is_checkout() || is_checkout_pay_page()) {

$paymentwallGateway = new Paymentwall_Gateway();

if (!$paymentwallGateway->is_available()) {
return $availableGateways;
}

if (!array_key_exists(Paymentwall_Gateway::PAYMENTWALL_METHOD, $availableGateways)) {
$availableGateways[Paymentwall_Gateway::PAYMENTWALL_METHOD] = $paymentwallGateway;
}
}

return $availableGateways;
}

add_filter('woocommerce_available_payment_gateways', 'addBrickGateway', 100, 2);
function addBrickGateway($availableGateways)
{

if (is_checkout() || is_checkout_pay_page()){

$brickGateway = new Paymentwall_Brick();

if (!$brickGateway->is_available()) {
return $availableGateways;
}

if (!array_key_exists(Paymentwall_Brick::BRICK_METHOD, $availableGateways)) {
$availableGateways[Paymentwall_Brick::BRICK_METHOD] = $brickGateway;
}
}
return $availableGateways;
}

add_action('woocommerce_review_order_before_payment', 'html_payment_system');
function html_payment_system() {
$paymentwallGateway = new Paymentwall_Gateway();

if (!$paymentwallGateway->is_available()) {
return;
}

$paymentMethods = $paymentwallGateway->get_local_payment_methods();
if (is_array($paymentMethods) && !empty($paymentMethods)) {
echo '<ul class="wc_payment_methods payment_methods methods paymentwall-method">';
foreach ($paymentMethods as $gateway) {
$dataPaymentSystem = array(
'id' => $gateway['id'],
'name' => $gateway['name']
);
?>
<li class="wc_payment_method payment_method_paymentwall_ps">
<input id="payment_method_<?php echo esc_attr($gateway['id']); ?>" type="radio"
class="input-radio pw_payment_system" name="payment_method"
data-payment-system='<?php echo json_encode($dataPaymentSystem); ?>'
value="paymentwall"/>
<label for="payment_method_<?php echo esc_attr($gateway['id']); ?>">
<?php echo $gateway['name']; ?> <img alt="<?php echo $gateway['name']; ?>"
src="<?php echo $gateway['img_url']; ?>">
</label>
</li>
<?php
}
echo '</ul>';
?>
<input id="pw_gateway" type="hidden" class="hidden" name="pw_payment_system" value=""/>
<style>li.wc_payment_method.payment_method_paymentwall {
display: none
}

.wc_payment_methods:not(.paymentwall-method) {
margin-top: 1rem;
} </style>
<?php
}
}

0 comments on commit bca4cfd

Please sign in to comment.