Installation
On this page
Table of Contents#
- Overview
- pub.dev Dependency Setup
- Service Provider Registration
- main.dart
- Which Platform Gets Which Rail
- CLI Setup
- Next Steps
Overview#
Magic Payments is a multi-rail billing plugin for the Magic Framework. It puts one entitlement contract in front of two payment rails: Stripe on the web, and the platform's own in-app purchase system on iOS and Android. A consuming app asks two questions, what is this customer entitled to and where do they manage it, and the answers are rail-neutral.
pub.dev Dependency Setup#
Add the package to your pubspec.yaml:
dependencies:
magic_payments: ^0.0.12
Then fetch dependencies:
flutter pub get
Service Provider Registration#
Register PaymentsServiceProvider in your app's provider list, the same way as any other Magic
plugin:
import 'package:magic_payments/magic_payments.dart';
final providers = [
// ... other providers
(app) => PaymentsServiceProvider(app),
];
PaymentsServiceProvider runs the usual two-phase boot: register() binds one string-keyed
singleton under 'payments', and boot() wires the platform driver through the package's
conditional-import factory. Neither phase requires a config file to exist for the five reads or the
web rail to work. See Service Provider for the full sequence.
main.dart#
Register the published config the same way every other plugin config is registered. payments:install
does this for you; the shape is here so you can check its work:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Magic.init(
configFactories: [
() => appConfig,
() => paymentsConfig,
],
);
runApp(MyApp());
}
The five READS and the web rail boot without a single key, so a web-only app whose factory is missing
still works and payments:doctor is the only thing that notices. The STORE rail is different: it
reads payments.revenuecat.public_sdk_key the first time it needs the SDK, so on iOS and Android an
unregistered factory turns into a BillingException under the customer's finger on the purchase
sheet.
See Configuration for every key and for why the store rail's key is resolved per platform.
Which Platform Gets Which Rail#
| Contract | Web | iOS / Android | Reason |
|---|---|---|---|
BillingService (5 reads) |
Yes | Yes | The backend is the authority on an entitlement whatever rail sold it, so a read never has to refuse a platform. |
WebBillingService (checkout, swap, cancel, openPortal) |
Yes | No (null) |
The web rail bills a card directly through a hosted checkout and portal. |
StoreBillingService (identify, purchase, products, restore, openStoreManagement) |
No (null) |
Yes (RevenueCatStoreService) |
StoreKit and Play Billing take the money, through RevenueCat. |
Which rail is present is decided by the package's own conditional-import factory, not by
kIsWeb or Platform.is. See Rails and Drivers.
CLI Setup#
Magic Payments ships three CLI commands on fluttersdk_artisan: install, configure and
doctor.
dart run magic_payments doctor
The exact flags each command accepts are still settling alongside the rest of the public API in
this version; run a command with --help for the authoritative set, and see
CLI Reference for what each command is for.
Next Steps#
- Read Configuration for the
payments.*namespace. - Read Rails, especially the section on entitlement authority, before wiring a purchase button.
- Read Drivers to see how a build resolves the driver it can serve.
Related