fix(medusa): cart completion payment sessions (#5995)
* fix(medusa): cart completion payment sessions * Create seven-moose-scream.md * fix unit tests
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): cart completion payment sessions
|
||||||
@@ -62,9 +62,7 @@ const toTest = [
|
|||||||
|
|
||||||
expect(cartServiceMock.authorizePayment).toHaveBeenCalledTimes(1)
|
expect(cartServiceMock.authorizePayment).toHaveBeenCalledTimes(1)
|
||||||
expect(cartServiceMock.authorizePayment).toHaveBeenCalledWith(
|
expect(cartServiceMock.authorizePayment).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({
|
"test-cart",
|
||||||
id: "test-cart",
|
|
||||||
}),
|
|
||||||
{
|
{
|
||||||
idempotency_key: {
|
idempotency_key: {
|
||||||
idempotency_key: "ikey",
|
idempotency_key: "ikey",
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ import {
|
|||||||
IEventBusService,
|
IEventBusService,
|
||||||
IInventoryService,
|
IInventoryService,
|
||||||
ReservationItemDTO,
|
ReservationItemDTO,
|
||||||
WithRequiredProperty,
|
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AbstractCartCompletionStrategy,
|
AbstractCartCompletionStrategy,
|
||||||
CartCompletionResponse,
|
CartCompletionResponse,
|
||||||
} from "../interfaces"
|
} from "../interfaces"
|
||||||
import { Cart, IdempotencyKey, Order } from "../models"
|
import { IdempotencyKey, Order } from "../models"
|
||||||
import {
|
import {
|
||||||
PaymentProviderService,
|
PaymentProviderService,
|
||||||
ProductVariantInventoryService,
|
ProductVariantInventoryService,
|
||||||
@@ -247,39 +246,10 @@ class CartCompletionStrategy extends AbstractCartCompletionStrategy {
|
|||||||
|
|
||||||
const txCartService = this.cartService_.withTransaction(manager)
|
const txCartService = this.cartService_.withTransaction(manager)
|
||||||
|
|
||||||
let cart: Cart | WithRequiredProperty<Cart, "total"> =
|
const cart = await txCartService.authorizePayment(id, {
|
||||||
await txCartService.retrieveWithTotals(id, {
|
...context,
|
||||||
relations: [
|
idempotency_key: idempotencyKey,
|
||||||
"items.variant.product.profiles",
|
})
|
||||||
"items.adjustments",
|
|
||||||
"discounts",
|
|
||||||
"discounts.rule",
|
|
||||||
"gift_cards",
|
|
||||||
"shipping_methods",
|
|
||||||
"shipping_methods.shipping_option",
|
|
||||||
"billing_address",
|
|
||||||
"shipping_address",
|
|
||||||
"region",
|
|
||||||
"region.tax_rates",
|
|
||||||
"region.payment_providers",
|
|
||||||
"payment_sessions",
|
|
||||||
"customer",
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
if (cart.payment_sessions?.length) {
|
|
||||||
await txCartService.setPaymentSessions(
|
|
||||||
cart as WithRequiredProperty<Cart, "total">
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
cart = await txCartService.authorizePayment(
|
|
||||||
cart as WithRequiredProperty<Cart, "total">,
|
|
||||||
{
|
|
||||||
...context,
|
|
||||||
idempotency_key: idempotencyKey,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (cart.payment_session) {
|
if (cart.payment_session) {
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user