0
我跟进了针对objective-c的BrainTree
教程并结束了以下实施。我想知道,我怎么能够存储用户的信用卡信息,如Uber
或AirBnb
。每次用户点击进行付款,并显示信用卡信息输入视图控制器。商店用户信用信息
顺便说一句,交易成功发生,我可以在我的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);
}
}];
}
更新:我想看看下面突出显示的部分
请参阅我的更新。 – hotspring
对于上面的要求,您需要按照上述评论中的链接显示以前存储的付款方式。这个UI是通过将'customer_id'传递到服务器端的ClientToken.generate()调用中创建的。这不是你在前端编写的代码。只有该客户存储了付款方式时才会显示此信息。因此,您还需要如上所述进行PaymentMethod.create()调用。 –