我已经跟进了 objective-c 的 BrainTree
教程并完成了以下实现。我想知道,我怎么能存储用户信用卡信息,例如 Uber
或 AirBnb
。每次,用户点击付款,并显示信用卡信息条目 View Controller 。
顺便说一下,交易成功了,我可以在我的 BrainTree
沙盒账户上看到费用。
- (IBAction)placeOrderBtnClicked:(id)sender {
[self showDropIn: TOKEN];
}
- (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");
[self dismissViewControllerAnimated:YES completion:NULL];
} else {
[self postNonceToServer:result.paymentMethod.nonce];
}
}];
[self presentViewController:dropIn animated:YES completion:nil];
}
- (void)postNonceToServer:(NSString *)paymentMethodNonce {
self.manager = [AFHTTPSessionManager manager];
NSDictionary *params = @{@"amount" : @"44", @"payment_method_nonce" : paymentMethodNonce};
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:URLString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull operation, id _Nonnull responseObject) {
NSLog (@"transaction is succesfull");
} failure:^(NSURLSessionDataTask * _Nullable operation, NSError * _Nonnull error) {
}];
}
// the following method never gets called!!!
- (void)fetchExistingPaymentMethod:(NSString *)clientToken {
[BTDropInResult fetchDropInResultForAuthorization:clientToken handler:^(BTDropInResult * _Nullable result, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"ERROR");
} else {
// Use the BTDropInResult properties to update your UI
NSLog(@"Payment method :%@", result.paymentMethod);
NSLog(@"Payment Description :%@", result.paymentDescription);
NSLog(@"Payment option type :%ld", (long)result.paymentOptionType);
}
}];
}
更新:我想查看以下突出显示的部分
最佳答案
完全披露:我在 Braintree 工作。如果您还有任何疑问,请随时联系support .
您的意思是您希望付款表单显示已存储的付款,还是问如何存储付款?为了让 Drop-in 显示以前存储的付款方式,您需要将 customer_id 传递到 ClientToken.generate()在您的服务器端调用。如果您要保存付款方式,那么这又会发生在您的服务器端调用上,因为您必须将随机数从客户端传递到服务器并在 PaymentMethod.create() 中使用该随机数。称呼。
关于ios - 存储用户信用信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44606697/