forked from adrien2p/medusa-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(medusa/payment-paytr): Finalize paytr payment
- Loading branch information
Showing
7 changed files
with
64 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ coverage | |
|
||
/api/ | ||
/services/ | ||
/subscribers/ | ||
utils.js | ||
types.js | ||
index.js | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import EventBusService from '@medusajs/medusa/dist/services/event-bus'; | ||
import OrderService from '@medusajs/medusa/dist/services/order'; | ||
import CartService from '@medusajs/medusa/dist/services/cart'; | ||
import PaymentProviderService from '@medusajs/medusa/dist/services/payment-provider'; | ||
import { PaymentSessionStatus } from '@medusajs/medusa/dist'; | ||
|
||
export default class OrderSubscriber { | ||
readonly #orderService: OrderService; | ||
readonly #cartService: CartService; | ||
readonly #paymentProviderService: PaymentProviderService; | ||
readonly #eventBus: EventBusService; | ||
|
||
constructor({ orderService, cartService, eventBusService, paymentProviderService }) { | ||
this.#eventBus = eventBusService; | ||
this.#orderService = orderService; | ||
this.#paymentProviderService = paymentProviderService; | ||
this.#cartService = cartService; | ||
|
||
this.#eventBus.subscribe(OrderService.Events.PLACED, async ({ id }) => { | ||
return await this.onOrderPlaces(id); | ||
}); | ||
} | ||
|
||
async onOrderPlaces(id: string) { | ||
const order = await this.#orderService.retrieve(id); | ||
const cart = await this.#cartService.retrieve(order.cart_id, { | ||
relations: ['payment'], | ||
}); | ||
const paymentStatus = await this.#paymentProviderService.getStatus(cart.payment); | ||
if (paymentStatus === PaymentSessionStatus.AUTHORIZED) { | ||
return await this.#orderService.capturePayment(id); | ||
} | ||
} | ||
} |