Skip to content

Commit

Permalink
feat(medusa,medusa-payment-stripe): Move database mutation from plugi…
Browse files Browse the repository at this point in the history
…n to core (medusajs#2743)

**what**
The goal of that PR is to first refactor the payment provider and payment plugin to support the new API that removes the data mutation from within the plugin to be done by the core instead. In any case, this pr does not include the steps of the deeper refactoring. The last part will come in later pr.

**How**
- The payment plugin is now capable to handle both the deprecated and new API and the plugin works the same as it use to works.
- The mutation made by the plugin have been moved into the core as well as the subscriber
- The tests have been updated to reflect the changed
- Remove all new methods introduced by the payment collections
  - Mutualise types
  - Update provider and payment collection services
  - cleanup around all those refactoring including cleanup of the payment collection
  - refactor stripe payment plugin

FIXES CORE-887
  • Loading branch information
adrien2p authored Dec 19, 2022
1 parent 8dcc805 commit c8724da
Show file tree
Hide file tree
Showing 87 changed files with 1,134 additions and 1,425 deletions.
6 changes: 6 additions & 0 deletions .changeset/strong-radios-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"medusa-payment-stripe": patch
"@medusajs/medusa": patch
---

feat(medusa,medusa-payment-stripe): Move database mutation from plugin to core
3 changes: 0 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ packages/*
# List of packages to Lint
!packages/medusa

integration-tests/*
#!integration-tests/api


**/models/*
Expand All @@ -18,6 +16,5 @@ integration-tests/*
**/node_modules/*
**/migrations/*
**/__mocks__/*
**/__tests__/*

.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,37 +149,6 @@ Object {
}
`;
exports[`/admin/price-lists POST /admin/price-lists/:id updates price list prices (inser a new MA for a specific region) 1`] = `
Array [
Object {
"amount": 101,
"created_at": Any<String>,
"currency_code": "eur",
"deleted_at": null,
"id": Any<String>,
"max_quantity": null,
"min_quantity": null,
"price_list_id": "pl_with_some_ma",
"region_id": "region-pl",
"updated_at": Any<String>,
"variant_id": "test-variant",
},
Object {
"amount": 1001,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "ma_test_4",
"max_quantity": null,
"min_quantity": null,
"price_list_id": "pl_with_some_ma",
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant",
},
]
`;
exports[`/admin/price-lists POST /admin/price-lists/:id updates the amount and currency of a price in the price list 1`] = `
Object {
"amount": 250,
Expand Down
54 changes: 28 additions & 26 deletions integration-tests/api/__tests__/admin/price-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,32 +638,34 @@ describe("/admin/price-lists", () => {
expect(response.status).toEqual(200)

expect(response.data.price_list.prices.length).toEqual(2)
expect(response.data.price_list.prices).toMatchSnapshot([
{
id: expect.any(String),
currency_code: "eur",
amount: 101,
min_quantity: null,
max_quantity: null,
price_list_id: "pl_with_some_ma",
variant_id: "test-variant",
region_id: "region-pl",
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
},
{
id: "ma_test_4",
currency_code: "usd",
amount: 1001,
price_list_id: "pl_with_some_ma",
variant_id: "test-variant",
region_id: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
},
])
expect(response.data.price_list.prices).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
currency_code: "eur",
amount: 101,
min_quantity: null,
max_quantity: null,
price_list_id: "pl_with_some_ma",
variant_id: "test-variant",
region_id: "region-pl",
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
}),
expect.objectContaining({
id: "ma_test_4",
currency_code: "usd",
amount: 1001,
price_list_id: "pl_with_some_ma",
variant_id: "test-variant",
region_id: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
}),
])
)
})
})

Expand Down
1 change: 1 addition & 0 deletions packages/medusa-core-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export { parseCorsOrigins } from "./parse-cors-origins"
export { transformIdableFields } from "./transform-idable-fields"
export { default as Validator } from "./validator"
export { default as zeroDecimalCurrencies } from "./zero-decimal-currencies"
export * from "./is-defined"

File renamed without changes.
4 changes: 2 additions & 2 deletions packages/medusa-payment-stripe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"medusa-test-utils": "^1.1.37"
},
"scripts": {
"build": "babel src -d . --ignore **/__tests__",
"build": "babel src -d . --ignore **/__tests__ --ignore **/__mocks__",
"prepare": "cross-env NODE_ENV=production yarn run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__",
"watch": "babel -w src --out-dir . --ignore **/__tests__ --ignore **/__mocks__",
"test": "jest"
},
"peerDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/medusa-payment-stripe/src/__mocks__/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export const carts = {
customer: IdMap.getId("not-lebron"),
},
},
region: { currency_code: "usd" },
total: 100,
shipping_address: {},
billing_address: {},
discounts: [],
Expand Down
4 changes: 2 additions & 2 deletions packages/medusa-payment-stripe/src/__mocks__/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export const StripeMock = {
if (data.customer === "cus_123456789_new") {
return Promise.resolve({
id: "pi_lebron",
amount: 100,
amount: data.amount,
customer: "cus_123456789_new",
description: data?.description,
})
}
if (data.customer === "cus_lebron") {
return Promise.resolve({
id: "pi_lebron",
amount: 100,
amount: data.amount,
customer: "cus_lebron",
description: data?.description,
})
Expand Down
Loading

0 comments on commit c8724da

Please sign in to comment.