| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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<String?> getPlatformVersion() async {
- final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
- return version;
- }
- @override
- Future<Map<String, dynamic>> purchase({
- required String productId,
- String? appAccountToken,
- }) async {
- try {
- final result = await methodChannel.invokeMethod<Map<dynamic, dynamic>>(
- 'purchase',
- {
- 'appleId': productId,
- 'appAccountToken': appAccountToken,
- },
- );
- return result?.cast<String, dynamic>() ?? {
- 'success': false,
- 'error': 'No result returned',
- };
- } catch (e) {
- return {
- 'success': false,
- 'error': e.toString(),
- };
- }
- }
- @override
- Future<Map<String, dynamic>> restore() async {
- try {
- final result = await methodChannel.invokeMethod<Map<dynamic, dynamic>>(
- 'restore',
- );
- return result?.cast<String, dynamic>() ?? {
- 'success': false,
- 'error': 'No result returned',
- };
- } catch (e) {
- return {
- 'success': false,
- 'error': e.toString(),
- };
- }
- }
- @override
- Future<void> check() async {
- await methodChannel.invokeMethod<void>(
- 'check',
- );
- }
- }
|