1

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' );

?>
user229044
  • 232,980
  • 40
  • 330
  • 338
Trix
  • 11
  • 3
  • Please specify what **API** you are trying to access – Fabian de Pabian Mar 18 '15 at 16:14
  • the payment gateway -- actually this one http://jdma.biz/temp/contact-us-2/ try to input some details i need it to go to --> payments.paysimple.com/ but it return that errors – Trix Mar 18 '15 at 16:14
  • What payment gateway are you using, could you provide a link to the documentation? Did you encrypt your `POST` request? Most payment providers require you to do this with a preset `secret key` – Fabian de Pabian Mar 18 '15 at 16:18
  • @FabiandePabian https://payments.paysimple.com/ ------> here's the docu --> developer.paysimple.com --> i use custom wordpress plugin to integrate it to the website – Trix Mar 18 '15 at 16:26
  • That pages requires a password, please update your question with the snippet from the documentation that regards your problem. Also please post a code sample so we know what we are dealing with. – Fabian de Pabian Mar 18 '15 at 16:29
  • Hi I've updated it @FabiandePabian really appreciate your responses im really hoping to resolve this :) – Trix Mar 18 '15 at 16:42

1 Answers1

0

I think your problem lies in the paySimple method.

Payment providers provide you with a way in which you need to encrypt your data before sending it to their server. In this case they require you to use hmac and base64 encryption. This is documenter in their documentation here.

In your example i found the following code:

// $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));

I believe you should uncomment those lines and try again.

PaySimple requires you to send with every request a computed signature of the request with your secret key included.

If you follow their instructions correctly they can also calculate a signature from your request and compare it with the signature you have send. This way they can ensure nobody has tampered with the request data. This is why it is really important to never disclose your secret key.

Fabian de Pabian
  • 599
  • 4
  • 20
  • Thank you for this i will try this but they never issue a secret key. so i really didn't know what to do.. – Trix Mar 18 '15 at 17:17
  • Hi could you tell me what they are trying to say i have talk to PaySimple regarding this matter and they said is this **You are incorrectly setting the Content-Type header to 'application/x-www-form-urlencoded'. The Content-Type header should instead be set to 'application/json'** Can you explain what they mean? @Fabian de Pabian – Trix Mar 19 '15 at 14:56
  • This is not related to the original question. Please see this post (http://stackoverflow.com/questions/8115683/php-curl-custom-headers) on adding headers to a `cURL` request. – Fabian de Pabian Mar 19 '15 at 16:42
  • Okay... by the way i uncomment those lines and nothing happen i have the same error though... – Trix Mar 19 '15 at 18:23
  • The server probably doesnt accept normal request. With the `JSON` header you can tell the receiving server you are accepting a `JSON` response. If the header is not present it might give you a 500 status – Fabian de Pabian Mar 19 '15 at 19:53
  • I already changed it to JSON .. i got a different error i think it needs a superSecretCode do you have any idea where to get this? (because that's the only left part that doesn't have data --> $superSecretCode = ""; – Trix Mar 20 '15 at 17:33
  • You have to obtain that from the control panel on the PaySimple website. – Fabian de Pabian Mar 23 '15 at 09:18
  • Is your problem resolved? If my answer helped would you mind pressing the grayed out check to select it as your answer – Fabian de Pabian Apr 01 '15 at 11:17