存储用户信用信息

时间:2017-06-17 16:13:42

标签: ios objective-c braintree

我已经跟进了目标-c的BrainTree教程并最终完成了以下实施。我想知道,我怎样才能存储用户信用卡信息,例如UberAirBnb。每次用户点击进行付款,并显示信用卡信息条目视图控制器。

顺便说一句,交易成功完成,我可以在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);
        }
    }];
}

更新:我想看到以下突出显示的部分

enter image description here

1 个答案:

答案 0 :(得分:1)

完全披露:我在Braintree工作。如果您有任何其他问题,请随时联系support

您的意思是您希望付款表单显示存储的付款,还是您要询问如何存储付款?为了使Drop-in显示以前存储的付款方式,您需要将customer_id传递到服务器端的ClientToken.generate()电话。如果您希望保存付款方式,那么这将在您的服务器端调用中发生,因为您必须将nonce从客户端传递到服务器并在PaymentMethod.create()调用中使用该nonce。