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

Requesting payment methods not optimal #7

Closed
remcotolsma opened this issue Jun 30, 2022 · 1 comment
Closed

Requesting payment methods not optimal #7

remcotolsma opened this issue Jun 30, 2022 · 1 comment

Comments

@remcotolsma
Copy link
Member

To retrieve the available payment methods we currently do 6 requests:

/**
* Get available payment methods.
*
* @see Core_Gateway::get_available_payment_methods()
* @return array<int, string>
*/
public function get_available_payment_methods() {
$payment_methods = [];
$resources = [ ResourceType::PAYMENTS, ResourceType::ORDERS ];
$sequence_types = [ Sequence::ONE_OFF, Sequence::RECURRING, Sequence::FIRST ];
$results = [];
foreach ( $resources as $resource ) {
foreach ( $sequence_types as $sequence_type ) {
// Get active payment methods for Mollie account.
$result = $this->client->get_payment_methods( $sequence_type, $resource );
if ( Sequence::FIRST === $sequence_type ) {
foreach ( $result as $method => $title ) {
unset( $result[ $method ] );
// Get WordPress payment method for direct debit method.
$method = Methods::transform_gateway_method( $method );
$payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true );
if ( $payment_method ) {
$results[ $payment_method ] = $title;
}
}
}
if ( is_array( $result ) ) {
$results = array_merge( $results, $result );
}
}
}
// Transform to WordPress payment methods.
foreach ( $results as $method => $title ) {
$method = (string) $method;
$payment_method = Methods::transform_gateway_method( $method );
if ( PaymentMethods::is_recurring_method( $method ) ) {
$payment_method = $method;
}
if ( null !== $payment_method ) {
$payment_methods[] = (string) $payment_method;
}
}
$payment_methods = array_unique( $payment_methods );
return $payment_methods;
}

$this->factory->fake( 'https://api.mollie.com/v2/methods?includeWallets=applepay&resource=payments&sequenceType=oneoff', __DIR__ . '/../http/api-mollie-com-v2-methods-oneoff.http' );
$this->factory->fake( 'https://api.mollie.com/v2/methods?includeWallets=applepay&resource=payments&sequenceType=recurring', __DIR__ . '/../http/api-mollie-com-v2-methods-recurring.http' );
$this->factory->fake( 'https://api.mollie.com/v2/methods?includeWallets=applepay&resource=payments&sequenceType=first', __DIR__ . '/../http/api-mollie-com-v2-methods-recurring.http' );
$this->factory->fake( 'https://api.mollie.com/v2/methods?includeWallets=applepay&resource=orders&sequenceType=oneoff', __DIR__ . '/../http/api-mollie-com-v2-methods-oneoff.http' );
$this->factory->fake( 'https://api.mollie.com/v2/methods?includeWallets=applepay&resource=orders&sequenceType=recurring', __DIR__ . '/../http/api-mollie-com-v2-methods-recurring.http' );
$this->factory->fake( 'https://api.mollie.com/v2/methods?includeWallets=applepay&resource=orders&sequenceType=first', __DIR__ . '/../http/api-mollie-com-v2-methods-recurring.http' );

This is not optimal and we can simplify it in the future via, for example, https://docs.mollie.com/reference/v2/methods-api/list-all-methods.

This is also related to the following issue:

@remcotolsma
Copy link
Member Author

This is fixed / simplified in aba5a4f.

Repository owner moved this from Todo to Done in Pronamic Pay Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

1 participant