6

I want to use Braintree API in my iOS app.

My app is used for renting purpose i.e. requester user has to make payment to the owner of asset he wanted for rent.

I have checked following links : http://www.youtube.com/watch?v=s7GlgBFM20I

https://www.braintreepayments.com/developers

http://www.youtube.com/watch?v=2y8Tsml6JYo

https://www.braintreepayments.com/braintrust/venmo-touch-screencasts-add-one-touch-payments-to-your-app-in-15-minutes etc.

But I didn't get any idea where to provide receiver's account details using Braintree or Venmo api, For Example we can pass e-mail of receiver in PayPal iOS sdk, and then PayPal pays the amount to the user registered with that e-mail.

The same thing I am searching in Braintree Payment API.

Any help is greatly appreciated.

Thanks in advance.

I am using below code : (Used from a sample code given by braintree)

/* Get called when user pay on Pay button on screen. 
   User wil see a form for entering his credit card number, CVV and expiration date. */
-(IBAction)payButtonClicked 
{
    self.paymentViewController =
    [BTPaymentViewController paymentViewControllerWithVenmoTouchEnabled:YES];
    self.paymentViewController.delegate = self;

    [self presentViewController:self.paymentViewController animated:YES completion:nil];
}

// When a user types in their credit card information correctly, the BTPaymentViewController sends you
// card details via the `didSubmitCardWithInfo` delegate method.
//
// NB: you receive raw, unencrypted info in the `cardInfo` dictionary, but
// for easy PCI Compliance, you should use the `cardInfoEncrypted` dictionary
// to securely pass data through your servers to the Braintree Gateway.
- (void)paymentViewController:(BTPaymentViewController *)paymentViewController
        didSubmitCardWithInfo:(NSDictionary *)cardInfo
         andCardInfoEncrypted:(NSDictionary *)cardInfoEncrypted {
    [self savePaymentInfoToServer:cardInfoEncrypted]; // send card through your server to Braintree Gateway
}

// When a user adds a saved card from Venmo Touch to your app, the BTPaymentViewController sends you
// a paymentMethodCode that you can pass through your servers to the Braintree Gateway to
// add the full card details to your Vault.
- (void)paymentViewController:(BTPaymentViewController *)paymentViewController
didAuthorizeCardWithPaymentMethodCode:(NSString *)paymentMethodCode {
    // Create a dictionary of POST data of the format
    // {"payment_method_code": "[encrypted payment_method_code data from Venmo Touch client]"}
    NSMutableDictionary *paymentInfo = [NSMutableDictionary dictionaryWithObject:paymentMethodCode
                                                                          forKey:@"payment_method_code"];
    [self savePaymentInfoToServer:paymentInfo]; // send card through your server to Braintree Gateway
}

#define SAMPLE_CHECKOUT_BASE_URL @"http://venmo-sdk-sample-two.herokuapp.com"
//#define SAMPLE_CHECKOUT_BASE_URL @"http://localhost:4567"

// Pass payment info (eg card data) from the client to your server (and then to the Braintree Gateway).
// If card data is valid and added to your Vault, display a success message, and dismiss the BTPaymentViewController.
// If saving to your Vault fails, display an error message to the user via `BTPaymentViewController showErrorWithTitle`
// Saving to your Vault may fail, for example when
// * CVV verification does not pass
// * AVS verification does not pass
// * The card number was a valid Luhn number, but nonexistent or no longer valid
- (void) savePaymentInfoToServer:(NSDictionary *)paymentInfo {

    NSURL *url;
    if ([paymentInfo objectForKey:@"payment_method_code"]) {
        url = [NSURL URLWithString: [NSString stringWithFormat:@"%@/card/payment_method_code", SAMPLE_CHECKOUT_BASE_URL]];
    } else {
        url = [NSURL URLWithString: [NSString stringWithFormat:@"%@/card/add", SAMPLE_CHECKOUT_BASE_URL]];
    }
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    // You need a customer id in order to save a card to the Braintree vault.
    // Here, for the sake of example, we set customer_id to device id.
    // In practice, this is probably whatever user_id your app has assigned to this user.
    NSString *customerId = [[UIDevice currentDevice] identifierForVendor].UUIDString;
    [paymentInfo setValue:customerId forKey:@"customer_id"];

    request.HTTPBody = [self postDataFromDictionary:paymentInfo];
    request.HTTPMethod = @"POST";

    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response, NSData *body, NSError *requestError)
     {
         NSError *err = nil;
         if (!response && requestError) {
             NSLog(@"requestError: %@", requestError);
             [self.paymentViewController showErrorWithTitle:@"Error" message:@"Unable to reach the network."];
             return;
         }

         NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:body options:kNilOptions error:&err];
         NSLog(@"saveCardToServer: paymentInfo: %@ response: %@, error: %@", paymentInfo, responseDictionary, requestError);

         if ([[responseDictionary valueForKey:@"success"] isEqualToNumber:@1]) { // Success!
             // Don't forget to call the cleanup method,
             // `prepareForDismissal`, on your `BTPaymentViewController`
             [self.paymentViewController prepareForDismissal];
             // Now you can dismiss and tell the user everything worked.
             [self dismissViewControllerAnimated:YES completion:^(void) {
                 [[[UIAlertView alloc] initWithTitle:@"Success" message:@"Saved your card!" delegate:nil
                                   cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
                 [[VTClient sharedVTClient] refresh];
             }];

         } else { // The card did not save correctly, so show the error from server with convenenience method `showErrorWithTitle`
             [self.paymentViewController showErrorWithTitle:@"Error saving your card" message:[self messageStringFromResponse:responseDictionary]];
         }
     }];
}
Richa
  • 544
  • 1
  • 8
  • 15
  • Why down vote here ? please let me know the reason too. – Richa Dec 06 '13 at 14:37
  • 1
    your question would be more welcomed if you would add some code that shows what you're trying to do and where you're stuck. – Nir Alfasi Dec 07 '13 at 07:03
  • Thanks alfasin , I also provided my code snippet. – Richa Dec 09 '13 at 06:01
  • @Richa I am also planning to use braintree in the iOS app. Is your app accepted by apple? I have read many threads and it says that the app can be rejected because this falls outside of the In-App purchase guidelines.So, I wanted to do investigation before starting. Thanks in advance. – Akbari Dipali Apr 03 '15 at 11:16
  • @AkbariDipali there are thousands of apps using Braintree, so it depends on what you're doing with it, not just that you're using it. – agf Apr 08 '15 at 17:39
  • Just to clarify: your app will not be rejected just for using Braintree if you are selling physical goods. If you are selling virtual goods, or if you are selling a subscription for virtual goods, then your app is subject to Apple's 30% cut. – Richard Shin Apr 29 '16 at 17:23

1 Answers1

1

I work at Braintree. If you've got more questions or need more help, please reach out to our support team.

The Braintree iOS SDK docs include a quickstart guide, as well as detailed information about the features of the library.

If you're looking for information specifically on how to make payments between users of your app / web site, you should take a look at the marketplace guide and the Venmo APIs.

agf
  • 171,228
  • 44
  • 289
  • 238
  • Thanks so much @agf for your answer, I'll look over all these links. – Richa Dec 07 '13 at 06:27
  • @agf I am also planning to use braintree in the iOS app. I have read many threads and it says that apple can reject the app because this falls outside of the In-App purchase guidelines. Is there any possibility of app rejection? I am concerned about app acceptance by apple before starting with braintree. Thanks in advance. – Akbari Dipali Apr 03 '15 at 11:32
  • @AkbariDipali I'd suggest you send our support team an email. Basically, it depends on what you're selling. – agf Apr 08 '15 at 17:38
  • @agf Thank you for the response. Yes, I also got the answer, it depends on product to be sold and according to the app requirement, I have started using braintree :) – Akbari Dipali Apr 08 '15 at 17:52
  • @agf Is it possible to use custom cedict card view for Braintree? Or we can use only the drop in view Braintree provides? – DD_ Apr 29 '16 at 10:04
  • @MicRO You can use a custom credit card view with Braintree. If you clone the [GitHub repo](https://github.com/braintree/braintree_ios), there's a demo app that has a custom card form that performs tokenization. Here's a [direct link](https://github.com/braintree/braintree_ios/blob/master/Demo/Features/Credit%20Card%20Tokenization/BraintreeDemoCardTokenizationViewController.m#L61-L77) to the relevant code. (Source: I am responsible for the Braintree iOS SDK.) – Richard Shin Apr 29 '16 at 17:18
  • @RichardShin Thank you for the info! Will try it – DD_ May 03 '16 at 16:22
  • @agf How to test card and billing address verification in sandbox mode by using BT iOS SDK (i.e. from iOS app)? – ViruMax May 06 '16 at 14:41
  • @RichardShin Would you be able to answer my above question? – ViruMax May 06 '16 at 15:23
  • @Virumax If you're looking to verify real card numbers, you'll need to do that in production. There's no support for billing address verification, although you can add the billing postal code to the payload during tokenization. If you need further help, please contact Braintree support. – Richard Shin May 09 '16 at 17:44