feat(payment, payment-stripe): Add Stripe module provider (#6311)

This commit is contained in:
Oli Juhl
2024-02-26 19:48:15 +01:00
committed by GitHub
parent ac829fc67f
commit ce39b9b66e
49 changed files with 1256 additions and 119 deletions
@@ -24,21 +24,21 @@ export const defaultPaymentSessionData = [
id: "pay-sess-id-1",
amount: 100,
currency_code: "usd",
provider_id: "system",
provider_id: "pp_system_default",
payment_collection: "pay-col-id-1",
},
{
id: "pay-sess-id-2",
amount: 100,
currency_code: "usd",
provider_id: "system",
provider_id: "pp_system_default",
payment_collection: "pay-col-id-2",
},
{
id: "pay-sess-id-3",
amount: 100,
currency_code: "usd",
provider_id: "system",
provider_id: "pp_system_default",
payment_collection: "pay-col-id-2",
},
]
@@ -50,7 +50,7 @@ export const defaultPaymentData = [
currency_code: "usd",
payment_collection: "pay-col-id-1",
payment_session: "pay-sess-id-1",
provider_id: "system",
provider_id: "pp_system_default",
authorized_amount: 100,
data: {},
},
@@ -61,7 +61,7 @@ export const defaultPaymentData = [
currency_code: "usd",
payment_collection: "pay-col-id-2",
payment_session: "pay-sess-id-2",
provider_id: "system",
provider_id: "pp_system_default",
data: {},
},
]
@@ -0,0 +1,76 @@
import { IPaymentModuleService } from "@medusajs/types"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { Modules } from "@medusajs/modules-sdk"
import { initModules } from "medusa-test-utils"
import { MikroOrmWrapper } from "../../utils"
import { getInitModuleConfig } from "../../utils/get-init-module-config"
import { createPaymentCollections } from "../../__fixtures__"
jest.setTimeout(30000)
describe("Payment Module Service", () => {
let service: IPaymentModuleService
let repositoryManager: SqlEntityManager
let shutdownFunc: () => Promise<void>
beforeAll(async () => {
await MikroOrmWrapper.setupDatabase()
const initModulesConfig = getInitModuleConfig()
const { medusaApp, shutdown } = await initModules(initModulesConfig)
service = medusaApp.modules[Modules.PAYMENT]
shutdownFunc = shutdown
})
afterAll(async () => {
await shutdownFunc()
})
beforeEach(async () => {
await MikroOrmWrapper.setupDatabase()
repositoryManager = await MikroOrmWrapper.forkManager()
await createPaymentCollections(repositoryManager)
})
afterEach(async () => {
await MikroOrmWrapper.clearDatabase()
})
describe("providers", () => {
it("should load payment plugins", async () => {
let error = await service
.createPaymentCollections([
{
amount: 200,
region_id: "req_123",
} as any,
])
.catch((e) => e)
expect(error.message).toContain(
"Value for PaymentCollection.currency_code is required, 'undefined' found"
)
})
it("should create a payment collection successfully", async () => {
const [createdPaymentCollection] = await service.createPaymentCollections(
[{ currency_code: "USD", amount: 200, region_id: "reg_123" }]
)
expect(createdPaymentCollection).toEqual(
expect.objectContaining({
id: expect.any(String),
status: "not_paid",
payment_providers: [],
payment_sessions: [],
payments: [],
currency_code: "USD",
amount: 200,
})
)
})
})
})
@@ -39,7 +39,7 @@ moduleIntegrationTestRunner({
const paymentSession = await service.createPaymentSession(
paymentCollection.id,
{
provider_id: "system",
provider_id: "pp_system_default",
providerContext: {
amount: 200,
currency_code: "USD",
@@ -48,7 +48,6 @@ moduleIntegrationTestRunner({
customer: {},
billing_address: {},
email: "test@test.test.com",
resource_id: "cart_test",
},
}
)
@@ -86,7 +85,7 @@ moduleIntegrationTestRunner({
id: expect.any(String),
currency_code: "USD",
amount: 200,
provider_id: "system",
provider_id: "pp_system_default",
status: "authorized",
authorized_at: expect.any(Date),
}),
@@ -96,7 +95,7 @@ moduleIntegrationTestRunner({
id: expect.any(String),
amount: 200,
currency_code: "USD",
provider_id: "system",
provider_id: "pp_system_default",
captures: [
expect.objectContaining({
amount: 200,
@@ -335,7 +334,7 @@ moduleIntegrationTestRunner({
describe("create", () => {
it("should create a payment session successfully", async () => {
await service.createPaymentSession("pay-col-id-1", {
provider_id: "system",
provider_id: "pp_system_default",
providerContext: {
amount: 200,
currency_code: "usd",
@@ -365,7 +364,7 @@ moduleIntegrationTestRunner({
authorized_at: null,
currency_code: "usd",
amount: 200,
provider_id: "system",
provider_id: "pp_system_default",
}),
]),
})
@@ -376,7 +375,7 @@ moduleIntegrationTestRunner({
describe("update", () => {
it("should update a payment session successfully", async () => {
let session = await service.createPaymentSession("pay-col-id-1", {
provider_id: "system",
provider_id: "pp_system_default",
providerContext: {
amount: 200,
currency_code: "usd",
@@ -423,7 +422,7 @@ moduleIntegrationTestRunner({
})
const session = await service.createPaymentSession(collection.id, {
provider_id: "system",
provider_id: "pp_system_default",
providerContext: {
amount: 100,
currency_code: "usd",
@@ -445,9 +444,8 @@ moduleIntegrationTestRunner({
expect.objectContaining({
id: expect.any(String),
amount: 100,
authorized_amount: 100,
currency_code: "usd",
provider_id: "system",
provider_id: "pp_system_default",
refunds: [],
captures: [],
@@ -467,7 +465,7 @@ moduleIntegrationTestRunner({
currency_code: "usd",
amount: 100,
raw_amount: { value: "100", precision: 20 },
provider_id: "system",
provider_id: "pp_system_default",
data: {},
status: "authorized",
authorized_at: expect.any(Date),
@@ -475,7 +473,6 @@ moduleIntegrationTestRunner({
id: expect.any(String),
}),
payment: expect.objectContaining({
authorized_amount: 100,
cart_id: null,
order_id: null,
order_edit_id: null,
@@ -488,7 +485,7 @@ moduleIntegrationTestRunner({
captures: [],
amount: 100,
currency_code: "usd",
provider_id: "system",
provider_id: "pp_system_default",
}),
},
})
@@ -10,6 +10,21 @@ export function getInitModuleConfig() {
schema: process.env.MEDUSA_PAYMENT_DB_SCHEMA,
},
},
providers: [
{
resolve: "@medusajs/payment-stripe",
options: {
config: {
dkk: {
apiKey: "pk_test_123",
},
usd: {
apiKey: "pk_test_456",
},
},
},
},
],
}
const injectedDependencies = {}