Wordpress 集成Paysimple API(请检查有何错误)

Wordpress 集成Paysimple API(请检查有何错误),wordpress,api,payment-gateway,internal-server-error,paysimple,Wordpress,Api,Payment Gateway,Internal Server Error,Paysimple,我正在使用Paysimple API集成一次性简单支付,我总是遇到以下错误: 弦(196) {“Meta”:{“Errors”:{“ErrorCode”:“意外错误”,“ErrorMessages”:[],“TraceCode”:“API8D22C4FA49D9E36”},“HttpStatus”:“InternalServerError”,“HttpStatusCode”:500,“PagingDetails”:null},“Response”:null}” 答复:500 下面是custom

我正在使用Paysimple API集成一次性简单支付,我总是遇到以下错误:

弦(196) {“Meta”:{“Errors”:{“ErrorCode”:“意外错误”,“ErrorMessages”:[],“TraceCode”:“API8D22C4FA49D9E36”},“HttpStatus”:“InternalServerError”,“HttpStatusCode”:500,“PagingDetails”:null},“Response”:null}”

答复:500

下面是custom form.php的代码

PaySimple的文档: 支付

 <?php
  /*
 Plugin Name: Custom Contact Form
 Plugin URI: http://example.com
  Description: Simple non-bloated WordPress Contact Form
 Version: 1.0
*/

add_action('wp_enqueue_scripts','custom_form_init');

function custom_form_init() {
    wp_enqueue_script('custom-form-js', plugins_url( '/js/custom-form.js', __FILE__ ));
}

function html_form_code() {
    echo '<span class="show-error" style="border: 1px solid red;padding: 5px;border-radius: 3px;color: rgb(251, 7, 7);"></span>';
    echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post" class="custom-contact-form">
    <p>Your Name (required)<br>
        <span class="wpcf7-form-control-wrap your-name">
            <input type="text" 
            name="name" 
            value=""
            id="contact-name"
            size="40" 
            class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" 
            aria-required="true" 
            aria-invalid="false">
        </span>
    </p>

    <p>Your Email (required)<br>
        <span class="wpcf7-form-control-wrap your-email">
            <input type="email" 
            name="email"
            id="contact-email"
            value="" size="40" 
            class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" 
            aria-required="true" 
            aria-invalid="false">
        </span> 
    </p>

    <p>Amount  (required<br>
        <span class="wpcf7-form-control-wrap text-981">
            <input type="text" 
            name="amount" 
            value="" 
            id="contact-amount"
            size="40" 
            class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" 
            aria-required="true" 
            aria-invalid="false">
        </span>
    </p>

    <p>Comment <br>
    <span class="wpcf7-form-control-wrap textarea-520">
            <textarea name="comment" 
            cols="40" 
            rows="10" 
            id="contact-comment"
            class="wpcf7-form-control wpcf7-textarea" 
            aria-invalid="false"></textarea>
        </span>
    </p>

    <p><input type="submit" value="Send" class="confirmation-btn submit"></p>

    <p style="color:red;font-weight:bold;">Note : * - required fields</p>

    <p> When you proceed you will be forwarded to payments.paysimple.com secure payment site. You will need your card number, expiration, and you will need to enter your name. The other fields are optional. It is our preference that you reference the invoice you are paying as well.</p>
    </form>';


    echo '<div class="confirmation" style="display:hidden;">';
    echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post" class="custom-contact-submit-form">';
    echo '<p><strong>Your Name</strong><br><span class="confirm-name"></span></p>';
    echo '<p><strong>Your Email</strong><br><span class="confirm-email"></span></p>';
    echo '<p><strong>Your Amount</strong><br><span class="confirm-amount"></span></p>';
    echo '<p><strong>Your Comment</strong><br><span class="confirm-comment"></span></p>';

    echo '<input type="hidden" name="hname" value="!">';
    echo '<input type="hidden" name="hemail" value="!">';
    echo '<input type="hidden" name="hamount" value="!">';
    echo '<input type="hidden" name="hcomment" value="!">';

    echo '<p><input type="submit" name="submit-form" value="Proceed to Checkout" class="submit-btn"></p>';

    echo '</form>';
    echo '</div>';

    // echo '<form action="https://api.paysimple.com/v4/payment" method="POST">
    //     <input type="text" name="AccountId">
    //     <input type="text" name="Amount">
    //     <input type="submit" name="submit">
    // </form>';

}


function deliver_mail() {
     // custom-contact-form
    // if the submit button is clicked, send the email
    if (isset($_POST['submit-form'])) {

        // sanitize form values
        $name    = sanitize_text_field( $_POST['hname'] );
        $comment = sanitize_text_field( $_POST['hcomment'] );
        $amount  = sanitize_text_field( $_POST['hamount'] );
        $email   = sanitize_email( $_POST['hemail'] );
        $subject = 'New Payment! Pay Our Fees';

        $message = '
        From: '.$name.' <'. $email .'>
        Comment :'.esc_textarea($comment).'
        Amount: '.sanitize_text_field($amount).'
        --
        This e-mail was sent from a contact form on James D Miller CPA and Associates (http://jdma.biz/temp)';enter code here

        // get the blog administrator's email address
        // $to = get_option( 'admin_email' );
        $to = 'I WILL INSERT MY EMAIL HERE';

        $headers = "From: $name <$email>" . "\r\n";

        // If email has been process for sending, display a success message
        if ( wp_mail( $to, $subject, $message, $headers ) ) {
            echo '<div>';
            echo '<p>Thanks for contacting me, expect a response soon.</p>';
            echo '</div>';
        } else {
            echo 'An unexpected error occurred';
        }

    }
}

function paySimple() {

    if ( isset( $_POST['submit-form'] ) ) {

    // $userName = "<MYUSERNAME>";
    // $superSecretCode = "<CODE HERE>";
    // $timestamp = gmdate("c");
    // $hmac = hash_hmac("sha256", $timestamp, $superSecretCode, true); //note the raw output parameter
    // $hmac = base64_encode($hmac);                                                                                                                                                                                                                            
    // $auth = "Authorization: PSSERVER AccessId = $userName; Timestamp = $timestamp; Signature = $hmac";
    $url = "https://api.paysimple.com/v4/payment";

    $post_args      = json_encode(array('AccountId'  => 37706,'Amount' => $_POST['hamount']));

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_args);
    // curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth));

    $result = curl_exec($curl);

    var_dump(curl_exec($curl));
    $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    curl_close($curl);
    echo "<br>response: $responseCode <br><br>";
    die();
    }

}


function cf_shortcode() {
    ob_start();
    html_form_code();
    deliver_mail();
    paySimple();

    return ob_get_clean();
}

add_shortcode( 'contact_form', 'cf_shortcode' );

?>

我认为你的问题在于
paySimple
方法

支付提供商为您提供了一种方式,您需要在将数据发送到其服务器之前对其进行加密。 在这种情况下,它们要求您使用
hmac
base64
加密。这是他们文档中的文档管理员

在您的示例中,我发现了以下代码:

// $userName = "jdmcpa4u";
// $superSecretCode = "<CODE HERE>";
// $timestamp = gmdate("c");
// $hmac = hash_hmac("sha256", $timestamp, $superSecretCode, true); //note the raw output parameter
// $hmac = base64_encode($hmac);                                                                                                                                                                                                                            
// $auth = "Authorization: PSSERVER AccessId = $userName; Timestamp = $timestamp; Signature = $hmac";
$url = "https://api.paysimple.com/v4/payment";

$post_args      = json_encode(array('AccountId'  => 37706,'Amount' => $_POST['hamount']));

$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_args);
// curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth));
/$userName=“jdmcpa4u”;
//$superSecretCode=“”;
//$timestamp=gmdate(“c”);
//$hmac=hash_hmac(“sha256”,时间戳,$superSecretCode,true)//注意原始输出参数
//$hmac=base64_编码($hmac);
//$auth=“Authorization:PSSERVER AccessId=$userName;Timestamp=$Timestamp;Signature=$hmac”;
$url=”https://api.paysimple.com/v4/payment";
$post_args=json_encode(数组('AccountId'=>37706,'Amount'=>$post['hamount']);
$curl=curl_init();
curl_setopt($curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
curl_setopt($curl,CURLOPT_URL,$URL);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post_args);
//curl_setopt($curl,CURLOPT_HTTPHEADER,数组($auth));
我认为你应该取消这些行的注释,然后再试一次

PaySimple要求您在每个请求中发送一个包含密钥的请求计算签名


如果您正确遵循他们的指示,他们还可以根据您的请求计算签名,并将其与您发送的签名进行比较。这样,他们可以确保没有人篡改请求数据。这就是为什么绝对不要泄露您的密钥非常重要。

请指定您试图访问支付网关的API——实际上,这一API尝试输入一些详细信息,我需要它转到-->payments.paysimple.com/但它返回错误您使用的支付网关是什么,您能提供到文档的链接吗?您是否加密了您的
POST
请求?大多数支付提供商要求您使用预设的
密钥来完成此操作
@FabiandePabian------>这里是docu-->developer.paysimple.com-->我使用自定义wordpress插件将其集成到网站如果页面需要密码,请使用文档中与您的问题相关的片段更新您的问题。另外,请张贴一个代码示例,以便我们知道我们正在处理什么。谢谢你,我将尝试这个,但他们从未颁发过密钥。所以我真的不知道该怎么办..嗨,你能告诉我他们想说什么吗?我已经就此事与PaySimple进行了交谈,他们说你将内容类型标题错误地设置为“application/x-www-form-urlencoded”。内容类型头应该改为“application/json”,你能解释一下它们的意思吗@法比安·德·帕比安这与最初的问题无关。请参阅这篇关于向
cURL
请求添加标题的帖子()。。。顺便说一句,我取消了对这些行的注释,但什么也没发生,我也有同样的错误……服务器可能不接受正常的请求。使用
JSON
标题,您可以告诉接收服务器您正在接受
JSON
响应。如果标题不存在,则可能会显示500状态