duanshan7261 2018-06-27 01:04
浏览 37

我无法通过PHP-Curl发布和重定向到支付网关

I have built a form that requires the info ,including $amount.

Supposedly , the form will post the info to the MYSQL Db for storing . <form name="payFormCcard" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">

For the PHP part , some payment info(e.g. $amount ,some info will be posted in hard coded form ) will post to Payment Gateway via Curl. And I will redirect to the Payment Gateway compulsorily header("Location:https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp");

Now , the data can save into the DB successfully .Although it goes to the Payment Gateway at the end ,the data cannot post to the Gateway .

One the Gateway site ,

Error Message

Parameter merchantId Incorrect

Hence , sth is wrong on the Curl method .All parameters cannot pass to the payment Gateway successfully .

PHP Part in the create.php:

// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Validate name
    $input_CName = trim($_POST["CName"]);
    if (empty($input_CName)) {
        $CName_err = "Please enter a name.";
    } elseif (!filter_var(trim($_POST["CName"]), FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[a-zA-Z'-.\s ]+$/")))) {
        $CName_err = 'Please enter a valid name.';
    } else {
        $CName = $input_CName;
    }
....Other field validation ...

....Storing to DB if every field is okay .
  if (empty($CName_err) && empty($Address_err) && empty($amount_err) && empty($Phone_err)) {
        // Prepare an insert statement
        $pdo = Database::connect();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "INSERT INTO donation (CName, Address, Phone, Amount ,Ticket, Purpose) VALUES (?, ?, ?, ? ,?, ?)";

        $q = $pdo->prepare($sql);
        $q->execute(array($CName, $Address, $Phone, $amount ,$Ticket ,$Purpose));
        Database::disconnect();

Curl Part ......

$fields = array(
   'amount' => $amount,
      'merchantId'   => 'sth',
            'orderRef'    => 'sth',
            'currCode'   => '344',
            'mpsMode'    => 'NIL',
       'successUrl' =>'http://www.yourdomain.com/Success.html',
 'failUrl' =>'http://www.yourdomain.com/Fail.html',
'cancelUrl'=>'http://www.yourdomain.com/Cancel.html',
            'payType'    => 'N',
            'lang'       => 'E',
            'payMethod'  => 'CC',
            'secureHash'=> 'sth'
);

// build the urlencoded data
$postvars = http_build_query($fields);
    $ch = curl_init();
//
curl_setopt($ch, CURLOPT_URL,"https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp");
curl_setopt($ch, CURLOPT_POST,  count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
//
//// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

   header("Location:https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp"); 
}

}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法