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

Regarding cutom fields in gateways #351

Closed knit-pay closed 1 year ago

knit-pay commented 1 year ago

Hello Team

In https://github.com/pronamic/wp-pronamic-pay/issues/154 , you have introduced a way using which we can create custom fields that are required for certain payment methods for a gateway. I have a query regarding the same. There are certain fields for example "Phone Number". Some payment gateway needs a customer phone number field. Some WordPress plugins like Woocommerce by default ask for customer phone number, so this can easily be passed to gateway. But some plugins like EDD, Give etc don't ask for customer phone number by default. If we will create a custom phone number field for that particular payment method/provider, it will ask for phone number again on Woocommerce also. It's not good to ask phone number again when customer has already entered it while filling the checkout form. Where as for EDD and Give, customer needs to enter phone number because this field is missing in these plugins. Kindly suggest how to proceed with this.

rvdsteege commented 1 year ago

We have the same going on with some of our own fields. Please see how we've resolved that in https://github.com/pronamic/wp-pronamic-pay-woocommerce/blob/c46f2a96aeb4c48afc91823dc34ea8a0a6f15ab9/src/Gateway.php#L958-L994

Does that answer your question?

knit-pay commented 1 year ago

Thanks, will try that and let you know if more help needed.

knit-pay commented 6 months ago

Hello @rvdsteege, The solution below is not fully working for me.

We have the same going on with some of our own fields. Please see how we've resolved that in https://github.com/pronamic/wp-pronamic-pay-woocommerce/blob/c46f2a96aeb4c48afc91823dc34ea8a0a6f15ab9/src/Gateway.php#L958-L994

In this method, there is a challenge. For each custom field in the payment method of the gateway, we will have to define it in each extension, if we want to show that field for that extension or not. It will create lots of combinations and will make coding difficult.

For example, I am writing code for a custom gateway, where a phone number is mandatory. So I write below code in my gateway constructor

        $method = new PaymentMethod( PaymentMethods::CREDIT_CARD );

        $field_customer_phone = new TextField( 'knit_pay_customer_phone' );
        $field_customer_phone->set_label( __( 'Phone', 'knit-pay-lang' ) );
        $field_customer_phone->set_required( true );
        $field_customer_phone->meta_key = 'customer_phone';

        $method->add_field($field_customer_phone);

This phone field should be displayed on the configuration page for testing, but should not be displayed on WooCommerce checkout, because WooCommerce already has a pre-defined phone field on its checkout. So, we don't want to confuse customers by showing the phone field twice.

Now if I write the code to hide phone for this gateway in woocommerce, It will work only for this gateway. If I have 50 such custom fields in different gateways, we will have to write code for the custom fields in all the extensions.

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

Proposed Solution: In my opinion, before asking custom fields for a gateway using at $payment_method_object->get_fields() https://github.com/pronamic/wp-pronamic-pay-woocommerce/blob/1af5496b74b23aacc4f48f00f943dda4cfb90c93/src/Gateway.php#L1012C4-L1012C40

We should tell Gateway, what all pre-defined fields we have in this extension Let's say, here https://github.com/pronamic/wp-pronamic-pay-woocommerce/blob/1af5496b74b23aacc4f48f00f943dda4cfb90c93/src/Gateway.php#L999

In woocommerce, we have pre-defined fields like (customer_firstname, customer_lastname, customer_phone, customer_address etc).

After telling gateway that we already have these pre-defined fields, then we should ask gateway if gateway wants to show any other fields apart from pre-defined fields. https://github.com/pronamic/wp-pronamic-pay-woocommerce/blob/1af5496b74b23aacc4f48f00f943dda4cfb90c93/src/Gateway.php#L1012C4-L1012C40

We can also tell the gateway name of the extension (eg woocommerce), so that gateway can return more personalized results.

@rvdsteege and @remcotolsma what is your opinion on the same? Was I able to explain my concern properly? or you need more clarity?

remcotolsma commented 6 months ago

That is indeed a challenge, how do we know which input is provided by plugins such as WooCommerce, Easy Digital Download, Gravity Forms, Contact Form 7, etc. etc.. A WooCommerce telephone number field can also be disabled/removed. And these fields may or may not be mandatory. 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. I don't know what the best approach is, I suggest opening a new issue for this.