Showing
2 changed files
with
44 additions
and
1 deletions
| ... | @@ -24,4 +24,19 @@ class OrderApi extends BaseApi { | ... | @@ -24,4 +24,19 @@ class OrderApi extends BaseApi { |
| 24 | return json.decode(value.data); | 24 | return json.decode(value.data); |
| 25 | }); | 25 | }); |
| 26 | } | 26 | } |
| 27 | + | ||
| 28 | + Future<dynamic> verifyOrder(String orderId, String type, String token, {Map<String, dynamic>? others}) { | ||
| 29 | + var data = { | ||
| 30 | + "order_sn": orderId, | ||
| 31 | + "pay_type": type, | ||
| 32 | + "token": token, | ||
| 33 | + "others": others ?? {}, | ||
| 34 | + }; | ||
| 35 | + return post("pay", data: data).then((value) { | ||
| 36 | + if (TextUtil.isEmpty(value.data)) { | ||
| 37 | + return {}; | ||
| 38 | + } | ||
| 39 | + return value.data; | ||
| 40 | + }); | ||
| 41 | + } | ||
| 27 | } | 42 | } | ... | ... |
| ... | @@ -4,8 +4,12 @@ import 'package:Parlando/apis/api_order.dart'; | ... | @@ -4,8 +4,12 @@ import 'package:Parlando/apis/api_order.dart'; |
| 4 | import 'package:Parlando/membership/models/membership_entity.dart'; | 4 | import 'package:Parlando/membership/models/membership_entity.dart'; |
| 5 | import 'package:common_utils/common_utils.dart'; | 5 | import 'package:common_utils/common_utils.dart'; |
| 6 | import 'package:in_app_purchase/in_app_purchase.dart'; | 6 | import 'package:in_app_purchase/in_app_purchase.dart'; |
| 7 | +import 'package:in_app_purchase_android/in_app_purchase_android.dart'; | ||
| 8 | +import 'package:in_app_purchase_storekit/in_app_purchase_storekit.dart'; | ||
| 7 | 9 | ||
| 8 | class PaymentSdk { | 10 | class PaymentSdk { |
| 11 | + var currentOrder; | ||
| 12 | + | ||
| 9 | PaymentSdk._privateConstructor(); | 13 | PaymentSdk._privateConstructor(); |
| 10 | 14 | ||
| 11 | static final PaymentSdk _instance = PaymentSdk._privateConstructor(); | 15 | static final PaymentSdk _instance = PaymentSdk._privateConstructor(); |
| ... | @@ -59,6 +63,7 @@ class PaymentSdk { | ... | @@ -59,6 +63,7 @@ class PaymentSdk { |
| 59 | onFailed?.call(); | 63 | onFailed?.call(); |
| 60 | return; | 64 | return; |
| 61 | } | 65 | } |
| 66 | + currentOrder = orderId; | ||
| 62 | final PurchaseParam purchaseParam = PurchaseParam(productDetails: details, applicationUserName: orderId); | 67 | final PurchaseParam purchaseParam = PurchaseParam(productDetails: details, applicationUserName: orderId); |
| 63 | if (_isConsumable(details)) { | 68 | if (_isConsumable(details)) { |
| 64 | InAppPurchase.instance.buyConsumable(purchaseParam: purchaseParam); | 69 | InAppPurchase.instance.buyConsumable(purchaseParam: purchaseParam); |
| ... | @@ -97,7 +102,30 @@ class PaymentSdk { | ... | @@ -97,7 +102,30 @@ class PaymentSdk { |
| 97 | } | 102 | } |
| 98 | 103 | ||
| 99 | void _deliverProduct(PurchaseDetails purchaseDetails) { | 104 | void _deliverProduct(PurchaseDetails purchaseDetails) { |
| 100 | - onPaySuccess?.call(); | 105 | + String type = ""; |
| 106 | + Map<String, dynamic> otherField = {}; | ||
| 107 | + if (purchaseDetails is GooglePlayPurchaseDetails) { | ||
| 108 | + currentOrder = purchaseDetails.billingClientPurchase.obfuscatedAccountId; | ||
| 109 | + type = "google"; | ||
| 110 | + otherField["google"] = { | ||
| 111 | + "originalJson": purchaseDetails.billingClientPurchase.originalJson, | ||
| 112 | + }; | ||
| 113 | + } | ||
| 114 | + if (purchaseDetails is AppStorePurchaseDetails) { | ||
| 115 | + type = "apple"; | ||
| 116 | + otherField["apple"] = { | ||
| 117 | + "transactionIdentifier": purchaseDetails.skPaymentTransaction.transactionIdentifier, | ||
| 118 | + "originalTransactionIdentifier": | ||
| 119 | + purchaseDetails.skPaymentTransaction.originalTransaction?.transactionIdentifier ?? "", | ||
| 120 | + }; | ||
| 121 | + } | ||
| 122 | + var serverVerifyStr = purchaseDetails.verificationData.serverVerificationData; | ||
| 123 | + var verifySource = purchaseDetails.verificationData.source; | ||
| 124 | + otherField["source"] = verifySource; | ||
| 125 | + OrderApi.request.verifyOrder(currentOrder, type, serverVerifyStr, others: otherField).then((value) { | ||
| 126 | + if (value != null) {} | ||
| 127 | + onPaySuccess?.call(); | ||
| 128 | + }); | ||
| 101 | } | 129 | } |
| 102 | 130 | ||
| 103 | void _handleInvalidPurchase(PurchaseDetails purchaseDetails) { | 131 | void _handleInvalidPurchase(PurchaseDetails purchaseDetails) { | ... | ... |
-
Please register or login to post a comment