Welcome Guest, Not a member yet? Register   Sign In
Bean Stream payment gateway
#2

[eluser]darkhouse[/eluser]
I really like Bean Stream, their system is pretty simple. Here's a library we use for them.

Code:
<?php

if( !defined('BASEPATH') )
    exit('No direct script access allowed');
    
class Beanstream
{
    var $CI = null;
    
    // PROD merchant ID
//    var $merchant_id = 'xxx'; //put your production merchant id here

    // DEV merchant ID
        var $merchant_id = 'xxx'; //put your development merchant id here
    

    function Beanstream()
    {
        $this->CI = &get;_instance();
    }

    
    function ProcessPayment($orderNumber, $amount, $cardOwner, $cardNumber, $expMonth, $expYear, $email, $name, $phone, $address1, $address2, $city, $provinceCode, $postalCode, $countryCode)
    {
        $pf = array(
            'requestType=' . urlencode('BACKEND'),
            'merchant_id=' . urlencode($this->merchant_id),
    
            'trnOrderNumber=' . urlencode(sprintf('d', $orderNumber)),
            'trnAmount=' . urlencode($amount),
            'trnCardOwner=' . urlencode($cardOwner),
            'trnCardNumber=' . urlencode($cardNumber),
            'trnExpMonth=' . urlencode(sprintf('d', $expMonth)),
            'trnExpYear=' . urlencode(sprintf('d', substr($expYear, -2))),
            
            'ordEmailAddress=' . urlencode($email),
            'ordName=' . urlencode($name),
            'ordPhoneNumber=' . urlencode($phone),
            'ordAddress1=' . urlencode($address1),
            'ordAddress2=' . urlencode($address2),
            'ordCity=' . urlencode($city),
            'ordProvince=' . urlencode($provinceCode),
            'ordPostalCode=' . urlencode($postalCode),
            'ordCountry=' . urlencode($countryCode)
        );
        
        $post_str = implode('&', $pf);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, "https://www.beanstream.com/scripts/process_transaction.asp");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);        
        $txResult = curl_exec($ch);
        curl_close($ch);
        
        $response = array();
        parse_str($txResult, $response);
        
        return $response;
    }
}

And then usage in a controller is just like this:

Code:
$txnResult = $this->beanstream->ProcessPayment(
                $your_order_number,
                $total,
                $cardholder,
                $cc_number,
                $exp_month,
                $exp_year,
                $email,
                $first_name.' '.$last_name,
                $phone,
                $address,
                $address2,
                $city,
                $province,
                $postal,
                $country
            );

if($txnResult['trnApproved']){
   //process data and display receipt/thank you page
} else {
   $error = $txnResult['messageText'];
   //display error
}

Good luck.


Messages In This Thread
Bean Stream payment gateway - by El Forum - 08-04-2009, 06:58 PM
Bean Stream payment gateway - by El Forum - 08-04-2009, 11:38 PM
Bean Stream payment gateway - by El Forum - 08-04-2009, 11:48 PM
Bean Stream payment gateway - by El Forum - 08-05-2009, 07:28 AM
Bean Stream payment gateway - by El Forum - 08-05-2009, 10:56 AM
Bean Stream payment gateway - by El Forum - 11-02-2010, 01:15 AM
Bean Stream payment gateway - by El Forum - 11-02-2010, 01:24 AM
Bean Stream payment gateway - by El Forum - 11-02-2010, 11:07 PM
Bean Stream payment gateway - by El Forum - 11-12-2010, 12:25 AM
Bean Stream payment gateway - by El Forum - 11-12-2010, 03:14 AM
Bean Stream payment gateway - by El Forum - 11-13-2010, 08:32 AM
Bean Stream payment gateway - by El Forum - 11-16-2010, 06:28 AM
Bean Stream payment gateway - by El Forum - 11-16-2010, 08:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB