- Add [envify] to pubspec.yaml
dependencies:
envify: any
dev_dependencies:
envify_generator: any
build_runner: any
- Set up .env
// .env
BUX_API_KEY=api_key
BUX_SANDBOX=true
BUX_CLIENT_ID=0000000001
BUX_API_SECRET=secret
- create
lib/env/env.dart
on your project
//env.dart
import 'package:envify/envify.dart';
part 'env.g.dart';
@Envify()
abstract class Env {
static const bool buxSandbox = _Env.buxSandbox;
static const String buxApiKey = _Env.buxApiKey;
static const String buxClientId = _Env.buxClientId;
static const String buxApiSecret = _Env.buxApiSecret;
}
- Run Build Runner
# dart
pub run build_runner build
# flutter
flutter pub run build_runner build
Note: Make sure to re-run this if you change any in your .env file
- add to .gitigniore this entry
env.g.dart
and.env
- Add to Your pubspec.yaml
dependencies:
buxdotph: any
- Initialize Bux
// generated env.dart
import 'env/env.dart';
import 'package:buxdotph/buxdotph.dart';
final Bux bux = const Bux(
apiKey: Env.buxApiKey,
apiSecret: Env.buxApiSecret,
clientId: Env.buxClientId,
sandbox: Env.buxSandbox,
);
- Create CheckoutPayload
// with all paramaters filled up
import 'package:buxdotph/buxdotph';
import 'package:example/env/env.dart';
...
final CheckoutPayload payload = CheckoutPayload(
amount: 1000,
req_id: 'uuid_from_backend',
client_id: ${Env.buxClientId},
description: 'subscription',
notification_url: 'https://google.com',
expiry: 2,
email: '[email protected]',
contact: '09155555555',
name: 'John Dela Cruz',
redirect_url: 'https://goldcoders.dev',
param1: 'username',
param2: 'address',
);
// with minimum required parameters filled up
CheckoutPayload payload = CheckoutPayload(
amount: 1000,
req_id: 'bux001',
client_id: clientId,
description: 'test',
notification_url: 'https://goldcoders.dev/notify',
);
- Pass the Payload to bux checkout
import 'package:buxdotph/buxdotph.dart';
...
await bux.checkout(payload);