Enable Recurring Payments

Enable recurring payments for your transactions

The SDK allows activation of recurring payment for the following payment types:

  • Card (Credit Card and Debit Card)
  • PayPal
  • Unzer Direct Debit (secured)

To activate recurring for a payment type, you need to call activateRecurring and to pass along the returnUrl to which the customer will be redirected after performing actions outside the shop (for example, authorizing a PayPal payment).

$unzer     = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$card      = $unzer->fetchPaymentType('s-crd-9wmri5mdlqps');
$recurring = $card->activateRecurring('https://your.return.url');
$unzer     = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$card      = $unzer->fetchPaymentType('s-crd-9wmri5mdlqps');
$recurring = $unzer->activateRecurringPayment($card, 'https://your.return.url');

When activating recurring, an object of type UnzerSDK\Resources\Recurring is returned which has the property redirectUrl. If this URL is not empty you need to redirect the customer to it so they can authenticate the payment.

// Redirect to the 3ds page or to success depending on the state of the transaction
$redirect = !empty($recurring->getRedirectUrl());
  if (!$redirect && $recurring->isSuccess()) {
    // Redirect to success page
  } elseif ($redirect && $recurring->isPending()) {
    // redirect to $recurring->getRedirectUrl()
  }

When the customer returns and all has been successful the method isRecurring of the payment type should return true.

$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$card  = $unzer->fetchPaymentType('s-crd-9wmri5mdlqps');

if ($card->isRecurring()) {
  // handle as success
}
// else handle as failure
Special treatment of Unzer Direct Debit
With Unzer Direct Debit recurring is activated automatically when a charge has been successful. It cannot be activated using the methods described here.

Arguments to PaymentType::activateRecurring

Parameter Type Description
returnUrl string The URL the API leads the customer to after they finished entering payment information outside of the shop (e.g. PayPal).
This needs to be set to a valid URL, no matter whether a redirect is necessary or not.
Required: true
recurrenceType string Recurrence type used for card recurring payment.

Required: false
Default: null

Arguments to Unzer::activateRecurringPayment

Parameter Type Description
paymentType string | UnzerSDK\Resources\PaymentTypes\BasePaymentType Reference to the payment type to use either by ID or the object itself.
Required: true
returnUrl string The URL the API leads the customer to after they finished entering payment information outside of the shop (e.g. PayPal).
This needs to be set to a valid URL, no matter whether a redirect is necessary or not.
Required: true
recurrenceType string Recurrence type used for card recurring payment.

Required: false
Default: null