向webhook添加更多详细信息

时间:2017-03-12 13:41:22

标签: php payment webhooks instamojo

我正在使用Instamojo作为我的laravel应用程序。

我有一个输入名称的表单,如vtype,vname,name,phone,date,price。

我的instamojo index.php看起来像这样 -

<?php

    use App\Vname;

    $vname = Vname::find($request->vname);
    $api = new Instamojo\Instamojo(config('instamojo.api_key'), config('instamojo.auth_token'), 'https://test.instamojo.com/api/1.1/');

    try {
        $response = $api->paymentRequestCreate(array(
            "purpose" => "Online Vazhipad",
            "amount" => $vname->price,
            "buyer_name" => $request->name,
            "phone" => $request->phone,
            "send_email" => true,
            "email" => Auth::user()->email,
            "allow_repeated_payments" => false,
            "redirect_url" => url('/online_vazhipad/thankyou')
            "webhook" => url('/online_vazhipad/webhook')
        ));
        $pay_ulr = $response['longurl'];
        header("Location: $pay_ulr");
        exit();
    }
    catch (Exception $e) {
        print('Error: ' . $e->getMessage());
    }

?>

我的webhook文件看起来像这样 -

<?php

    $data = $_POST;
    $mac_provided = $data['mac'];
    unset($data['mac']);

    $ver = explode('.', phpversion());
    $major = (int) $ver[0];
    $minor = (int) $ver[1];

    if($major >= 5 and $minor >= 4){
        ksort($data, SORT_STRING | SORT_FLAG_CASE);
    }
    else{
        uksort($data, 'strcasecmp');
    }

    $mac_calculated = hash_hmac("sha1", implode("|", $data), config('instamojo.private_salt'));

    if($mac_provided == $mac_calculated){
        echo "MAC is fine";
        if($data['status'] == "Credit"){

            // Payment was successful my database code will be placed here

        }
        else{
            return 'failed';
        }
    }
    else{
        echo "Invalid MAC passed";
    }

?>

我想在我的数据库中添加更多信息,比如vtype和vname,但我不知道如何从表单中获取数据到这里。

从我发现的文档来看,我们从instamojo获得的帖子请求只包含this much

请帮帮我。

0 个答案:

没有答案