> ## Documentation Index
> Fetch the complete documentation index at: https://adyen-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Billie via Klarna

> Accept Billie payments through a connection with Klarna.

Billie is a Berlin-based Buy Now Pay Later (BNPL) provider that specializes in providing open invoice and deferred payment options to Business-to-Business (B2B) customers. With Billie, merchants can accept invoice payments that are immediately settled in full.

Adyen offers Billie through a Klarna integration.

| Payment type | Payment flow | Countries | Currencies | [Recurring](https://adyen-preview.mintlify.site/online-payments/tokenization) | [Refunds](https://adyen-preview.mintlify.site/online-payments/refund.md) | [Partial refunds](https://adyen-preview.mintlify.site/online-payments/refund.md#refund-a-payment) | [Multiple partial refunds](https://adyen-preview.mintlify.site/online-payments/refund.md) | [Separate captures](https://adyen-preview.mintlify.site/online-payments/capture) | [Partial captures](https://adyen-preview.mintlify.site/online-payments/capture#partial-capture) | [Multiple partial captures](https://adyen-preview.mintlify.site/online-payments/capture#multiple-partial-captures) | [Chargebacks](https://adyen-preview.mintlify.site/risk-management/chargeback-guidelines) |
| - | - | - | - | - | - | - | - | - | - | - | - |
| Buy Now Pay Later | Redirect, Inline widget | International | Multiple | ![x](https://docs.adyen.com/user/data/smileys/emoji/x.png) | ![checkmark](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | ![checkmark](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | ![checkmark](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | ![checkmark](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | ![checkmark](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | ![checkmark](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | ![checkmark](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) |

## Requirements

| Requirement | Description |
| - | - |
| **Integration type** | Make sure that you have built your [Klarna integration](https://adyen-preview.mintlify.site/payment-methods/klarna) for the intended platform (Web, iOS, Android, React) and integration (API-only, Drop-in, Components). |
| **Setup steps** | Before you begin, [add Billie in your test Customer Area](https://adyen-preview.mintlify.site/payment-methods/add-payment-methods). |

## Required fields

Billie is an extension to a Klarna integration. Wherever you must specify `paymentMethod.type`, use **klarna\_b2b** to process a Billie payment.

Billie requires that your payment request includes the [shopperName](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-shopperName) object and the [company](https://docs.adyen.com/api-explorer/Checkout/latest/post/sessions#request-company) object, which contains details about the company you are invoicing:

| Parameter | Required | Description |
| - | - | - |
| `company.name` | ![-white\_check\_mark-](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | The company name. |
| `company.homepage` | | The company website's home page. |
| `company.registrationNumber` | ![-white\_check\_mark-](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | The company's registration number. Required for all countries except DE and AT. |
| `company.registryLocation` | | The country code where the company is located. Format: the two-letter [ISO-3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code. Exception: **QZ** (Kosovo). |
| `company.taxId` | | The company's tax ID. |
| `company.type` | | The company's type. For example, **GmbH** or **AB**. |

## Payment request and response

The following is a sample [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) request for Billie. Note the required `paymentMethod` and `company` objects:

**Sample Billie request**

```bash curl theme={null}
curl https://checkout-test.adyen.com/v72/payments \
-H 'x-api-key: ADYEN_API_KEY' \
-H 'content-type: application/json' \
-d '{
    "merchantAccount":"ADYEN_MERCHANT_ACCOUNT",
    "reference":"YOUR_ORDER_REFERENCE",
    "paymentMethod":{
       "type":"klarna_b2b",
    },
    "amount":{
       "currency":"EUR",
       "value": 50000
    },
    "shopperLocale":"de_DE",
    "countryCode":"DE",
    "telephoneNumber": "+49 840 839 298",
    "shopperEmail":"youremail@email.com",
    "shopperName":{
        "firstName":"Testperson-de",
        "lastName":"Approved"
    },
    "shopperReference":"YOUR_UNIQUE_SHOPPER_ID",
    "billingAddress":{
        "city":"Berlin",
        "country":"DE",
        "houseNumberOrName":"4",
        "postalCode":"10969",
        "street":"Charlottenstrasse"
    },
    "returnUrl":"https://your-company.example.com/?shopperOrder=12xy..",
    "company":{
        "homepage":"https://www.billie.io/",
        "name":"Billie GmbH",
        "registrationNumber":"HRB182428",
        "registryLocation":"DE",
        "taxId":"DE310295470",
        "type":"GmbH"
    },
    "lineItems":[
        {
           "quantity":"1",
           "taxPercentage":"2100",
           "description":"Hammer",
           "id":"Item #1",
           "amountIncludingTax":"20000",
           "productUrl": "URL_TO_PURCHASED_ITEM",
           "imageUrl": "URL_TO_PICTURE_OF_PURCHASED_ITEM"
       },
       {
           "quantity":"2",
           "taxPercentage":"2100",
           "description":"Nails",
           "id":"Item #2",
           "amountIncludingTax":"15000",
           "productUrl": "URL_TO_PURCHASED_ITEM",
           "imageUrl": "URL_TO_PICTURE_OF_PURCHASED_ITEM"
       }
   ]
}'
```

```java Java theme={null}
// Adyen Java API Library v25.0.0
import com.adyen.Client;
import com.adyen.enums.Environment;
import com.adyen.model.checkout.*;
import java.time.OffsetDateTime;
import java.util.*;
import com.adyen.model.RequestOptions;
import com.adyen.service.checkout.*;

Client client = new Client("ADYEN_API_KEY", Environment.TEST);

// Request objects
Amount amount = new Amount()
	.currency("EUR")
	.value(50000L);

LineItem lineItem1 = new LineItem()
	.quantity(1L)
	.taxPercentage(2100L)
	.imageUrl("URL_TO_PICTURE_OF_PURCHASED_ITEM")
	.description("Hammer")
	.id("Item #1")
	.amountIncludingTax(20000L)
	.productUrl("URL_TO_PURCHASED_ITEM");

LineItem lineItem2 = new LineItem()
	.quantity(2L)
	.taxPercentage(2100L)
	.imageUrl("URL_TO_PICTURE_OF_PURCHASED_ITEM")
	.description("Nails")
	.id("Item #2")
	.amountIncludingTax(15000L)
	.productUrl("URL_TO_PURCHASED_ITEM");

Name name = new Name()
	.firstName("Testperson-de")
	.lastName("Approved");

KlarnaDetails klarnaDetails = new KlarnaDetails()
	.subtype("sdk")
	.type(KlarnaDetails.TypeEnum.KLARNA_B2B);

Company company = new Company()
	.registrationNumber("HRB182428")
	.registryLocation("DE")
	.taxId("DE310295470")
	.name("Billie GmbH")
	.type("GmbH")
	.homepage("https://www.billie.io/");

BillingAddress billingAddress = new BillingAddress()
	.country("DE")
	.city("Berlin")
	.houseNumberOrName("4")
	.street("Charlottenstrasse")
	.postalCode("10969");

PaymentRequest paymentRequest = new PaymentRequest()
	.amount(amount)
	.telephoneNumber("+49 840 839 298")
	.shopperEmail("youremail@email.com")
	.reference("YOUR_ORDER_REFERENCE")
	.lineItems(Arrays.asList(lineItem1, lineItem2))
	.shopperName(name)
	.merchantAccount("ADYEN_MERCHANT_ACCOUNT")
	.countryCode("DE")
	.paymentMethod(new CheckoutPaymentMethod(klarnaDetails))
	.company(company)
	.shopperLocale("de_DE")
	.billingAddress(billingAddress)
	.returnUrl("https://your-company.example.com/?shopperOrder=12xy..")
	.shopperReference("YOUR_UNIQUE_SHOPPER_ID");

// Make the request
PaymentsApi service = new PaymentsApi(client);
PaymentResponse response = service.payments(paymentRequest, new RequestOptions().idempotencyKey("UUID"));
```

```php PHP theme={null}
// Adyen PHP API Library v17.4.0
use Adyen\Client;
use Adyen\Environment;
use Adyen\Model\Checkout\Amount;
use Adyen\Model\Checkout\LineItem;
use Adyen\Model\Checkout\Name;
use Adyen\Model\Checkout\CheckoutPaymentMethod;
use Adyen\Model\Checkout\Company;
use Adyen\Model\Checkout\BillingAddress;
use Adyen\Model\Checkout\PaymentRequest;
use Adyen\Service\Checkout\PaymentsApi;

$client = new Client();
$client->setXApiKey("ADYEN_API_KEY");
$client->setEnvironment(Environment::TEST);


// Request objects
$amount = new Amount();
$amount
	->setCurrency("EUR")
	->setValue(50000);

$lineItem1 = new LineItem();
$lineItem1
	->setQuantity(1)
	->setTaxPercentage(2100)
	->setImageUrl("URL_TO_PICTURE_OF_PURCHASED_ITEM")
	->setDescription("Hammer")
	->setId("Item #1")
	->setAmountIncludingTax(20000)
	->setProductUrl("URL_TO_PURCHASED_ITEM");

$lineItem2 = new LineItem();
$lineItem2
	->setQuantity(2)
	->setTaxPercentage(2100)
	->setImageUrl("URL_TO_PICTURE_OF_PURCHASED_ITEM")
	->setDescription("Nails")
	->setId("Item #2")
	->setAmountIncludingTax(15000)
	->setProductUrl("URL_TO_PURCHASED_ITEM");

$name = new Name();
$name
	->setFirstName("Testperson-de")
	->setLastName("Approved");

$checkoutPaymentMethod = new CheckoutPaymentMethod();
$checkoutPaymentMethod
	->setSubtype("sdk")
	->setType("klarna_b2b");

$company = new Company();
$company
	->setRegistrationNumber("HRB182428")
	->setRegistryLocation("DE")
	->setTaxId("DE310295470")
	->setName("Billie GmbH")
	->setType("GmbH")
	->setHomepage("https://www.billie.io/");

$billingAddress = new BillingAddress();
$billingAddress
	->setCountry("DE")
	->setCity("Berlin")
	->setHouseNumberOrName("4")
	->setStreet("Charlottenstrasse")
	->setPostalCode("10969");

$paymentRequest = new PaymentRequest();
$paymentRequest
	->setAmount($amount)
	->setTelephoneNumber("+49 840 839 298")
	->setShopperEmail("youremail@email.com")
	->setReference("YOUR_ORDER_REFERENCE")
	->setLineItems(array($lineItem1, $lineItem2))
	->setShopperName($name)
	->setMerchantAccount("ADYEN_MERCHANT_ACCOUNT")
	->setCountryCode("DE")
	->setPaymentMethod($checkoutPaymentMethod)
	->setCompany($company)
	->setShopperLocale("de_DE")
	->setBillingAddress($billingAddress)
	->setReturnUrl("https://your-company.example.com/?shopperOrder=12xy..")
	->setShopperReference("YOUR_UNIQUE_SHOPPER_ID");

$requestOptions['idempotencyKey'] = 'UUID';

// Make the request
$service = new PaymentsApi($client);
$response = $service->payments($paymentRequest, $requestOptions);
```

```cs C# theme={null}
// Adyen .net API Library v14.3.0
using Adyen;
using Environment = Adyen.Model.Environment;
using Adyen.Model;
using Adyen.Model.Checkout;
using Adyen.Service.Checkout;

var config = new Config()
{
    XApiKey = "ADYEN_API_KEY",
    Environment = Environment.Test
};
var client = new Client(config);

// Fill in your request objects
Amount amount = new Amount
{
	Currency = "EUR",
	Value = 50000
};

LineItem lineItem1 = new LineItem
{
	Quantity = 1,
	TaxPercentage = 2100,
	ImageUrl = "URL_TO_PICTURE_OF_PURCHASED_ITEM",
	Description = "Hammer",
	Id = "Item #1",
	AmountIncludingTax = 20000,
	ProductUrl = "URL_TO_PURCHASED_ITEM"
};

LineItem lineItem2 = new LineItem
{
	Quantity = 2,
	TaxPercentage = 2100,
	ImageUrl = "URL_TO_PICTURE_OF_PURCHASED_ITEM",
	Description = "Nails",
	Id = "Item #2",
	AmountIncludingTax = 15000,
	ProductUrl = "URL_TO_PURCHASED_ITEM"
};

Name name = new Name
{
	FirstName = "Testperson-de",
	LastName = "Approved"
};

KlarnaDetails klarnaDetails = new KlarnaDetails
{
	Subtype = "sdk",
	Type = KlarnaDetails.TypeEnum.KlarnaB2b
};

Company company = new Company
{
	RegistrationNumber = "HRB182428",
	RegistryLocation = "DE",
	TaxId = "DE310295470",
	Name = "Billie GmbH",
	Type = "GmbH",
	Homepage = "https://www.billie.io/"
};

BillingAddress billingAddress = new BillingAddress
{
	Country = "DE",
	City = "Berlin",
	HouseNumberOrName = "4",
	Street = "Charlottenstrasse",
	PostalCode = "10969"
};

PaymentRequest paymentRequest = new PaymentRequest
{
	Amount = amount,
	TelephoneNumber = "+49 840 839 298",
	ShopperEmail = "youremail@email.com",
	Reference = "YOUR_ORDER_REFERENCE",
	LineItems = new List<LineItem>{ lineItem1, lineItem2 },
	ShopperName = name,
	MerchantAccount = "ADYEN_MERCHANT_ACCOUNT",
	CountryCode = "DE",
	PaymentMethod = new CheckoutPaymentMethod(klarnaDetails),
	Company = company,
	ShopperLocale = "de_DE",
	BillingAddress = billingAddress,
	ReturnUrl = "https://your-company.example.com/?shopperOrder=12xy..",
	ShopperReference = "YOUR_UNIQUE_SHOPPER_ID"
};

// Make the request
var service = new PaymentsService(client);
var response = service.Payments(paymentRequest, requestOptions: new RequestOptions { IdempotencyKey = "UUID"});
```

```js NodeJS (JavaScript) theme={null}
// Adyen Node API Library v16.1.0
// Require the parts of the module you want to use
const { Client, CheckoutAPI } = require('@adyen/api-library');

// Initialize the client object
const client = new Client({apiKey: "YOUR_X_API_KEY", environment: "TEST"});

// Create the request object
const paymentRequest = {
  merchantAccount: "YOUR_MERCHANT_ACCOUNT",
  reference: "YOUR_ORDER_REFERENCE",
  paymentMethod: {
    type: "klarna_b2b",
  },
  amount: {
    currency: "EUR",
    value: 50000
  },
  shopperLocale: "de_DE",
  countryCode: "DE",
  telephoneNumber: "+49 840 839 298",
  shopperEmail: "youremail@email.com",
  shopperName: {
    firstName: "Testperson-de",
    lastName: "Approved"
  },
  shopperReference: "YOUR_UNIQUE_SHOPPER_ID",
  billingAddress: {
    city: "Berlin",
    country: "DE",
    houseNumberOrName: "4",
    postalCode: "10969",
    street: "Charlottenstrasse"
  },
  returnUrl: "https://your-company.example.com/?shopperOrder=12xy..",
  company: {
    homepage: "https://www.billie.io/",
    name: "Billie GmbH",
    registrationNumber: "HRB182428",
    registryLocation: "DE",
    taxId: "DE310295470",
    type: "GmbH"
  },
  lineItems: [ {
    quantity: "1",
    taxPercentage: "2100",
    description: "Hammer",
    id: "Item #1",
    amountIncludingTax: "20000",
    productUrl: "URL_TO_PURCHASED_ITEM",
    imageUrl: "URL_TO_PICTURE_OF_PURCHASED_ITEM"
  }, {
    quantity: "2",
    taxPercentage: "2100",
    description: "Nails",
    id: "Item #2",
    amountIncludingTax: "15000",
    productUrl: "URL_TO_PURCHASED_ITEM",
    imageUrl: "URL_TO_PICTURE_OF_PURCHASED_ITEM"
  } ]
}

// Make the request
const checkoutAPI = new CheckoutAPI(client);
const response = checkoutAPI.PaymentsApi.payments(paymentRequest, { idempotencyKey: "UUID" });
```

```go Go theme={null}
// Adyen Go API Library v9.2.0
import (
	"context"
	"github.com/adyen/adyen-go-api-library/v9/src/common"
	"github.com/adyen/adyen-go-api-library/v9/src/adyen"
	"github.com/adyen/adyen-go-api-library/v9/src/checkout"
)

client := adyen.NewClient(&common.Config{
    ApiKey:      "ADYEN_API_KEY",
    Environment: common.TestEnv,
})

// Fill in your request objects
amount := checkout.Amount{
	Currency: "EUR",
	Value: 50000,
}

lineItem1 := checkout.LineItem{
	Quantity: common.PtrInt64(1),
	TaxPercentage: common.PtrInt64(2100),
	ImageUrl: common.PtrString("URL_TO_PICTURE_OF_PURCHASED_ITEM"),
	Description: common.PtrString("Hammer"),
	Id: common.PtrString("Item #1"),
	AmountIncludingTax: common.PtrInt64(20000),
	ProductUrl: common.PtrString("URL_TO_PURCHASED_ITEM"),
}

lineItem2 := checkout.LineItem{
	Quantity: common.PtrInt64(2),
	TaxPercentage: common.PtrInt64(2100),
	ImageUrl: common.PtrString("URL_TO_PICTURE_OF_PURCHASED_ITEM"),
	Description: common.PtrString("Nails"),
	Id: common.PtrString("Item #2"),
	AmountIncludingTax: common.PtrInt64(15000),
	ProductUrl: common.PtrString("URL_TO_PURCHASED_ITEM"),
}

name := checkout.Name{
	FirstName: "Testperson-de",
	LastName: "Approved",
}

klarnaDetails := checkout.KlarnaDetails{
	Subtype: common.PtrString("sdk"),
	Type: "klarna_b2b",
}

company := checkout.Company{
	RegistrationNumber: common.PtrString("HRB182428"),
	RegistryLocation: common.PtrString("DE"),
	TaxId: common.PtrString("DE310295470"),
	Name: common.PtrString("Billie GmbH"),
	Type: common.PtrString("GmbH"),
	Homepage: common.PtrString("https://www.billie.io/"),
}

billingAddress := checkout.BillingAddress{
	Country: "DE",
	City: "Berlin",
	HouseNumberOrName: "4",
	Street: "Charlottenstrasse",
	PostalCode: "10969",
}

paymentRequest := checkout.PaymentRequest{
	Amount: amount,
	TelephoneNumber: common.PtrString("+49 840 839 298"),
	ShopperEmail: common.PtrString("youremail@email.com"),
	Reference: "YOUR_ORDER_REFERENCE",
	LineItems: []checkout.LineItem{
			lineItem1, lineItem2,
	},
	ShopperName: &name,
	MerchantAccount: "ADYEN_MERCHANT_ACCOUNT",
	CountryCode: common.PtrString("DE"),
	PaymentMethod: checkout.KlarnaDetailsAsCheckoutPaymentMethod(&klarnaDetails),
	Company: &company,
	ShopperLocale: common.PtrString("de_DE"),
	BillingAddress: &billingAddress,
	ReturnUrl: "https://your-company.example.com/?shopperOrder=12xy..",
	ShopperReference: common.PtrString("YOUR_UNIQUE_SHOPPER_ID"),
}

// Make the request
service := client.Checkout()
req := service.PaymentsApi.PaymentsInput().IdempotencyKey("UUID").PaymentRequest(paymentRequest)
res, httpRes, err := service.PaymentsApi.Payments(context.Background(), req)
```

```py Python theme={null}
# Adyen Python API Library v12.0.0
import Adyen

adyen = Adyen.Adyen()
adyen.client.xapikey = "ADYEN_API_KEY"
adyen.client.platform = "test" # The environment to use library in.

json_request = {
  "merchantAccount": "ADYEN_MERCHANT_ACCOUNT",
  "reference": "YOUR_ORDER_REFERENCE",
  "paymentMethod": {
    "type": "klarna_b2b",
  },
  "amount": {
    "currency": "EUR",
    "value": 50000
  },
  "shopperLocale": "de_DE",
  "countryCode": "DE",
  "telephoneNumber": "+49 840 839 298",
  "shopperEmail": "youremail@email.com",
  "shopperName": {
    "firstName": "Testperson-de",
    "lastName": "Approved"
  },
  "shopperReference": "YOUR_UNIQUE_SHOPPER_ID",
  "billingAddress": {
    "city": "Berlin",
    "country": "DE",
    "houseNumberOrName": "4",
    "postalCode": "10969",
    "street": "Charlottenstrasse"
  },
  "returnUrl": "https://your-company.example.com/?shopperOrder=12xy..",
  "company": {
    "homepage": "https://www.billie.io/",
    "name": "Billie GmbH",
    "registrationNumber": "HRB182428",
    "registryLocation": "DE",
    "taxId": "DE310295470",
    "type": "GmbH"
  },
  "lineItems": [ {
    "quantity": "1",
    "taxPercentage": "2100",
    "description": "Hammer",
    "id": "Item #1",
    "amountIncludingTax": "20000",
    "productUrl": "URL_TO_PURCHASED_ITEM",
    "imageUrl": "URL_TO_PICTURE_OF_PURCHASED_ITEM"
  }, {
    "quantity": "2",
    "taxPercentage": "2100",
    "description": "Nails",
    "id": "Item #2",
    "amountIncludingTax": "15000",
    "productUrl": "URL_TO_PURCHASED_ITEM",
    "imageUrl": "URL_TO_PICTURE_OF_PURCHASED_ITEM"
  } ]
}

result = adyen.checkout.payments_api.payments(request=json_request, idempotency_key="UUID")
```

```rb Ruby theme={null}
# Adyen Ruby API Library v9.1.0
require "adyen-ruby-api-library"

adyen = Adyen::Client.new
adyen.api_key = 'ADYEN_API_KEY'
adyen.env = :test # Set to "live" for live environment

request_body = {
  :merchantAccount => 'YOUR_MERCHANT_ACCOUNT',
  :reference => 'YOUR_ORDER_REFERENCE',
  :paymentMethod => {
    :type => 'klarna_b2b',
  },
  :amount => {
    :currency => 'EUR',
    :value => 50000
  },
  :shopperLocale => 'de_DE',
  :countryCode => 'DE',
  :telephoneNumber => '+49 840 839 298',
  :shopperEmail => 'youremail@email.com',
  :shopperName => {
    :firstName => 'Testperson-de',
    :lastName => 'Approved'
  },
  :shopperReference => 'YOUR_UNIQUE_SHOPPER_ID',
  :billingAddress => {
    :city => 'Berlin',
    :country => 'DE',
    :houseNumberOrName => '4',
    :postalCode => '10969',
    :street => 'Charlottenstrasse'
  },
  :returnUrl => 'https://your-company.example.com/?shopperOrder=12xy..',
  :company => {
    :homepage => 'https://www.billie.io/',
    :name => 'Billie GmbH',
    :registrationNumber => 'HRB182428',
    :registryLocation => 'DE',
    :taxId => 'DE310295470',
    :type => 'GmbH'
  },
  :lineItems => [ {
    :quantity => '1',
    :taxPercentage => '2100',
    :description => 'Hammer',
    :id => 'Item #1',
    :amountIncludingTax => '20000',
    :productUrl => 'URL_TO_PURCHASED_ITEM',
    :imageUrl => 'URL_TO_PICTURE_OF_PURCHASED_ITEM'
  }, {
    :quantity => '2',
    :taxPercentage => '2100',
    :description => 'Nails',
    :id => 'Item #2',
    :amountIncludingTax => '15000',
    :productUrl => 'URL_TO_PURCHASED_ITEM',
    :imageUrl => 'URL_TO_PICTURE_OF_PURCHASED_ITEM'
  } ]
}

result = adyen.checkout.payments_api.payments(request_body, headers: { 'Idempotency-Key' => 'UUID' })
```

```ts NodeJS (TypeScript) theme={null}
// Adyen Node API Library v16.2.0
// Require the parts of the module you want to use
import { Client, CheckoutAPI, Types } from "@adyen/api-library";

// Initialize the client object
const client = new Client({apiKey: "ADYEN_API_KEY", environment: "TEST"});

// Create the request objects
const amount: Types.checkout.Amount = {
	currency: "EUR",
	value: 50000
};

const lineItem1: Types.checkout.LineItem = {
	quantity: 1,
	taxPercentage: 2100,
	imageUrl: "URL_TO_PICTURE_OF_PURCHASED_ITEM",
	description: "Hammer",
	id: "Item #1",
	amountIncludingTax: 20000,
	productUrl: "URL_TO_PURCHASED_ITEM"
};

const lineItem2: Types.checkout.LineItem = {
	quantity: 2,
	taxPercentage: 2100,
	imageUrl: "URL_TO_PICTURE_OF_PURCHASED_ITEM",
	description: "Nails",
	id: "Item #2",
	amountIncludingTax: 15000,
	productUrl: "URL_TO_PURCHASED_ITEM"
};

const name: Types.checkout.Name = {
	firstName: "Testperson-de",
	lastName: "Approved"
};

const klarnaDetails: Types.checkout.KlarnaDetails = {
	subtype: "sdk",
	type: Types.checkout.KlarnaDetails.TypeEnum.KlarnaB2b
};

const company: Types.checkout.Company = {
	registrationNumber: "HRB182428",
	registryLocation: "DE",
	taxId: "DE310295470",
	name: "Billie GmbH",
	type: "GmbH",
	homepage: "https://www.billie.io/"
};

const billingAddress: Types.checkout.BillingAddress = {
	country: "DE",
	city: "Berlin",
	houseNumberOrName: "4",
	street: "Charlottenstrasse",
	postalCode: "10969"
};

const paymentRequest: Types.checkout.PaymentRequest = {
	amount: amount,
	telephoneNumber: "+49 840 839 298",
	shopperEmail: "youremail@email.com",
	reference: "YOUR_ORDER_REFERENCE",
	lineItems: [lineItem1, lineItem2],
	shopperName: name,
	merchantAccount: "ADYEN_MERCHANT_ACCOUNT",
	countryCode: "DE",
	paymentMethod: klarnaDetails,
	company: company,
	shopperLocale: "de_DE",
	billingAddress: billingAddress,
	returnUrl: "https://your-company.example.com/?shopperOrder=12xy..",
	shopperReference: "YOUR_UNIQUE_SHOPPER_ID"
};

// Make the request
const checkoutAPI = new CheckoutAPI(client);
const response = checkoutAPI.PaymentsApi.payments(paymentRequest, { idempotencyKey: "UUID" });
```

If you use the [inline widget](#widget), additionally include `paymentMethod.subtype`: **sdk**.

The response to your [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) request depends on which payment flow you are using:

* [Redirect](#redirect)
* [Inline widget](#widget)

### Redirect to Billie

If you use the default redirect flow, the shopper is redirected to Klarna to complete the payment. The response contains an `action` object with the information you need to redirect the shopper:

**Sample Billie response (redirect)**

```bash theme={null}
{
    "additionalData": {
        "pspref": "TXDMTP4PCTGLNK82",
        "klarnapayments.session_id": "85b820c2-9048...",
        "klarnapayments.client_token": "eyJhbGciOiJSUz..."
    },
    "pspReference": "TXDMTP4PCTGLNK82",
    "resultCode": "RedirectShopper",
    "action": {
        "paymentMethodType": "klarna_b2b",
        "url": "https://checkoutshopper-test.adyen.com...",
        "method": "GET",
        "type": "redirect"
    }
}
```

### Inline widget

To use the inline widget, your `/payments` request must include `paymentMethod.subtype`: **sdk**.

The shopper completes the payment in your checkout. The `/payments` response contains:

* `resultCode`: **Pending**
* `paymentData`: A value that you need to submit to the [/payments/details](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/details) endpoint later.
* `redirect`: Object containing a client token.

**Sample Billie response (widget)**

```bash theme={null}
{
   "resultCode":"Pending",
   "details":[
      {
         "key":"token",
         "type":"text"
      }
   ],
   "paymentData":"abcxyz...",
   "redirect":{
      "data":{
         "klarnapayments.client_token":"eyJhbGciOiJu ..."
      }
   }
}
```

## Test and go live

Test Billie in your Customer Area with the Billie sandbox.

## How do you want to integrate?

> [card] [Web](https://adyen-preview.mintlify.site/payment-methods/klarna/web)
>
> Use our pre-built UI solutions to add Billie to your website.

> [card] [iOS](https://adyen-preview.mintlify.site/payment-methods/klarna/ios)
>
> Use our pre-built UI solutions to add Billie to your iOS app.

> [card] [Android](https://adyen-preview.mintlify.site/payment-methods/klarna/android)
>
> Use our pre-built UI solutions to add Billie to your Android app.

> [card] [API-only](https://adyen-preview.mintlify.site/payment-methods/klarna/api-only)
>
> Use our pre-built UI solutions to add Billie to your API-only integration.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.