fix(medusa, medusa-payment-paypal): Add missing data in Payment Collection input (#3010)

This commit is contained in:
Adrien de Peretti
2023-01-13 16:26:39 +01:00
committed by GitHub
parent 8221e089b8
commit 142c8aa70f
8 changed files with 140 additions and 21 deletions
@@ -41,6 +41,26 @@ describe("KlarnaProviderService", () => {
order_amount: 100,
})
})
it("creates Klarna order using new API", async () => {
const result = await klarnaProviderService.createPayment({
email: "",
context: {},
shipping_methods: [],
shipping_address: null,
id: "",
region_id: carts.frCart.region_id,
total: carts.frCart.total,
resource_id: "resource_id",
currency_code: carts.frCart.region.currency_code,
amount: carts.frCart.total
})
expect(result).toEqual({
order_id: "123456789",
order_amount: 100,
})
})
})
describe("retrievePayment", () => {
@@ -152,6 +172,30 @@ describe("KlarnaProviderService", () => {
order_id: "123456789",
})
})
it("returns updated Klarna order using new API", async () => {
result = await klarnaProviderService.updatePayment(
{
order_id: "123456789",
},
{
email: "",
context: {},
shipping_methods: [],
shipping_address: null,
id: "",
region_id: carts.frCart.region_id,
total: carts.frCart.total,
resource_id: "resource_id",
currency_code: carts.frCart.region.currency_code,
amount: carts.frCart.total
}
)
expect(result).toEqual({
order_id: "123456789",
})
})
})
describe("cancelPayment", () => {
@@ -5,7 +5,7 @@ import { PaymentService } from "medusa-interfaces"
class KlarnaProviderService extends PaymentService {
static identifier = "klarna"
constructor({ logger, shippingProfileService, totalsService }, options) {
constructor({ logger, shippingProfileService }, options) {
super()
/**
@@ -42,15 +42,12 @@ class KlarnaProviderService extends PaymentService {
/** @private @const {ShippingProfileService} */
this.shippingProfileService_ = shippingProfileService
/** @private @const {TotalsService} */
this.totalsService_ = totalsService
}
async lineItemsToOrderLines_(cart) {
let order_lines = []
for (const item of cart.items) {
for (const item of cart.items ?? []) {
// Withdraw discount from the total item amount
const quantity = item.quantity
@@ -67,7 +64,7 @@ class KlarnaProviderService extends PaymentService {
})
}
if (cart.shipping_methods.length) {
if (cart.shipping_methods?.length) {
const name = []
let total = 0
let tax = 0
@@ -103,7 +100,7 @@ class KlarnaProviderService extends PaymentService {
async cartToKlarnaOrder(cart) {
let order = {
// Cart id is stored, such that we can use it for hooks
merchant_data: cart.id,
merchant_data: cart.resource_id ?? cart.id,
locale: "en-US",
}
@@ -147,8 +144,8 @@ class KlarnaProviderService extends PaymentService {
}
order.order_amount = total
order.order_tax_amount = tax_total - cart.gift_card_tax_total
order.purchase_currency = region.currency_code.toUpperCase()
order.order_tax_amount = tax_total - cart.gift_card_tax_total ?? 0
order.purchase_currency = region?.currency_code?.toUpperCase() ?? "SE"
order.merchant_urls = {
terms: this.options_.merchant_urls.terms,