feat: Create payment sessions (#6549)

~~Opening a draft PR to discuss a couple of implementation details that we should align on~~

**What**

Add workflow and API endpoint for creating payment sessions for a payment collection. Endpoint is currently `POST /store/payment-collection/:id/payment-sessions`. I suggested an alternative in a comment below.

Please note, we intentionally do not want to support creating payment sessions in bulk, as this would become a mess when having to manage multiple calls to third-party providers.
This commit is contained in:
Oli Juhl
2024-03-05 08:40:47 +00:00
committed by GitHub
parent 908b1dc3a2
commit 84208aafc1
30 changed files with 603 additions and 182 deletions
@@ -21,17 +21,9 @@ moduleIntegrationTestRunner({
}: SuiteOptions<IPaymentModuleService>) => {
describe("Payment Module Service", () => {
describe("Payment Flow", () => {
beforeEach(async () => {
const repositoryManager = MikroOrmWrapper.forkManager()
await createPaymentCollections(repositoryManager)
await createPaymentSessions(repositoryManager)
await createPayments(repositoryManager)
})
it("complete payment flow successfully", async () => {
let paymentCollection = await service.createPaymentCollections({
currency_code: "USD",
currency_code: "usd",
amount: 200,
region_id: "reg_123",
})
@@ -40,11 +32,11 @@ moduleIntegrationTestRunner({
paymentCollection.id,
{
provider_id: "pp_system_default",
providerContext: {
amount: 200,
currency_code: "USD",
payment_session_data: {},
context: {},
amount: 200,
currency_code: "usd",
data: {},
context: {
extra: {},
customer: {},
billing_address: {},
email: "test@test.test.com",
@@ -72,7 +64,7 @@ moduleIntegrationTestRunner({
expect(paymentCollection).toEqual(
expect.objectContaining({
id: expect.any(String),
currency_code: "USD",
currency_code: "usd",
amount: 200,
// TODO
// authorized_amount: 200,
@@ -83,7 +75,7 @@ moduleIntegrationTestRunner({
payment_sessions: [
expect.objectContaining({
id: expect.any(String),
currency_code: "USD",
currency_code: "usd",
amount: 200,
provider_id: "pp_system_default",
status: "authorized",
@@ -94,7 +86,7 @@ moduleIntegrationTestRunner({
expect.objectContaining({
id: expect.any(String),
amount: 200,
currency_code: "USD",
currency_code: "usd",
provider_id: "pp_system_default",
captures: [
expect.objectContaining({
@@ -336,11 +328,11 @@ moduleIntegrationTestRunner({
it("should create a payment session successfully", async () => {
await service.createPaymentSession("pay-col-id-1", {
provider_id: "pp_system_default",
providerContext: {
amount: 200,
currency_code: "usd",
payment_session_data: {},
context: {},
amount: 200,
currency_code: "usd",
data: {},
context: {
extra: {},
customer: {},
billing_address: {},
email: "test@test.test.com",
@@ -377,11 +369,11 @@ moduleIntegrationTestRunner({
it("should update a payment session successfully", async () => {
let session = await service.createPaymentSession("pay-col-id-1", {
provider_id: "pp_system_default",
providerContext: {
amount: 200,
currency_code: "usd",
payment_session_data: {},
context: {},
amount: 200,
currency_code: "usd",
data: {},
context: {
extra: {},
customer: {},
billing_address: {},
email: "test@test.test.com",
@@ -391,15 +383,15 @@ moduleIntegrationTestRunner({
session = await service.updatePaymentSession({
id: session.id,
providerContext: {
amount: 200,
currency_code: "eur",
amount: 200,
currency_code: "eur",
data: {},
context: {
resource_id: "res_id",
context: {},
extra: {},
customer: {},
billing_address: {},
email: "new@test.tsst",
payment_session_data: {},
},
})
@@ -424,11 +416,11 @@ moduleIntegrationTestRunner({
const session = await service.createPaymentSession(collection.id, {
provider_id: "pp_system_default",
providerContext: {
amount: 100,
currency_code: "usd",
payment_session_data: {},
context: {},
amount: 100,
currency_code: "usd",
data: {},
context: {
extra: {},
resource_id: "test",
email: "test@test.com",
billing_address: {},
@@ -447,7 +439,6 @@ moduleIntegrationTestRunner({
amount: 100,
currency_code: "usd",
provider_id: "pp_system_default",
refunds: [],
captures: [],
data: {},
@@ -458,9 +449,7 @@ moduleIntegrationTestRunner({
deleted_at: null,
captured_at: null,
canceled_at: null,
payment_collection: expect.objectContaining({
id: expect.any(String),
}),
payment_collection_id: expect.any(String),
payment_session: expect.objectContaining({
id: expect.any(String),
updated_at: expect.any(Date),
@@ -472,6 +461,10 @@ moduleIntegrationTestRunner({
data: {},
status: "authorized",
authorized_at: expect.any(Date),
payment_collection: expect.objectContaining({
id: expect.any(String),
}),
payment_collection_id: expect.any(String),
}),
})
)