Client SDK

Client SDK

The Client SDK is a JavaScript library that shows Buckaroo payment widgets and buttons on your own page. Your server starts the payment, and the SDK handles the part in the customer's browser: it shows a QR code or button, opens the payment app on a mobile device, follows the status and sends the customer to your return URL.


What you can use it for

Payment methodWhat the SDK doesSDK module
BancontactShows a button that opens a QR code, or opens the Bancontact app on a mobile deviceBuckarooSdk.BancontactMobile
iDEAL QRShows a button that opens a QR codeBuckarooSdk.IdealQr
PayconiqShows a QR code, or opens the Payconiq app on a mobile deviceBuckarooSdk.Payconiq
PayPalShows the PayPal Express Checkout buttonsBuckarooSdk.PayPal

The same script also contains the modules for Apple Pay, Google Pay and Click to Pay. Those are described with the payment method itself, for example on the Apple Pay integration page.


Add the SDK

Load jQuery and then the SDK at the bottom of the <body> of your page:

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://checkout.buckaroo.nl/api/buckaroosdk/script"></script>

The SDK adds its own stylesheet to the page. All functions are available under BuckarooSdk.

  • The SDK needs jQuery 1.9 or higher, and it has no other dependencies
  • Always load the script from Buckaroo. Do not host or cache a copy, so that you stay in sync with updates

Language

The widget texts are Dutch by default. Add a language code to the script URL for English (en), French (fr) or Dutch (nl):

<script src="https://checkout.buckaroo.nl/api/buckaroosdk/script/en"></script>

How a QR payment works

  1. Start the payment on your server.
    Send the Pay request for the payment method. The response contains the transaction key in the Key field.
  2. Start the widget on your page.
    Call the initiate function of the payment method with a container and the transaction key.
  3. The customer pays.
    On a desktop the customer scans the QR code. On a mobile device, the SDK opens the payment app where the method supports it.
  4. The SDK redirects the customer.
    When the payment succeeds, fails or is cancelled, the SDK shows the result and sends the customer to your return URL after a few seconds.

Update your order from the push message, not from what the widget shows. The widget runs in the customer's browser, and the customer can close the page before the redirect.

Every initiate function takes these two arguments first:

ArgumentTypeDescription
Container selectorStringA query selector for the element the widget is added to, such as #bancontact
Transaction keyStringThe Key from the response to your server-side Pay request

Bancontact

<div id="bancontact"></div>

<script>
    $(function () {
        BuckarooSdk.BancontactMobile.initiate('#bancontact', 'YOUR_TRANSACTION_KEY');
    });
</script>

The SDK adds a button to the container. On a desktop, the button opens a popup with the QR code. On a mobile device, it opens the Bancontact app.

For a test transaction, the popup shows buttons to simulate a successful, failed or cancelled payment.


iDEAL QR

<div id="ideal-qr"></div>

<script>
    $(function () {
        BuckarooSdk.IdealQr.initiate('#ideal-qr', 'YOUR_TRANSACTION_KEY', false);
    });
</script>

The SDK adds a button to the container that opens a popup with the QR code.

ArgumentTypeDescription
ProcessingBooleanThe third argument. true if your iDEAL subscription is a processing subscription, otherwise false
InlineBooleanOptional fourth argument. true shows the QR code directly in the container, without the button and popup

Payconiq

<div id="payconiq"></div>

<script>
    $(function () {
        BuckarooSdk.Payconiq.initiate('#payconiq', 'YOUR_TRANSACTION_KEY');
    });
</script>

The SDK shows the QR code in the container. On a mobile device, it opens the Payconiq app.


Follow the status yourself

BancontactMobile.initiate and Payconiq.initiate take an optional callback as third argument. The SDK calls it on every status change.

BuckarooSdk.BancontactMobile.initiate('#bancontact', 'YOUR_TRANSACTION_KEY', function (status, params) {
    if (status === 'SUCCESS') {
        // params[0] is the URL the customer is redirected to
    }

    return true; // true: let the SDK redirect. false: handle the redirect yourself
});
StatusMeaning
WAITINGThe QR code is shown and waiting to be scanned. Bancontact only
PROCESSINGThe customer scanned the code and is completing the payment
SUCCESSThe payment succeeded
FAILEDThe payment failed
CANCELLEDThe payment was cancelled. Bancontact only

For SUCCESS, FAILED and CANCELLED, the SDK redirects the customer when your callback returns true. Return false to stay on the page and handle the next step yourself.


PayPal Express Checkout

With PayPal Express Checkout, the customer pays with PayPal straight from your product page or shopping cart.

Requirements

  • Your PayPal account is connected in Plaza under PayPal
  • One-off payments only

Show the buttons

<div id="paypal-container"></div>

<script>
    $(function () {
        BuckarooSdk.PayPal.initiate({
            containerSelector: '#paypal-container',
            buckarooWebsiteKey: 'YOUR_STORE_KEY',
            paypalMerchantId: 'YOUR_PAYPAL_MERCHANT_ID',
            currency: 'EUR',
            amount: 10.00,
            createPaymentHandler: createPayment,
            onSuccessCallback: function () {
                window.location.href = '/checkout/thank-you';
            },
            onErrorCallback: function (reason) {
                // show an error message
            },
            onCancelCallback: function () {
                // the customer closed the PayPal window
            },
        });
    });

    // Called after the customer approves the payment in PayPal
    function createPayment(data) {
        // Send the PayPal order ID to your server, which creates the PayPal Pay request at Buckaroo
        return fetch('/checkout/paypal', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ paypalOrderId: data.orderID }),
        }).then(function (response) {
            if (!response.ok) {
                throw new Error('Payment could not be created');
            }
        });
    }
</script>

Options

OptionRequiredTypeDescription
containerSelectorYesStringWhere the PayPal buttons are shown
buckarooWebsiteKeyYesStringYour Buckaroo store key
paypalMerchantIdYesStringYour PayPal merchant ID
currencyYesStringThe currency of the payment
amountYesNumberThe amount of the payment
createPaymentHandlerYesFunctionCalled with the PayPal approval data after the customer approves the payment. Create the PayPal Pay request on your server with the PayPal order ID, and return a Promise
onSuccessCallbackYesFunctionCalled when createPaymentHandler succeeds. Use it to send the customer to your confirmation page
onErrorCallbackNoFunctionCalled with the reason when PayPal reports an error or createPaymentHandler fails
onCancelCallbackNoFunctionCalled when the customer cancels in PayPal
onShippingChangeHandlerNoFunctionCalled with data and actions when the customer changes the shipping address in PayPal. Use it to update the shipping costs or reject an address
onInitCallbackNoFunctionCalled when the PayPal buttons are shown
onClickCallbackNoFunctionCalled when the customer clicks a PayPal button
invoiceIdNoStringYour invoice number for the PayPal order
intentNoStringAuthorize to reserve the amount and capture it later. Leave it out for a direct payment

The buckarooWebsiteKey option takes your store key.
The store key used to be called the website key, and the option kept its name.


Update the shipping costs

onShippingChangeHandler receives the same data and actions as the onShippingChange callback of the PayPal JavaScript SDK. This example rejects addresses outside the Netherlands and adds the shipping costs to the order:

var orderAmount = '10.00';
var shippingAmount = '4.95';

function onShippingChange(data, actions) {
    if (data.shipping_address.country_code !== 'NL') {
        return actions.reject();
    }

    return actions.order.patch([
        {
            op: 'replace',
            path: "/purchase_units/@reference_id=='default'/amount",
            value: {
                currency_code: 'EUR',
                value: (parseFloat(orderAmount) + parseFloat(shippingAmount)).toFixed(2),
                breakdown: {
                    item_total: { currency_code: 'EUR', value: orderAmount },
                    shipping: { currency_code: 'EUR', value: shippingAmount },
                },
            },
        },
    ]);
}


Did this page help you?