Skip to main content
Version: 5.11.6

UseCoupon

public BackendReturnObject UseCoupon(string couponCode);

Parameter

ValueTypeDescription
couponCodestringCoupon code issued from BACKND Console

Description

Uses the coupon registered in the console.

  • You can use both new and old version coupons.

Example

Synchronous

Backend.Coupon.UseCoupon("18c7c2e1d16e779b");

Asynchronous

Backend.Coupon.UseCoupon("18c7c2e1d16e779b", (callback) =>
{
// Post-process
});

SendQueue

SendQueue.Enqueue(Backend.Coupon.UseCoupon, "18c7c2e1d16e779b", (callback) =>
{
// Post-process
});

Return cases

Success cases

When a coupon without an item is used statusCode : 200

returnValue : {"uuid":613}

When a new coupon with an item is used statusCode : 200

returnValue : refer to GetReturnValuetoJSON for the new coupon

When an old version coupon with an item is used statusCode : 200

returnValue : refer to GetReturnValuetoJSON for the old version coupon

Error cases

When a serial coupon that is prohibited from duplicate use is used again statusCode : 404 errorCode : NotFoundException

When the recovery rate of a single coupon is 100% statusCode : 404 errorCode : NotFoundException

When the coupon has expired
statusCode : 404
errorCode : NotFoundException

When a gamer attempts to redeem a single coupon more than once
statusCode : 404
errorCode : NotFoundException

GetReturnValuetoJSON

// New coupon
{
// Coupon uuid
uuid: "400",
// Since new coupons can have multiple items,
// items are returned as a list.
itemObject : [
{
item: {
// Chart file name
chartFileName: "chartExample.xlsx",
// Item information
itemID: "i101",
itemName: "Item1",
hpPower: "1",
num: "1"
},
itemCount: "1" // Number of items to be handed out
},
...
]
}

// Old coupon
{
// Coupon uuid
uuid: "628",
// Item information registered to the coupon
items:{
// Chart file name
chartFileName: "chartExample.xlsx",
// Item information
itemID: "i101",
itemName: "Item1",
hpPower: "1",
num: "1"
},
itemCount: "1" // Number of items to be handed out
}

Sample code

// This item was made using the BACKND sample chart provided by default.  
// Please change the variables to match the column names in the chart you have uploaded.
public class CouponItem
{
public string uuid;
public string chartFileName;
public string itemID;
public string itemName;
public int hpPower;
public int itemCount;
public override string ToString()
{
return $"itemID : {itemID}\n" +
$"itemName : {itemName}\n" +
$"hpPower : {hpPower}\n" +
$"itemCount : {itemCount}\n" +
$"chartFileName : {chartFileName}\n" +
$"uuid : {uuid}\n";
}
}

public void UseCouponTest()
{
string couponUUID = "2d64e2210493ca6cf5";

var bro = Backend.Coupon.UseCoupon(couponUUID);

if(!bro.IsSuccess())
{
Debug.LogError(bro.ToString());
return;
}

List<CouponItem> couponItemList = new List<CouponItem>();

LitJson.JsonData json = bro.GetReturnValuetoJSON();

for(int i = 0; i < json["itemObject"].Count; i++)
{
CouponItem couponItem = new CouponItem();

couponItem.uuid = json["uuid"].ToString();
couponItem.itemCount = int.Parse(json["itemObject"][i]["itemCount"].ToString());
couponItem.itemID = json["itemObject"][i]["item"]["itemID"].ToString();
couponItem.itemName = json["itemObject"][i]["item"]["itemName"].ToString();
couponItem.hpPower = int.Parse(json["itemObject"][i]["item"]["hpPower"].ToString());
couponItem.chartFileName = json["itemObject"][i]["item"]["chartFileName"].ToString();

couponItemList.Add(couponItem);
}

foreach(var couponItem in couponItemList)
{
Debug.Log(couponItem.ToString());
}
}