Extra merchant data

Providing Klarna with extra merchant data

In some cases, Klarna requires additional information regarding the customer and the purchase in order to make a correct risk assessment. 
In this tutorial you will learn what information Klarna requires, and how you can send it to Klarna.

 

Use cases

  • Airline Tickets - when creating an order to sell an airline ticket, information about the passenger and itinerary to be booked should be provided to Klarna.
  • Event sales merchant - when creating an order for selling a ticket to an event, information about the event should be provided to Klarna.
  • Recurring orders - when creating an order for subscriptions or recurring payments, subscription and customer account information should be provided to Klarna.

 

1. Create the extra merchant data

Add the relevant data, based on the specification and your product vertical. To know which product vertical is right for you, please contact your integration sales representative.

The example below relates to recurring orders, which requires the subscription and customer_account_info details.

const EMD_FORMAT = 'Y-m-d\TH:m:s\Z';

$emd = [
    "subscription" => [
        [
            "subscription_name" => "Test Testperson",
            "start_time" => (new DateTime())->format(EMD_FORMAT),
            "end_time" => (new DateTime())->modify('+12 months')->format(EMD_FORMAT),
            "auto_renewal_of_subscription" => false
        ]
    ],
    "customer_account_info" => [
        [
            "unique_account_identifier" => "user@example.com",
            "account_registration_date" => (new DateTime())->format(EMD_FORMAT),
            "account_last_modified" => (new DateTime())->format(EMD_FORMAT)
        ]
    ]
];
final List<Subscription> subscription = new ArrayList<Subscription>() {
    {
        add(new Subscription()
                .setSubscriptionName("One year monthly recurring payments")
                .setStartTime(DateTime.now())
                .setEndTime(DateTime.now().plusMonths(12))
                .setAutoRenewalOfSubscription(false));
    }
};

final List<CustomerAccountInformation> customerInfo = new ArrayList<CustomerAccountInformation>() {
    {
        add(new CustomerAccountInformation()
                .setUniqueAccountIdentifier("user@example.com")
                .setAccountRegistrationDate(DateTime.now())
                .setAccountLastModified(DateTime.now()));
    }
};

final ExtraMerchantDataBody extraMerchantDataBody = new ExtraMerchantDataBody() {
    {
        setSubscription(subscription);
        setCustomerAccountInfo(customerInfo);
    }
};

final ExtraMerchantData extraMerchantData = new ExtraMerchantData() {
    {
        setBody(extraMerchantDataBody);
    }
};
List<Subscription> subscription = new List<Subscription>
{
    new Subscription
    {
        SubscriptionName = "One year monthly recurring payments",
        StartTime = DateTime.Now,
        EndTime = DateTime.Now.AddMonths(12),
        AutoRenewalOfSubscription  = False
    }
};

List<CustomerAccountInformation> customerInfo = new List<CustomerAccountInformation>
{
    new CustomerAccountInformation
    {
        UniqueAccountIdentifier = "user@example",
        AccountRegistrationDate = DateTime.Now,
        AccountLastModified = DateTime.Now
    }
};

ExtraMerchantData extraMerchantData = new ExtraMerchantData
{
    Body = new ExtraMerchantDataBody
    {
        Subscription = subscription,
        CustomerAccountInfo = customerInfo
    }
};

2. Attach the data to the order

Once the data is created, you would need to include it under the attachment property. Once it is populated simply send the data as you learned in the Embed the checkout tutorial.

$orderData['attachment'] = [
    "content_type" => "application/vnd.klarna.internal.emd-v2+json",
    "body" => json_encode($emd)
];
orderData.setAttachment(extraMerchantData.toAttachment());
orderData.Attachment = extraMerchantData;

Note: Find out more about the different data fields by checking the attachments specification.