0

I am trying to integrate Klarna as an additional payment option to an existing eCommerce website that has been custom built. I have trialed the json script in Postman and have received the correct response. I now want to transfer this over to the actual site but can't figure out how I can retrieve the client token from the response which I subsequently need to create the widget in the next step.

JSON Script below:

POST /payments/v1/sessions
Authorization: Basic pwhcueUff0MmwLShJiBE9JHA==
Content-Type: application/json

{
  "purchase_country": "GB",
  "purchase_currency": "GBP",
  "locale": "en-GB",
  "order_amount": 1000,
  "order_tax_amount": 0,
  "order_lines": [{
    "type": "physical",
    "name": "Shirt",
    "quantity": 1,
    "unit_price": 1000,
    "tax_rate": 0,
    "total_amount": 1000,
    "total_tax_amount": 0

  }]
}

Correct Response from Klarna:

HTTP/1.1 200 OK
Content-Type: application/json

{
"session_id": "068df369-13a7-4d47-a564-62f8408bb760",
"client_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAwMDAwMDAwMDAtMDAwMDAtMDAwMC0wMDAwMDAwMC0wMDAwIiwidXJsIjoiaHR0cHM6Ly9jcmVkaXQtZXUua2xhcm5hLmNvbSJ9.A_rHWMSXQN2NRNGYTREBTkGwYwtm-sulkSDMvlJL87M",
"payment_method_categories": [{
    "identifier": "pay_later"
    "name" : "Buy now, pay later",
    "asset_urls" : {
      "descriptive" : "https://x.klarnacdn.net/payment-method/assets/badges/generic/klarna.svg",
      "standard" : "https://x.klarnacdn.net/payment-method/assets/badges/generic/klarna.svg"
    }
}]

How can I retrieve the information above like the client_token from the server? I was thinking using GET but not certain I am on the right track. Any help would be really appreciated.

tripleee
  • 175,061
  • 34
  • 275
  • 318

0 Answers0