ok
Direktori : /home2/selectio/public_html/a-pay/ |
Current File : /home2/selectio/public_html/a-pay/index.php |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Phone Integration</title> </head> <body> <br> <center><h1>Phone Pay Integration </h1> <br> <hr> <form action="#" method="post"> <label for="amountEnterByUsers">Enter Amount</label> <input type="number" name="amountEnterByUsers" id="amountEnterByUsers"> <br><hr> <button type="submit" name="submit_form">Pay Now</button> </form> </center> </body> </html> <?php if (isset($_POST['submit_form'])) { $amount = $_POST['amountEnterByUsers']; //$merchantKey = '4c6ab592-0990-4292-8b4a-f9537fa6d02f'; // live : 4c6ab592-0990-4292-8b4a-f9537fa6d02f $merchantKey ='28b3c178-4421-4ca1-a162-053df2fb4da4'; // testing : 14fa5465-f8a7-443f-8477-f986b8fcfde9 $data = array( "merchantId" => "M2218VERX8YAK", //M1WU3XVU5GAA - Drwaingscart Live id //PGTESTPAYUAT77 - Testing "merchantTransactionId" => bin2hex(random_bytes(6))."-000000000000", "merchantUserId" => "MU125", "amount" => $amount*100, "redirectUrl" => "https://selectionsilks.com/a-pay/paymentsuccess.php", "redirectMode" => "POST", "callbackUrl" => "https://selectionsilks.com/a-pay/paymentsuccess.php", "mobileNumber" => "99426579900", "param1" => "Ganesan", "paymentInstrument" => array( "type" => "PAY_PAGE" ) ); // Convert the Payload to JSON and encode as Base64 $payloadMain = base64_encode(json_encode($data)); $payload = $payloadMain."/pg/v1/pay".$merchantKey; $Checksum = hash('sha256', $payload); $Checksum = $Checksum.'###1'; //X-VERIFY - SHA256(base64 encoded payload + "/pg/v1/pay" + salt key) + ### + salt index //https://api.phonepe.com/apis/hermes/pg/v1/pay //https://api-preprod.phonepe.com/apis/pg-sandbox/pg/v1/pay $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://api.phonepe.com/apis/hermes/pg/v1/pay", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode([ 'request' => $payloadMain ]), CURLOPT_HTTPHEADER => [ "Content-Type: application/json", "X-VERIFY: ".$Checksum, "accept: application/json" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); print_r($response); if ($err) { // echo "cURL Error #:" . $err; header('Location: paymentfailed.php?cURLError='.$err); // echo 'failed Page'; // print_r($err); } else { $responseData = json_decode($response, true); $url = $responseData['data']['instrumentResponse']['redirectInfo']['url']; header('Location: '.$url); /*echo 'else Page<br>'; print_r($responseData);*/ } }?>