I'm currently developing a payment module for Magento 2.4 which integrates with external Payment Service Provider (PSP). The flow is:
1. Customer adds product to cart
2. Proceeds to checkout
3. Picks my payment method
4. After pressing "Place Order" the Customer is redirected to external PSP site.
5. Customer pay for the order using PSP methods - the payment started to process on PSP side
6. The customer is redirected back to the shop
For now I've implemented the Authorization operation which invokes Authorize command, redirects customer to the external PSP and creates payment on PSP side and adds order to magento (the state is Processing).
1. Is Capture command responsible for receiving notifications from PSP (about Payment state) - or is it Capture operation?
2. Should I use the Sale operation for this kind of flow?
3. Does the Administrator create invoice manually for each order?
4. Should an invoice be created automatically in this particular situation?
5. If Capture command is responsible for manually/automatically creating invoices, then what would be the best approach for recieving the notifications from PSP?
If anyone have any suggestions feel free to share.
Here are some answers to your questions:
1. The Capture command is responsible for actually capturing the funds from the customer's account, so it should not be used to receive notifications from the PSP about the payment state. Instead, you can use webhooks or APIs provided by the PSP to receive these notifications.
2. The Sale operation is typically used when the payment is being processed immediately and there is no need to authorize the payment first. Since you are authorizing the payment and then capturing it later, using the Authorization and Capture operations is appropriate.
3. It depends on the specific business requirements of the merchant. In some cases, the administrator may need to create invoices manually. In other cases, invoices can be created automatically.
4. Again, it depends on the specific business requirements. If the merchant wants invoices to be created automatically, then you can implement this functionality in your module.
5. As mentioned earlier, you can use webhooks or APIs provided by the PSP to receive notifications about the payment state. Once you receive these notifications, you can use the Capture command to capture the funds and create an invoice if necessary.
I hope this helps! Let me know if you have any further questions