Why is Klarna returning a 204 no content response when authorizing a purchase? - klarna

I'm following Klarna's direct integration documentation with the Klarna javascript SDK. I successfully create a payment session, the Klarna widget loads without issues as well.
However I get a 204 no content response when authorizing the purchase, instead of an authorization token or error code. Without the token I can't complete the purchase. This occurs with Klarnas example request which i've been using below. The Authorize call also doesn't appear in the merchant portal logs; while the create session call does.
Klarna.Payments.authorize({
payment_method_category: 'pay_over_time'
}, {
purchase_country: "GB",
purchase_currency: "GBP",
locale: "en-GB",
billing_address: {
given_name: "John",
family_name: "Doe",
email: "john#doe.com",
title: "Mr",
street_address: "13 New Burlington St",
street_address2: "Apt 214",
postal_code: "W13 3BG",
city: "London",
region: "",
phone: "01895808221",
country: "GB"
}, function(res) {
console.debug(res);
}
})

Related

How to retrieve client token with Klarna checkout

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.

Magento 2 API Create Order As guest: {"message":"\"%fieldName\" is required. Enter and try again.","parameters":{"fieldName":"email"}}

I'm trying to place an order via Magento 2 API as a guest, following the guidance shown here:
https://devdocs.magento.com/guides/v2.4/rest/tutorials/orders/order-create-order.html
The end point I'm using is:
https://[domain]/rest/V1/guest-carts/'.$quote_id.'/payment-information
with quote_id being the ID of the quote created initially
Steps 1-6 complete successfully with relevant response being returned as expected.
But sending the following payload (literally a copy and paste from the docs) to the above endpoint:
{
"paymentMethod": {
"method": "banktransfer"
},
"billing_address": {
"email": "jdoe#example.com",
"region": "New York",
"region_id": 43,
"region_code": "NY",
"country_id": "US",
"street": [
"123 Oak Ave"
],
"postcode": "10577",
"city": "Purchase",
"telephone": "512-555-1111",
"firstname": "Jane",
"lastname": "Doe"
}
}
Results in this error message:
{"message":""%fieldName" is required. Enter and try again.","parameters":{"fieldName":"email"}}
The email address IS obviously being supplied, and am really at a loss as to what's going wrong.
For info, the API this is being sent to is a vanilla install of Magento set up with a test product for testing purposes
Does anyone have any ideas, or at least some suggestions as to how I can debug given the not very usefulness of the error message given?
You are Sending POST Request so you also have to send data in POST request in json format like :{ ""id"": {}}
And have to set Content-Type:application/json in http header.

Google Analytics API - RemarketingAudiences.insert only working when linkedAdAccounts is AD_WORDS

I'm writing a Google Apps Script for creating audiences in Google Analytics. I keep getting the very unhelpful error message of There was an internal error.
As per [this guide][1], I am able to insert new audiences with the type AD_WORDS without issue. However my current task involves duplicating audiences of type ANALYTICS.
It seems that the linkedAdAccounts attribute of the resource I submit is incorrect. I can see that the official docs mention 3 possible options for the type: ADWORDS_LINKS, DBM_LINKS, MCC_LINKS or OPTIMIZE. Unfortunately, no detailed explanation is given for how these work other than ADWORDS_LINKS.
Here is the payload which is being rejected:
{
name: "newName",
linkedViews: ["123445677"],
linkedAdAccounts: [
{
kind: "analytics#linkedForeignAccount",
internalWebPropertyId: "12345678",
status: "OPEN",
remarketingAudienceId: "aaaaaaaaaaaaaaaaaaaaa",
id: "xxxxxxxxxxxxxxxxxxxxx",
webPropertyId: "UA-1234567-1",
type: "ANALYTICS",
accountId: "12345678",
},
],
audienceType: "SIMPLE",
audienceDefinition: {
includeConditions: {
daysToLookBack: 7,
segment: "users::condition::ga:sessionDuration>60",
membershipDurationDays: 30,
isSmartList: false,
},
},
}
It turns out you can't add an id for an ANALYTICS linkedAdAccount. Just adding the following is sufficient.
linkedAdAccounts: [
{
type: "ANALYTICS",
},
],

Swagger Format for PayPal Payment API

I'm new to OpenAPI and I need some help to create a basic swagger file for PayPal's payment API to create a payment from our platform. Note: OAuth is already configured.
Below is a basic swagger file but I don't know where to add the paymet request information (i.e. intent, payer, transactions etc.) into:
{
"swagger": "2.0",
"info": {
"description": "this is a payment request to through PayPal",
"title": "Swagger PayPal Payment",
"version": "1.0.0"
},
"host": "api.sandbox.paypal.com",
"basePath": "/v1/payments", //
"schemes": [ "https" ],
"paths": {
"/payment":
{
"post": {
"summary": "Creates a payment"
"description": "Creates a payment request to Paypal",
"parameters": {
},
//"intent": "sale",
//"payer":
//{
// "payment_method": "paypal"
//},
//"transactions": [
// {
// "amount": {
// "total": "9.00",
// "currency": "EUR"
// }
// }
//],
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
Testing the file on editor.swagger, I get an "OBJECT_ADDITIONAL_PROPERTIES" error on transactions, payer, and intent.
JSON payload is defined as a body parameter (parameter with in: body), and this parameter needs a schema that defines the JSON object properties.
You would typically define object schemas in the global definitions section and reference them using $ref.
Here is the YAML version for readability. To convert it to JSON, paste it into http://editor.swagger.io and use File > Download JSON.
swagger: "2.0"
info:
description: this is a payment request to through PayPal
title: Swagger PayPal Payment
version: "1.0.0"
host: api.sandbox.paypal.com
basePath: /v1/payments
schemes: [ https ]
paths:
/payment:
post:
summary: Creates a payment
description: Creates a payment request to Paypal
parameters:
- in: body
name: payment
required: true
schema:
$ref: "#/definitions/Payment" # <--------
responses:
"200":
description: OK
definitions:
# Request body object
Payment:
type: object
properties:
intent:
type: string
payer:
$ref: "#/definitions/Payer"
transactions:
type: array
items:
$ref: "#/definitions/Transaction"
Payer:
type: object
properties:
payment_method:
type: string
example: paypal
Transaction:
type: object
properties:
... # TODO

wso2 data mapper unable to parse the json

So I was trying to make a map for this json response but I am getting an error when I use the data mapper and load the json file from the file system.
I use the data mapper mediator to map it. Maybe there is another way to do this?
"Error occurred while opening file."
Reason: File content cannot be parsed.
here is the json
{
movie: [{
omdbapi: {
title: "The Legend of Tarzan",
id: "tt0918940",
runtime: "109 min",
year: 2016,
originaltitle: "The Legend of Tarzan",
plot: "Tarzan, having acclimated to life in London, is called back to his former home in the jungle to investigate the activities at a mining encampment.",
rating: "PG-13",
genre: "Action, Adventure",
director: "David Yates",
thumb: "http://ia.media-imdb.com/images/M/MV5BMzY3OTI0OTcyMF5BMl5BanBnXkFtZTgwNjkxNTAwOTE#._V1_SX300.jpg"
}
}, {
moviedbapi: {
adult: false,
backdrop_path: "/75GFqrnHMKqkcNZ2wWefWXfqtMV.jpg",
belongs_to_collection: null,
budget: 180000000,
genres: [{
name: "Action",
id: 28
}, {
name: "Adventure",
id: 12
}],
homepage: "http://legendoftarzan.com",
id: 258489,
imdb_id: "tt0918940",
original_language: "en",
original_title: "The Legend of Tarzan",
overview: "Tarzan, having acclimated to life in London, is called back to his former home in the jungle to investigate the activities at a mining encampment.",
popularity: 34.036008,
poster_path: "/6FxOPJ9Ysilpq0IgkrMJ7PubFhq.jpg",
production_companies: [{
name: "Dark Horse Entertainment",
id: 552
}, {
name: "Jerry Weintraub Productions",
id: 2596
}],
release_date: "2016-06-29",
revenue: 0,
runtime: 109,
spoken_languages: {
name: "English",
iso_639_1: "en"
},
status: "Released",
tagline: "Human. Nature.",
title: "The Legend of Tarzan",
video: false,
vote_average: 4.6,
vote_count: 501
}
}]
}
Your sample schema can be imported without an issue in new WSO2 ESB Tooling 5.0.0 Beta2. You can get released version from : https://github.com/wso2/devstudio-tooling-esb/releases/tag/v5.0.0-BETA2
There has been a significant amount of improvements done to Data Mapper mediator and tooling and it's best if you use the latest version.