feat(medusa-payment-paypal): Migrate to the new payment processor API (#3414)

* feat(medusa-payment-paypal): Migrate to the new payment processor API

* WIP

* WIP

* WIP unit tests

* WIP

* unit tests

* fix package.json

* yarn

* cleanup

* address feedback 1/2

* Start to implement a new Paypal SDK

* cleanup

* finalise sdk

* cleanup

* fix push missing file

* rename sdk methods

* unit test the http client

* WIP

* fix http client

* Create .changeset/empty-melons-eat.md

* refactor tests

* fix quote

* fix options

* cleanup

* do not retry auth

* WIP

* retry mechanism max attempts

* use both old and new options

* fix capture

* remove totals fields

* add missing method

* cleanup

* fix current tests

* authorize should update the data with the fresh order

* remove comments

* fix tests

* Update packages/medusa-payment-paypal/src/core/paypal-http-client.ts

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>

* fix unit tests

* update changeset

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
authored and GitHub committed 2023-03-28 13:49:09 +02:00
1 parent 5f41cd9a67
commit 5307408894
44 files changed
+2272 -1037

No files matched your search

@@ -101,7 +101,6 @@ describe("StripeTest", () => {
beforeAll(async () => {
const scopedContainer = { ...container }
stripeTest = new StripeTest(scopedContainer, { api_key: "test" })
await stripeTest.init()
})
beforeEach(() => {
@@ -232,7 +231,6 @@ describe("StripeTest", () => {
beforeAll(async () => {
const scopedContainer = { ...container }
stripeTest = new StripeTest(scopedContainer, { api_key: "test" })
await stripeTest.init()
})
beforeEach(() => {
@@ -257,7 +255,6 @@ describe("StripeTest", () => {
beforeAll(async () => {
const scopedContainer = { ...container }
stripeTest = new StripeTest(scopedContainer, { api_key: "test" })
await stripeTest.init()
})
beforeEach(() => {
@@ -300,7 +297,6 @@ describe("StripeTest", () => {
beforeAll(async () => {
const scopedContainer = { ...container }
stripeTest = new StripeTest(scopedContainer, { api_key: "test" })
await stripeTest.init()
})
beforeEach(() => {
@@ -309,7 +305,7 @@ describe("StripeTest", () => {
it("should succeed", async () => {
const result = await stripeTest.capturePayment(
capturePaymentContextSuccessData
capturePaymentContextSuccessData.paymentSessionData
)
expect(result).toEqual({
@@ -319,7 +315,7 @@ describe("StripeTest", () => {
it("should fail on intent capture but still return the intent", async () => {
const result = await stripeTest.capturePayment(
capturePaymentContextPartiallyFailData
capturePaymentContextPartiallyFailData.paymentSessionData
)
expect(result).toEqual({
@@ -330,11 +326,11 @@ describe("StripeTest", () => {
it("should fail on intent capture", async () => {
const result = await stripeTest.capturePayment(
capturePaymentContextFailData
capturePaymentContextFailData.paymentSessionData
)
expect(result).toEqual({
error: "An error occurred in deletePayment",
error: "An error occurred in capturePayment",
code: "",
detail: "Error",
})
@@ -347,7 +343,6 @@ describe("StripeTest", () => {
beforeAll(async () => {
const scopedContainer = { ...container }
stripeTest = new StripeTest(scopedContainer, { api_key: "test" })
await stripeTest.init()
})
beforeEach(() => {
@@ -391,7 +386,6 @@ describe("StripeTest", () => {
beforeAll(async () => {
const scopedContainer = { ...container }
stripeTest = new StripeTest(scopedContainer, { api_key: "test" })
await stripeTest.init()
})
beforeEach(() => {
@@ -429,7 +423,6 @@ describe("StripeTest", () => {
beforeAll(async () => {
const scopedContainer = { ...container }
stripeTest = new StripeTest(scopedContainer, { api_key: "test" })
await stripeTest.init()
})
beforeEach(() => {
@@ -464,7 +457,6 @@ describe("StripeTest", () => {
beforeAll(async () => {
const scopedContainer = { ...container }
stripeTest = new StripeTest(scopedContainer, { api_key: "test" })
await stripeTest.init()
})
beforeEach(() => {
@@ -186,11 +186,11 @@ abstract class StripeBase extends AbstractPaymentProcessor {
}
async capturePayment(
context: PaymentProcessorContext
paymentSessionData: Record<string, unknown>
): Promise<
PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]
> {
const id = context.paymentSessionData.id as string
const id = paymentSessionData.id as string
try {
const intent = await this.stripe_.paymentIntents.capture(id)
return intent as unknown as PaymentProcessorSessionResponse["session_data"]
@@ -201,7 +201,7 @@ abstract class StripeBase extends AbstractPaymentProcessor {
}
}
return this.buildError("An error occurred in deletePayment", error)
return this.buildError("An error occurred in capturePayment", error)
}
}
@@ -0,0 +1,8 @@
export * from "./types"
export * from "./core/stripe-base"
export * from "./services/stripe-blik"
export * from "./services/stripe-bancontact"
export * from "./services/stripe-giropay"
export * from "./services/stripe-ideal"
export * from "./services/stripe-przelewy24"
export * from "./services/stripe-provider"