Processing Payments with GraphQL Mutations
This guide will teach you how to process payments with GraphQL mutations.
It is recommended that you:
- have Stripe configured correctly as explained in Integrating Stripe
- understand how GraphQL mutations work
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 ---
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
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
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
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.