Payment Page

In order to use the Payment Page feature Payment page with the PHP SDK you need to 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 here Embedded Payment Page
  • or redirect your customer to the redirectURL to use the hosted Payment Page as shown here Hosted Payment Page
You can not initialize the Payment Page from your JavaScript
You need your private key to fetch the Payment Page ID and redirectUrl which can not be done from the front end since usage of the private key is prohibited in the frontend. The Payment Page has to be initialized with a server-to-server call (e. g. using this SDK).

Embedded Payment Page

$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')
        ->setShopName('My Test Shop')
        ->setTagline('We are selling goods.')
        ->setOrderId('OrderId')
        ->setInvoiceId('InvoiceId')
        ->setCard3ds(true)
        ->setEffectiveInterestRate(4.99)
        ->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 Payment Page ID
$payPageId = $paypage->getId();

// pass the tokenId to the frontend and render the Payment Page

// Note: you have to store the paymentId (e.g. in the checkout session) to be able to fetch the payment result later.
$paymentId = $paypage->getPaymentId();
var checkout = new window.checkout(response.paymentPageId);

// Initialize the Payment Page
checkout.init().then(function() {
    // On success open the dialogue
  checkout.open();

  // Add your event listeners for abort or success event
  checkout.abort(function() {
    $errorHolder.html('Transaction canceled by user.');
    $submitButton.attr("disabled", false);
  });

  checkout.success(function(data) {
    // redirect to your result handler
    window.location.href = 'https://your.return.url';
  });
}).catch(function(error) {
        // handle error on init
    $errorHolder.html(error.message);
    $submitButton.attr("disabled", false);
});
// your-return-controller

$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');

// fetch the payment to handle it according to its status
$payment = $unzer->fetchPayment($paymentId);

if ($payment->isCompleted()) {
    // The payment process has been successful.
    // You can create the order and show a success page.
} elseif ($payment->isPending()) {
    // In case of authorization this is normal since you will later charge the payment.
    // You can create the order with status pending payment and show a success page to the customer if you want.

    // In cases of redirection to an external service (e.g. 3D secure, PayPal, etc) it sometimes takes time for
    // the payment to update it's status. In this case it might be pending at first and change to cancel or success later.
    // Use the notification feature to stay informed about changes of the payment (e.g. cancel, success)
    // then you can cancel the order later or mark it paid as soon as the event is triggered.

    // In any case, the payment is not done when the payment is pending and you should not ship until it changes to success.
}
// If the payment is neither success nor pending something went wrong.
// In this case do not create the order.
// Redirect to an error page in your shop and show an error message if you want.
Use our JavaScript
To finish the web integration you will need a JavaScript file from Unzer. Please refer to the description here for further details.

Hosted Payment Page

$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('OrderId')
        ->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('InvoiceId')
        ->setCard3ds(true)
        ->setEffectiveInterestRate(4.99)
        ->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 (e.g. in the checkout session) to be able to fetch the payment result later.
$paymentId = $paypage->getPaymentId();
// your-return-controller

$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');

// fetch the payment to handle it according to its status
$payment = $unzer->fetchPayment($paymentId);

if ($payment->isCompleted()) {
    // The payment process has been successful.
    // You can create the order and show a success page.
} elseif ($payment->isPending()) {
    // In case of authorization this is normal since you will later charge the payment.
    // You can create the order with status pending payment and show a success page to the customer if you want.

    // In cases of redirection to an external service (e.g. 3D secure, PayPal, etc) it sometimes takes time for
    // the payment to update it's status. In this case it might be pending at first and change to cancel or success later.
    // Use the notification feature to stay informed about changes of the payment (e.g. cancel, success)
    // then you can cancel the order later or mark it paid as soon as the event is triggered.

    // In any case, the payment is not done when the payment is pending and you should not ship until it changes to success.
}
// If the payment is neither success nor pending something went wrong.
// In this case do not create the order.
// Redirect to an error page in your shop and show an message if you want.

Exclude payment types

In order to remove payment types from the Payment Page you can can pass along a list of the names of the payment types you want to be removed before calling $unzer->initPayPageCharge($paypage) or $unzer->initPayPageAuthorize($paypage).

$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');

// set mendatory 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());

// ...or set a list of excluded types
$paypage->setExcludeTypes([UnzerSDK\Resources\PaymentTypes\Card::getResourceName(), UnzerSDK\Resources\PaymentTypes\Giropay::getResourceName()]);