All Projects → memspace → iap

memspace / iap

Licence: BSD-3-Clause License
Flutter plugin for interacting with iOS StoreKit and Android Billing Library

Programming Languages

dart
5743 projects
objective c
16641 projects - #2 most used programming language
java
68154 projects - #9 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to iap

flutter example
flutter code,flutter-banner,flutter-codekk,flutter-panda,flutter_tab
Stars: ✭ 94 (+422.22%)
Mutual labels:  flutter-plugin
theme mode handler
Flutter widget to change `themeMode` during runtime and persist it across restarts.
Stars: ✭ 28 (+55.56%)
Mutual labels:  flutter-plugin
x5 webview flutter
一个基于腾讯x5引擎的webview flutter插件,简化集成,一行代码打开视频播放,暂时只支持android使用
Stars: ✭ 90 (+400%)
Mutual labels:  flutter-plugin
flutter launch whatsapp
Plugin flutter to launch whatsapp
Stars: ✭ 46 (+155.56%)
Mutual labels:  flutter-plugin
flutter-tunein
Dynamically themed Music Player built with flutter
Stars: ✭ 108 (+500%)
Mutual labels:  flutter-plugin
nativeweb
Build your Own Plugin using (PlatformViews) Demo for Flutter Live 2018 Extended Event - Hyderabad
Stars: ✭ 26 (+44.44%)
Mutual labels:  flutter-plugin
flutter opencv
OpenCV bindings plugin for Flutter apps [work in progress]
Stars: ✭ 81 (+350%)
Mutual labels:  flutter-plugin
flutter paystack
💳 A robust Flutter plugin for making payments via Paystack Payment Gateway. Completely supports Android and iOS
Stars: ✭ 146 (+711.11%)
Mutual labels:  flutter-plugin
pub-scaff
scaff, scaffold generator for Dart and Flutter
Stars: ✭ 27 (+50%)
Mutual labels:  flutter-plugin
qrcode
A flutter plugin for scanning QR codes. Use AVCaptureSession in iOS and zxing in Android.
Stars: ✭ 69 (+283.33%)
Mutual labels:  flutter-plugin
oscilloscope
A Flutter package that can display an Oscilloscope type graphical display
Stars: ✭ 17 (-5.56%)
Mutual labels:  flutter-plugin
r scan
📷🖨Flutter二维码&条形码扫描插件,支持相机、文件、链接、Uint8List类型扫描
Stars: ✭ 108 (+500%)
Mutual labels:  flutter-plugin
audio manager
A flutter plugin for music playback, including notification handling.
Stars: ✭ 94 (+422.22%)
Mutual labels:  flutter-plugin
flutter-elinux-plugins
Flutter plugins for embedded Linux (eLinux)
Stars: ✭ 21 (+16.67%)
Mutual labels:  flutter-plugin
A-Complete-Guide-To-Flutter
This repo contains all the small snippets related to Flutter Apps. Most of the projects/apps are deployed on Flutter Web using GitHub Actions CI Pipeline.
Stars: ✭ 70 (+288.89%)
Mutual labels:  flutter-plugin
lang table
lang_table is a dart plugin to generate string files from a source. Use a table to manage all multi-language resources. Inspired by fetch-mobile-localization-from-airtable
Stars: ✭ 17 (-5.56%)
Mutual labels:  flutter-plugin
amap search fluttify
高德地图 搜索组件 Flutter插件
Stars: ✭ 56 (+211.11%)
Mutual labels:  flutter-plugin
nami-apple
Easy Apple subscriptions & in-app purchases, powered by on-device machine learning to grow your revenue. The smartest way to sell subscriptions.
Stars: ✭ 34 (+88.89%)
Mutual labels:  storekit
cross connectivity
A Flutter plugin for handling Connectivity and REAL Connection state in the mobile, web and desktop platforms. Supports iOS, Android, Web, Windows, Linux and macOS.
Stars: ✭ 27 (+50%)
Mutual labels:  flutter-plugin
Flutter-Apps
🌀 This is mainly focus on a complete application for production
Stars: ✭ 18 (+0%)
Mutual labels:  flutter-plugin

Flutter plugin for interacting with iOS StoreKit and Android Billing Library.

Build Status codecov

Work in progress.

How this plugin is different from others

The main difference is that instead of providing unified interface for in-app purchases on iOS and Android, this plugin exposes two separate APIs.

There are several benefits to this approach:

  • We can expose complete API interfaces for both platforms, without having to look for lowest common denominator of those APIs.
  • Dart interfaces are designed to match native ones most of the time. StoreKit for iOS follows native interface in 99% of cases. BillingClient for Android is very similar as well, but also simplifies some parts of native protocol (mostly replaces listeners with Dart Futures).
  • Developers familiar with native APIs would find it easier to learn. You can simply refer to official documentation in most cases to find details about certain method of field.

All Dart code is thoroughly documented with information taken directly from Apple Developers website (for StoreKit) and Android Developers website (for BillingClient).

Note that future versions may introduce unified interfaces for specific use cases, for instance, handling of in-app subscriptions.

StoreKit (iOS)

Plugin currently implements all native APIs except for downloads. If you are looking for this functionality consider submitting a pull request or leaving your 👍 here.

Interacting with StoreKit in Flutter is almost 100% identical to the native ObjectiveC interface.

Prerequisites

Make sure to

  • Complete Agreements, Tax and Bankings
  • Setup your products in AppStore Connect
  • Enable In-App Purchases for your app in XCode

Complete example

Checkout a complete example of interacting with StoreKit in the example app in this repo. Note that in-app purchases is a complex topic and it would be really hard to cover everything in a simple example app like this, so it is highly recommended to read official documentation on setting up in-app purchases for each platform.

Getting products

final productIds = ['my.product1', 'my.product2'];
final SKProductsResponse response = await StoreKit.instance.products(productIds);
print(response.products); // list of valid [SKProduct]s
print(response.invalidProductIdentifiers) // list of invalid IDs

App Store Receipt

// Get receipt path on device
final Uri receiptUrl = await StoreKit.instance.appStoreReceiptUrl;
// Request a refresh of receipt
await StoreKit.instance.refreshReceipt();

Handling payments and transactions

Payments and transactions are handled within SKPaymentQueue.

It is important to set an observer on this queue as early as possible after your app launch. Observer is responsible for processing all events triggered by the queue. Create an observer by extending following class:

abstract class SKPaymentTransactionObserver {
  void didUpdateTransactions(SKPaymentQueue queue, List<SKPaymentTransaction> transactions);
  void didRemoveTransactions(SKPaymentQueue queue, List<SKPaymentTransaction> transactions) {}
  void failedToRestoreCompletedTransactions(SKPaymentQueue queue, SKError error) {}
  void didRestoreCompletedTransactions(SKPaymentQueue queue) {}
  void didUpdateDownloads(SKPaymentQueue queue, List<SKDownload> downloads) {}
  void didReceiveStorePayment(SKPaymentQueue queue, SKPayment payment, SKProduct product) {}
}

See API documentation for more details on these methods.

Make sure to implement didUpdateTransactions and process all transactions according to your needs. Typical implementation should normally look like this:

void didUpdateTransactions(
    SKPaymentQueue queue, List<SKPaymentTransaction> transactions) async {
  for (final tx in transactions) {
    switch (tx.transactionState) {
      case SKPaymentTransactionState.purchased:
        // Validate transaction, unlock content, etc...
        // Make sure to call `finishTransaction` when done, otherwise
        // this transaction will be redelivered by the queue on next application
        // launch.
        await queue.finishTransaction(tx);
        break;
      case SKPaymentTransactionState.failed:
        // ...
        await queue.finishTransaction(tx);
        break;
      // ...
    }
  }
}

Before attempting to add a payment always check if the user can actually make payments:

final bool canPay = await StoreKit.instance.paymentQueue.canMakePayments();

When that's verified and you've set an observer on the queue you can add payments. For instance:

final SKProductsResponse response = await StoreKit.instance.products(['my.inapp.subscription']);
final SKProduct product = response.products.single;
final SKPayment = SKPayment.withProduct(product);
await StoreKit.instance.paymentQueue.addPayment(payment);
// ...
// Use observer to track progress of this payment...

Restoring completed transactions

await StoreKit.instance.paymentQueue.restoreCompletedTransactions();
/// Optionally implement `didRestoreCompletedTransactions` and 
/// `failedToRestoreCompletedTransactions` on observer to track
/// result of this operation.

BillingClient (Android)

This plugin wraps official Google Play Billing Library. Use BillingClient class as the main entry point.

Constructor of BillingClient class expects an instance of PurchaseUpdatedListener interface which looks like this:

/// Listener interface for purchase updates which happen when, for example,
/// the user buys something within the app or by initiating a purchase from
/// Google Play Store.
abstract class PurchasesUpdatedListener {
  /// Implement this method to get notifications for purchases updates.
  ///
  /// Both purchases initiated by your app and the ones initiated by Play Store
  /// will be reported here.
  void onPurchasesUpdated(int responseCode, List<Purchase> purchases);
}

Using BillingClient

To begin working with Play Billing service always start from establishing connection using startConnection method:

import 'package:iap/iap.dart';

bool _connected = false;

void main() async {
  final client = BillingClient(yourPurchaseListener);
  await client.startConnection(onDisconnect: handleDisconnect);
  _connected = true;

  // ...fetch SKUDetails, launch billing flows, query purchase history, etc

  await client.endConnection(); // Always call [endConnection] when work with this client is done.
}

void handleDisconnect() {
  // Client disconnected. Make sure to call [startConnection] next time before invoking
  // any other method of the client.
  _connected = false;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].