Skip to content

Commit

Permalink
Merge pull request #157 from antondrob/master
Browse files Browse the repository at this point in the history
WCS fixing
  • Loading branch information
maxwhite authored Sep 23, 2022
2 parents f2d0f48 + ab290a1 commit a4f3423
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
1 change: 1 addition & 0 deletions Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The Reepay plugin extends WooCommerce allowing you to take payments on your stor
See installation guide right here: https://intercom.help/reepay/reepay-plugins/woocommerce-plugin

== Changelog ==
v 1.4.31 - WC subscription fixing
v 1.4.30 - Fix capture
v 1.4.29 - Mobile conditions subscriptions, allow any webhooks, subscriptions recurring
v 1.4.28 - Settle fee on complete
Expand Down
8 changes: 5 additions & 3 deletions includes/abstracts/abstract-wc-gateway-reepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public function process_payment($order_id)
);
}

if (wcs_cart_only_subscriptions()) {
if (wc_cart_only_reepay_subscriptions()) {
$method = $this->api->request('GET', 'https://api.reepay.com/v1/payment_method/' . $token->get_token());
if (!empty($method) && $method['state'] == 'active') {

Expand Down Expand Up @@ -628,9 +628,11 @@ public function process_payment($order_id)
$customer_handle = $this->api->get_customer_handle_order($order->get_id());

// If here's Subscription or zero payment
if (abs($order->get_total()) < 0.01 || wcs_cart_only_subscriptions()) {
if (abs($order->get_total()) < 0.01 || wc_cart_only_reepay_subscriptions()) {
var_dump(wc_cart_only_reepay_subscriptions());
exit;
$params = [
'locale' > $this->get_language(),
'locale' => $this->get_language(),
'button_text' => __('Pay', 'woocommerce-gateway-reepay-checkout'),
'create_customer' => [
'test' => $this->test_mode === 'yes',
Expand Down
6 changes: 4 additions & 2 deletions includes/class-wc-reepay-order-statuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ public static function set_pending_status(WC_Order $order, $note, $transaction_i
*/
public static function set_authorized_status(WC_Order $order, $note, $transaction_id)
{
if ('1' === $order->get_meta('_reepay_state_authorized')) {
$authorized_status = apply_filters('reepay_authorized_order_status', 'on-hold', $order);

if (!empty($order->get_meta('_reepay_state_authorized')) || $order->get_status() == $authorized_status) {
return;
}

Expand All @@ -401,7 +403,7 @@ public static function set_authorized_status(WC_Order $order, $note, $transactio

self::update_order_status(
$order,
apply_filters('reepay_authorized_order_status', 'on-hold', $order),
$authorized_status,
$note,
$transaction_id
);
Expand Down
22 changes: 18 additions & 4 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ function wcs_cart_have_subscription()
{
if (class_exists('WC_Subscriptions_Product')) {
// Check is Recurring Payment
$cart = WC()->cart->get_cart();
foreach ($cart as $key => $item) {
if (is_object($item['data']) && WC_Subscriptions_Product::is_subscription($item['data'])) {
return true;
if (!is_null(WC()->cart)) {
$cart = WC()->cart->get_cart();
foreach ($cart as $key => $item) {
if (is_object($item['data']) && WC_Subscriptions_Product::is_subscription($item['data'])) {
return true;
}
}
}
}
Expand Down Expand Up @@ -136,6 +138,18 @@ function wcs_cart_only_subscriptions()
}
}

if (!function_exists('wc_cart_only_reepay_subscriptions')) {
/**
* Check is Cart have only Subscription Products.
*
* @return bool
*/
function wc_cart_only_reepay_subscriptions()
{
return apply_filters('wcs_cart_only_subscriptions', false);
}
}

if (!function_exists('rp_prepare_amount')) {
/**
* Prepare amount.
Expand Down
31 changes: 28 additions & 3 deletions reepay-woocommerce-payment.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/*
* Plugin Name: WooCommerce Reepay Checkout Gateway
* Description: Provides a Payment Gateway through Reepay for WooCommerce.
* Plugin Name: Reepay Checkout for WooCommerce
* Description: Get a plug-n-play payment solution for WooCommerce, that is easy to use, highly secure and is built to maximize the potential of your e-commerce.
* Author: reepay
* Author URI: http://reepay.com
* Version: 1.4.30
* Version: 1.4.31
* Text Domain: reepay-checkout-gateway
* Domain Path: /languages
* WC requires at least: 3.0.0
Expand Down Expand Up @@ -60,6 +60,7 @@ public function __construct()
add_action('woocommerce_loaded', array($this, 'woocommerce_loaded'), 40);
add_action('init', __CLASS__ . '::may_add_notices');
add_action('wp_enqueue_scripts', array($this, 'add_scripts'));
add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);

// Add statuses for payment complete
add_filter('woocommerce_valid_order_statuses_for_payment_complete', array(
Expand All @@ -82,6 +83,30 @@ public function __construct()
}
}

/**
* Show row meta on the plugin screen.
*
* @param mixed $links Plugin Row Meta.
* @param mixed $file Plugin Base file.
*
* @return array
*/
public function plugin_row_meta($links, $file)
{

if (plugin_basename(__FILE__) !== $file) {
return $links;
}

$row_meta = array(
'account' => '<a target="_blank" href="https://signup.reepay.com/?_gl=1*1iccm28*_gcl_aw*R0NMLjE2NTY1ODI3MTQuQ2p3S0NBandrX1dWQmhCWkVpd0FVSFFDbVJaNDJmVmVQWFc4LUlpVDRndE83bWRmaW5NNG5wZDhkaG12dVJFOEZkbDR4eXVMNlZpMTRSb0N1b2NRQXZEX0J3RQ..*_ga*MjA3MDA3MTk4LjE2NTM2MzgwNjY.*_ga_F82PFFEF3F*MTY2Mjk2NTEwNS4xOS4xLjE2NjI5NjUxODkuMC4wLjA.&_ga=2.98685660.319325710.1662963483-207007198.1653638066#/en">' . esc_html__('Get free test account', 'reepay-checkout-gateway') . '</a>',
'pricing' => '<a target="_blank" href="https://reepay.com/pricing/">' . esc_html__('Pricing', 'reepay-checkout-gateway') . '</a>',
);


return array_merge($links, $row_meta);
}

/**
* Install
*/
Expand Down

0 comments on commit a4f3423

Please sign in to comment.