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

Refactor PaymentMethods class, PaymentMethods::get_active_payment_methods() and PaymentMethods::is_active( $payment_method = null ) methods #71

Open
remcotolsma opened this issue Aug 25, 2022 · 1 comment

Comments

@remcotolsma
Copy link
Member

In pronamic/wp-pronamic-pay#334 I ran into a problem with the PaymentMethods::update_active_payment_methods() method.

Saving a gateway configuration will trigger the Pronamic\WordPress\Pay\Core\PaymentMethods::update_active_payment_methods( ) method, exceptions in this method are not handled, how should we proceed?

Originally posted by @remcotolsma in pronamic/wp-pronamic-pay#334 (comment)


The PaymentMethods::update_active_payment_methods() is not very scalable with a 'nopaging' => true WP_Query. Currently we mainly use the PaymentMethods class to hide some less common payment methods in for example the WooCommerce checkout settings page and in the payment methods field of forms plugins.


We need a way to register payment methods globally in the plugin. I would like to suggest that we create a settings page to give each registered payment method a status.

Payment Methods

Payment Method Status
iDEAL 'active'
AfterPay ''
Credit Card 'inactive'

Payment methods with an undefined status ('') could be auto activated by a gateway. If a user disabled a payment method (inactive) the status would never be auto updated. On saving a gateway configuration we only have to activate the payment methods that have an undefined status ('' or null). We no longer need to loop through all the gateway configurations and request which payment methods are active. We also no longer have to save that information per gateway configuration.

To implement this we could introduce a PaymentMethodsContainer or PaymentMethodsCollection class. Both the Gateway class and the Plugin class could use this class.

class PaymentMethodsCollection {

}

class Gateway {
	public function get_payment_methods() : PaymentMethodsCollection {

	}
}

class Plugin {
	public function get_payment_methods() : PaymentMethodsCollection {

	}
}
@rvdsteege
Copy link
Member

Currently, a payment method can be listed as 'Active' on the 'Payment methods' tab in the payment gateway configuration settings, while the method does not appear in e.g. WooCommerce. Updating the payment gateway configuration resolved the issue.

Internal Help Scout ticket: https://secure.helpscout.net/conversation/2023558897/24522/

@remcotolsma remcotolsma removed their assignment Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants