makePurchase static method

Future<MakePurchaseResponse> makePurchase(
  1. Product product
)

Launches a new purchase transaction using Apple interface.

When you want to make a purchase transaction, just pass the Product object parameter to the method, then appmate will communicate with AppStore and handle Apple purchase process.

Provide the Product object you want to purchase.

Callbacks MakePurchaseResponse and GenericError in case of failure.

Implementation

static Future<MakePurchaseResponse> makePurchase(Product product) async {
  List<Object?>? response = await _channel.invokeMethod(
      'makePurchase', {"product": json.encode(product.toJson())});
  MakePurchaseResponse? result = new MakePurchaseResponse(null, null);
  if (response != null) {
    if (response[0] != null) {
      var jsonResponse = json.decode(response[0]!.toString());
      if (jsonResponse["purchaseInfo"] is List) {
        result =
            MakePurchaseResponse.fromJson(jsonResponse["purchaseInfo"][0]);
      } else {
        result = MakePurchaseResponse.fromJson(jsonResponse);
      }
    }
    if (response[1] != null) {
      GenericError error =
          GenericError.fromJson(json.decode(response[1]!.toString()));
      result = new MakePurchaseResponse(null, error);
    }
    return result;
  }
  return result;
}