Skip to content

Commit

Permalink
For renewal orders, update payment method to SEPA Direct Debit when n…
Browse files Browse the repository at this point in the history
…eeded, closes #120
  • Loading branch information
davdebcom committed Aug 23, 2017
1 parent 11f4ac4 commit 333d7ec
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,28 @@ public function scheduled_subscription_payment( $amount_to_charge, $renewal_orde
unset($data['customerId']);
$payment = Mollie_WC_Plugin::getApiHelper()->getApiClient($test_mode)->payments->create($data);
}

// Update payment method to actual payment method used for renewal order, this is
// for subscriptions where the first order used methods like iDEAL as first payment and
// later renewal orders switch to SEPA Direct Debit.

$methods_needing_update = array (
'mollie_wc_gateway_ideal',
'mollie_wc_gateway_mistercash',
'mollie_wc_gateway_bancontact',
'mollie_wc_gateway_sofort',
'mollie_wc_gateway_kbc',
'mollie_wc_gateway_belfius',
'mollie_wc_gateway_creditcard', // TODO DAVID -- REMOVE
);

$current_method = get_post_meta( $renewal_order_id, '_payment_method', $single = true );

if ( in_array( $current_method, $methods_needing_update ) && $payment->method == 'directdebit' ) {
update_post_meta( $renewal_order_id, '_payment_method', 'mollie_wc_gateway_directdebit' );
update_post_meta( $renewal_order_id, '_payment_method_title', 'SEPA Direct Debit' );
}

Mollie_WC_Plugin::debug($this->id . ': Created payment for order ' . $renewal_order_id. ' payment json response '.json_encode($payment));
Mollie_WC_Plugin::getDataHelper()->unsetActiveMolliePayment($renewal_order_id);
// Set active Mollie payment
Expand Down

0 comments on commit 333d7ec

Please sign in to comment.