[英]Stripe API create charge through iOS Code?
我一直在ApplePay與條紋,所有罰款,直至采取條紋令牌PKPayment這里每個人都提到把你帶令牌服務器並收取金額。 我不具備創建Web服務並將令牌發送到服務器的知識。 因此,我計划通過iOS代碼對卡進行收費。
創建費用文檔: 鏈接
curl https://api.stripe.com/v1/charges \
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
-d amount=999 \
-d currency=usd \
-d description="Example charge" \
-d source=tok_IPLStrXFSITtr78XW5SyDWL8
在這里,我們不知道如何使用密鑰創建帖子數據。
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/.
我們看過類似的問題, Apple Pay使用Stripe將令牌發送到服務器並收取購買費用
提前致謝..
您永遠不要*永遠*不要*在iOS應用程序內創建費用。 您需要使用密鑰來產生費用,從應用程序內部存儲api密鑰或在應用程序中檢索密鑰並不安全。
您的公鑰可以安全地存儲在應用程序中以創建令牌,然后您可以將該令牌發送到后端以創建費用。 這樣可以將您的密鑰安全地存儲在服務器上。
這是Stripe在ruby中的示例后端,向您展示了如何使用創建的令牌創建費用: https : //github.com/stripe/example-ios-backend
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.