Reputation: 443
I am creating a payment app and using braintree for that. I want to use braintree dropIn UI. Installed BraintreeDropIn through pod. Using the following code to present dropIn UI.
func showDropIn(clientTokenOrTokenizationKey: String) {
let request = BTDropInRequest()
let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error) in
if (error != nil) {
print("ERROR")
} else if (result?.cancelled == true) {
print("CANCELLED")
} else if result != nil {
// Use the BTDropInResult properties to update your UI
// result.paymentOptionType
// result.paymentMethod
// result.paymentIcon
// result.paymentDescription
}
controller.dismissViewControllerAnimated(true, completion: nil)
}
self.presentViewController(dropIn!, animated: true, completion: nil)
}
I got tokenization
key from sandbox control panel under Tokenization Keys
and I am passing it to showDropIn function. Still its not showing anything, not going inside this function
(BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error))
Upvotes: 2
Views: 322
Reputation: 909
In Objective - C:
- (void)showDropIn:(NSString *)clientTokenOrTokenizationKey {
BTDropInRequest *request = [[BTDropInRequest alloc] init];
BTDropInController *dropIn = [[BTDropInController alloc] initWithAuthorization:clientTokenOrTokenizationKey request:request handler:^(BTDropInController * _Nonnull controller, BTDropInResult * _Nullable result, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"ERROR");
} else if (result.cancelled) {
NSLog(@"CANCELLED");
} else {
// Use the BTDropInResult properties to update your UI
// result.paymentOptionType
// result.paymentMethod
// result.paymentIcon
// result.paymentDescription
}
dispatch_async(dispatch_get_main_queue(), ^{
[controller dismissViewControllerAnimated:YES completion:nil];
});
}];
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:dropIn animated:YES completion:nil];
});
}
Upvotes: 0
Reputation: 4451
Try using this:
func showDropIn(clientTokenOrTokenizationKey: String) {
let request = BTDropInRequest()
let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error) in
if (error != nil) {
print("ERROR")
} else if (result?.cancelled == true) {
print("CANCELLED")
} else if result != nil {
// Use the BTDropInResult properties to update your UI
// result.paymentOptionType
// result.paymentMethod
// result.paymentIcon
// result.paymentDescription
}
dispatch_async(dispatch_get_main_queue(), ^{
controller.dismissViewControllerAnimated(true, completion: nil)
});
}
dispatch_async(dispatch_get_main_queue(), ^{
self.presentViewController(dropIn!, animated: true, completion: nil)
});
}
Hope this will work...!!
Upvotes: 2