Created with Sketch.
Created with Sketch.

How to get started

On this page you will find information about how to authenticate with the Checkout 3.0 Backend API, construct the authentication header and how to Initialize payment.


API Authentication

Base URLs

Avarda base URLs for Checkout 3.0 Backend API:

Stage environment: https://avdonl-s-checkout.avarda.org

Production environment: https://avdonl-p-checkout.avarda.org

Obtain Partner access token

“Partner access token” is used as authentication for all further communication with the Checkout 3.0 Backend API. This token should never be displayed to the user or sent to the frontend of the application.

To obtain the token send POST request with clientId and clientSecret as a JSON to /api/partner/tokens.

# Obtain Partner access token
GET {api_url}/api/partner/tokens
Content-type: application/json

{
  "clientId": "659e57c9-d970-4db8-b003-8ba04cc157f9",
  "clientSecret": "4~{x*6%gvBt(:aD"
}

Payload:

PropertyData type
clientIdstring
clientSecretstring

Example

<?php
$api_url = "https://avdonl-s-checkout.avarda.org";
// Use your CLIENT_ID and CLIENT_SECRET
$client_id = "659e57c9-d970-4db8-b003-8ba04cc157f9";
$client_secret = "4~{x*6%gvBt(:aD";

// Send POST request and save "Partner access token"
$request_url = "$api_url/api/partner/tokens";
$request_payload = array('clientId' => $client_id, 'clientSecret' => $client_secret);

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\n",
        'method'  => 'POST',
        'content' => json_encode($request_payload)
    )
);

$context = stream_context_create($options);
$result = file_get_contents($request_url, false, $context);
if ($result === false) { /* Handle error */
} else {
    $json_data = json_decode($result);
    $partner_access_token = $json_data->token;
    echo (string) $partner_access_token;
};

Return Value

{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSIsImtpZCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSJ9.eyJhdWQiOiIwMDAwMDAwMi0w..."
}

Initialize payment

Initialize payment and set up initial parameters such as: language; items list; etc. Please check the full list of options below.

Send a POST request with “Partner access token” as authorization with JSON data. Successful initialization returns a unique “Purchase JWT token” and “PurchaseId”. “Purchase JWT token” is used to display Checkout 3.0 form on the frontend of your application. “PurchaseId” is used in other Checkout 3.0 Backend API calls.

# Initialize a new payment
POST {api_url}/api/partner/payments
Content-type: application/json
Authorization: Bearer {partner_access_token}

{
  "language": "English",
  "items": [
    {
      "description": "Test Item Description",
      "notes": "Additional Notes",
      "amount": 50,
      "taxCode": "20",
      "taxAmount": 10
    }
  ]
}

Payload

PropertyData typeDescription
languageenumLanguage which application should be displayed in.
Supported values: English/Swedish/Finnish/Norwegian/Estonian/Danish
Default value: English
items[]List of item objects
orderReferencestringPartner custom ID reference.
phonestringCustomer’s phone number to be pre-filled in the form.
emailstringCustomer’s E-mail to be pre-filled in the form.
invoicingAddress.firstNamestringFirst name to be pre-filled for invoicing address.
invoicingAddress.lastNamestringLast name to be pre-filled for invoicing address.
invoicingAddress.address1stringFirst line of invoicing address to be pre-filled.
invoicingAddress.address2stringSecond line of invoicing address to be pre-filled.
invoicingAddress.zipstringZip to be pre-filled for invoicing address.
invoicingAddress.citystringCity to be pre-filled for invoicing address.
deliveryAddress.countrystringCountry to be pre-filled for delivery address.
deliveryAddress.firstNamestringFirst name to be pre-filled for delivery address.
deliveryAddress.lastNamestringLast name to be pre-filled for delivery address.
deliveryAddress.address1stringFirst line of the delivery address to be pre-filled.
deliveryAddress.address2stringSecond line of the delivery address to be pre-filled.
deliveryAddress.zipstringZip to be pre-filled for delivery address.
deliveryAddress.citystringCity to be pre-filled for delivery address.
loyaltyNumberstringCan be a number of a customer’s membership card.
productGroupstringString that defines the product category.
selectedPaymentMethodenumPayment method that will be selected by default.
Supported values: Loan/Invoice/Card/Direct/PayPal/Swish/PartPayment/PayOnDelivery
recurringPaymentsenumIndicates whether to show recurring payments checkbox and its default state.
Supported values: Hidden/Checked/Unchecked
newsleterSubscriptionenumIndicates whether to show newsletter subscription checkbox and its default state.
Supported values: Hidden/Checked/Unchecked
emailInvoiceenumIndicates whether to show email invoice checkbox and its default state.
Supported values: Hidden/Checked/Unchecked

Item

PropertyData typeDescription
customerDetails{}Object
emailstringcustomer contact email
phonestringCustomer contact phone
ZipstringCustomer Zipcode
StreetstringCustomer street address
CitystringCustomer city

Example

<?php
$api_url = "https://avdonl-s-checkout.avarda.org";
// "Partner access token" generated by calling `$api_url/api/partner/tokens` see more info: <https://docs.avarda.com/?post_type=checkout30&p=1552#accessToken-obtaining>
$partner_access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSIsImtpZCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSJ9.eyJhdWQiOiIwMDAwMDAwMi0wMDAwLTAwMDAtYzAw...";

// Send POST request, save "Purchase JWT token" and "PurchaseId"
$request_url = "$api_url/api/partner/payments";
$request_payload = array(
    "language" => "English", "items" => array(array(
        "description" => "Test Item Description",
        "notes" => "Additional Notes",
        "amount" => 50,
        "taxCode" => "20",
        "taxAmount" => 10
    )),
);

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: Bearer $partner_access_token\r\n",
        'method'  => 'POST',
        'content' => json_encode($request_payload)
    )
);
$context = stream_context_create($options);
$init_result = file_get_contents($request_url, false, $context);
if ($init_result === false) { /* Handle error */
} else {
    $init_data = json_decode($init_result);
    $purchase_jwt_token = $init_data->jwt;
    $purchase_id = $init_data->purchaseId;
    echo (string) $purchase_id;
    echo (string) $purchase_jwt_token;
}

Return Value

{
    "purchaseId": "AVT3gn",
    "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJDaGVja291dCIsImp0aSI6IjljZGRhZWI4LWU1N2UtNGIwNC04ZDdjLTBjODc0YTA1MDY2MyIsIlB1cmNoYXNlSWQiOiJBVlQzZ24iLCJleHAiOjE1Nzg5MTE0OTh9.HMRidZgeOQtOQtXyHwanmfS0KwYXb73m5lkTeQ449co"
}