4

I have used the three variables which are posting form the html and passing in the $postdata array

    $cardnum= $_POST['Card_Num'];
    $cardexp= $_POST['Card_Exp'];
    $amount =$_POST['amount'];

passing these three variables in the $postdata array

$postdata = array(

                "vpc_CardNum" => $cardnum,
                "vpc_CardExp" => $cardexp,
                "vpc_AccessCode" => $accessCode,
                "vpc_Amount" => ($amount*100),
                "vpc_Command" => 'pay',
                "vpc_Locale" => 'en',
                "vpc_MerchTxnRef" => $unique_id,
                "vpc_Merchant" => $merchantId,
                "vpc_OrderInfo" => 'this is a product',
                "vpc_ReturnURL" => "https://localhost/success.php",
                "vpc_Version" => '1');

The complete code is given below the html is given:-

<!DOCTYPE html>

<html>
<head>
</head>
<body>

<form method="POST" action="integrate.php">
Credit Card Number
<input type="text" name="Card_Num">
<input type="text" name="Card_Exp" maxlength="4">
<input type="number" name="amount">
<input type="submit" value="Submit payment">

</form
</body>
</html>

The complete php code is given below and it is giving the status of 400 error

<?php

        $cardnum= $_POST['Card_Num'];
        $cardexp= $_POST['Card_Exp'];
        $amount =$_POST['amount'];


        $SECURE_SECRET = "YEOCOEN29B0785F1FF1E3C0FA8A3FUJK";   
        $accessCode = '546484645';
        $merchantId = 'ABERCROMBIEKIDS#119GARDENCITYNY';


        $cardnum= $_POST['Card_Num'];
        $cardexp= $_POST['Card_Exp'];
        $amount =$_POST['amount'];
        $unique_id = rand(999999,8988888888);//this is a sample random no
        $postdata = array(

                "vpc_CardNum" => $cardnum,
                "vpc_CardExp" => $cardexp,
                "vpc_AccessCode" => $accessCode,
                "vpc_Amount" => ($amount*100),
                "vpc_Command" => 'pay',
                "vpc_Locale" => 'en',
                "vpc_MerchTxnRef" => $unique_id,
                "vpc_Merchant" => $merchantId,
                "vpc_OrderInfo" => 'this is a product',
                "vpc_ReturnURL" => "https://localhost/success.php",
                "vpc_Version" => '1');


        $vpcURL = 'https://migs.mastercard.com.au/vpcpay?';
        $md5Hash = $SECURE_SECRET;
        $appendAmp = 0;


        foreach ($postdata as $key => $value) {

            if (strlen($value) > 0) {

                if ($appendAmp == 0) {
                    $vpcURL .= urlencode($key) . '=' . urlencode($value);
                    $appendAmp = 1;
                } else {
                    $vpcURL .= '&' . urlencode($key) . "=" . urlencode($value);
                }
                $md5Hash .= $value;
            }
        }

            var_dump($postdata);
                print_r($postdata);
        if (strlen($SECURE_SECRET) > 0) {
            $vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5Hash));
        }
        header("Location: " . $vpcURL);

        ?>

1 Answers1

0

vpc_ReturnURL should be a live server not your localhost, mastercard (or paypal .. etc) can't access your localhost and post data.


How You Might See the 400 Error:

"400 Bad Request"

"Bad Request. Your browser sent a request that this server could not understand."

"Bad Request - Invalid URL"

"HTTP Error 400 - Bad Request"

"Bad Request: Error 400"

"HTTP Error 400. The request hostname is invalid."

"400 - Bad request. The request could not be understood by the server due to malformed syntax. The client should not repeat the request without modifications."

Shady Alset
  • 4,850
  • 3
  • 19
  • 31