Skip to content

Commit

Permalink
Merge branch 'develop' into feat/stripe-webhook-delay
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl authored Jan 5, 2024
2 parents c25e96c + 37fba9a commit 7d99018
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-moose-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): cart completion payment sessions
6 changes: 6 additions & 0 deletions .changeset/smart-zoos-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/medusa": patch
"medusa-payment-stripe": patch
---

fix(medusa, medusa-payment-stripe): fix stripe error handling
14 changes: 7 additions & 7 deletions packages/medusa-payment-stripe/src/core/stripe-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ abstract class StripeBase extends AbstractPaymentProcessor {

protected buildError(
message: string,
e: Stripe.StripeRawError | PaymentProcessorError | Error
error: Stripe.StripeRawError | PaymentProcessorError | Error
): PaymentProcessorError {
return {
error: message,
code: "code" in e ? e.code : "",
detail: isPaymentProcessorError(e)
? `${e.error}${EOL}${e.detail ?? ""}`
: "detail" in e
? e.detail
: e.message ?? "",
code: "code" in error ? error.code : "unknown",
detail: isPaymentProcessorError(error)
? `${error.error}${EOL}${error.detail ?? ""}`
: "detail" in error
? error.detail
: error.message ?? "",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/interfaces/payment-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,5 +777,5 @@ export abstract class AbstractPaymentProcessor implements PaymentProcessor {
export function isPaymentProcessorError(
obj: any
): obj is PaymentProcessorError {
return obj && typeof obj === "object" && (obj.error || obj.code || obj.detail)
return obj && typeof obj === "object" && obj.error && obj.code && obj.detail
}
4 changes: 1 addition & 3 deletions packages/medusa/src/strategies/__tests__/cart-completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ const toTest = [

expect(cartServiceMock.authorizePayment).toHaveBeenCalledTimes(1)
expect(cartServiceMock.authorizePayment).toHaveBeenCalledWith(
expect.objectContaining({
id: "test-cart",
}),
"test-cart",
{
idempotency_key: {
idempotency_key: "ikey",
Expand Down
40 changes: 5 additions & 35 deletions packages/medusa/src/strategies/cart-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import {
IEventBusService,
IInventoryService,
ReservationItemDTO,
WithRequiredProperty,
} from "@medusajs/types"
import {
AbstractCartCompletionStrategy,
CartCompletionResponse,
} from "../interfaces"
import { Cart, IdempotencyKey, Order } from "../models"
import { IdempotencyKey, Order } from "../models"
import {
PaymentProviderService,
ProductVariantInventoryService,
Expand Down Expand Up @@ -247,39 +246,10 @@ class CartCompletionStrategy extends AbstractCartCompletionStrategy {

const txCartService = this.cartService_.withTransaction(manager)

let cart: Cart | WithRequiredProperty<Cart, "total"> =
await txCartService.retrieveWithTotals(id, {
relations: [
"items.variant.product.profiles",
"items.adjustments",
"discounts",
"discounts.rule",
"gift_cards",
"shipping_methods",
"shipping_methods.shipping_option",
"billing_address",
"shipping_address",
"region",
"region.tax_rates",
"region.payment_providers",
"payment_sessions",
"customer",
],
})

if (cart.payment_sessions?.length) {
await txCartService.setPaymentSessions(
cart as WithRequiredProperty<Cart, "total">
)
}

cart = await txCartService.authorizePayment(
cart as WithRequiredProperty<Cart, "total">,
{
...context,
idempotency_key: idempotencyKey,
}
)
const cart = await txCartService.authorizePayment(id, {
...context,
idempotency_key: idempotencyKey,
})

if (cart.payment_session) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Node.js is the environment that makes it possible for Medusa to run, so you must

:::warning

Medusa supports v16+ of Node.js. You can check your Node.js version using the following command:
Medusa requires version 16.14.0 or higher of Node. You can check your Node version using the following command:

```bash noReport
node -v
Expand Down

0 comments on commit 7d99018

Please sign in to comment.