|
|
@@ -2,6 +2,7 @@ import 'dart:async';
|
|
|
|
|
|
import 'package:electronic_assistant/sdk/pay/assist/apple_or_google_pay_info.dart';
|
|
|
import 'package:electronic_assistant/sdk/pay/assist/product_type.dart';
|
|
|
+import 'package:flutter/cupertino.dart';
|
|
|
import 'package:in_app_purchase/in_app_purchase.dart';
|
|
|
|
|
|
import '../code/agile_pay_code.dart';
|
|
|
@@ -83,5 +84,33 @@ abstract class AppleOrGooglePay extends AgilePayStateInfo {
|
|
|
_purchaseUpdatedSubscription.cancel();
|
|
|
}
|
|
|
|
|
|
- void listenToPurchaseUpdated(List<PurchaseDetails> purchaseDetailsList);
|
|
|
+ void listenToPurchaseUpdated(List<PurchaseDetails> 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);
|
|
|
+ }
|
|
|
}
|