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

Custom Field in gateways visible 2 times if the extension has that predefined field #366

Open knit-pay opened 8 months ago

knit-pay commented 8 months ago

This ticket is in continuation with https://github.com/pronamic/wp-pronamic-pay/issues/351

If we define phone custom field in a Payment Gateway, in woocommerce or other extension, phone field are visible twice, one is predefined field from WooCommerce (or extension) and another from customer field defined in Gateway.

rvdsteege commented 8 months ago

Quoting @remcotolsma from #351:

We do have some specific code in the WooCommerce library for Pronamic Pay for filtering date of birth and gender fields: https://github.com/pronamic/wp-pronamic-pay-woocommerce/blob/1af5496b74b23aacc4f48f00f943dda4cfb90c93/src/Gateway.php#L991-L1027. This is not yet very nice, so there is certainly room for improvement.

However, I'm not sure on how to improve. Maybe @remcotolsma already has some ideas?

knit-pay commented 8 months ago

I have another suggestion, that is not fully workable but can work as a workaround.

On the gateway's configuration page, we can provide checkboxes where website owners can decide if they want to show custom fields on the extension's checkout page or not. In this way, if the fields are getting duplicated, owners will have control to hide them.

@rvdsteege and @remcotolsma What is your opinion or the same?

rvdsteege commented 8 months ago

To me, that sounds a bit like cluttering the configuration settings and you might still need a way to 'map' custom fields to a corresponding field in the payment (e.g. with MemberPress). We've had some ideas and internal discussion on how to for example solve field mapping and add a lot of flexibility to the plugin (also regarding adding support for subscriptions to other extensions). We've already started experimenting a bit with this idea but have not yet decided if we really want to go this direction.

remcotolsma commented 8 months ago

The date of birth and gender field was a requirement for AfterPay.nl at the time, which is now called Riverty. Because Riverty (formerly AfterPay.nl) offers the option to pay afterwards, they could probably do a better risk analysis with date of birth and gender. However, you may wonder whether date of birth and gender are really payment method specific fields. It is different from the credit card payment method where a credit card number really belongs to the payment method. Or in the case of the Dutch payment method iDEAL, where customers must choose their bank (issuer). We may wonder how far we should ultimately go in this regard. If a plugin does not provide basic information such as first name, last name, email, amount, etc. available, should we also show payment method fields for this? WooCommerce also has a standard field for phone number:

Scherm­afbeelding 2024-03-13 om 11 05 04

However, site owners can decide for themselves whether they want to show and/or make it mandatory ☝️. Perhaps a site owner also wants to make the telephone number only mandatory for WooCommerce gateway/payment method X, Y and/or Z. We may also have to prevent Pronamic Pay from also becoming a complete checkout fields manager. I see, for example, that a plugin such as https://www.themehigh.com/docs/conditional-rules-for-woocommerce-checkout-fields-display-rules/ does have the option to set conditions for fields based on payment and shipping method.

https://www.themehigh.com/docs/conditional-rules-for-woocommerce-checkout-fields-display-rules/#Conditions_18

Which specific payment method/provider requires the phone number @knit-pay and why is it necessary? Maybe that will give us some more insight into how we can move forward with this.

After the rebranding of AfterPay.nl to Riverty, the date of birth and gender fields may no longer be necessary for us. We may eventually be able to completely remove the specific code for these fields in our WooCommerce integration.

knit-pay commented 8 months ago

Thanks @remcotolsma and @rvdsteege for replies.

Which specific payment method/provider requires the phone number @knit-pay and why is it necessary? Maybe that will give us some more insight into how we can move forward with this.

In India, every payment gateway asks for a customer's phone number and email address. Without these details, they don't accept payments. I am not sure if it's RBI's (Reserve Bank of India's) regulation to collect these details, or if payment gateways are just collecting these details for maintaining data. In some payment gateways like Instamojo and Razorpay, If we pass a phone number and email while making an API call, they don't ask for the phone number and email again from the customer. And if we don't pass those details, they ask for a phone number and email from the customer on the payment page before accepting payment. So, Instamojo and Razorpay can work even if the plugin on which the customer is making payment, does not ask for a phone number or email. Because, for these payment gateways, customers can enter these details later on the payment page.

There are some other payment gateways also, like Easebuzz, where it's mandatory to pass the correct phone number while making an API call to generate a payment link. If the correct phone number and email are not passed to Easebuzz while making an API call, they throw an error to pass these details. They don't provide any payment link where customers can enter these details later. I also asked the Easebuzz support team to make necessary changes at their end and ask for the phone number later on the payment page. But even after 2 years, changes have not been implemented yet. Please check the below docs of Easebuzz, where phone number, customer name, and email are mandatory fields https://docs.easebuzz.in/docs/payment-gateway/8ec545c331e6f-initiate-payment-api

Similarly, SSLCommerz is a payment gateway from Bangladesh country. In this payment gateway also, phone number is mandatory. https://developer.sslcommerz.com/doc/v4/#initiate-payment

It's not only about Easebuzz/SSLCommerz for WooCommerce. I am trying to find some permanent solution. So that most of the payment gateways can work with most of the plugins. Because other countries might have different rules and regulations for payment gateways from those countries.

knit-pay commented 8 months ago

I added this file in the EDD plugin code just to add a phone number field in EDD to make Indian payment gateways compatible with EDD. But I think it's not a good idea to add such code because, in many payment gateways, the phone field is not mandatory. So, this code will be useless for them. https://github.com/knit-pay/extension-easy-digital-downloads/blob/develop/src/custom-field-phone.php

remcotolsma commented 8 months ago

We have thought about this for a while, but we don't know how to proceed with this at the moment. It is difficult to set up a good abstract API to manage this. WooCommerce, Easy Digital Downloads, etc. checkout fields can be managed in many ways. For WooCommerce you can probably check whether the WooCommerce phone number field is mandatory. Based on this, you may be able to determine whether or not to show the payment method telephone number field. Similar to how we do this now with date of birth and gender field:

https://github.com/pronamic/wp-pronamic-pay-woocommerce/blob/1af5496b74b23aacc4f48f00f943dda4cfb90c93/src/Gateway.php#L991-L1027

You can also choose to always show the payment method telephone number field and, if possible, automatically fill it via JavaScript based on the WooCommerce telephone number field if there is one. In this way, a customer can provide a different telephone number for the order than for payment. Perhaps similar to the "☑️ Ship to a different address?" feature from WooCommerce, but then: "☑️ Use different phone number for payment."

You can also place a warning in the WordPress admin dashboard for WooCommerce gateways that require a telephone number that the WooCommerce telephone number field is required.

if ( 'required' !== \get_option( 'woocommerce_checkout_phone_field' ) ) {
    \esc_html_e( 'To use this gateway, the WooCommerce phone number checkout field must be set as required.', 'knit-pay' );
}

In the case of WooCommerce you can also use:

knit-pay commented 8 months ago

Thanks, @remcotolsma for taking the time to check this. I will review your suggestions and will try to implement them. Will let you know if I will have any other suggestions.