New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAG1: Correct order state/status and payment flow behavior #97

Merged
merged 9 commits into from Nov 12, 2017

Conversation

Projects
None yet
1 participant
@guzzilar
Collaborator

guzzilar commented Nov 9, 2017

1. Objective

There are various ways to handle payment flow and order status behavior in Magento world.
After tons of researches have been passed on a possibility to proper handle a checkout flow. From the begin, at placing order step to the end, invoiced an order (there are still some more, 'shipped order', 'completed' for example. But we aren't gonna mention here since it's not payment related).

So, this PR aims to clean up, and correcting behavior of payment flow and order status.

2. Description of change

From all payment methods that we have, we can separate them and focus on one by one to see their behaviors as follows:

# Credit Card Payment
From the checkout step until completed payment process, order state/status will be set to either processing or pending depends on what you've set in the payment setting page.

But note that:
For payment action auth only:

  • A transaction[type: AUTH] object will be created with isClosed = false.

For payment action auth and capture:

  • A transaction[type: CAPTURE] object will be created with isClosed = true.
  • An invoice object will be created with status = paid.

..

# Credit Card 3-D Secure Payment

  1. After place an order at the checkout step, an order state/status will be set to pending-payment
  2. Then, once buyer finish his/her 3-D Secure process, they will be redirected back to merchant's store.
  3. Here, order state/status will be set to either processing/pending (depends on your setting) if payment is successful or canceled if payment is failed.

Also note that:
For payment action auth only:

  • A transaction[type: AUTH] object will be created with isClosed = false and stay false even after finish 3-D Secure process.

For payment action auth and capture:

  • A transaction[type: CAPTURE] object will be created with isClosed = false at first, then isClosed = true when finish 3-D Secure process.
  • An invoice object will be created with status = pending, then status will be either paid or canceled depends on the 3-D Secure result.

..

# Internet Banking Payment

  1. After place an order at the checkout step, an order state/status will be set to pending-payment
  2. Then, once buyer finish his/her internet banking process, they will be redirected back to merchant's store.
  3. Here, order state/status will be set to either processing/pending (depends on your setting) if payment is successful, canceled if payment is failed or payment-review if payment is still in process.

⚠️ IMPORTANT: For payment-review state/status.
This case might happen sometimes due to bank(s) process, it might take a little bit time before resolve the payment and return us a result.
So in this case, order state/status will be set to payment-review. And that will allow merchant to review the payment result manually at Omise Dashboard before either 'accept' or 'denied' that payment (note that Webhook feature is coming and it will make this process to be automatic).

Also note that:

  • A transaction[type: ORDER] object will be created with isClosed = false and turns to isClosed = true once buyer finish their internet banking process.
  • An invoice object will be created with status = pending, and turns to status = processing once buyer finish their internet banking process.

Note that Alipay Payment (coming feature) will behave the same as Internet Banking Payment

3. Quality assurance

🔧 Environments:

  • Magento CE: v1.9.3.6
  • PHP: v5.6.30

✏️ Details:

Internet Banking Payment
Make sure that invoice and transaction objects are created properly when place an order with internet banking payment.

BEFORE USER COMPLETE INTERNET BANKING PROCESS

  • An invoice object will be created at this step, with status=pending.
  • A transaction object will be created at this step, with isClosed=false and type=ORDER.
  • An order object's state/status will be set to pending-payment.
    tab: order information
    tab: invoice
    tab: transaction

SUCCESSFUL CASE

  • Invoice's status will be set to paid.
  • Transaction's isClosed will be set to true.
  • An order object's state/status will be set to processing.
    006

FAILED CASE

  • Invoice's status will be set to canceled.
  • Transaction's isClosed will be set to true.
  • An order object's state/status will be set to processing then canceled.
    007

PENDING CASE

  • Invoice's status will still stay with pending.
  • Transaction's isClosed will still stay with false.
  • An order object's state/status will be set to payment-review.
    008

Note that if you click Accept Payment, it goes to SUCCESSFUL CASE. In the other hand, Deny Payment will go to FAILED CASE.

Credit Card Payment
Make sure that invoice and transaction objects are created properly when place an order with credit card payment (without 3-D Secure).

3-D Secure Payment
Make sure that invoice and transaction objects are created properly when place an order with 3-D Secure payment.

Payment Action: Auth only. PLACE ORDER
When you first create charge with 3-D Secure payment method

  • A transaction object will be created at this step, with isClosed=false and type=AUTH.
  • An order object's state/status will be set to pending-payment.
    009
    010

Payment Action: Auth only. SUCCESSFUL CASE

  • Transaction's isClosed still stay as false.
  • An order object's state/status will be set to processing.
    011

Payment Action: Auth only. FAILED CASE

  • Transaction's isClosed will be set to true.
  • An order object's state/status will be set to canceled.
    012

Payment Action: Auth and Capture. PLACE ORDER

  • An invoice object will be created at this step, with status=pending.
  • A transaction object will be created at this step, with isClosed=false and type=CAPTURE.
  • An order object's state/status will be set to pending-payment.
    014
    015
    013

Payment Action: Auth and Capture. SUCCESSFUL CASE

  • Invoice's status will be set to paid.
  • Transaction's isClosed will be set to true.
  • An order object's state/status will be set to processing.
    016

Payment Action: Auth and Capture. FAILED CASE

  • Invoice's status will be set to canceled.
  • Transaction's isClosed will be set to true.
  • An order object's state/status will be set to processing then canceled.
    017

4. Impact of the change

None.

5. Priority of change

Normal

6. Additional Notes

None.

CreditCard Method: perform 'initialize' action if 3-D Secure payment …
…is enabled.

Previously, order status flow when using 3-D Secure payment was, 'payment-review' > 'accept-payment' > 'processing' which is,
in fact, we should reserve that 'payment-review' for other situation and use 'pending-payment' instead due to that
there is no transaction at the time user is redirected to 3-D Secure page until user validate with OTP.

To correct the 3-D Secure payment behaviour, we need to rely on the payment 'initialize' method to set an order's status to be 'pending-payment'.
Note that there is no other way to set an order status to 'pending-payment' without using payment 'initialize' method.

guzzilar added some commits Nov 9, 2017

Correct CreditCard 3-D Secure payment method behaviours.
When make charge with CreditCard 3-D Secure payment:
- On both auth & auth-capture, order status will be set to 'pending payment'.
- Payment action 'auth-capture' will create an invoice object with 'pending' status.
- On both 'auth' & 'auth-capture' payment actions, a transaction object will be created with 'inClosed = false' status.
Correct order state/status flow at callback of 3-D Secure payment.
When user is redirected back to merchant store after 3-D Secure process:
For payment action = auth only:
- If success, order state/status will be set to 'processing'.
- If fail, order state/status will be set to 'canceled', a transaction object will be 'isClosed=true'.

For payment action = auth-capture:
- If success, order state/status will be set to 'processing', an invoiced object will be 'paid', a transaction object will be 'isClosed = true'.
- If fail, order state/status will be set to 'canceled', an invoiced object will be 'canceled', a transaction object will be 'isCloed = true'.
Correct Internet Banking payment method behaviours.
When make charge with internet banking payment:
- Order state/status will be set to 'pending-payment'.
- An invoice object will be created with 'pending' status.
- A transaction object will be created with 'isClosed=false', 'type=order'.
Correct order state/status flow at callback of internet banking payment.
When user is redirected back to merchant store after internet banking process:
Successful case
- An order status will be set to 'processing'
- An invoice status will be set to 'paid'
- A transaction 'isClosed' status will be set to 'true'

Failed case
- An order status will be set to 'canceled'
- An invoice status will be set to 'canceled'
- A transaction 'isClosed' status will be set to 'true'

Pending case
- An order status will be set to 'payment-review'
- An invoice status will still stay 'pending'
- A transaction 'isClosed' status will still stay 'false'

@guzzilar guzzilar changed the title from [WIP] MAG1: Correct order state/status and payment flow behavior to MAG1: Correct order state/status and payment flow behavior Nov 12, 2017

@guzzilar

This comment has been minimized.

Show comment
Hide comment
@guzzilar

guzzilar Nov 12, 2017

Collaborator

Updated PR's description.

Collaborator

guzzilar commented Nov 12, 2017

Updated PR's description.

@guzzilar

This comment has been minimized.

Show comment
Hide comment
@guzzilar

guzzilar Nov 12, 2017

Collaborator

👍

Collaborator

guzzilar commented Nov 12, 2017

👍

@guzzilar guzzilar merged commit 347f8b2 into 1-stable Nov 12, 2017

@guzzilar guzzilar deleted the 1-correct-order-status-flow branch Nov 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment