fix(core-flows): delete existing payment session before creating new (#7751)
what: Multiple active sessions are used for split payments. We don't currently support split payments. Until we have that implemented, this change is to ensure that whenever we create a new payment session, we delete an existing session if present. RESOLVES CORE-2284
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
beforeAll(() => {})
|
||||
|
||||
beforeEach(async () => {
|
||||
const container = getContainer()
|
||||
await createAdminUser(dbConnection, adminHeaders, container)
|
||||
})
|
||||
|
||||
describe("POST /admin/payment-collections/:id/payment-sessions", () => {
|
||||
let region
|
||||
|
||||
beforeEach(async () => {
|
||||
region = (
|
||||
await api.post(
|
||||
"/admin/regions",
|
||||
{ name: "United States", currency_code: "usd", countries: ["us"] },
|
||||
adminHeaders
|
||||
)
|
||||
).data.region
|
||||
})
|
||||
|
||||
it("should create a payment session", async () => {
|
||||
const paymentCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
region_id: region.id,
|
||||
cart_id: "cart.id",
|
||||
amount: 150,
|
||||
currency_code: "usd",
|
||||
})
|
||||
).data.payment_collection
|
||||
|
||||
await api.post(
|
||||
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
|
||||
{ provider_id: "pp_system_default" }
|
||||
)
|
||||
|
||||
// Adding a second payment session to ensure only one session gets created
|
||||
const {
|
||||
data: { payment_collection },
|
||||
} = await api.post(
|
||||
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
|
||||
{ provider_id: "pp_system_default" }
|
||||
)
|
||||
|
||||
expect(payment_collection.payment_sessions).toEqual([
|
||||
expect.objectContaining({
|
||||
currency_code: "usd",
|
||||
provider_id: "pp_system_default",
|
||||
status: "pending",
|
||||
amount: 150,
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -27,18 +27,23 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
describe("createPaymentSessionWorkflow", () => {
|
||||
it("should create payment sessions", async () => {
|
||||
const region = await regionModule.create({
|
||||
let region
|
||||
let paymentCollection
|
||||
|
||||
beforeEach(async () => {
|
||||
region = await regionModule.create({
|
||||
currency_code: "usd",
|
||||
name: "US",
|
||||
})
|
||||
|
||||
let paymentCollection = await paymentModule.createPaymentCollections({
|
||||
paymentCollection = await paymentModule.createPaymentCollections({
|
||||
currency_code: "usd",
|
||||
amount: 1000,
|
||||
region_id: region.id,
|
||||
})
|
||||
})
|
||||
|
||||
it("should create payment sessions", async () => {
|
||||
await createPaymentSessionsWorkflow(appContainer).run({
|
||||
input: {
|
||||
payment_collection_id: paymentCollection.id,
|
||||
@@ -72,6 +77,47 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
it("should delete existing sessions when create payment sessions", async () => {
|
||||
await createPaymentSessionsWorkflow(appContainer).run({
|
||||
input: {
|
||||
payment_collection_id: paymentCollection.id,
|
||||
provider_id: "pp_system_default",
|
||||
context: {},
|
||||
data: {},
|
||||
},
|
||||
})
|
||||
|
||||
await createPaymentSessionsWorkflow(appContainer).run({
|
||||
input: {
|
||||
payment_collection_id: paymentCollection.id,
|
||||
provider_id: "pp_system_default",
|
||||
context: {},
|
||||
data: {},
|
||||
},
|
||||
})
|
||||
|
||||
paymentCollection = await paymentModule.retrievePaymentCollection(
|
||||
paymentCollection.id,
|
||||
{ relations: ["payment_sessions"] }
|
||||
)
|
||||
|
||||
expect(paymentCollection).toEqual(
|
||||
expect.objectContaining({
|
||||
id: paymentCollection.id,
|
||||
currency_code: "usd",
|
||||
amount: 1000,
|
||||
region_id: region.id,
|
||||
payment_sessions: [
|
||||
expect.objectContaining({
|
||||
amount: 1000,
|
||||
currency_code: "usd",
|
||||
provider_id: "pp_system_default",
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
describe("compensation", () => {
|
||||
it("should delete created payment collection if a subsequent step fails", async () => {
|
||||
const workflow = createPaymentSessionsWorkflow(appContainer)
|
||||
|
||||
Reference in New Issue
Block a user