Skip to content

Commit

Permalink
Merge pull request #46 from pronamic/45-prevent-payment-method-change…
Browse files Browse the repository at this point in the history
…-note

45 prevent payment method change note
  • Loading branch information
rvdsteege authored Mar 22, 2024
2 parents c60ee6e + 8ff5054 commit 1948c7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1623,14 +1623,26 @@ public function update_subscription_mandate( Subscription $subscription, $mandat
$method_transformer = new MethodTransformer();

$old_method = $subscription->get_payment_method();
$new_method = ( null === $payment_method && \property_exists( $mandate, 'method' ) ? $method_transformer->transform_mollie_to_wp( $mandate->method ) : $payment_method );
$new_method = $payment_method;

if ( null === $payment_method && \property_exists( $mandate, 'method' ) ) {
$pronamic_methods = $method_transformer->from_mollie_to_pronamic( $mandate->method );

$new_method = in_array( $old_method, $pronamic_methods, true ) ? $old_method : null;

$first_pronamic_method = reset( $pronamic_methods );

if ( null === $new_method && false !== $first_pronamic_method ) {
$new_method = $first_pronamic_method;
}
}

if ( ! empty( $old_method ) && $old_method !== $new_method ) {
$subscription->set_payment_method( $new_method );

// Add note.
$note = \sprintf(
/* translators: 1: old payment method, 2: new payment method */
/* translators: 1: old payment method, 2: new payment method */
\__( 'Payment method for subscription changed from "%1$s" to "%2$s".', 'pronamic_ideal' ),
\esc_html( (string) PaymentMethods::get_name( $old_method ) ),
\esc_html( (string) PaymentMethods::get_name( $new_method ) )
Expand Down
2 changes: 1 addition & 1 deletion src/MethodTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function transform_mollie_to_wp( $method ) {
* Transform Mollie method to Pronamic payment method(s).
*
* @param string $method Mollie method.
* @return array
* @return array<string>
*/
public function from_mollie_to_pronamic( $method ) {
return \array_keys(
Expand Down

0 comments on commit 1948c7f

Please sign in to comment.