fix(medusa-payment-stripe): Missing transactions in Stripe provider (#2603)
This commit is contained in:
1 parent
d0809bdf25
commit
9e91a50df1
4 files changed
+58
-47
No files matched your search
@@ -27,7 +27,12 @@ import {
|
||||
isCart,
|
||||
LineItemUpdate,
|
||||
} from "../types/cart"
|
||||
import { AddressPayload, FindConfig, TotalField } from "../types/common"
|
||||
import {
|
||||
AddressPayload,
|
||||
FindConfig,
|
||||
TotalField,
|
||||
WithRequiredProperty,
|
||||
} from "../types/common"
|
||||
import { buildQuery, isDefined, setMetadata } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import { validateEmail } from "../utils/is-email"
|
||||
@@ -281,7 +286,7 @@ class CartService extends TransactionBaseService {
|
||||
cartId: string,
|
||||
options: FindConfig<Cart> = {},
|
||||
totalsConfig: TotalsConfig = {}
|
||||
): Promise<Cart> {
|
||||
): Promise<WithRequiredProperty<Cart, "total">> {
|
||||
const relations = this.getTotalsRelations(options)
|
||||
|
||||
const cart = await this.retrieve(cartId, {
|
||||
@@ -823,15 +828,14 @@ class CartService extends TransactionBaseService {
|
||||
relations,
|
||||
})
|
||||
|
||||
const originalCartCustomer = { ...(cart.customer ?? {}) }
|
||||
if (data.customer_id) {
|
||||
await this.updateCustomerId_(cart, data.customer_id)
|
||||
} else {
|
||||
if (isDefined(data.email)) {
|
||||
const customer = await this.createOrFetchUserFromEmail_(data.email)
|
||||
cart.customer = customer
|
||||
cart.customer_id = customer.id
|
||||
cart.email = customer.email
|
||||
}
|
||||
} else if (isDefined(data.email)) {
|
||||
const customer = await this.createOrFetchUserFromEmail_(data.email)
|
||||
cart.customer = customer
|
||||
cart.customer_id = customer.id
|
||||
cart.email = customer.email
|
||||
}
|
||||
|
||||
if (isDefined(data.customer_id) || isDefined(data.region_id)) {
|
||||
@@ -937,7 +941,10 @@ class CartService extends TransactionBaseService {
|
||||
|
||||
const updatedCart = await cartRepo.save(cart)
|
||||
|
||||
if ("email" in data || "customer_id" in data) {
|
||||
if (
|
||||
(data.email && data.email !== originalCartCustomer.email) ||
|
||||
(data.customer_id && data.customer_id !== originalCartCustomer.id)
|
||||
) {
|
||||
await this.eventBus_
|
||||
.withTransaction(transactionManager)
|
||||
.emit(CartService.Events.CUSTOMER_UPDATED, updatedCart.id)
|
||||
@@ -1486,13 +1493,6 @@ class CartService extends TransactionBaseService {
|
||||
|
||||
const { total, region } = cart
|
||||
|
||||
if (typeof total === "undefined") {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.UNEXPECTED_STATE,
|
||||
"cart.total must be defined"
|
||||
)
|
||||
}
|
||||
|
||||
// If there are existing payment sessions ensure that these are up to date
|
||||
const seen: string[] = []
|
||||
if (cart.payment_sessions?.length) {
|
||||
@@ -2104,7 +2104,7 @@ class CartService extends TransactionBaseService {
|
||||
async decorateTotals(
|
||||
cart: Cart,
|
||||
totalsConfig: TotalsConfig = {}
|
||||
): Promise<Cart> {
|
||||
): Promise<WithRequiredProperty<Cart, "total">> {
|
||||
const manager = this.transactionManager_ ?? this.manager_
|
||||
const newTotalsServiceTx = this.newTotalsService_.withTransaction(manager)
|
||||
|
||||
@@ -2192,7 +2192,7 @@ class CartService extends TransactionBaseService {
|
||||
cart.tax_total -
|
||||
(cart.gift_card_total + cart.discount_total + cart.gift_card_tax_total)
|
||||
|
||||
return cart
|
||||
return cart as Cart & { total: number }
|
||||
}
|
||||
|
||||
protected async refreshAdjustments_(cart: Cart): Promise<void> {
|
||||
|
||||
Reference in new issue
Block a user