Skip to content

Commit

Permalink
Merge pull request #213 from antondrob/master
Browse files Browse the repository at this point in the history
v 1.4.61 - Code refactor, Woo blocks fixes fatal
  • Loading branch information
markusbrunke authored Apr 3, 2023
2 parents ab8a841 + 4cd1f0a commit 845940f
Show file tree
Hide file tree
Showing 10 changed files with 475 additions and 477 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.61 - Code refactor, Woo blocks fixes fatal
v 1.4.60 - Fix subscriptions coupons, Add Woo blocks
v 1.4.59 - Fix WC 7.5.0 checkout bug
v 1.4.58 - Fix multilingual webhook endpoints
Expand Down
56 changes: 38 additions & 18 deletions includes/abstracts/abstract-wc-gateway-reepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class WC_Gateway_Reepay extends WC_Payment_Gateway {
/**
* @var WC_Reepay_Api
*/
public $api;
public $api = null;

/**
* Test Mode
Expand All @@ -26,18 +26,18 @@ abstract class WC_Gateway_Reepay extends WC_Payment_Gateway {
/**
* @var string
*/
public $private_key;
public $private_key = '';

/**
* @var
*/
public $private_key_test;
public $private_key_test = '';

/**
* @var string
*/

public $public_key;
public $public_key = '';

/**
* Settle
Expand Down Expand Up @@ -167,10 +167,15 @@ public function __construct() {
// Cancel actions
add_action( 'wp_ajax_reepay_cancel_payment', array( $this, 'reepay_cancel_payment' ) );
add_action( 'wp_ajax_nopriv_reepay_cancel_payment', array( $this, 'reepay_cancel_payment' ) );
add_action( 'woocommerce_checkout_create_order_line_item', array(
$this,
'action_checkout_create_order_line_item'
), 10, 4 );
add_action(
'woocommerce_checkout_create_order_line_item',
array(
$this,
'action_checkout_create_order_line_item',
),
10,
4
);

static $handler_added = false;

Expand Down Expand Up @@ -228,10 +233,18 @@ public function is_configured() {
return $configured;
}


/**
* @param WC_Payment_Gateway_Reepay_Interface $gateway
* @param bool $is_test
*
* @return array|mixed|object|WP_Error
*/
public function get_account_info( $gateway, $is_test = false ) {
if ( isset( $_GET['tab'] ) && $_GET['tab'] == 'checkout' && ! empty( $_GET['section'] ) && $_GET['section'] == 'reepay_checkout' ) {

$default_test_mode = $this->test_mode;
$this->test_mode = $is_test ? 'yes' : 'false';

$this->api = new WC_Reepay_Api( $gateway );

$key = 'account_info';
Expand All @@ -243,9 +256,16 @@ public function get_account_info( $gateway, $is_test = false ) {
$account_info = get_transient( $key );
if ( empty( $account_info ) ) {
$account_info = $this->api->request( 'GET', 'https://api.reepay.com/v1/account' );

if ( is_wp_error( $account_info ) ) {
return $account_info;
}

set_transient( $key, $account_info, 5 );
}

$this->test_mode = $default_test_mode;

return $account_info;
}

Expand Down Expand Up @@ -706,7 +726,7 @@ public function process_payment( $order_id ) {
}
}

$order = wc_get_order( $order_id );
$order = wc_get_order( $order_id );

if ( $is_woo_blocks_checkout_request ) {
/**
Expand All @@ -717,16 +737,16 @@ public function process_payment( $order_id ) {

$token_id = isset( $_POST[ 'wc-' . $this->id . '-payment-token' ] ) ? wc_clean( $_POST[ 'wc-' . $this->id . '-payment-token' ] ) : 'new';

if ( $token_id === 'new' && isset( $_POST[ 'wc-' . $this->id . '-new-payment-method' ] ) && $_POST[ 'wc-' . $this->id . '-new-payment-method' ] !== false ) {
$maybe_save_card = $_POST[ 'wc-' . $this->id . '-new-payment-method' ] === 'true';
if ( 'yes' === $this->save_cc
&& $token_id === 'new'
&& isset( $_POST[ 'wc-' . $this->id . '-new-payment-method' ] )
&& $_POST[ 'wc-' . $this->id . '-new-payment-method' ] !== false
) {
$maybe_save_card = $_POST[ 'wc-' . $this->id . '-new-payment-method' ] === 'true';
} else {
$maybe_save_card = wcs_cart_have_subscription();
}

if ( 'yes' !== $this->save_cc ) {
$token_id = 'new';
$maybe_save_card = false;
}
$WC_Countries = new WC_Countries();
$country = '';
if ( method_exists( $WC_Countries, 'country_exists' ) ) {
Expand Down Expand Up @@ -1435,8 +1455,8 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
public function get_order_items( $order, $not_settled = false ) {
$prices_incl_tax = wc_prices_include_tax();

$items = [];
$setup_fees = [];
$items = array();
$setup_fees = array();
$sub_amount_discount = 0;
foreach ( $order->get_items() as $order_item ) {
/** @var WC_Order_Item_Product $order_item */
Expand Down
Loading

0 comments on commit 845940f

Please sign in to comment.