wc-rest-payment

Process Payments via REST API for WooCommerce.

Stripe Gateway

WooCommerce Stripe Gateway is an Addon Gateway Officially Supported by WooCommerce.

Stripe is available in:

  • United States
  • Canada
  • UK
  • Australia
  • Belgium
  • France
  • Germany
  • Ireland
  • The Netherlands
  • and more

WooCommerce Stripe Gateway supports payments through the classic Stripe Checkout.

This documentation covers how to process payment using REST API via Stripe Checkout only. Before getting started, we recommend you to go through Stripe’s Quickstart Guide.

For other Stripe Payment Methods, you can find them at the bottom.


Before you Start

Please make sure you have followed Getting Started and know the basics.

Also, check it out our Demo Shop, place an test order,

It will help your understanding of the WorkFlow.

Installation & Setup

For installation, install & activate WooCommerce Stripe Payment Gateway and WC REST Payment - Stripe Gateway from you wp-admin Dashboard.

You can enable or disable it in your wp-admin Dashboard.

  1. Visit WooCommerce > Settings
  2. Click Payments tab
  3. Toggle the switch in Enabled column
  4. Click Save Changes

For help setting up and configuring, please refer to the user guide

Demo

Check it out our Demo Shop, place an test order,

It will help your understanding of the WorkFlow.


Stripe Checkout Workflow

Checkout securely accepts your customer’s payment details and directly passes them to Stripe’s servers. Stripe returns a token representation of those payment details, which can then be submitted to your server for use.

Here’s how Stripe Checkout works WooCommerce and WC REST Payment.

  1. From your Client (App, Website, etc), the customer’s payment details are securely sent directly to Stripe’s servers.
  2. Stripe returns a Token to the Client.
  3. Send the Token, along with order_id, to your WooCommerce site using REST API.
  4. (Done Automatically) The Token, along with WooCommerce Order data, will be sent to Stripe, to create a charge.
  5. (Done Automatically) Stripe returns a response to your WooCommerce site, and your site returns the resnponse to your Client.

For more detail, you can read the full description here.

Let’s dive in!


Generating Token (Step 1 & 2)

Depending on your Client, there are few different ways to Generate Token.

Please follow the Stripe Official Tutorial to Generate Token.

iOS App

Android App

Web App

If you have successfully generated the Token, Congratulations!

If not, you can use a testing Token fow now. A list of test Card numbers and Tokens can be found on Stripe Testing page.


Process Payment using REST API (Step 3, 4 & 5)

URL HTTP payment_method
/wp-json/wc/v2/process_payment POST stripe

Request

POST: /wp-json/wc/v2/process_payment

{
	"order_id": 65,
	"payment_method": "stripe",
	"stripe_token":"tok_mastercard",
	"create_account": false
}
Parameter Required Description (External Docs are for references only. No coding required.)
order_id Yes ID of an existing WooCommerce Order Object, without the #.
payment_method Yes Each WooCommerce Payment Gateway has a unique ID. You can find the corresponding payment_method above.
stripe_token Yes Token returned by Stripe, or a testing Token.
create_account No Set to true if you wish to Create a Stripe Customer (Authentication Required.), false otherwise. Default is false.

WC REST API will take care of Step 4 & 5, and return you with payment Response.

Response

If the request was successful.

You will receive a response similar to the following.

{
    "code": 200,
    "message": "Payment Successful.",
    "data": {
        "result": "success",
        "redirect": "http://localhost:8888/v/5.1/checkout/order-received/65/?key=wc_order_XXXXXXXXXXXXX"
    }
}

The redirect contains the url to order confirmation page.

If the request failed.

You will receive a response similar to the following.

{
    "code": 403,
    "message": "Order status is 'processing', meaning it had already received a successful payment. Duplicate payments to the order is not allowed. The allow status it is either 'pending' or 'failed'. ",
    "data": {
        "status": 400
    }
}

The message contains the error message and how to fix it.

Summary

That’s it! Easy right? Here’s a quick summary.

  1. Generate a Token by sending payment details to Stripe.
  2. Send a REST API POST Request to /wp-json/wc/v2/process_payment.
  3. Include a JSON Body with order_id, process_payment as stripe and stripe_token.
  4. WC REST Payment and WooCommerce will process the payment with Stripe
  5. You will get the result via REST API Response.

Next Step

There’re a lot more Stripe Gateways that WC REST Payment support!

Looking for other Gateways? Check them out at WC REST Payment Gateways here!