Browse Source

add check payment method

master
parent
commit
50125bad94
5 changed files with 56 additions and 14 deletions
  1. +21
    -0
      android/src/main/java/ir/appeto/myketpayment/MyketpaymentPlugin.java
  2. +17
    -0
      example/lib/main.dart
  3. +6
    -6
      example/pubspec.lock
  4. +6
    -2
      lib/myketpayment.dart
  5. +6
    -6
      pubspec.lock

+ 21
- 0
android/src/main/java/ir/appeto/myketpayment/MyketpaymentPlugin.java View File

@@ -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);

}


+ 17
- 0
example/lib/main.dart View File

@@ -69,6 +69,23 @@ class _MyAppState extends State<MyApp> {
}
},
),
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");
}
},
),
],
),
),


+ 6
- 6
example/pubspec.lock View File

@@ -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"

+ 6
- 2
lib/myketpayment.dart View File

@@ -7,8 +7,8 @@ class Myketpayment {
static const MethodChannel _channel = const MethodChannel('myketpayment');


static Future<bool> setup(String rsa) async {
final bool version = await _channel.invokeMethod('setup', {"rsa": rsa});
static Future<bool> 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<bool> check() async {
final bool version = await _channel.invokeMethod('check', {});
return version;
}

}

+ 6
- 6
pubspec.lock View File

@@ -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"

Loading…
Cancel
Save