条带API通过iOS代码创建费用?
我一直在使用stripe开发ApplePay,一切正常,直到使用PKPayment获取stripe令牌这里提到的每个人都将您的stripe令牌发送到服务器并收取金额。我不知道如何创建web服务和向服务器发送令牌。所以我计划通过iOS代码给卡充电 创建费用单据: 在这里,我们不知道如何使用密钥生成post数据条带API通过iOS代码创建费用?,ios,objective-c,stripe-payments,Ios,Objective C,Stripe Payments,我一直在使用stripe开发ApplePay,一切正常,直到使用PKPayment获取stripe令牌这里提到的每个人都将您的stripe令牌发送到服务器并收取金额。我不知道如何创建web服务和向服务器发送令牌。所以我计划通过iOS代码给卡充电 创建费用单据: 在这里,我们不知道如何使用密钥生成post数据 NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
NSString *urlString = @"https://api.stripe.com/v1/charges";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = @"POST";
NSString *postBody = [NSString stringWithFormat:@"source=%@&amount=%@", sourceID, @1099];
NSData *data = [postBody dataUsingEncoding:NSUTF8StringEncoding];
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
fromData:data
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if (!error && httpResponse.statusCode != 200) {
error = [NSError errorWithDomain:StripeDomain
code:STPInvalidRequestError
userInfo:@{NSLocalizedDescriptionKey: @"There was an error connecting to your payment backend."}];
}
if (error) {
completion(STPBackendChargeResultFailure, error);
} else {
completion(STPBackendChargeResultSuccess, nil);
}
}];
[uploadTask resume];
错误:
You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.
我们看到了类似的问题
提前感谢。您不应该在iOS应用程序中创建费用。您需要您的密钥来创建费用,从应用程序中存储您的api密钥或在应用程序中检索您的密钥都是不安全的
您的公钥可以安全地存储在应用程序中以创建令牌,然后您可以将该令牌发送到后端以创建费用。这允许您的密钥安全地存储在服务器上
下面是Stripe的ruby后端示例,它向您展示了如何使用您创建的令牌创建费用:
You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.