<?php

// Enable CORS headers
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: Content-Type");

require_once 'db.php';

$recharge_id = $_GET['recharge_id'];


                                $ch = curl_init();
                                
                                curl_setopt($ch, CURLOPT_URL, 'https://www.instamojo.com/api/1.1/payment-requests/');
                                curl_setopt($ch, CURLOPT_HEADER, FALSE);
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                                curl_setopt($ch, CURLOPT_HTTPHEADER,
                                            array("X-Api-Key:1d669faa0e7a78c873be118a90ec32ab",
                                                  "X-Auth-Token:869077c17183783d03866dfd91e6ca30"));
                                $payload = Array(
                                    'purpose' => 'FIFA 16',
                                    'amount' => '9',
                                    'phone' => '7002484119',
                                    'buyer_name' => 'John Doe',
                                     
                                    'redirect_url' => "https://agriexpertt.com/mobile/Flutter/insta_response.php?recharge_id=$recharge_id",

                                    'send_email' => true,
                                    'send_sms' => true,
                                    'email' => 'zzubizubi@gmail.com',
                                    'allow_repeated_payments' => false
                                );
                                curl_setopt($ch, CURLOPT_POST, true);
                                curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
                                $response = curl_exec($ch);
                                curl_close($ch); 
                                
                                $response_new = json_decode($response);
                                echo '<pre>';
                                print_r ($response_new);
                                 
                                header('Location:' . $response_new->payment_request->longurl);

                                
                                ?>