Need script for Beanstream payment gateway integration

1.7k Views Asked by At

I need to implement BeanStream payment gateway in my php code.I am new in payment gateway implementation. Can anybody help me with any demo project or scripts? prior thanks.

2

There are 2 best solutions below

0
Craig Nakamoto On

I know this is an old question, but since I just implemented the Beanstream payment gateway in my code I thought I would answer for the record anyway:

Once you have an account with Beanstream you will be able to access their API manuals which provide some good documentation on all of the request and response fields. You can use the curl library in PHP to connect to the Beanstream API this very easily. Here is a sample method for performing a simple payment based on their documentation ($global_ccauth is just an ORM object that contains my request information, which I store each time in my database, including the response string from Beanstream, but BE CAREFUL AND YOU PROBABLY WANT TO obfuscate the credit card number in the ORM model before it is saved to the database, like I do):

public static function do_payment($global_ccauth, $submitted_card_number) {
    $payment_result = array(
        'status' => FALSE,
        'response' => array(),
    );

    // attempt to process the payment using CURL and a POST request to the Beanstream server as per Beanstream's example
    $request = curl_init();

    // Get curl to POST
    curl_setopt($request, CURLOPT_POST, 1);
    curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($request, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // return the results instead of echoing them
    curl_setopt($request, CURLOPT_URL, BEANSTREAM_URL);

    // These are the transaction parameters that we will POST
    $auth_parameters = "requestType=BACKEND";
    $auth_parameters .= "&merchant_id=" . BEANSTREAM_MERCHANT;
    $auth_parameters .= "&username=" . BEANSTREAM_API_USER;
    $auth_parameters .= "&password=" . BEANSTREAM_API_PASS;
    $auth_parameters .= "&trnCardOwner=" . $global_ccauth->trnCardOwner;
    $auth_parameters .= "&trnCardNumber=". $submitted_card_number;
    $auth_parameters .= "&trnExpMonth=" . $global_ccauth->trnExpMonth;
    $auth_parameters .= "&trnExpYear=" . $global_ccauth->trnExpYear;
    //$auth_parameters .= "&trnCardCvd=";
    $auth_parameters .= "&trnOrderNumber=" . $global_ccauth->trnOrderNumber ;
    $auth_parameters .= "&trnAmount=" . $global_ccauth->trnAmount;
    $auth_parameters .= "&ordName=" . $global_ccauth->ordName;
    $auth_parameters .= "&ordEmailAddress=" . $global_ccauth->ordEmailAddress;
    $auth_parameters .= "&ordPhoneNumber=" . $global_ccauth->ordPhoneNumber;
    $auth_parameters .= "&ordAddress1=" . $global_ccauth->ordAddress1;
    $auth_parameters .= "&ordAddress2=" . $global_ccauth->ordAddress2;
    $auth_parameters .= "&ordCity=" . $global_ccauth->ordCity;
    $auth_parameters .= "&ordProvince=" . $global_ccauth->ordProvince;
    $auth_parameters .= "&ordPostalCode=" . $global_ccauth->ordPostalCode;
    $auth_parameters .= "&ordCountry=" . $global_ccauth->ordCountry;

    curl_setopt($request, CURLOPT_POSTFIELDS, $auth_parameters);

    // Now POST the transaction. $txResult will contain Beanstream's response
    $auth_result = curl_exec($request);
    curl_close($request);

    if ($auth_result !== FALSE) {
        // save the raw results
        $global_ccauth->response = $auth_result;
        $global_ccauth->save();

        // parse the results
        parse_str($auth_result, $parsed_result);
        $payment_result['response'] = $parsed_result;
        if ( ! empty($parsed_result['trnApproved']) && $parsed_result['trnApproved'] == 1) {
            // the request was approved
            $payment_result['status'] = TRUE;
        } else {
            // the request was not approved
            // do something smart
        }
    } else {
        // curl POST request failed
        // do something smart
    }

    return $payment_result;
}

I have also implemented their recurring payments for processing monthly payments automatically and it seems to be working well. You just have to adjust the parameters you send as per their API documentation.

0
MikeMurko On

PHP-Payments seems to be what you're looking for http://payments.calvinfroedge.com/