Skip to content

Commit

Permalink
Implement payment process for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ersjoh committed Feb 28, 2019
1 parent fb83e6f commit 46a4955
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
5 changes: 3 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ PODS:
- BraintreeDropIn/UIKit (7.0.0)
- Flutter (1.0.0)
- flutter_braintree (0.0.1):
- Braintree/PayPal
- BraintreeDropIn
- Flutter

Expand All @@ -54,8 +55,8 @@ SPEC CHECKSUMS:
Braintree: e814ec196208d3e961c488cf4071de043f399cf9
BraintreeDropIn: 7eb460717213ae39a3b457c90671f9975747dcab
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
flutter_braintree: 5335db07a4f8296c92ac8f4e24e9db49de8376d4
flutter_braintree: 84f4a11d29c54772a3222147c935218961f73350

PODFILE CHECKSUM: e9e6b2d1b4659eb7ca9c31439eb8716d7d418981
PODFILE CHECKSUM: 424be0dc71903659c46ce73622634f011af61c76

COCOAPODS: 1.5.3
10 changes: 7 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
7EC0CF8FB25143F4DEAF0378 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C06296977A6AD4BA85BB055B /* libPods-Runner.a */; };
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
Expand Down Expand Up @@ -174,7 +173,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0910;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = "The Chromium Authors";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -208,7 +207,6 @@
files = (
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
Expand Down Expand Up @@ -360,12 +358,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -433,12 +433,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -487,12 +489,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -46,7 +45,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
22 changes: 19 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
String _nonce = 'Unknown';
final _controller = TextEditingController();

@override
Widget build(BuildContext context) {
Expand All @@ -22,10 +23,15 @@ class _MyAppState extends State<MyApp> {
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextField(
controller: _controller,
decoration: InputDecoration(hintText: 'Your client token'),
),
RaisedButton(
child: Text('Pay'),
onPressed: _pay,
onPressed: () => _pay(_controller.text),
),
Text(_nonce),
],
Expand All @@ -35,7 +41,17 @@ class _MyAppState extends State<MyApp> {
);
}

void _pay() async {
String nonce = await FlutterBraintree.showDropIn('token');
void _pay(String token) async {
String nonce;

try {
nonce = await FlutterBraintree.showDropIn(token);
} on PlatformException catch (e) {
nonce = e.message;
}

setState(() {
_nonce = nonce;
});
}
}
13 changes: 9 additions & 4 deletions ios/Classes/FlutterBraintreePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
#import "BraintreeDropIn.h"


@implementation FlutterBraintreePlugin {
UIViewController *_viewController;
}
@interface FlutterBraintreePlugin ()
@property (nonatomic, strong) UIViewController *viewController;
@end


@implementation FlutterBraintreePlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"info.keepinmind.flutter_braintree" binaryMessenger:[registrar messenger]];
Expand Down Expand Up @@ -43,10 +46,12 @@ - (void)showDropIn:(NSString *)clientTokenOrTokenizationKey withResult:(FlutterR
if (error != nil) {
flutterResult([FlutterError errorWithCode:[NSString stringWithFormat:@"%li", error.code] message:error.localizedDescription details:nil]);
} else if (result.cancelled) {
flutterResult([FlutterError errorWithCode:@"CANCELLED" message:error.localizedDescription details:nil]);
flutterResult([FlutterError errorWithCode:@"CANCELLED" message:@"Purchase process was cancelled." details:nil]);
} else {
flutterResult(result.paymentMethod.nonce);
}

[self.viewController dismissViewControllerAnimated:YES completion:nil];
}];

[_viewController presentViewController:dropIn animated:YES completion:nil];
Expand Down
4 changes: 3 additions & 1 deletion ios/flutter_braintree.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'BraintreeDropIn'

s.dependency 'Braintree/PayPal'
s.ios.deployment_target = '10.0'
s.static_framework = true

end

0 comments on commit 46a4955

Please sign in to comment.