Enable Recurring Payments
Enable recurring payments for your transactions
Supported payment methods
The SDK allows activation of recurring payment for the following payment types:
- Card (Credit Card and Debit Card)
- PayPal
- Unzer Direct Debit (secured)
Registering a credit card
For recurring card payment set the recurrenceType for your charge/authorize transaction according to your recurring use case. For more details on recurring payments for credit cards, see card use cases.
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$card = $unzer->fetchPaymentType('s-crd-xxxxxxxxxx');
$charge = new \UnzerSDK\Resources\TransactionTypes\Charge(200.0, 'EUR', RETURN_CONTROLLER_URL);
$charge->setRecurrenceType(\UnzerSDK\Constants\RecurrenceTypes::UNSCHEDULED, $card);
$unzer->performCharge($charge, $card);
Registering PayPal
note-paypal$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$paypal = $unzer->fetchPaymentType('s-ppl-xxxxxxxxxx');
$recurring = $unzer->activateRecurringPayment($paypal, 'https://your.return.url');
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$paypal = $unzer->fetchPaymentType('s-ppl-xxxxxxxxxx');
$recurring = $paypal->activateRecurring('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 PayPal 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');
$paypal = $unzer->fetchPaymentType('s-ppl-xxxxxxxxxx');
if ($paypal->isRecurring()) {
// handle as success
}
// else handle as failure
Arguments to Paypal::activateRecurring
| Parameter | Type | Description |
|---|---|---|
returnUrl | string | The URL the API leads the customer to after they finished entering payment information outside of the shop (for example, 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 or UnzerSDK\Resources\PaymentTypes\Paypal | 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 (for example, PayPal). This needs to be set to a valid URL, no matter whether a redirect is necessary or not. Required: true |
Registering Unzer Direct Debit
With Unzer Direct Debit recurring is activated automatically when a charge has been successful.
