Selecting a payment method
How to select a payment method for the order
Last updated
How to select a payment method for the order
Last updated
You have a pending order and you want to give your customer the possibility to select a payment method.
Within Commerce Layer, an order must have a valid payment method before the order can be placed. To let the customer select a payment method, first you need to get the list of available payment methods for the order and display them to the customer. Then you can associate the selected payment method with the order. To do that:
Send a GET
request to the /api/orders/:id
endpoint, including the associated available_payment_methods
.
Send a PATCH request to the /api/orders/:id
endpoint, setting its payment_method
relationship.
The following request retrieves the available payment methods associated with the order identified by the "NgojhKoyYN" ID:
The following request associated the selected payment method (identified by the "zmdjPsavMW" ID) with the order identified by the "NgojhKoyYN" ID:
The image below shows how the related action during the checkout process is mapped to a specific relationship of the order object.
When redeeming a gift card, it is possible that the order amount due goes to zero and no additional payment methods are required. Instead, if the gift card balance doesn't cover the total amount of the order, you need to select an additional payment method before it can be placed.
Each payment method has a payment_source_type
attribute which determines the type of payment source that can be used to pay for the order. Many payment source types are strictly related to a specific payment gateway, rather than a payment instrument type.
For example, if you want to collect credit card payments with Stripe, the payment source type is stripe_payment
, rather than something like "CreditCard". This lets you leverage the Stripe APIs, official libraries, and documentation to build the integration on the client-side while using Commerce Layer as your server-side endpoint.
For more details, please refer to the payments guide.
See our documentation if you need more information about the payment method and gift card objects or on how to update an order and include associations.