在 iOS 应用中使用 Braintree 支付 api
Posted
技术标签:
【中文标题】在 iOS 应用中使用 Braintree 支付 api【英文标题】:Use Braintree payment api in iOS app 【发布时间】:2013-12-23 19:22:18 【问题描述】:我想在我的 ios 应用中使用 Braintree API。
我的应用用于出租目的,即请求者用户必须向他想要出租的资产的所有者付款。
我检查了以下链接: 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 等等
但我不知道在哪里使用 Braintree 或 Venmo api 提供接收者的帐户详细信息,例如我们可以在 PayPal iOS sdk 中传递接收者的电子邮件,然后 PayPal 将金额支付给注册的用户电子邮件。
与我在 Braintree Payment API 中搜索的内容相同。
非常感谢任何帮助。
提前致谢。
我正在使用下面的代码:(来自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]];
];
【问题讨论】:
为什么要在这里投反对票?也请告诉我原因。 如果您添加一些代码来显示您正在尝试做的事情以及您遇到的问题,那么您的问题会更受欢迎。 感谢 alfasin,我还提供了我的代码 sn-p。 @Richa 我也计划在 iOS 应用中使用 Braintree。你的应用程序被苹果接受了吗?我已经阅读了很多帖子,它说该应用程序可以被拒绝,因为这超出了应用程序内购买指南。所以,我想在开始之前进行调查。提前致谢。 @AkbariDipali 有数以千计的应用程序使用 Braintree,所以这取决于你在用它做什么,而不仅仅是你在使用它。 【参考方案1】:我在布伦特里工作。如果您有更多问题或需要更多帮助,请联系our support team。
Braintree iOS SDK docs 包括quickstart guide,以及有关库功能的详细信息。
如果您正在寻找有关如何在您的应用/网站用户之间进行付款的具体信息,您应该查看the marketplace guide 和Venmo APIs。
【讨论】:
非常感谢@agf 的回答,我会查看所有这些链接。 @agf 我也计划在 iOS 应用中使用 Braintree。我读过很多帖子,它说苹果可以拒绝该应用程序,因为这超出了应用内购买指南。应用程序是否有被拒绝的可能性?在开始使用 Braintree 之前,我担心苹果对应用程序的接受度。提前致谢。 @AkbariDipali 我建议您向我们的支持团队发送电子邮件。基本上,这取决于你在卖什么。 @agf 感谢您的回复。是的,我也得到了答案,这取决于要销售的产品,根据应用程序的要求,我已经开始使用braintree :) @agf 是否可以为 Braintree 使用自定义 cedict 卡片视图?或者我们可以只使用 Braintree 提供的 drop in 视图?以上是关于在 iOS 应用中使用 Braintree 支付 api的主要内容,如果未能解决你的问题,请参考以下文章
Braintree for iOS 应用程序与 paypal 集成
Braintree v.zero iOS SDK 是不是支持自适应支付?