Skip to content

CafeBazaar APIs (In-App Purchase, Intents, UpdateChecker, LoginChecker) in flutter, works only in Android platform

License

Notifications You must be signed in to change notification settings

DJafari/flutter_bazaar

Repository files navigation

SHOW PERSIAN README

flutter_bazaar

CafeBazaar API (In-App Purchase, Intents, UpdateChecker, LoginChecker) in flutter, works only in Android platform

Getting Started

first, add flutter_bazaar to your pubspec dependencies.

flutter_bazaar: <LAST VERSION>

To import flutter_bazaar:

import 'package:flutter_bazaar/flutter_bazaar.dart';

Done!

API

In-App purchase

InAppPurchase of this library build by Poolakey, new cafebazaar IAP library

Initialization

first you must initialized iap :

final _bazaar = FlutterBazaar.instance;
final iap = _bazaar.inAppPurchase(PUBLIC_KEY);

PUBLIC_KEY is your public RSA key from cafebazaar control panel

Purchase a product

final PurchaseInfo purchaseInfo = await iap.purchase("productId", payLoad: "Your payload");
if(purchaseInfo != null) {
  print('success: $purchaseResult');
}

if purchaseInfo != null purchase is successful

purchaseInfo is full detail of purchase :

class PurchaseInfo {
  final String orderId;
  final String purchaseToken;
  final String payload;
  final String packageName;
  final String purchaseState;
  final int purchaseTime;
  final String productId;
  final String dataSignature;
}

Subscribe to product

final PurchaseInfo purchaseInfo = await iap.subscribe("productId", payLoad: "Your payload");
if(purchaseInfo != null) {
  print('success: $subscribeResult');
}

if purchaseInfo != null subscription is successful

Consume a purchase

final bool consumeResult = await iap.consume("PURCHASE TOKEN"); //IN PurchaseInfo.purchaseToken

note: if you need PurchaseToken after purchase you can getting it from purchaseInfo.purchaseToken

User purchases

for getting all purchases of user :

final List<PurchaseInfo> purchasedProducts = await iap.getPurchasedProducts();
print(purchasedProducts);

User Subscriptions

for getting all subscriptions of user :

final List<PurchaseInfo> subscribedProducts = await iap.getSubscribedProducts();
print(subscribedProducts);

Disconnect

for disconnect connection of app and cafebazaar :

await iap.disconnect();

Intents

Open application detail page

for open details page of your app ( or another application ) you can use this method :

final _bazaar = FlutterBazaar.instance;
await _bazaar.openDetail([String packageName]);
print('USER BACK TO YOUR APP');

if packageName == null this library open details page of current packageName

note: this method is Future, and you can found when user back to app

Open Developer applications List

for open list of all applications of developer, you can use this method :

final _bazaar = FlutterBazaar.instance;
await _bazaar.openDeveloperPage(String developerId);
print('USER BACK TO YOUR APP');

note: this method is Future, and you can found when user back to app

Open comment form

for open comment form of this app ( or given packageName app ) use this method :

final _bazaar = FlutterBazaar.instance;
await _bazaar.openCommentForm([String packageName]);
print('USER BACK TO YOUR APP');

if packageName == null this library open comment form of current packageName

note: this method is Future, and you can found when user back to app

Update Checker

for getting current version of your app in cafebazaar market :

final _bazaar = FlutterBazaar.instance;
final int versionCode = await _bazaar.getLatestVersion();

Login Checker

for getting current status of logged user in cafebazaar, you can use this method :

final _bazaar = FlutterBazaar.instance;
final bool isLoggedIn = await _bazaar.isLoggedIn();

for more info check Example