import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'apple_pay_platform_interface.dart'; /// An implementation of [ApplePayPlatform] that uses method channels. class MethodChannelApplePay extends ApplePayPlatform { /// The method channel used to interact with the native platform. @visibleForTesting final methodChannel = const MethodChannel('apple_pay'); @override Future getPlatformVersion() async { final version = await methodChannel.invokeMethod('getPlatformVersion'); return version; } @override Future> purchase({ required String productId, String? appAccountToken, }) async { try { final result = await methodChannel.invokeMethod>( 'purchase', { 'appleId': productId, 'appAccountToken': appAccountToken, }, ); return result?.cast() ?? { 'success': false, 'error': 'No result returned', }; } catch (e) { return { 'success': false, 'error': e.toString(), }; } } @override Future> restore() async { try { final result = await methodChannel.invokeMethod>( 'restore', ); return result?.cast() ?? { 'success': false, 'error': 'No result returned', }; } catch (e) { return { 'success': false, 'error': e.toString(), }; } } @override Future check() async { await methodChannel.invokeMethod( 'check', ); } }