How PaygreenJS handle payment

PaygreenJS works with a system of PaymentFlow. The purpose of this guide is to explain what is a payment flow and how PGJS handle them.

What is a payment flow

A payment flow is a PGJS concept used to define the information of a payment attempt. A payment flow contains the payment method chosen, the status, the amount and many more information.
Once created, a payment flow has no method defined (unless for the first where it can be defined with paymentMethod option at init). As long as there is no method, none payment form will be displayed. You can use the method setPaymentMethod() to change the actual flow method.
They are particularly useful in payment mode.

How are they used ?

PGJS creates a payment flow each time the buyer try to pay until the full amount of the payment order is reached. To handle multiple payment methods (e.g bank card + meal voucher) you will have 2 payment flows

Logic breaking cases

Sometimes, PGJS must break the payment flow logic. There is 3 cases where PGJS will stop and end the session:

  • The max_operation attribute of the payment order is reached
  • The partial_allowed attribute of the payment order is true, when a first payment flow status is success
  • The payment order status has changed and is not pending anymore

Important notes

  • The amount of a payment flow is null until the status is success. Indeed, this is impossible to know exactly the authorized/captured amount before the API return it.
  • You can have additional information on a flow by parsing the payment order operations (using status method)