我正在使用Stripe iOS SDK创建客户并在我的应用程序中付款。话虽如此,我在Stripe文档(https://stripe.com/docs/mobile/ios/standard)中注意到,每次显示“付款方式”屏幕时,他们都会创建临时密钥(新客户)吗?我的用户的卡详细信息按原样保存,但问题出在 这行:
STPCustomerContext * customerContext = [[STPCustomerContext alloc] initWithKeyProvider:[StripeAPIBackend sharedInstance]];
是我的用户每次选择查看其付款方式时,它们都不可见,因为每次点击按钮都会创建一个新的客户ID。有谁知道我该如何避免这种情况的发生?
ViewController.m
- (void)handlePaymentMethodsButtonTapped {
STPCustomerContext *customerContext = [[STPCustomerContext alloc] initWithKeyProvider:[StripeAPIBackend sharedInstance]];
// Setup payment methods view controller
STPPaymentMethodsViewController *paymentMethodsViewController = [[STPPaymentMethodsViewController alloc] initWithConfiguration:[STPPaymentConfiguration sharedConfiguration] theme:[STPTheme defaultTheme] customerContext:customerContext delegate:self];
// Present payment methods view controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:paymentMethodsViewController];
[self presentViewController:navigationController animated:YES completion:nil];
}
StripeAPIBackend.m
- (void)createCustomerKeyWithAPIVersion:(NSString *)apiVersion completion:(STPJSONResponseCompletionBlock)completion {
NSString *email = @"test@test.com";
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
[manager POST:self.baseURL.absoluteString
parameters:@{@"api_version": apiVersion, @"email": email}
// progress:nil
success:^(NSURLSessionDataTask *task, id responseObject) {
completion(responseObject, nil);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
completion(nil, error);
}];
}