Latest Commerce API release adds support for on-site payments

Celebrating a new release

Our Drupal contributions and client engagements this year have let us continue to expand JSON:API support in Drupal Commerce. We released the first alpha version of the Commerce API module earlier this year and have been constantly working on it since then, resulting in the module's 1.0-beta4 release last week.

What's new in the latest release?

One feature that has been heavily requested is the ability to use on-site payment gateways like Braintree or Stripe in a decoupled context, and guess what? This is now possible since the latest release! Furthermore, "manual" payment gateways (i.e "offline" payments such as cash on delivery...) are now also fully supported.

Great! But... how does this work?

The frontend application is responsible for collecting (usually through a gateway's JS library) and submitting a "payment_instrument" to the backend. The payment instrument instructs the Drupal Commerce backend how to process a customer's payment through the specified payment gateway.

This payload for Braintree demonstrates the payment instrument format:

         "last2" => 18,

Note that the expected "payment_details" differs for each payment gateway.

The "payment_instrument" is submitted by performing a "PATCH" request to the /jsonapi/checkout/{commerce_order} resource.

Once the payment instrument is collected and the customer is ready to pay, a "POST" request must be made to the /jsonapi/checkout/{commerce_order}/payment resource to authorize or capture the payment.

What's next in our roadmap?

Although Commerce API is in beta, we still consider it "production ready" as we're already using it on several projects! However, we can't assert yet that it's completely "battle tested" and expect we may fix minor bugs and / or make minor improvements to the module down the road.

If you're working on decoupled Drupal Commerce sites, give it a try and let us know how we can make it even better. Install Commerce API like any other Drupal module (i.e. via Composer) and learn more about its features in the documentation.

If you just want to try a demo, we do maintain a blazing fast React demo:

The code powering that demo is now publicly available on Github.

Add new comment