forked from inspireui/flutter_paystack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlutterPaystackPlugin.m
More file actions
65 lines (53 loc) · 2.76 KB
/
Copy pathFlutterPaystackPlugin.m
File metadata and controls
65 lines (53 loc) · 2.76 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
#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:@"plugins.wilburt/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([@"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];
}
@end