###前提・実現したいこと
coincheckのAPIを使用して自分のECサイトで、ビットコインで決済ができるよう導入したいです。
そのために 支払い用ボタンの生成 を行いたいです。
PHPを使用しています。
coincheck API ドキュメント
https://coincheck.com/ja/documents/payment/api/auth
https://coincheck.com/ja/documents/payment/api/payment-button
ご教授お願い致します。
###発生している問題・エラーメッセージ
返り値を表示すると
string(50) "{"success":false,"error":"invalid authentication"}"
こうなり、認証がうまくできていないのかと思います。
正常だとボタンを表示するhtml等が返ってくるらしいです。
###該当のソースコード
PHP
1 2$strUrl = "https://coincheck.com/api/ec/buttons"; 3$intNonce = time(); 4$strCallbackUrl = "https://www.google.co.jp/"; 5$arrQuery = array("button" => array( 6 "name" => "注文 #123", 7 "currency" => "JPY", 8 "amount" => 5000, 9 "callback_url" => $strCallbackUrl, 10 "max_times" => 1 11)); 12$strAccessSecret = "実際には秘密鍵が入ります"; 13$strMessage = $intNonce . $strUrl . http_build_query($arrQuery); 14 15# hmacで署名 16$strSignature = hash_hmac("sha256", $strMessage, $strAccessSecret); 17 18$headers = array( 19 "ACCESS-KEY:実際にはAPIキーが入ります", 20 "ACCESS-SIGNATURE:" . $strSignature, 21 "ACCESS-NONCE:" . $intNonce 22 ); 23 24$url = "https://coincheck.com/api/ec/buttons"; 25$ch = curl_init(); 26curl_setopt($ch, CURLOPT_URL, $url); 27curl_setopt($ch,CURLOPT_POST, true); 28curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 29 30 31// ヘッダー追加 32curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 33 34// postdata追加 35$post_data = array('button[name]' => "注文 #123" ,'button[currency]'=> "JPY" ,"button[display_currency]"=>"JPY",'button[amount]' => 5000,'button[callback_url]'=> "http://www.example.com/coincheck/callback" ,"button[success_url]"=>"http://google.co.jp/" ,"button[max_times]"=>1 ,"button[include_name]"=>true ,"button[include_email]"=>true,"button[include_address]"=>false,"button[custom]"=>"123","button[notify_mispayment]"=>true); 36curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data)); 37 38 39$html = curl_exec($ch); 40var_dump($html); 41 42curl_close($ch);
回答3件
あなたの回答
tips
プレビュー