LoginSignup
1
2

More than 5 years have passed since last update.

決済でkomoju Hookをphpで受け取る

Posted at

例によって検証用でございます。
公式サイトのシグネチャの説明がRubyでちょっと中身がわかりにく若干苦労しました。
管理画面で適宜URLやらトークンやらは設定してください。

hook.php
$token = "管理画面で設定したトークン";
//headerの必要な情報を取得
foreach (getallheaders() as $name => $value) {
    //Komoju id
    if($name == "X-Komoju-Id"){
        $request_id = $value;
    }
    //シグネチャ
    if($name == "X-Komoju-Signature"){
        $request_signature = $value;
    }
    //イベント種別
    if($name == "X-Komoju-Event"){
        $request_event = $value;
    }
    echo "$name: $value\n";
}
//シグネチャはボディのハッシュになります
$body = file_get_contents('php://input');
$signature = hash_hmac("sha256",$body,$token);

//シグネチャの正当性を確認
if($signature === $request_signature){
    echo "Good request!\n";
    echo $request_id."\n";
    echo $request_event."\n";
/*
この後に決済完了とかそういうしょりをね、入れていくわけです
*/
}else{
    echo "Bad request!";
}

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2