I am integrating a one time simple payment using the Paysimple API and I always get this error:
string(196) "{"Meta":{"Errors":{"ErrorCode":"UnexpectedError","ErrorMessages":[],"TraceCode":"API8D22C4FA49D9E36"},"HttpStatus":"InternalServerError","HttpStatusCode":500,"PagingDetails":null},"Response":null}"
response: 500
Here's the code of the custom form.php
Documentation of PaySimple : http://developer.paysimple.com/documentation/ Go to Payments
<?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' );
?>