目的:Pay.jpによるSwiftアプリケーションのApple pay決済機能を実装したい
具体的な内容:決済認証のリクエストを送り、決済をサーバーサイドで完了させるがドキュメントに書かれていない。そのためcurl文をSwiftに書き直したい
教えて欲しいこと:以下のcurl文をswiftに直して欲しい
curl https://api.pay.jp/v1/charges \ -u sk_test_c62fade9d045b54cd76d7036: \ -d card=tok_76e202b409f3da51a0706605ac81 \ -d amount=3500 \ -d currency=jpy
試したこと:
Alamofire(https://github.com/Alamofire/Alamofire)のライブラリを使い、リクエストを投げる
if let url = URL(string: "https://api.pay.jp/v1/charges"){ var urlRequest = URLRequest(url: url ) urlRequest.httpMethod = HTTPMethod.post.rawValue urlRequest.addValue("tokから始まるトークン", forHTTPHeaderField: "card") urlRequest.addValue("300", forHTTPHeaderField: "amount") urlRequest.addValue("jpy", forHTTPHeaderField: "currency") urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type") AF.request(urlRequest) .responseJSON { response in print(response) } }
エラー文:
SUCCESS: { error = { code = "bad_request"; message = "The server could not comply with the request since it is either malformed or otherwise incorrect."; status = 400; type = "client_error"; }; }
あなたの回答
tips
プレビュー