Payment
Now for the payment logic. In the controller, let's add a route to pay an order.
Register the order inside the TypeOrmModule
in the PaymentsModule
, as we'll use a repository for it in the next step. Now, in the service, we'll create the method that makes a payment.
First, an order
will be searched for, and brought with its payment
. If the order
is not found, or a payment
is already present, an exception is thrown. Then, a payment
will be created. After that, the order
will have the payment
associated with it, and change its status
to AWAITING_SHIPMENT
. Finally, the order
will be saved together with the payment
.
As the payment logic is being made in a single operation, we don't need to use a Transaction, which we'll learn about in the next section.
In the Extra module 1 - Authentication/Authorization, we'll learn how to check if the payer is indeed the order's owner, among other security measures.
Commit - Implementing payment logic
Last updated