Skip to main content

Apple Pay - Flutter SDK

This guide shows you how to integrate Nium’s Apple Pay Push Provisioning SDK into a Flutter app. You'll set up the project, configure iOS settings, and implement card provisioning using a platform channel.

Step 1: Create a new Flutter project​

  1. Open Terminal and run:
flutter create apple_push_provisioning_demo
  1. Navigate into the project directory:
cd apple_push_provisioning_demo
  1. Open the project in your preferred IDE (such as VS Code or Android Studio).

Step 2: Configure iOS settings​

Set up the iOS configuration by updating the Podfile.

  1. Navigate to the ios directory:
cd ios
  1. If a Podfile doesn’t exist, create one:
pod init
  1. Open the Podfile and add:
target 'Runner' do
use_frameworks!

# CocoaPods source repositories
source 'https://github.com/CocoaPods/Specs.git'
source 'https://bitbucket.org/instadevelopers/push-provisioning-pod.git'

# Apple Push Provisioning SDK
pod 'NiumPayPushProvisioning'
pod 'TrustKit'
end
  1. Save and install dependencies:
pod install

Step 3: Add card provisioning​

Use a platform channel to connect your Flutter app with native iOS code and call the SDK.

Set up Flutter method channel​

Update lib/main.dart:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
static const MethodChannel _channel = MethodChannel('push_provisioning');

Future<void> provisionCard(Map<String, dynamic> parameters) async {
try {
final result = await _channel.invokeMethod('provisionCard', parameters);
debugPrint('Card provisioned: $result');
} on PlatformException catch (e) {
debugPrint('Failed to provision card: ${e.message}');
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Apple Push Provisioning SDK')),
body: Center(
child: ElevatedButton(
onPressed: () => provisionCard({
'cardId': 'CardId',
'additionalParam': 'value',
}),
child: Text('Provision Card'),
),
),
);
}
}

Implement the iOS method handler​

Update ios/Runner/AppDelegate.swift:

import UIKit
import Flutter
import NiumPayPushProvisioning
import TrustKit

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

GeneratedPluginRegistrant.register(with: self)

// TrustKit Configuration
let trustKitConfig: [String: Any] = [
kTSKSwizzleNetworkDelegates: false,
kTSKPinnedDomains: [
"nium.com": [
kTSKEnforcePinning: true,
kTSKIncludeSubdomains: true,
kTSKPublicKeyHashes: ["yourHashValue"],
kTSKReportUris: ["<https://overmind.datatheorem.com/trustkit/report>"]
]
]
]
TrustKit.initSharedInstance(withConfiguration: trustKitConfig)

do {
try NiumCardsPushProvisioning.initialize(
clientHashId: "clientHashId",
customerHashId: "customerHashId",
walletHashId: "walletHashId",
apiSecret: "apiSecret",
env: .production
)
print("NiumCardsPushProvisioning SDK initialized successfully")
} catch {
print("Error initializing SDK: \(error)")
}

let controller = window?.rootViewController as! FlutterViewController
let channel = FlutterMethodChannel(name: "push_provisioning", binaryMessenger: controller.binaryMessenger)

channel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) in
if call.method == "provisionCard" {
guard let args = call.arguments as? [String: Any], let cardId = args["cardId"] as? String else {
result(FlutterError(code: "INVALID_ARGUMENT", message: "Card ID is required", details: nil))
return
}
let sdk = NiumCardsPushProvisioning.shared
sdk?.addToWallet(viewController: controller, cardHashId: cardId) { sdkResult in
switch sdkResult {
case .success(let message):
print("Success: \(message)")
case .failure(let error):
print("Error: \(error)")
}
}
}
}

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

Step 4: Build and test​

  1. Run your app on an iOS device:
flutter run
  1. In the app, tap Provision Card to start the provisioning flow. If successful, the card is added to the Apple Wallet.

Troubleshooting​

Authentication errors with Bitbucket​

If you encounter access errors when pulling the SDK from Bitbucket, use a Bitbucket username and App Password.

Use this format in your Podfile:

source 'https://<username>:<app_password>@bitbucket.org/instadevelopers/push-provisioning-pod.git'

CocoaPods issues​

Clear the CocoaPods cache if you face dependency problems:

rm -rf ~/.cocoapods/repos/bitbucket-instadevelopers-push-provisioning-pod
pod cache clean --all
pod repo update
pod install

If you continue to run into any issues, please contact your Nium account manager or support@nium.com.

LLM-ready documentation:: llms.txt and llms-full.txt
Was this page helpful?