creditToPlayerWallet function

Future<PlayerBalance> creditToPlayerWallet(
  1. String playerUid,
  2. Transaction transaction,
  3. Config config
)

Implementation

Future<PlayerBalance> creditToPlayerWallet(
    String playerUid, Transaction transaction, Config config) async {
  final response =
      await http.post(Uri.parse('${config.server}/api/wallet/transactions'),
          headers: <String, String>{
            'Content-Type': 'application/json; charset=UTF-8',
          },
          body: jsonEncode(<String, dynamic>{
            "operator_id": config.operatorId,
            "client_secret": config.clientSecret,
            "client_id": config.clientId,
            "player_uid": playerUid,
            "amount": transaction.amount,
            "currency": transaction.currency,
            "coins": transaction.coins,
            "uid": transaction.uid,
            "reference": transaction.reference,
            "remarks": transaction.remarks,
            "productId": transaction.productId,
            "productName": transaction.productName,
            "sku": transaction.sku,
            "isCredit": true
          }));

  if (response.statusCode == 200) {
    // If the server did return a 200 OK response,
    // then parse the JSON.
    var rb = response.body;
    var data = json.decode(rb);
    PlayerBalance playerBalance =
        PlayerBalance.fromJson(data["currentBalance"]);
    return playerBalance;
  } else {
    // If the server did not return a 200 OK response,
    // then throw an exception.
    throw Exception(
        'Failed to make deposit transaction. Make sure that you have set all the required parameters and also uid is unique (not used earlier in previous transaction)');
  }
}