gpt4 book ai didi

ios - 有什么方法可以从 iOS 应用程序对卡进行收费,而无需从我们的服务器进行后端收费。(Stripe - iOS)

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:20:57 25 4
gpt4 key购买 nike

我正在使用 Stripe 进行支付。我想从我的应用程序中对卡进行收费。目前我正在使用以下代码对卡进行收费,但该过程是从服务器端完成的。有什么方法可以从应用程序对卡进行收费而不是将 stripeToken 发送到服务器吗?

-(void)createBackendChargeWithToken:(STPToken *)token completion:(void (^)(PKPaymentAuthorizationStatus))completion {
NSURL *url = [NSURL URLWithString:@"https://example.com/token"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = @"POST";
NSString *body = [NSString stringWithFormat:@"stripeToken=%@&amount=%@", token.tokenId,_txtAmount.text];
request.HTTPBody = [body dataUsingEncoding:NSUTF8StringEncoding];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
NSURLSessionDataTask *task =
[session dataTaskWithRequest:request
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
if (error) {
completion(PKPaymentAuthorizationStatusFailure);
// [self customeAlertView:@"Payment not successful" message:@"Please try again later."];
NSLog(@"Payment not successful. Please try again later.");
} else {
completion(PKPaymentAuthorizationStatusSuccess);
// [self customeAlertView:@"Success" message:@"Please enjoy your new purchase."];
NSLog(@"Payment Success. Please enjoy your new purchase.");
}
}];
[task resume];
}

最佳答案

不,这是不可能的。 Stripe 的iOSAndroid绑定(bind)仅用于收集卡信息和创建 token ,很像 Stripe.jsCheckout在 Web 应用程序中执行。

创建 token 后,必须将其发送到外部服务器,您可以在其中在 API 请求中使用它,例如至 create a charge .

必须使用外部服务器的原因是除了 token 创建之外的所有 API 请求都必须使用您的 secret API key 发出,不得直接在您的应用程序中使用,否则恶意用户将能够检索它并使用它访问您的帐户。

关于ios - 有什么方法可以从 iOS 应用程序对卡进行收费,而无需从我们的服务器进行后端收费。(Stripe - iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36053730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com