Payment Page

In order to use the Payment Page Feature Payment page with the PHP SDK you need to create a PayPage object and initialize it with the heidelpay facade.

As a result you get a token id and a redirectURL which can be used to show the PayPage:

  • use the token 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
Don't attempt to initialize the Payment Page from your JavaScript
You need your private key to fetch the tokenId/redirectUrl which should not be done in the front end since it would make the private key visible for everybody using your shop. The payment page should always be initialized with a server-2-server call (e. g. using the PHP SDK).

Embedded Payment Page

$heidelpay = new \heidelpayPHP\Heidelpay('s-priv-xxxxxxxxxx');

// set mendatory parameters
$paypage = new \heidelpayPHP\Resources\PaymentTypes\Paypage(100.0, 'EUR', 'https://route.to-your-return-controller.de');

// set optional parameters
$paypage->setLogoImage('https://dev.heidelpay.com/devHeidelpay_400_180.jpg')
                ->setShopName('My Test Shop')
        ->setTagline('Try and stop us from being awesome!')
        ->setOrderId('My Unique OrderId')
        ->setInvoiceId('My_Unique_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 ...
$heidelpay->initPayPageCharge($paypage);

// ... or init payment page to authorize transaction
$heidelpay->initPayPageAuthorize($paypage);

// get the token
$tokenId = $paypage->getId();

// pass the tokenId to the frontend and render the Payment Page
// you have to store the paymentId (e.g. in the checkout session) to fetch the payment result later on
$paymentId = $paypage->getPaymentId();
var checkout = new window.checkout(response.token);
// 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 result handler
    window.location.href = 'https://route.to-your-return-controller.de';
  });
}).catch(function(error) {
        // handle error on init
    $errorHolder.html(error.message);
    $submitButton.attr("disabled", false);
});
// your-return-controller

$heidelpay = new \heidelpayPHP\Heidelpay('s-priv-xxxxxxxxxx');

// fetch the payment to handle it according to its status
$payment = $heidelpay->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 webhooks 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 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.
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

$heidelpay = new \heidelpayPHP\Heidelpay('s-priv-xxxxxxxxxx');

// set mendatory parameters
$paypage = new \heidelpayPHP\Resources\PaymentTypes\Paypage(100.0, 'EUR', 'https://route.to-your-return-controller.de');

// set optional parameters
$paypage->setLogoImage('https://dev.heidelpay.com/devHeidelpay_400_180.jpg')
            ->setFullPageImage('https://www.heidelpay.com/fileadmin/content/header-Imges-neu/Header_Phone_12.jpg')
            ->setShopName('My Test Shop')
            ->setShopDescription('Best shop in the whole world!')
            ->setTagline('Try and stop us from being awesome!')
            ->setOrderId('My unique OrderId')
            ->setTermsAndConditionUrl('https://www.heidelpay.com/en/')
            ->setPrivacyPolicyUrl('https://www.heidelpay.com/de/')
            ->setImprintUrl('https://www.heidelpay.com/it/')
            ->setHelpUrl('https://www.heidelpay.com/at/')
            ->setContactUrl('https://www.heidelpay.com/en/about-us/about-heidelpay/')
            ->setInvoiceId('My_unique_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 ...
$heidelpay->initPayPageCharge($paypage);

// ... or init payment page to authorize transaction
$heidelpay->initPayPageAuthorize($paypage);

// get the token
$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
// your-return-controller

$heidelpay = new \heidelpayPHP\Heidelpay('s-priv-xxxxxxxxxx');

// fetch the payment to handle it according to its status
$payment = $heidelpay->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 webhooks 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 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 Pay Page you can can pass along a list of the names of the payment types you want to be removed before calling $heidelpay->initPayPageCharge($paypage) or $heidelpay->initPayPageAuthorize($paypage).f

$heidelpay = new \heidelpayPHP\Heidelpay('s-priv-xxxxxxxxxx');

// set mendatory parameters
$paypage = new \heidelpayPHP\Resources\PaymentTypes\Paypage(100.0, 'EUR', 'https://route.to-your-return-controller.de');

// add a single payment type to exclude list
$paypage->addExcludeType(Card::getResourceName());

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