2012-05-14 7 views
0

curlを使用した支払いシステム用のバーチャルマーチャント決済ゲートウェイに支払い情報を送信しています。これは私のコードです:Curlリクエストレスポンスが得られません

$Url= "https://www.myvirtualmerchant.com/VirtualMerchant/process.do"; 
    // is cURL installed yet? 
    if (!function_exists('curl_init')){ 
     die('Sorry cURL is not installed!'); 
    } 

    // OK cool - then let's create a new cURL resource handle 
    $ch = curl_init(); 

    // Now set some options (most are optional) 

    // Set URL to download 
    curl_setopt($ch, CURLOPT_URL, $Url); 


    // Include header in result? (0 = yes, 1 = no) 
    // curl_setopt($ch, CURLOPT_HEADER, 0); 

    // Should cURL return or print out the data? (true = return, false = print) 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

    // Timeout in seconds 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); 


    $fields = array(
      'ssl_card_number'=>urlencode($_POST['ssl_card_number']), 
      'ssl_exp_date'=>urlencode($_POST['ssl_exp_date']), 
      'ssl_cvv2cvc2'=>urlencode($_POST['ssl_cvv2cvc2']), 
      'ssl_avs_address'=>urlencode($_POST['ssl_avs_address']), 
      'ssl_avs_zip'=>urlencode($_POST['ssl_avs_zip']), 
      'ssl_merchant_id'=>urlencode($_POST['ssl_merchant_id']), 
      'ssl_user_id'=>urlencode($_POST['ssl_user_id']), 
      'ssl_pin'=>urlencode($_POST['ssl_pin']), 
      'ssl_transaction_type'=>urlencode($_POST['ssl_transaction_type']), 
      'ssl_amount'=>urlencode($_POST['ssl_amount']), 
      'ssl_show_form'=>urlencode($_POST['ssl_show_form']), 
      'TransactionType'=>urlencode($_POST['TransactionType']) 
     ); 

    //url-ify the data for the POST 
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
    rtrim($fields_string,'&'); 
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); 

    // Download the given URL, and return output 
    echo $output = curl_exec($ch); 

    // Close the cURL resource, and free system resources 
    curl_close($ch); 

    print_r($output); 

しかし、私は何も得ていない、何かエラーやメッセージです。それは間違っているのですか?教えてください ?

+0

お試しください:$ info = curl_getinfo($ ch); –

+0

許可要求にVirtualMerchant IDが指定されていませんでした。 – swapnesh

+0

ssl_merchant_idがバーチャルマーチャント –

答えて

0

は前

var_dump(curl_error($ch)); 

エラーを見つけるために、これを試してみて、あなたはHTTPSのページを呼び出しているcurl_exec($ch);

+0

答えがそれだとは思わない –

+0

どうすればいいですか? curl_exec()を呼び出す前にcurl_error()を呼び出します。 –

0

を参照してくださいすると、エラーがカール近く前にこのコードを与える探してみてください次に

print_r($result); 
exit; 
0

はこれを試してみてください:

$output = curl_exec($ch); 
$response = curl_getinfo($ch); 
echo "<pre>"; 
print_r($response); 
echo "</pre>"; 

は、あなたが応答を取得願っています:)

1

まず、私はあなたのmechant_idを確認したい、ピンなどの下に、私は同様の問題を通して作業後に作成されたコードを進めています。

<html> 
    <body> 
     <p>--start--</p> 

<?php 
//if you have a live account don't use the "demo" post url it won't work 
$post_url = 'https://www.myvirtualmerchant.com/VirtualMerchant/process.do'; 

//replace the xxx's with your proper merchant_id, etc. 
//they will give you these when you activate your account 

//I've set form to not show, and ssl_result_format =>ascii to get a string returned 

$fields = array(
    'ssl_merchant_id'   =>'xxxxxx', 
    'ssl_user_id'    =>'xxx', 
    'ssl_pin'    =>'xxxxx', 
    'ssl_show_form'    =>'false', 
    'ssl_result_format'   =>'ascii', 
    'ssl_test_mode'    =>'false', 
    'ssl_transaction_type'  =>'ccsale', 
    'ssl_amount'    =>'1.44', 
    'ssl_card_number'   =>'5000300020003003', 
    'ssl_exp_date'    =>'1214', 
    'ssl_avs_address'   =>'Test 3', 
    'ssl_avs_zip'    =>'123456', 
    'ssl_cvv2cvc2'    =>'123', 
); 

//build the post string 
$fields_string = ''; 
foreach($fields as $key=>$value) { $fields_string .=$key.'='.$value.'&'; } 
rtrim($fields_string, "&"); 

//open curl session 
// documentation on curl options at http://www.php.net/curl_setopt 

$ch = curl_init(); 
//begin seting curl options 
//set URL 
curl_setopt($ch, CURLOPT_URL, $post_url); 

//set method 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

//set post data string 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); 

//these two options are frequently necessary to avoid SSL errors with PHP 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 

$result = curl_exec($ch); 

if($result === FALSE) { 
    //post failed 
    die(curl_error($ch)); 

} else { 
    //got a response 
    //some people seem to get name/value pairs delimited with "&" 
    //but currently mine is \n 
    //support told me there's no way to change it.. 
    $response_array = explode("\n",$result); 

    //make it nice and useful 
    foreach($response_array as $k=>$v){ 
     $v=explode("=",$v); 
     $a[$v[0]]=$v[1]; 
    } 

    //show the whole array 
    print_r($a); 

    //use a specific return value 
    //returns "APPROVAL" if it went through 
    echo('<h1>'. $a[ssl_result_message] . '</h1>'); 
} 
?> 

     <p>--end--</p> 
    </body> 
</html> 

上記のコードはあなたにこのような画面が正味する必要があります

--start-- 

Array ([ssl_card_number] => 50**********3003 [ssl_exp_date] => 1214 [ssl_amount] => 1.44 [ssl_customer_code] => [ssl_salestax] => [ssl_invoice_number] => [ssl_description] => [ssl_departure_date] => [ssl_completion_date] => [ssl_company] => [ssl_first_name] => [ssl_last_name] => [ssl_avs_address] => Test 3 [ssl_address2] => [ssl_city] => [ssl_state] => [ssl_avs_zip] => 123456 [ssl_country] => [ssl_phone] => [ssl_email] => [ssl_result] => 0 [ssl_result_message] => APPROVAL [ssl_txn_id] => AA49315-1234567-F78F-468F-AF1A-F5C4ADCFFB1E [ssl_approval_code] => N53032 [ssl_cvv2_response] => [ssl_avs_response] => [ssl_account_balance] => 0.00 [ssl_txn_time] => 01/15/2014 11:53:15 AM) 

APPROVAL 

--end-- 

あなたがテストを終えたとき、あなたは、これらすべてのテスト購入を削除していることを確認します。私は彼らがあなたの本当の購入を掲載から禁じると言われます。

+0

$ 50以下のテスト用のメモを追加しました。承認済み、$ 50以上の金額が拒否されました。 – integris

+0

curl_setopt($ userReq、CURLOPT_SSL_VERIFYHOST、false);および curl_setopt($ userReq、CURLOPT_SSL_VERIFYPEER、false);私のためにそれをしました。サーバーはSSL証明書を更新する必要がありました。 – Quinnland23

関連する問題