Creating an Inline Session {#klarna-session-cr-in-intro}
========================================================

Create a new session whenever the customer displays your checkout page.

Inline Specifications
:
When you send a session request, set the apSessionService_paymentFlowMode field to `inline`. `Cybersource` responds with a pre-approval token in the processorInformation.token field. Set the Klarna widget installed in the merchant website to token. When the customer completes the checkout using the Klarna widget, the widget responds with an authorization token. Include the authorization token in the authorization request to link the authorization to the session.

Klarna Payment Methods
----------------------

When you request the session service, you can determine the Klarna payment method you want to offer your customers. Set the optional paymentInformation.paymentType.method.type request field to a value listed in the Payment Method column.

| Payment Method Field Value |                    Description                     |                                       Klarna Products                                       |
|----------------------------|----------------------------------------------------|---------------------------------------------------------------------------------------------|
| `pay_later`                | Customer pays total bill at a set date.            | * Klarna Invoice * Klarna Pay Later * Klarna Pay Later by Card (PLBC)                       |
| `pay_now`                  | Customer pays total bill at the time of checkout.  | * Klarna Direct Bank Transfer * Klarna Direct Debit                                         |
| `pay_over_time`            | Customer pays bill in equal multiple installments. | * Klarna Account * Klarna Financing * Klarna Fixed Installment Plans * Klarna Interest Free |
[Payment Methods]

Example: Payment Methods in Session Request
:

    ```
    {
      "paymentInformation": {
        "paymentType": {
          "method": {
            "type": "pay_later"
          }
        }
      }
    }
    ```

Calculating the Grand Total Amount
----------------------------------

Klarna requires that the grand total amount of a purchase be included in the request using the orderInformation.amountDetails.totalAmount field. The country of the transaction and the use of coupons affect how to calculate the grand total amount.  
For more information about how to calculate the grand total amount, see [Calculating the Grand Total Amount](/docs/cybs/en-us/klarna/developer/all/rest/klarna/klarna-reference-info/klarna-intro-total.md "") in the Reference Information section.

Language Specification {#klarna-session-cr-in-intro_language}
-------------------------------------------------------------

To set the language for your Klarna checkout experience, include the buyerInformation.language field in your request. By not including this field, the Klarna checkout experience is set to English by default. For a list of all possible values, see the [*ISO Standard Language Codes*](https://developer.cybersource.com/docs/cybs/en-us/language-codes/reference/all/na/language-codes/language-codes.md "") guide.

Example: Language Specification
:

    ```
    {
      "buyerInformation": {
        "language": "es"
      }
    }
    ```

Line Items
----------

Klarna uses line items when you send a create session and update session requests. [Line items](# "") are used to include information about the goods that your customers purchase, such as product name, quantity, and price.  
Line items are represented in a request as the lineItem\[\] array request fields.  
For more information about how to properly format line items in your request, see [Using Line Items](/docs/cybs/en-us/klarna/developer/all/rest/klarna/klarna-reference-info/klarna-intro-items.md "") in the Reference Information section.

Endpoints
---------

**Production:** `POST ``https://api.cybersource.com``/pts/v2/payment-references`  
**Test:** `POST ``https://apitest.cybersource.com``/pts/v2/payment-references`

Response Status
---------------

The session service responds with one of these statuses as the status field value:

* `FAILED`: The session request is not successful. Send a new session request.{#klarna-session-cr-in-intro_d11e234}
  {#klarna-session-cr-in-intro_d11e234}

* `INITIATED`: The session is initiated and the customer may now checkout. Send periodic check status requests until the status updates to `COMPLETED`. For more information, see [Check a Request Status](/docs/cybs/en-us/klarna/developer/all/rest/klarna/klarna-services/klarna-status-intro.md "").{#klarna-session-cr-in-intro_d11e239}
  {#klarna-session-cr-in-intro_d11e239} {#klarna-session-cr-in-intro_d11e232}  
  When you send a check status request for an initiated session, you can receive one of these statuses when the session updates:

* `ABANDONED`: The customer did not complete the payment using the redirect URL or widget.{#klarna-session-cr-in-intro_d11e255}
  {#klarna-session-cr-in-intro_d11e255}

* `COMPLETED`: The customer completed the checkout process. You can now authorize the funds.{#klarna-session-cr-in-intro_d11e260}
  {#klarna-session-cr-in-intro_d11e260}

Requesting to Create an Inline Session {#klarna-session-cr-task-inl}
====================================================================

Follow these steps to successfully create an inline session.

1. Send a` POST` request to the `https://apitest.cybersource.com/pts/v2/payment-references` endpoint and include these required fields:

   > IMPORTANT Do not send any personally identifiable information (PII) data about the customer in the request to create a session.

   [clientReferenceInformation.code](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/client-ref-info-aa/client-ref-info-code.md "")
   :

   [merchantInformation.cancelUrl](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/merch-info-aa/merch-info-cancel-url.md "")
   :

   [merchantInformation.failureUrl](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/merch-info-aa/merch-info-failure-url.md "")
   :

   [merchantInformation.successUrl](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/merch-info-aa/merch-info-success-url.md "")
   :

   [orderInformation.amountDetails.currency](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-amount-details-currency.md "")
   :

   [orderInformation.amountDetails.totalAmount](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-amount-details-total-amount.md "")
   :

   [orderInformation.billTo.country](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-bill-to-country.md "")
   :

   [orderInformation.lineItems\[\].productName](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-product-name.md "")
   :

   [orderInformation.lineItems\[\].quantity](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-quantity.md "")
   :

   [orderInformation.lineItems\[\].totalAmount](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-total-amount.md "")
   :

   [orderInformation.lineItems\[\].unitPrice](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-unit-price.md "")
   :

   paymentInformation.paymentType.method.name
   :
   Set to `KLARNA`.

   paymentInformation.paymentType.method.type
   :

   [paymentInformation.paymentType.name](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/payment-info-aa/payment-info-payment-type-name.md "")
   :
   Set to `INVOICE`.

   [processingInformation.actionList](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/processing-info-aa/processing-info-action-list.md "")
   :
   Set to `AP_SESSIONS`.

   processingInformation.paymentFlowMode
   :
   Set to `inline` to display the Klarna widget on your checkout page.

   Non-US Countries
   :   [orderInformation.lineItems\[\].taxAmount](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-tax-amount-request.md "")

   US and Canada
   :
   > IMPORTANT
   > The billing state and billing postal code fields are required when the billing country is set to ` US ` or ` CA `.

   :
   [orderInformation.amountDetails.taxAmount](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-amount-details-tax-amount.md "")
   :
   [orderInformation.billTo.administrativeArea](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-bill-to-admin-area.md "")
   :
   [orderInformation.billTo.postalCode](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-bill-to-postal-code.md "")

2. You can include these optional fields in the request:

   [buyerInformation.language](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/buyer-info-aa/buyer-info-language.md "")
   :
   > IMPORTANT If this field is not included, the language is set to English by default.

   :
   For a list of possible values, see the [*ISO Standard Language Codes*](https://developer.cybersource.com/docs/cybs/en-us/language-codes/reference/all/na/language-codes/language-codes.md "") guide.

   [clientReferenceInformation.code](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/client-ref-info-aa/client-ref-info-code.md "")
   :

   [orderInformation.amountDetails.discountAmount](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-amount-details-discount-amount.md "")
   :

   [orderInformation.amountDetails.totalAmount](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-amount-details-total-amount.md "")
   :

   [orderInformation.billTo.address1](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-bill-to-address1.md "")
   :

   [orderInformation.billTo.email](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-bill-to-email.md "")
   :

   [orderInformation.billTo.firstName](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-bill-to-first-name.md "")
   :

   [orderInformation.billTo.lastName](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-bill-to-last-name.md "")
   :

   [orderInformation.billTo.locality](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-bill-to-locality.md "")
   :

   orderInformation.lineItems\[\].productCode
   :

   orderInformation.lineItems\[\].productDescription
   :

   [orderInformation.lineItems\[\].unitPrice](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-unit-price.md "")
   :

   orderInformation.lineItems\[\].quantity
   :

   orderInformation.lineItems\[\].taxAmount
   :

   paymentInformation.paymentType.method.type
   :

   paymentInformation.type
   :

   processingInformation.sessionType
   :

3. To include an optional coupon in the request, include these fields:

   [orderInformation.lineItems\[\].productCode](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-product-code.md "")
   :
   Set to `coupon`.

   [orderInformation.lineItems\[\].productName](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-product-name.md "")
   :

   [orderInformation.lineItems\[\].productSku](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-product-sku.md "")
   :

   [orderInformation.lineItems\[\].quantity](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-quantity.md "")
   :

   [orderInformation.lineItems\[\].unitPrice](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/rest/api-fields/order-info-aa/order-info-line-items-unit-price.md "")
   :
   {#klarna-session-cr-task-inl_d8e456}

4. Set the Session Token ID in the Klarna widget to the processorInformation.token field value from the session response.

   ```
   IDeyJhbGciOiJSUzI1NiIsImtpZCI6IjgyMzA1ZWJjLWI4MTEtMzYzNy...
   ```
5. When the customer completes the payment using the Klarna widget, the Klarna widget creates a unique authorization token. Store the token for the authorization request.

   ```
   Authorizaiton Token: a6b2229c-665b-5660-a5fe-063bef3d9a1e
   ```
6. When you send the follow-on authorization request, set the processorInformation.preApprovalToken request field to the authorization token value created by the Klarna widget.

   ```
   {
     "processorInformation": {
       "preApprovalToken": "a6b2229c-665b-5660-a5fe-063bef3d9a1e"
     }
   }
   ```

Example: Create an Inline Session {#klarna-session-cr-in-ex-rest}
=================================================================

Request

```
{
    "merchantInformation": {
    "cancelUrl": "https://www.test0.com",
    "successUrl": "https://www.google.com",
    "failureUrl": "https://www.test1.com"
  },
    "orderInformation": {
        "billTo": {
            "firstName": "John",
            "lastName": "Smith",
            "address1": "123 Happy St",
            "locality": "Sunnyville",
            "administrativeArea": "CA",
            "postalCode": "55555",
            "country": "US",
            "email": "test email dot com"
        },
        "amountDetails": {
            "totalAmount": "1.00",
            "currency": "USD"
        },
        "lineItems": [
            {
                "productCode": "A4890B5023",
                "productName": "Skirt on the sky",
                "productSku": "skirtonsky$bluegreen",
                "quantity": "1",
                "unitPrice": "1.00",
                "totalAmount": "1.00",
                "taxAmount": "0.00",
                "productDescription": "Amnesiac Shirt"
            }
        ]
    },
    "paymentInformation": {
        "paymentType": {
            "name": "INVOICE",
            "method": {
                "name": "KLARNA",
                "type": "pay_now"
            }
        }
    },
    "processingInformation": {
        "actionList": "AP_SESSIONS",
        "paymentFlowMode": "inline",
        "sessionType": "N"
    }
}
```

Response to a Successful Request

```
{
    "_links": {
        "self": {
            "method": "POST",
            "href": "/pts/v2/payment-references"
        },
        "updateSession": {
            "method": "PATCH",
            "href": "/pts/v2/payment-references/7322957972776014303955"
        },
        "status": {
            "method": "POST",
            "href": "/pts/v2/refresh-payment-status/7322957972776014303955"
        },
        "order": {
            "method": "POST",
            "href": "/pts/v2/payment-references/7322957972776014303955/intents"
        }
    },
    "clientReferenceInformation": {
        "code": "1732295797319"
    },
    "id": "7322957972776014303955",
    "orderInformation": {
        "amountDetails": {
            "totalAmount": "1.00",
            "currency": "USD"
        }
    },
    "processorInformation": {
        "responseDetails": "00000",
        "responseCode": "00000",
        "token": "inline_session_token_value"
    },
    "reconciliationId": "XEKSO3R50AFW",
    "status": "COMPLETED",
    "submitTimeUtc": "2024-11-22T171638Z"
}
```

