pronamic / wp-pronamic-pay

The Pronamic Pay plugin allows you to easily accept payments with payment methods like credit card, iDEAL, Bancontact and Sofort through a variety of payment providers on your WordPress website.
https://pronamicpay.com
35 stars 14 forks source link

Direct Debit method should not be used for verification payment on payment method update #361

Closed rvdsteege closed 1 year ago

rvdsteege commented 1 year ago

In internal support ticket https://secure.helpscout.net/conversation/2314990377/25976 it came to our attention that the Direct Debit payment method can be selected on the "Mandate Selection" page. However, this payment method results in an error:

Unprocessable Entity – The payment method does not support sequence type

The method is available in the select menu, because we're listing all payment methods with recurring feature support.

@remcotolsma any thoughts on how to improve this?

remcotolsma commented 1 year ago

Display the required fields for the direct debit payment method? Is probably a bit tricky, not all users want to offer the error-prone free IBAN and customer name input for direct debit payments. For now a specific filter on the DIRECT_DEBIT method on this line: https://github.com/pronamic/wp-pay-core/blob/5859217757f9229f671c51b035cc191365c871b2/views/subscription-mandate.php#L246. Or should we introduce a new supports flag for this? Because we now only support recurring payments with Mollie, it is still a bit difficult to see what is (re)usable. A specific filter at https://github.com/pronamic/wp-pay-core/blob/5859217757f9229f671c51b035cc191365c871b2/views/subscription-mandate.php#L246 is therefore perhaps the easiest solution.

rvdsteege commented 1 year ago

What about marking the consumer name and IBAN fields as required in the Mollie gateway and then leaving out payment methods with required fields, as we do not support fields at the moment? This way, we don't have to check specifically for the Direct Debit method (the Mollie gateway does not have any other payment method with required fields).

// Skip payment methods with required fields.
$required_fields = array_filter(
    $payment_method->get_fields(),
    function ( $field ) {
        return $field->is_required();
    }
);

if ( 0 !== count( $required_fields ) ) {
    continue;
}
remcotolsma commented 1 year ago

Yes, that could also be possible, go for this for now?

$payment_methods = array_filter(
    $payment_methods,
    function ( $payment_method ) {
        $required_fields = array_filter(
            $payment_method->get_fields(),
            function ( $field ) {
                return $field->is_required();
            }
        );

        return 0 === count( $required_fields );
    }
);