1

I am using Instamojo for my laravel app.

I have a form with input name like vtype, vname, name, phone, date, price.

My instamojo index.php looks like this --

<?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());
    }

?>

and my webhook file looks like this -

<?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";
    }

?>

I wanted to add more information to my database like vtype and vname, but I dont know how to get the data from the form to here.

From the documentation i came to know that, the post request we get from instamojo only contains this much.

Please help me.

Advaith
  • 2,490
  • 3
  • 21
  • 36

0 Answers0