【问题标题】:Payeezy Credit Card Payments always geting "HMAC validation Failure" error responsePayeezy 信用卡付款总是收到“HMAC 验证失败”错误响应
【发布时间】:2014-12-09 19:01:16
【问题描述】:

谁能回答,为什么我总是收到“HMAC 验证失败”错误响应。

我的代码:

$response_purchase_JSON = $payeezy - > purchase(array(

      "amount" => "420",
      "card_number" => "4012000033330026",
      "card_type" => "VISA",
      "card_holder_name" => "Test Account",
      "card_cvv" => "675",
      "card_expiry" => "1119",
      "merchant_ref" => "Transaction",
      "currency_code" => "USD",

));

print_r($response_purchase_JSON);

【问题讨论】:

    标签: php payment-gateway payment hmac


    【解决方案1】:

    您需要构造 HMAC 值。查看文档: https://developer.payeezy.com/content/hmac-validation-failure

    您的 JSON 有效负载也不正确。

    正确有效载荷示例(test.json):

    {
        "transaction_type": "authorize",
        "method": "credit_card",
        "amount": "420",
        "currency_code": "USD",
        "credit_card": {
            "type": "visa",
            "cardholder_name": "Test Account",
            "card_number": "4012000033330026",
            "exp_date": "1119",
            "cvv": "675"
        }
    }
    

    下面还有示例 PHP 代码:

    <?php
    
    $serviceURL = 'https://api-cert.payeezy.com/v1/transactions';
    $apikey = 'yourapikey';
    $token = 'yourapitoken';
    $apisecret = 'yourapisecret';
    
    list($usec, $sec) = explode(" ", microtime());
    $timestamp = round(((float)$usec + (float)$sec) * 1000);
    $timestamp = $timestamp - 5000;
    $nonce = rand();
    
    echo 'Timestamp is: '. $timestamp."\n";
    
    $reqbody = file_get_contents('./test.json', true);
    
    echo 'Request body: '.$reqbody."\n";
    
    $summarize = "";
    $summarize .= $apikey;
    $summarize .= $nonce;
    $summarize .= $timestamp;
    $summarize .= $token;
    $summarize .= $reqbody;
    
    
    $hmac = hash_hmac('SHA256', $summarize, $apisecret);
    
    echo "Hmac is: ".$hmac."\n";
    
    $hmac_enc = base64_encode($hmac);
    
    
    $curl = curl_init($serviceURL);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $reqbody);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    
    
    $headers = array(
        'Content-type: application/json',
        "Authorization: ".$hmac_enc,
        "apikey: ".$apikey,
        "token: ".$token,
        "timestamp: ".$timestamp,
        "nonce: ".$nonce,
    );
    
    
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    
    $json_response = curl_exec($curl);
    
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    
    if ( $status != 201 ) {
        die("Error: call to URL $serviceURL failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
    }
    
    
    curl_close($curl);
    
    $response = json_decode($json_response, true);
    
    echo "Response is: ".$response."\n";
    echo "JSON response is: ".$json_response."\n";
    
    ?> 
    

    【讨论】:

    • 我真的很讨厌 necroing 这个,但我一直在寻找一个更完整和愚蠢的证明(我)的例子并找到了这个,这个例子你提供@Boris,首先请求授权然后通过购买如果我理解正确?
    【解决方案2】:

    这些是“HMAC 验证失败”的常见原因:

    1. API 密钥和/或 API 机密不正确。
    2. API 密钥、API 机密、商家令牌中的前导或尾随空格。
    3. HTTP 标头中的时间戳不是以毫秒为单位的。
    4. HTTP 标头中的时间戳不代表 EPOCH 时间。
    5. 纪元时间不是根据 UTC 计算的。
    6. HTTP 标头中的时间戳不在我们服务器时间的 5 分钟内
    7. 系统时间不准确。

    如果您在本地机器上测试支付,并且您认为您已正确执行所有步骤但也遇到相同的错误,请尝试在服务器上运行代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-04
      • 2016-11-06
      • 2023-03-20
      • 1970-01-01
      • 2021-12-13
      • 2020-02-29
      相关资源
      最近更新 更多