data-src=../../../../includes/paas-only.md
createKlarnaPaymentsSession mutation
data-variant=info
data-slots=text
The createKlarnaPaymentsSession mutation initiates a Klarna session. You can create a session at any time before you display the available payment methods, but ideally, the cart would already contain products, the billing address, shipping address, and shipping method. If the cart changes afterward, you must run the mutation again to ensure that the latest payment methods are made available to the shopper. Factors such as the cart contents, the shipping and billing addresses, and the grand total after applying coupons can determine the payment methods Klarna offers.
The mutation response includes an array of payment method categories. When the shopper selects a Klarna payment method, prepend the string klarna_ to the selected identifer, and use the resulting string as the payment_method.code value in the subsequent setPaymentMethodOnCart mutation. For example, if the shopper selects the "Pay later in 30 days" payment method, the identifier value is pay_later, and the payment_method.code value is klarna_pay_later.
The response also contains a client token. You must also supply this value in the setPaymentMethodOnCart mutation.
Klarna payment method provides additional information about the workflow of Klarna transactions.
Syntax
mutation {
createKlarnaPaymentsSession(
input: createKlarnaPaymentsSessionInput!
) {
createKlarnaPaymentsSessionOutput
}
}
Example usage
Request:
mutation {
createKlarnaPaymentsSession(
input: {
cart_id: "VaP2GtqImwsTEXEf7azrh4vopebXp8gl"}
) {
client_token
payment_method_categories {
identifier
name
}
}
}
Response:
{
"data": {
"createKlarnaPaymentsSession": {
"client_token": "<token_value>",
"payment_method_categories": [
{
"identifier": "pay_later",
"name": "Pay later in 30 days"
},
{
"identifier": "pay_over_time",
"name": "Buy now, pay later"
}
]
}
}
}
Input attributes
createKlarnaPaymentsSessionInput attributes
The createKlarnaPaymentsSessionInput object must contain the following attribute.
cart_idOutput attributes
createKlarnaPaymentsSessionOutput attributes
The createKlarnaPaymentsSessionOutput object can contain the following attributes.
client_tokenpayment_method_categoriesCategories attributes
The Categories object can contain the following attributes.
asset_urlsidentifiernameAssets attributes
The Assets object can contain the following attributes.
descriptivestandardErrors
The Klarna payment method is not active.