Manage payment page
Manage payment pages
Overview
To be able use the Payment Page integration with the PHP SDK, you must create a Paypage
instance and initialize it using the Unzer
object. As a result you get an ID and a redirectURL
which can be used to show the Payment Page:
- Use the Payment Page ID to render the embedded Payment Page as described in Embedded Payment Page guide.
- Or redirect your customer to the
redirectURL
to use the hosted Payment Page as shown in the Hosted Payment Page guide.
Initialize a Payment Page
To initialize a payment page, you require at least an amount
, a currency
and the returnUrl
.
Optional parameter for the API request can be added to your paypage
instance using the setter function of the given property as demonstrated in the example below.
For a full list of parameters, see the API reference guide.
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
// set mendatory parameters
$paypage = new UnzerSDK\Resources\PaymentTypes\Paypage(100.0, 'EUR', 'https://your.return.url');
// set optional parameters
$paypage->setLogoImage('https://your.logo.image.url')
->setFullPageImage('https://your.full.page.image.url')
->setShopName('My Test Shop')
->setShopDescription('We are selling goods.')
->setTagline('We are selling goods.')
->setOrderId('YourShopOrderId')
->setTermsAndConditionUrl('https://your.tac.url')
->setPrivacyPolicyUrl('https://your.privacy.policy.url')
->setImprintUrl('https://your.imprint.url')
->setHelpUrl('https://your.help.url')
->setContactUrl('https://your.contact.url')
->setInvoiceId('YourShopInvoiceId')
->setCard3ds(true)
->setEffectiveInterestRate(4.99)
->setExemptionType(\UnzerSDK\Constants\ExemptionType::LOW_VALUE_PAYMENT)
->setCss([
'shopDescription' => 'color: purple',
'header' => 'background-color: red',
'helpUrl' => 'color: blue',
'contactUrl' => 'color: green',
]);
// init payment page to charge transaction ...
$unzer->initPayPageCharge($paypage);
// ... or init payment page to authorize transaction
$unzer->initPayPageAuthorize($paypage);
// get the redirectURL
$redirectUrl = $paypage->getRedirectUrl();
// redirect the customer to the redirectUrl
// after finishing the payment there the customer will be redirected to the returnUrl you set via the Payment Page constructor
// Note: you have to store the paymentId (for example, in the checkout session) to be able to fetch the payment result later.
$paymentId = $paypage->getPaymentId();
Arguments to Paypage::__construct
Parameter | Type | Description |
---|---|---|
amount | float | The amount to be charged Required: true |
currency | string | The currency of the amount. Required: true |
returnUrl | string | The URL the customer will be redirected to after a transaction. This needs to be set to a valid URL, no matter whether a redirect is necessary or not. Required: true |
Exclude payment types
To exclude specific payment types from the payment page, pass their list before calling $unzer->initPayPageCharge($paypage)
or $unzer->initPayPageAuthorize($paypage)
.
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
// set mandatory parameters
$paypage = new UnzerSDK\Resources\PaymentTypes\Paypage(100.0, 'EUR', 'https://your.return.url');
// add a single payment type to exclude list
$paypage->addExcludeType(UnzerSDK\Resources\PaymentTypes\Card::getResourceName());
$paypage->addExcludeType(UnzerSDK\Resources\PaymentTypes\Paypal::getResourceName());
// ...or set a list of excluded types
$paypage->setExcludeTypes([
UnzerSDK\Resources\PaymentTypes\Card::getResourceName(),
UnzerSDK\Resources\PaymentTypes\Paypal::getResourceName()
]);
// ...
Additional Attributes
In PHP SDK, you can set additional attributes either with a direct setter for specific use cases or you can call the general setter for adding additional attributes.
If you want to learn more about the use cases of additionalAttributes
, see Additional attributes list.
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
// set mandatory parameters
$paypage = new UnzerSDK\Resources\PaymentTypes\Paypage(
100.0,
'EUR',
'https://your.return.url'
);
// set additional attributes with direct setters.
$paypage->setExemptionType(\UnzerSDK\Constants\ExemptionType::LOW_VALUE_PAYMENT)
->setRecurrenceType(\UnzerSDK\Constants\RecurrenceTypes::UNSCHEDULED)
->setEffectiveInterestRate(3.99);
// ...
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
// set mandatory parameters
$paypage = new UnzerSDK\Resources\PaymentTypes\Paypage(
100.0,
'EUR',
'https://your.return.url'
);
// Set additional attributes via key value pair.
$paypage->setAdditionalAttribute('myAttributeName', 'mayValue');
// ...
Arguments to Paypage::setAdditionalAttribute
Parameter | Type | Description |
---|---|---|
attribute (required) | string | Name of the attribute. |
value (required) | mixed | Value for the given key. |
Fetch a Payment Page
You can feth a payment page using the paypageId.
$unzer = new Unzer('s-priv-xxxxxxxxxx');
$unzer->fetchPayPage('s-ppg-xxxxxxxxxxxx');
Arguments to Paypage::fetchPayPage
Parameter | Type | Description |
---|---|---|
payPage (required) | Paypage | string | The paypage object or the ID of a paypage. |