我已经跟踪了Objective-C的BrainTree
教程,并完成了以下实现。我想知道如何存储用户的信用卡信息,例如Uber
或AirBnb
。每次用户单击“付款”,并显示信用卡信息输入ViewController。
顺便说一句,交易成功完成了,我可以在自己的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()调用中使用该随机数。