Enable Recurring Payment

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

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

You can learn more about the basics of recurring payments here.

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

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.

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');
$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');
$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

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