@mia-burton/klarna-node
Version:
A Node.js module for Klarna
55 lines (54 loc) • 2.12 kB
text/typescript
import { OrderInput, UrlsInput } from "../types"
import { PaymentSessionInput } from "../types/klarna"
import { Utils } from "../utils"
export class SessionBodyBuilder {
public build(order: OrderInput, urls: UrlsInput): PaymentSessionInput {
return {
acquiring_channel: 'ECOMMERCE',
billing_address: order.billingAddress ? {
city: order.billingAddress.city,
country: order.billingAddress.country,
email: order.billingAddress.email,
family_name: order.billingAddress.lastName,
given_name: order.billingAddress.firstName,
phone: order.billingAddress.phone,
postal_code: order.billingAddress.postalCode,
region: order.billingAddress.region,
street_address: order.billingAddress.streetAddress,
street_address2: order.billingAddress.streetAddress2,
} : {},
shipping_address: order.shippingAddress ? {
city: order.shippingAddress.city,
country: order.shippingAddress.country,
email: order.shippingAddress.email,
family_name: order.shippingAddress.lastName,
given_name: order.shippingAddress.firstName,
phone: order.shippingAddress.phone,
postal_code: order.shippingAddress.postalCode,
region: order.shippingAddress.region,
street_address: order.shippingAddress.streetAddress,
street_address2: order.shippingAddress.streetAddress2,
} : {},
locale: order.locale,
merchant_reference1: order.mertchantReference,
merchant_urls: {
confirmation: urls.confirmation,
authorization: urls.authorization,
notification: urls.notification,
push: urls.push
},
order_amount: Utils.formatPrice(order.amount),
order_lines: order.lines.map((line) =>{
return {
name: line.name,
total_amount: Utils.formatPrice(line.totalAmount),
quantity: line.quantity,
unit_price: Utils.formatPrice(line.unitPrice)
}
}),
purchase_country: order.country,
purchase_currency: order.currency,
intent: 'buy'
}
}
}