flutter_applepay_sdk 0.0.2
flutter_applepay_sdk: ^0.0.2 copied to clipboard
This is Wallet SDK for Apple Pay. It is a Flutter plugin that provides functionality to integrate Apple Pay into Flutter applications. Powered by Bonum.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:flutter_applepay_sdk/flutter_applepay_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _walletInfo = 'Unknown';
String _secureCheckResult = 'Not checked';
@override
void initState() {
super.initState();
_retrieveWalletInformation();
}
// Retrieve Wallet Information
Future<void> _retrieveWalletInformation() async {
String walletInfo;
try {
walletInfo = await FlutterApplepaySdk.retrieveWalletInformation();
} catch (e) {
walletInfo = 'Failed to retrieve wallet information';
}
if (!mounted) return;
setState(() {
_walletInfo = walletInfo;
});
}
// Add Payment Pass
Future<void> _addPaymentPass() async {
final cardDetails = {
'cardholderName': 'TUVSHINSAIKHAN',
'primaryAccountSuffix': '8015',
'primaryAccountIdentifier': '',
'paymentNetwork': 'masterCard',
};
final networkDetails = {
'url': '', //URL to your server
'method': 'POST',
'header': [
"Content-Type: application/json",
"Authorization: Bearer " //Bearer token
],
'body': jsonEncode({
'data': "", //This will be the tokenized card data HEX
'holderName': "", //Cardholder name
'phoneNumber': "" //phonenumber
}),
};
final success = await FlutterApplepaySdk.presentAddPaymentPassViewController(cardDetails, networkDetails);
if (success) {
setState(() {
_walletInfo = 'Payment Pass added successfully!';
});
} else {
setState(() {
_walletInfo = 'Failed to add Payment Pass.';
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter Apple Pay SDK Example'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Wallet Information:',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 8),
Text(_walletInfo),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _addPaymentPass,
child: const Text('Add Payment Pass'),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () async {
try {
final exists = await FlutterApplepaySdk.secureElementPassExists("8015");
setState(() {
_secureCheckResult = exists ? 'Pass already exists in Wallet.' : 'Pass not found in Wallet.';
});
} catch (e) {
setState(() {
_secureCheckResult = 'Error: ${e.toString()}';
});
}
},
child: const Text('Check Secure'),
),
const SizedBox(height: 10),
Text('Secure Check Result: $_secureCheckResult'),
],
),
),
),
);
}
}