import 'dart:async'; import 'package:electronic_assistant/sdk/pay/applepay/apple_pay_info.dart'; import 'package:flutter/widgets.dart'; import 'package:in_app_purchase/in_app_purchase.dart'; import '../assist/apple_or_google_pay.dart'; import '../code/agile_pay_code.dart'; import '../listener/i_agile_pay.dart'; class ApplePay extends AppleOrGooglePay implements IAgilePay { final ApplePayInfo _payInfo; ApplePay(this._payInfo) : super(_payInfo); @override void listenToPurchaseUpdated(List purchaseDetailsList) { for (var purchaseDetails in purchaseDetailsList) { debugPrint( 'agilePay-applePay--PurchaseUpdated-> ${purchaseDetails.toString()}'); if (purchaseDetails.status == PurchaseStatus.pending) { } else if (purchaseDetails.status == PurchaseStatus.error) { _verifyErrorPurchase(purchaseDetails); } else if (purchaseDetails.status == PurchaseStatus.purchased) { _verifySuccessPurchase(purchaseDetails); } else if (purchaseDetails.status == PurchaseStatus.canceled) { sendError(AgilePayCode.payCodeCancelError, AgilePayCode.getMessageByCode(AgilePayCode.payCodeCancelError)); } } } void _verifyErrorPurchase(PurchaseDetails purchaseDetails) { if (purchaseDetails.error?.code == 'store_kit_network_error') { sendError(AgilePayCode.payCodeNetError, AgilePayCode.getMessageByCode(AgilePayCode.payCodeNetError)); } else { sendError(AgilePayCode.payCodeOtherError, AgilePayCode.getMessageByCode(AgilePayCode.payCodeOtherError)); } } void _verifySuccessPurchase(PurchaseDetails purchaseDetails) { sendPaySuccess(purchaseDetails.purchaseID); } }