Processing Payments with GraphQL Mutations

Last edit: Jun 24, 2019

This guide will teach you how to process payments with GraphQL mutations.

Requirements

It is recommended that you:

Steps

Processing payments with GraphQL mutations is a four-step process:

Step 1: Basics

It's up to you where and how you want to use the gateway_request mutation call. In this tutorial, we will present a simple scenario of mutation execution that can be placed anywhere. Each Request Type can be called with mutation instead of including a form as it was presented in the Integrating Stripe tutorial.

First create a test page where you can follow the example.

---
slug: payments-mutation-test
---

Make sure that the Payments Module and Stripe Module are installed on your site.

Step 2: Configuration and Data

Any gateway request mutation call needs to know what gateway to use and what kind of request to process. To do that, create a config object as you did with the include_form version.

Next one is data, please see the documentation for the request_type you are calling. Refund payment requires charge, payment_id and the amount that is being refunded.

To keep it simple, use payments created in the Integrating Stripe tutorial.

ExecuteQueryTagError: query: "modules/payments/get_payments" not found

Step 3: Execute migration

The configuration and data are prepared. You now need to wrap it in the format that's readable to the create_customization mutation:



And simply pass refund_data object to the GraphQL tag:

GraphqlTagError: Couldn't find "modules/payments/create_customization.graphql". 

Step 4: Test results

To confirm that your first mutation is executed correctly, sync or deploy the page to your instance and visit the page that you've just created. It should be available under the /payments-mutation-test path.

You should see the properties of the modules/payments/refund object that was created with page render. Visit your Stripe Dashboard to confirm that the last payment was refunded.

Congratulations! You now know how to use any request_type with GraphQL mutations.

Live example and source code

For code examples please go to platformOS payment examples project hosted on Github.

Questions?

We are always happy to help with any questions you may have.