forked from wilburx9/flutter_paystack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlutterPaystackPlugin.m
More file actions
100 lines (86 loc) · 4.15 KB
/
Copy pathFlutterPaystackPlugin.m
File metadata and controls
100 lines (86 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#import "FlutterPaystackPlugin.h"
#import <sys/utsname.h>
#import "PSTCKRSA.h"
#import "PSTCKAuthViewController.h"
@implementation FlutterPaystackPlugin {
UIViewController *_viewController;
}
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"flutter_paystack"
binaryMessenger:[registrar messenger]];
UIViewController *viewController =
[UIApplication sharedApplication].delegate.window.rootViewController;
FlutterPaystackPlugin* instance = [[FlutterPaystackPlugin alloc] initWithViewController: viewController];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (instancetype)initWithViewController:(UIViewController *)viewController {
self = [super init];
if (self) {
_viewController = viewController;
}
return self;
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getDeviceId" isEqualToString:call.method]) {
result([@"iossdk_" stringByAppendingString:[[[UIDevice currentDevice] identifierForVendor] UUIDString]]);
} else if([@"getUserAgent" isEqualToString:call.method]) {
result([self.class paystackUserAgentDetails]);
} else if([@"getVersionCode" isEqualToString:call.method]) {
result(PSTCKSDKBuild);
} else if([@"getAuthorization" isEqualToString:call.method]) {
NSDictionary *arguments = [call arguments];
NSString *url = arguments[@"authUrl"];
[self requestAuth:url result: result];
} else if([@"getEncryptedData" isEqualToString:call.method]) {
NSDictionary *arguments = [call arguments];
NSString *data = arguments[@"stringData"];
result([PSTCKRSA encryptRSA:data]);
} else {
result(FlutterMethodNotImplemented);
}
}
- (void) requestAuth:(NSString * _Nonnull) url result:(FlutterResult)result {
PSTCKAuthViewController* authorizer = [[[PSTCKAuthViewController alloc] init]
initWithURL:[NSURL URLWithString:url]
handler:^{
[self->_viewController dismissViewControllerAnimated:YES completion:nil];
NSDictionary *response = @{ @"status": @"requery", @"message": @"Reaffirm Transaction Status on Server"};
result([[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:[response copy] options:0 error:NULL] encoding:NSUTF8StringEncoding]);
}];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:authorizer];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
nc.modalPresentationStyle = UIModalPresentationFormSheet;
}
[self->_viewController presentViewController:nc animated:YES completion:nil];
}
+ (NSString *)paystackUserAgentDetails {
NSMutableDictionary *details = [@{
@"lang": @"objective-c",
@"bindings_version": PSTCKSDKVersion,
} mutableCopy];
#if TARGET_OS_IPHONE
NSString *version = [UIDevice currentDevice].systemVersion;
if (version) {
details[@"os_version"] = version;
}
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceType = @(systemInfo.machine);
if (deviceType) {
details[@"type"] = deviceType;
}
NSString *model = [UIDevice currentDevice].localizedModel;
if (model) {
details[@"model"] = model;
}
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
NSString *vendorIdentifier = [[[UIDevice currentDevice] performSelector:@selector(identifierForVendor)] performSelector:@selector(UUIDString)];
if (vendorIdentifier) {
details[@"vendor_identifier"] = vendorIdentifier;
}
}
#endif
return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:[details copy] options:0 error:NULL] encoding:NSUTF8StringEncoding];
}
@end