我正在使用Paysimple API集成一次性简单付款,我总是收到此错误:
的字符串(196) " {" META" {"错误" {"错误码":" UnexpectedError"" ErrorMessages&#34 ;:[]," TraceCode":" API8D22C4FA49D9E36"}"的HTTPStatus":" InternalServerError"" HttpStatusCode" :500," PagingDetails":空}"响应":空}"
回复:500
这是自定义form.php
的代码PaySimple的文档:http://developer.paysimple.com/documentation/ 转到付款
<?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' );
?>
答案 0 :(得分:0)
我认为您的问题在于paySimple
方法。
支付提供商为您提供了一种在将数据发送到服务器之前对其进行加密的方法。
在这种情况下,他们要求您使用hmac
和base64
加密。这是他们的文档here中的记录者。
在您的示例中,我找到了以下代码:
// $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));
我相信你应该取消注释这些行并再试一次。
PaySimple要求您在每次请求时发送包含您的密钥的请求的计算签名。
如果您按照他们的说明正确操作,他们也可以根据您的请求计算签名,并将其与您发送的签名进行比较。这样他们就可以确保没有人篡改请求数据。这就是为什么永远不要透露你的密钥非常重要的原因。