function mollie_payment_payment_recurring_can_stop in Mollie Payment 7
Same name and namespace in other branches
- 7.2 mollie_payment.module \mollie_payment_payment_recurring_can_stop()
Implements hook_payment_recurring_can_OPERATION() for stop.
File
- ./
mollie_payment.module, line 130 - Provides Mollie integration for the Payment platform.
Code
function mollie_payment_payment_recurring_can_stop(Payment $payment) {
// Initialize the client.
$client = mollie_payment_get_client($payment);
if ($payment && $client) {
$customer_id = $payment->context_data['payment']['customer'];
$subscription_id = $payment->context_data['payment']['subscription'];
// Mollie API Client throws an exception when trying to get a cancelled
// subscription.
try {
$subscription = $client->customers_subscriptions
->withParentId($customer_id)
->get($subscription_id);
if (in_array($subscription->status, array(
'cancelled',
'completed',
))) {
return FALSE;
}
} catch (Exception $e) {
return FALSE;
}
}
return TRUE;
}