Example using e-commerce platform(WooCommerce)

Please note that the same steps can be applied to different platforms with a slight changes based on your platform, we are only using WooCommerce for the sake of this example.

In this guide, we will show you how to integrate a platform's existing coupon system with Gameball backend, we will give example of integrating Gameball with WooCommerce coupon system.

Integrating With WooCommerce coupon API

We are only interested in the create coupon endpoint, so we can safely ignore others endpoints related to coupon.

  1. Search on google or in your platform documentation for the API responsible for creating coupons or coupon system API or similar keywords, you will find it here.

  2. Fill in the configurations based on the coupon HTTP request structure in your create coupon endpoint, for example WooCommerce will expect Gameball Backend to send an HTTP request with the following JSON body when creating a new coupon.

POST /wp-json/wc/v3/coupons HTTP/1.1
Content-Type: application/json
Authorization: Basic API_KEY:API_SECRET

{
  "code": "MYCOUPON",
  "amount": 10,
  "discount_type": "percent",
  "usage_limit": 100,
  "expiry_date": "2023-12-31"
  "product_ids" :"[]",
  "product_categories" : "[]",
}

Based on this structure, you will add the configurations we mentioned previously

Name
Value

Method

POST

Request Headers

{ Authorization : OAuth oauth_consumer_key="ck_c9943d372c50",oauth_signature_method="HMAC-SHA1",oauth_timestamp="",oauth_nonce="ESXiR5boeRS",oauth_version="1.0",oauth_signature="ws%2F6UwgNor56Huc4ULYTVp51bIQ%3D"

}

Payload

In the payload json object, the key is always fixed, only values between {{}} are changed based on coupon property names in the request body, for example if WooCommerce changed name of discount_type attribute in the coupon properties table to coupon_type the json body should looks like this :

{
 "playerUniqueId": "{{email_restrictions}}",
 "entitledProductIds":"{{product_ids}}",
 "entitledCollectionIds":"{{product_categories}}",
 "oncePerCustomer": "{{usage_limit_per_user}}",
 "code": "{{code}}",
 "usageLimit": "{{usage_limit}}",
 "value": "{{amount}}",
 "couponType": "{{coupon_type}}"
}

You need to pass the required attributes only, in WooCommerce coupon API, the coupon code attribute is the only required attribute, so the following payload is also valid :

{
"code":"{{code}}"
}

You can pass other attributes based on your preferences, for example, couponType attribute is not required in case you want to create the default type.

The coupon creation endpoint must return 200 code in order for coupon to be created successfully.

  1. Define coupon type values. You may have noticed there are four checkboxes at the end of the configurations page in dashboard, each checkbox represents one of the coupon types supported by Gameball, you need to check if WooCommerce support it or not and if it support it you need to provide value for it based on its corresponding type in WooCommerce coupon API, for example, there are three discount types in WooCommerce percent, fixed_cart and fixed_product. So, we will check fixed rate, percentage and free product coupons in dashboard and insert the corresponding value for each coupon type in WooCommerce, i.e: percentage coupon value will be percent.

  2. Click on test connection to check if your configurations is correct or not.

Now you are all set to start creating coupons for your customers !

Last updated