Appearance
Rewards System
Upshot's rewards module helps to reward users based on the actions performed by them on a mobile app or a website. This module allows to boost retention and helps increase user's loyalty towards applications.
Overview
Upshot.ai provides few API's(methods) to fetch list of reward programs achieved by the user. Transaction history, reward rules and redeem rewards for the program.
All reward responses will get via methodChannel as a callback.
Rewards Status
By using fetchRewards method you will get a list of active reward programs achieved by the user.
How to Fetch Rewards
dart
// Fetch active reward programs
FlutterUpshotPlugin.fetchRewards();
Response
Rewards data will be received via Method Channel callback:
dart
static const _channel = MethodChannel('flutter_upshot_plugin');
UpshotMethodChannel() {
_channel.setMethodCallHandler (_methodCallHandler);
}
Future<dynamic> _methodCallHandler(MethodCall call) async {
if (call.method == "upshotRewardsResponse") {
Map data = call.arguments as Map;
final response = data["response"];
}
}
Sample Response
json
{
"status": "success",
"statusCode": 200,
"status_code": 200,
"data": [
{
"program_description": "",
"display_name": "",
"program_name": "Sample",
"programId": "5dd268259834967b62dd6ff4",
"logo_url": "https://s3.amazonaws.com/albdock-bk/shared_folder/media/images/5dd26822442c2.png",
"balance": 60,
"rewards_redeemed": 20,
"rewards_earned": 120,
"rewards_penalty": 40,
"rewards_expired": 0
}
]
}
Redeem Rewards
Use the redeemRewards
method to request reward redemption. Upshot will check the user's balance against the redeem value and provide the status of the request.
How to Redeem Rewards
dart
// Redeem rewards parameters
FlutterUpshotPlugin.redeemRewards(programId, redeemAmount, transactionValue, "Tag");
Parameters
Below are the parameters to redeem rewards:
- programId: The ID of the reward program
- transactionValue: Value of the transaction
- redeemValue: Amount of rewards to redeem
- tag: Tag associated with the redemption
Response
Redemption response will be received via Method Channel:
dart
static const _channel = MethodChannel('flutter_upshot_plugin');
UpshotMethodChannel() {
_channel.setMethodCallHandler (_methodCallHandler);
}
Future<dynamic> _methodCallHandler(MethodCall call) async {
if (call.method == "upshotRedeemRewardsResponse") {
Map data = call.arguments as Map;
final response = data["response"];
}
}
Sample Responses
Success Response:
json
{
"status": "success",
"statusCode": 200
}
Failure Response:
json
{
"status": "Failed",
"statusCode": 200,
"statusMessage": "balance insufficient"
}
Reward History
Use the fetchRewardHistory
method to get the transaction history for a specific reward program based on programId and historyType.
How to Fetch Reward History
dart
FlutterUpshotPlugin.fetchRewardHistory(programId, historyType);
Parameters
Below are the parameters to fetch rewards history:
- programId: The ID of the reward program
- historyType: Type of history ("earned", "redeemed", or "all")
Transaction Types
- RewardEntireHistory (0) - Includes all transaction types
- RewardEarnHistory (1) - Shows only earned history
- RewardExpiryHistory (2) - Shows expired history
- RewardRedeemHistory (3) - Shows only redeemed history
- RewardNegativeHistory (4) - Shows negative/penalty history
Response
History data will be received via Method Channel:
dart
static const _channel = MethodChannel('flutter_upshot_plugin');
UpshotMethodChannel() {
_channel.setMethodCallHandler (_methodCallHandler);
}
Future<dynamic> _methodCallHandler(MethodCall call) async {
if (call.method == "upshotRewardHistoryResponse") {
Map data = call.arguments as Map;
final response = data["response"];
}
}
Sample Response
json
{
"status": "success",
"statusCode": 200,
"status_code": 200,
"data": [
{
"transaction_value": null,
"transaction_type": 4,
"transaction_date": 1574090603,
"reward_value": 10,
"tag": "pumping"
},
{
"transaction_value": null,
"transaction_type": 1,
"transaction_date": 1574091350,
"reward_value": 60,
"tag": "pumping"
}
]
}
Reward Rules
Use the fetchRewardRules
method to get the list of rules with name, description, and tag associated for a given programId.
How to Fetch Earning Rules for Reward
dart
FlutterUpshotPlugin.fetchRewardRules(programId);
Parameters
Below are the parameters to fetch reward rules:
- programId: The ID of the reward program
Response
Rules data will be received via Method Channel:
dart
static const _channel = MethodChannel('flutter_upshot_plugin');
UpshotMethodChannel() {
_channel.setMethodCallHandler (_methodCallHandler);
}
Future<dynamic> _methodCallHandler(MethodCall call) async {
if (call.method == "upshotRewardRulesResponse") {
Map data = call.arguments as Map;
final response = data["response"];
}
}
Sample Response
json
{
"status": "success",
"statusCode": 200,
"status_code": 200,
"data": {
"programId": "5dd268259834967b62dd6ff4",
"program_description": "",
"rules": [
{
"rule_name": "World Rule-1",
"ruleId": "5dd268e6c322233ae963830e",
"tag": "tag",
"rule_description": ""
},
{
"rule_name": "World Rule-2",
"ruleId": "5dd2694a9834967b62dd6ff5",
"tag": "tag",
"rule_description": ""
}
]
}
}