Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dimaspolohov #287

Merged
merged 4 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions includes/Gateways/ReepayCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public function __construct() {
$this->payment_type = $this->settings['payment_type'] ?: $this->payment_type;
$this->payment_methods = $this->settings['payment_methods'] ?: $this->payment_methods;
$this->skip_order_lines = $this->settings['skip_order_lines'] ?: $this->skip_order_lines;
$this->enable_order_autocancel = $this->settings['enable_order_autocancel'] ?: $this->enable_order_autocancel;
$this->failed_webhooks_email = $this->settings['failed_webhooks_email'] ?: $this->failed_webhooks_email;
$this->handle_failover = $this->settings['handle_failover'] ?: $this->handle_failover;

Expand Down Expand Up @@ -381,16 +380,6 @@ public function init_form_fields() {
),
'default' => 'no',
),
'enable_order_autocancel' => array(
'title' => __( 'The automatic order auto-cancel', 'reepay-checkout-gateway' ),
'description' => __( 'The automatic order auto-cancel', 'reepay-checkout-gateway' ),
'type' => 'select',
'options' => array(
'yes' => 'Enable auto-cancel',
'no' => 'Ignore / disable auto-cancel',
),
'default' => 'no',
),
'payment_button_text' => array(
'title' => __( 'Payment button text', 'reepay-checkout-gateway' ),
'type' => 'text',
Expand Down
23 changes: 15 additions & 8 deletions includes/Gateways/ReepayGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@ abstract class ReepayGateway extends WC_Payment_Gateway {
*/
public string $skip_order_lines = 'no';

/**
* If automatically cancel unpaid orders should be ignored
*
* @var string
*/
public string $enable_order_autocancel = 'no';

/**
* Email address for notification about failed webhooks
*
Expand Down Expand Up @@ -1396,7 +1389,6 @@ protected function apply_parent_settings() {
$this->debug = (string) reepay()->get_setting( 'debug' );
$this->payment_type = (string) reepay()->get_setting( 'payment_type' );
$this->skip_order_lines = (string) reepay()->get_setting( 'skip_order_lines' );
$this->enable_order_autocancel = (string) reepay()->get_setting( 'enable_order_autocancel' );
$this->handle_failover = (string) reepay()->get_setting( 'handle_failover' );
}

Expand Down Expand Up @@ -1563,6 +1555,21 @@ public function get_order_items( WC_Order $order, $only_not_settled = false ): a
);
}


// Add "PW Gift Cards" support.
foreach( $order->get_items( 'pw_gift_card' ) as $line ) {
$amount = apply_filters( 'pwgc_to_order_currency', floatval( $line->get_amount() ) * -1, $order );

$items[] = array(
// translators: gift card code.
'ordertext' => sprintf( __( 'PW gift card (%s)', 'reepay-checkout-gateway' ), $line->get_card_number() ),
'quantity' => 1,
'amount' => rp_prepare_amount( $amount, $order->get_currency() ),
'vat' => 0,
'amount_incl_vat' => $prices_incl_tax,
);
}

// Add "Gift Up!" discount.
if ( defined( 'GIFTUP_ORDER_META_CODE_KEY' ) &&
defined( 'GIFTUP_ORDER_META_REQUESTED_BALANCE_KEY' )
Expand Down
2 changes: 1 addition & 1 deletion includes/OrderFlow/OrderStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public function is_paid( bool $is_paid, WC_Order $order ): bool {
* @see wc_cancel_unpaid_orders()
*/
public function cancel_unpaid_order( bool $maybe_cancel, WC_Order $order ): bool {
if ( $maybe_cancel && rp_is_order_paid_via_reepay( $order ) && 'yes' !== reepay()->get_setting( 'enable_order_autocancel' ) ) {
if ( $maybe_cancel && rp_is_order_paid_via_reepay( $order ) ) {
$maybe_cancel = false;
}

Expand Down
13 changes: 8 additions & 5 deletions includes/OrderFlow/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,14 @@ public function process( array $data ) {
}
}

OrderStatuses::set_settled_status(
$order,
false,
$data['transaction']
);
if( empty( $order->get_meta( '_reepay_subscription_handle' ) )){
OrderStatuses::set_settled_status(
$order,
false,
$data['transaction']
);
}


update_post_meta( $order->get_id(), '_reepay_capture_transaction', $data['transaction'] );

Expand Down
1 change: 0 additions & 1 deletion reepay-woocommerce-payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public function get_setting( string $name ) {
'debug' => ! empty( $gateway_settings['debug'] ) ? $gateway_settings['debug'] : '',
'payment_type' => ! empty( $gateway_settings['payment_type'] ) ? $gateway_settings['payment_type'] : '',
'skip_order_lines' => ! empty( $gateway_settings['skip_order_lines'] ) ? $gateway_settings['skip_order_lines'] : '',
'enable_order_autocancel' => ! empty( $gateway_settings['enable_order_autocancel'] ) ? $gateway_settings['enable_order_autocancel'] : '',
'is_webhook_configured' => ! empty( $gateway_settings['is_webhook_configured'] ) ? $gateway_settings['is_webhook_configured'] : '',
'handle_failover' => ! empty( $gateway_settings['handle_failover'] ) ? $gateway_settings['handle_failover'] : '',
'payment_button_text' => ! empty( $gateway_settings['payment_button_text'] ) ? $gateway_settings['payment_button_text'] : '',
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/orderFlow/OrderStatusesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ public function test_is_paid( bool $default_value, bool $status_sync_enabled, bo
*
* @param bool $default_value
* @param bool $paid_via_reepay
* @param bool $enabled_order_autocancel
* @param bool $expected_value
*
* @testWith
Expand All @@ -611,12 +610,6 @@ public function test_cancel_unpaid_order( bool $default_value, bool $paid_via_re
$this->order_generator->set_prop( 'payment_method', reepay()->gateways()->checkout() );
}

self::$options->set_options(
array(
'enable_order_autocancel' => $enabled_order_autocancel ? 'yes' : 'no',
)
);

$this->assertSame(
$expected_value,
$this->order_statuses->cancel_unpaid_order( $default_value, $this->order_generator->order() ),
Expand Down
Loading