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()調用。 –