简体   繁体   中英

PHP+BillDesk payment gateway integration issue

I am trying to integrate BillDesk payment gateway with my PHP website. I am getting this below error when I run my simple PHP code

{"status":422,"error_type":"invalid_data_error","error_code":"GNIDE0004","message":"Invalid Content-type header"}

Here is my PHP code. Please note this is only for testing purpose

<?php
$str = "<MerchantId>|order45608988|NA|300.00|NA|NA|NA|INR|NA|TypeField1|<ClientID>|NA|NA|TypeField2|Txtadditionalinfo1|Txtadditionalinfo2|http://google.com";

$checksum = hash_hmac('sha256',$str,"<secretkey>", false); 
$checksum_value = strtoupper($checksum);


echo '<form action="https://pguat.billdesk.io/payments/ve1_2/orders/create" method="post" id="billdesk_payment_form">';
echo '<input type="hidden" name="MerchantId" value="<MerchantId>"/>';
echo '<input type="hidden" name="CurrencyType" value="INR"/>';
echo '<input type="hidden" name="SecurityId" value="<ClientID>"/>';
echo '<input type="hidden" name="txtCustomerID" value="order45608988" />';
echo '<input type="hidden" name="txtTxnAmount" value="300.00" />';
echo '<input type="hidden" name="txtAdditionalInfo1″ value="" />';
echo '<input type="hidden" name="RU" value="http://returnURL.com" />';
echo '<input type="hidden" name="CheckSumKey" value="<secretkey>"/>';
echo '<input type="hidden" name="CheckSum" value="'.$checksum_value.'"/>';
echo '<input type="hidden" name="msg" value="'.$str.'" />';
echo '</form>';

echo '<script>document.getElementById("billdesk_payment_form").submit();</script>';
?>

I have referenced the BillDesk docs and I am not getting exactly what changes I have to do.

Thank you in advance.

/* Billdesk has changed payment gateway. sample as given below */

/****
 config.php
*****/

    $MerchantID = "ABCDEF01";
    $ClientID = "abcdef01";
    $responseurl = "https://www.merchantwebsite.com/ru.php";
    $secretkey = 'xxxxxxxxxxxxxxxxxxxxxxxx';
    $returnURL = "https://www.merchantwebsite.com/paymentresponse.php";
    $billdesk_URL = "https://pguat.billdesk.io/payments/ve1_2/orders/create";
        
/****
 process.php
*****/

    use Firebase\JWT\JWT;

    /*****************************************/
        // Build headers
    /*****************************************/
    
    $headers = ["alg" => "HS256", "clientid" => $ClientID, "kid" => "HMAC"];

    $payload = [
      "mercid" => $MerchantID,
      "orderid" => $transaction_id,
      "amount" => $totalamount,
      "order_date" => $date_atom,
      "currency" => "356",
      "ru" => $responseurl,
      "additional_info" => [
        "additional_info1" => $CustomerID,
        "additional_info2" => $PaymentFor,
        "additional_info3" => "NA",
        "additional_info4" => "NA",
        "additional_info5" => "NA",
        "additional_info6" => "NA",
        "additional_info7" => "NA",
      ],
      "itemcode" => "DIRECT",
      "device" => [
        "init_channel" => "internet",
        "ip" => $ipaddress,
        "mac" => $macaddress,
        "imei" => $imei,
        "accept_header" => "text/html",
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0",
        "fingerprintid" => $fingerprintid
      ]
    ];
    
    

    /*****************************************/
        // Encode payload
    /*****************************************/

    $curl_payload = JWT::encode($payload, $secretkey, "HS256", null ,$headers);
    
    /*****************************************/
        // Submit to Billdesk
    /*****************************************/
    $ch = curl_init( $billdesk_URL );
    $ch_headers = array(
        "Content-Type: application/jose",
        "accept: application/jose",
        "BD-Traceid: $transaction_id",
        "BD-Timestamp: $servertimeYYYYMMddHHmmss"
    );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, $ch_headers);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $curl_payload);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
                        
    $result = curl_exec($ch);
    curl_close($ch);

    /*****************************************/
        // Billdesk Response
    /*****************************************/
    
    $launch_billdesk = false;
    try { 
        $result_decoded = JWT::decode($result, $secretkey, array('HS256'));
        $result_array = (array) $result_decoded;
            
        if ($result_decoded->status == 'ACTIVE') {
            $transactionid = $result_array['links'][1]->parameters->bdorderid;
            $authtoken = $result_array['links'][1]->headers->authorization;

            $launch_billdesk = true;   //write js code to launch sdk

        } else { // Response error
            echo "Response error";
        }
                        
    } catch (\Exception $e) {
        echo "<br><br>Return signature validation FAILED: $e";
    }
    
    
/****
 paymentresponse.php
*****/

    use Firebase\JWT\JWT;
        
    /*****************************************/
        // Read POST data
    /*****************************************/ 
    $tx = "";
    if(!empty($_POST)) { 
        $tx_array = $_POST;
        if (isset($tx_array['transaction_response'])) {
            $tx = $tx_array['transaction_response'];
        }
    } else {
        echo "<br><br>Invalid call<br>";
        die();
    }
    
    
    /*****************************************/
        // Signature validation
    /*****************************************/ 
    try { 
        $result_decoded = JWT::decode($tx, $secretkey, array('HS256'));
        $result_array = (array) $result_decoded;
        $result_json =  json_encode($result_array,JSON_PRETTY_PRINT);       
    } catch (\Exception $e) {
        //echo $e; 
        echo "<br><br>Invalid response<br>";
        die();
    }
    
    /*****************************************/
        // Process info
    /*****************************************/ 
    if ($result_decoded->transaction_error_type == 'success') {
        
        $orderid = $result_decoded->orderid;
        $transaction_date = $result_decoded->transaction_date;
        $transactionid = $result_decoded->transactionid;    //payment transaction id
        $charge_amount = $result_decoded->charge_amount;

        /*  SAVE TO DB and send receipt     */
        $success = updateTransactionToDB($result_array);        
        GenerateReceiptEmail($orderid, 1, $draftreceipt);
        
        echo "<h2>Transaction was successful....</h2>";
        echo "Transaction Date: $transaction_date<br>";
        echo "Transaction ID: $transactionid<br>";
        echo "Charge Amount: ₹$charge_amount<br>";          


    } else { // Error
        $txerror = $result_decoded->transaction_error_type;
        $txid = $result_decoded->transactionid;
        echo "<h2>Transaction FAILED....</h2>";
        echo "Transaction Date: $transaction_date<br>";
        echo "Transaction ID: $transactionid<br>";
        echo "Charge Amount: ₹$charge_amount<br>";          
        echo "Failure Reason: ₹$transaction_error_desc<br>";            
    }
    
    

Not worked for me. there are lots of parameter you used, but not define anywhere. can you please share full code here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM