diff --git a/android/src/main/java/ir/appeto/myketpayment/MyketpaymentPlugin.java b/android/src/main/java/ir/appeto/myketpayment/MyketpaymentPlugin.java index 8313de0..ea132e9 100644 --- a/android/src/main/java/ir/appeto/myketpayment/MyketpaymentPlugin.java +++ b/android/src/main/java/ir/appeto/myketpayment/MyketpaymentPlugin.java @@ -43,6 +43,8 @@ public class MyketpaymentPlugin implements FlutterPlugin, MethodCallHandler, Act public String payload; public String sku; public boolean consume; + public String purchasedSku; + public boolean isPurchased = false; @@ -75,6 +77,9 @@ public class MyketpaymentPlugin implements FlutterPlugin, MethodCallHandler, Act else if (call.method.equals("buy")) { buy(call, result); } + else if (call.method.equals("check")) { + check(call, result); + } else { result.notImplemented(); } @@ -82,6 +87,10 @@ public class MyketpaymentPlugin implements FlutterPlugin, MethodCallHandler, Act public void setup(@NonNull MethodCall call, @NonNull Result result) { Log.d(TAG, call.argument("rsa").toString()); + Log.d(TAG, call.argument("purchasedSku").toString()); + + purchasedSku = call.argument("purchasedSku").toString(); + // Create the helper, passing it our context and the public key to verify signatures with String base64EncodedPublicKey = call.argument("rsa").toString(); Log.d(TAG, "Creating IAB helper."); @@ -127,6 +136,10 @@ public class MyketpaymentPlugin implements FlutterPlugin, MethodCallHandler, Act mPurchaseFinishedListener, payload); } + public void check(@NonNull MethodCall call, @NonNull Result result) { + _result.success(isPurchased); + } + // Listener that's called when we finish querying the items and subscriptions we own IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { @Override @@ -146,6 +159,14 @@ public class MyketpaymentPlugin implements FlutterPlugin, MethodCallHandler, Act return; } Log.d(TAG, "Query inventory was successful."); + + if(purchasedSku != "") { + Purchase premiumPurchase = inventory.getPurchase(purchasedSku); + isPurchased = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase)); + Log.d(TAG, "User is " + (isPurchased ? "PREMIUM" : "NOT PREMIUM")); + } + + _result.success(true); } diff --git a/example/lib/main.dart b/example/lib/main.dart index 5e09e61..a1c475e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -69,6 +69,23 @@ class _MyAppState extends State { } }, ), + SizedBox(height: 20,), + FlatButton( + child: Text("check purchase"), + onPressed: () async { + if(!setup) { + setup = await Myketpayment.setup(rsa, purchasedSku: 'flunlimit'); + } + print("setup: $setup"); + if(setup) { + final result = await Myketpayment.check(); + print("IsPurchased: $result"); + } + else { + print("can not connect to myket"); + } + }, + ), ], ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index a488521..886f381 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -80,7 +80,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" myketpayment: dependency: "direct main" description: @@ -106,7 +106,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -141,7 +141,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.4.2" typed_data: dependency: transitive description: @@ -157,5 +157,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.10.0" diff --git a/lib/myketpayment.dart b/lib/myketpayment.dart index f0a7743..b2df304 100644 --- a/lib/myketpayment.dart +++ b/lib/myketpayment.dart @@ -7,8 +7,8 @@ class Myketpayment { static const MethodChannel _channel = const MethodChannel('myketpayment'); - static Future setup(String rsa) async { - final bool version = await _channel.invokeMethod('setup', {"rsa": rsa}); + static Future setup(String rsa, {String purchasedSku = ''}) async { + final bool version = await _channel.invokeMethod('setup', {"rsa": rsa, 'purchasedSku': purchasedSku}); return version; } @@ -17,5 +17,9 @@ class Myketpayment { return result; } + static Future check() async { + final bool version = await _channel.invokeMethod('check', {}); + return version; + } } diff --git a/pubspec.lock b/pubspec.lock index 8f4a32f..4fe6b9f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -73,7 +73,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -92,7 +92,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -127,7 +127,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.4.2" typed_data: dependency: transitive description: @@ -143,5 +143,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.10.0"