AwardCurrency
Award user the passed-in amount of currency. Returns an object representing the new currency values.
note
Awarding 0 or negative currency will return an error. Use ConsumeCurrency
to remove currency values.
caution
For security reasons calling this API from the client is not recommended, and is rejected at the server by default. To over-ride, enable the 'Allow Currency Calls from Client' compatibility setting in the Design Portal.
Service | Operation |
---|---|
virtualCurrency | AWARD_VC |
Method Parameters
Parameter | Description |
---|---|
vcId | The currency type to award. |
vcAmount | The amount of currency to award. |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string vcId = "coins";
int vcAmount = 1;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.VirtualCurrencyService.AwardCurrency(vcId, vcAmount, successCallback, failureCallback);
const char *vcId = "coins";
int vcAmount = 1;
_bc->getVirtualCurrencyService()->awardCurrency(vcId, vcAmount, this);
NSString *vcId = @"coins";
int vcAmount = 1;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc virtualCurrencyService] awardCurrency:vcId
vcAmount:vcAmount
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String vcId = "coins";
int vcAmount = 1;
this; // implements IServerCallback
_bc.getVirtualCurrencyService().awardCurrency(vcId, vcAmount, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var vcId = "coins";
var vcAmount = 1;
_bc.virtualCurrency.awardCurrency(vcId, vcAmount, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var vcId = "coins";
var vcAmount = 1;
ServerResponse result = await _bc.virtualCurrencyService.awardCurrency(vcId:vcId, vcAmount:vcAmount);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var vcId = "coins";
var vcAmount = 1;
var virtualCurrencyProxy = bridge.getVirtualCurrencyServiceProxy();
var postResult = virtualCurrencyProxy.awardCurrency(vcId, vcAmount);
if (postResult.status == 200) {
// Success!
}
{
"service": "virtualCurrency",
"operation": "AWARD_VC",
"data": {
"vcId": "coins",
"vcAmount": 1
}
}
JSON Response
{
"status": 200,
"data": {
"currencyMap": {
"gems": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0,
"revoked": 0
},
"gold": {
"purchased": 0,
"balance": 123,
"consumed": 0,
"awarded": 123,
"revoked": 0
}
}
}
}