Cameron
Cameron

Reputation: 661

Braintree Drop in UI - add credit card

Is there an option to just add a credit card to a User with the Braintree drop in UI, or can it only be used for a payment? I have my server configured to send tokens and receive payment, but I would like my Users to be able to add a credit card before using my app.

Upvotes: 1

Views: 1645

Answers (2)

foppa
foppa

Reputation: 11

It has been a little bit tricky to figure out but I could do that using the components included in the Braintree SDK for iOs ( v. 4.9.0 )

You have to get a "token" from your server without the "customerId" ( this avoid to save the card automatically )

When you receive the "token" you can do this:

            NSString* token = [jsonData valueForKey:@"response"];
            self.req=[[BTDropInRequest alloc] init];

            self.req.applePayDisabled = YES ;

            self.cardForm = [[BTDropInController alloc] initWithAuthorization:token request:self.req handler:^(BTDropInController * _Nonnull controller, BTDropInResult * _Nullable result, NSError * _Nullable error) {



            }];

            BTCardFormViewController* vd = [[BTCardFormViewController alloc] initWithAPIClient:self.cardForm.apiClient request:self.cardForm.dropInRequest];
            vd.supportedCardTypes = [NSArray arrayWithObject:@(BTUIKPaymentOptionTypeVisa)];
            vd.delegate = self;

            UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:vd];
            if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
                navController.modalPresentationStyle = UIModalPresentationPageSheet;
            }

            [self presentViewController:navController animated:YES completion:nil];

The code above will present the standard Braintree form to collect card data.

You have to implement the BTCardFormViewControllerDelegate to get the tokenized card.

- (void)cardTokenizationCompleted:(BTPaymentMethodNonce * _Nullable )tokenizedCard error:(NSError * _Nullable )error sender:(BTCardFormViewController *) sender;

Here you have access to the tokenized card and to the view controller with the card's data.

You can get the gateway configuration to display the supported card.

Hope can help.

Upvotes: 1

SRK
SRK

Reputation: 754

No, You can't add credit card only.

As per my email communication with the Braintree support team, If you're using Drop-in Payment UI, then you can't add a credit card only. While doing any transaction only, users will be able to add a credit card.

Upvotes: 2

Related Questions