buy method

Future<void> buy(
  1. String productId,
  2. dynamic callback(
    1. String productId,
    2. String trackingCode
    ),
  3. dynamic onError(
    1. String error
    )
)

Implementation

Future<void> buy(
    String productId,
    Function(String productId, String trackingCode) callback,
    Function(String error) onError) async {
  try {
    var buy = await InAppPurchasePlatform.instance.buy(productId);
    String? trackingCode = buy![1];
    if (trackingCode != null) {
      var data =
          (await Dio(BaseOptions(baseUrl: 'https://master.hupadstore.ir/'))
                  .post('/api/Wallet/CheckPurchase',
                      data: {'txid': trackingCode}))
              .data;
      if (data['status'] == 1) {
        callback(buy[0], data['entity']);
      } else {
        onError(data['error']?['message']);
      }
    } else {
      onError('field');
    }
  } on PlatformException catch (e) {
    onError(e.message.toString());
  }
}