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

Prevent customers from paying via iDEAL while a direct debit is already in progress #72

Merged
merged 3 commits into from
Oct 17, 2024
Merged
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
32 changes: 30 additions & 2 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
}

// Get payment.
$order_payment_id = (int) $order->get_meta( '_pronamic_payment_id' );

Check failure on line 320 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Cannot call method get_meta() on WC_Order|WC_Order_Refund|true.

Check failure on line 320 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Cannot cast mixed to int.

if ( empty( $order_payment_id ) ) {
return;
Expand Down Expand Up @@ -401,7 +401,7 @@
$order->add_order_note(
sprintf(
'%s %s.',
$payment_method_title,

Check failure on line 404 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.
__( 'reserved payment cancelled', 'pronamic_ideal' )
)
);
Expand Down Expand Up @@ -433,7 +433,7 @@
*
* @link https://github.com/pronamic/wp-pronamic-pay-woocommerce/issues/48
*/
if ( 'shop_subscription' === $order->get_type() ) {

Check failure on line 436 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Cannot call method get_type() on WC_Order|WC_Order_Refund|true.
return;
}

Expand All @@ -449,7 +449,7 @@
$payment_method_title = $payment->get_meta( 'woocommerce_payment_method_title' );

if ( empty( $payment_method_title ) ) {
$payment_method_title = WooCommerce::get_payment_method_title( $order );

Check failure on line 452 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Parameter #1 $order of static method Pronamic\WordPress\Pay\Extensions\WooCommerce\WooCommerce::get_payment_method_title() expects WC_Order, WC_Order|WC_Order_Refund|true given.
}

/**
Expand All @@ -459,9 +459,9 @@
/* translators: 1: payment URL, 2: payment ID, 3: WooCommerce payment method title, 4: Pronamic payment status */
__( '<a href="%1$s">Payment #%2$s</a> via "%3$s" updated to "%4$s".', 'pronamic_ideal' ),
esc_urL( $payment->get_edit_payment_url() ),
esc_html( $payment->get_id() ),

Check failure on line 462 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Parameter #1 $text of function esc_html expects string, int|null given.
esc_html( $payment_method_title ),

Check failure on line 463 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Parameter #1 $text of function esc_html expects string, mixed given.
esc_html( $payment->get_status_label() )

Check failure on line 464 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Parameter #1 $text of function esc_html expects string, string|null given.
);

/**
Expand All @@ -484,8 +484,12 @@
* @link https://github.com/woocommerce/woocommerce/blob/7897a61a1040ca6ed3310cb537ce22211058256c/plugins/woocommerce/includes/abstracts/abstract-wc-order.php#L402-L403
* @link https://github.com/pronamic/wp-pronamic-pay-woocommerce/issues/48
*/
if ( PaymentStatus::OPEN === $payment->get_status() && $order->needs_payment() && 'pending' !== $order->get_status() ) {
$new_status = WooCommerce::ORDER_STATUS_PENDING;
if ( PaymentStatus::OPEN === $payment->get_status() && $order->needs_payment() ) {

Check failure on line 487 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Cannot call method needs_payment() on WC_Order|WC_Order_Refund|true.
$order_status = self::get_open_payment_order_status( $payment );

if ( $order_status !== $order->get_status() ) {

Check failure on line 490 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Cannot call method get_status() on WC_Order|WC_Order_Refund|true.
$new_status = $order_status;
}
}

/**
Expand Down Expand Up @@ -538,6 +542,30 @@
}
}

/**
* Get the WooCommerce order status for open payment.
*
* @param Payment $payment Payment.
* @return string
*/
private static function get_open_payment_order_status( $payment ) {
$order_status = WooCommerce::ORDER_STATUS_PENDING;

/**
* Direct debit payments usually take a few days to process, in the
* meantime customers should not have the option to pay for the order
* via other payment methods. The `on-hold` order status ensures that
* this option is not available.
*
* @link https://github.com/pronamic/wp-pronamic-pay-woocommerce/issues/70
*/
if ( PaymentMethods::DIRECT_DEBIT === $payment->get_payment_method() ) {
$order_status = WooCommerce::ORDER_STATUS_ON_HOLD;
}

return $order_status;
}

/**
* Maybe update refunded payment.
*
Expand Down
Loading