Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Jan 10, 2023
1 parent 33d36b9 commit 45cb5c2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/medusa/src/services/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,10 @@ class CartService extends TransactionBaseService {
(s) => s.is_selected
)

if (currentlySelectedSession) {
if (
currentlySelectedSession &&
currentlySelectedSession.provider_id !== providerId
) {
const psRepo = transactionManager.getCustomRepository(
this.paymentSessionRepository_
)
Expand All @@ -1685,6 +1688,7 @@ class CartService extends TransactionBaseService {
await psRepo.save(currentlySelectedSession)
}

// TODO: keep for now but we will be able to remove it in the future since only one selected session can exists
const cartPaymentSessionIds = cart.payment_sessions.map((p) => p.id)
await psRepo.update(
{ id: In(cartPaymentSessionIds) },
Expand Down Expand Up @@ -1713,14 +1717,12 @@ class CartService extends TransactionBaseService {
payment_session_id: paymentSession.id,
}

if (paymentSession.is_selected) {
if (paymentSession.is_initiated) {
// update the session remotely
await this.paymentProviderService_
.withTransaction(transactionManager)
.updateSession(paymentSession, sessionInput)
}

if (!paymentSession.is_initiated) {
} else {
// Create the session remotely
paymentSession = await this.paymentProviderService_
.withTransaction(transactionManager)
Expand Down

0 comments on commit 45cb5c2

Please sign in to comment.