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

时间:2018-06-27 01:04:56

标签: php database payment-gateway payment-processing php-curl

我建立了一个需要信息的表格,包括$amount

据推测,该表单会将信息发布到MYSQL Db进行存储。  <form name="payFormCcard" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">

对于PHP部分,一些付款信息(例如$amount,有些信息将以硬编码形式发布)将通过Curl发布到Payment Gateway。然后,我将强制header("Location:https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp");

重定向到支付网关

现在,数据可以成功保存到数据库中了。尽管它最后到达了支付网关,但数据无法发布到网关。

  
    

一个网关站点

  
     

错误消息

     
    

mermaidId参数不正确

  

因此,Curl方法上的某事是错误的。所有参数都无法成功传递到支付网关。

create.php中的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 个答案:

没有答案