Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class BluePayment {
- /* merchant supplied parameters */
- protected $accountId; // ACCOUNT_ID Your 12-digit Bluepay Account ID.
- protected $merchant; // MERCHANT similar to accountID ( not accountId)
- protected $userId; // USER_ID (optional)
- protected $tps; // TAMPER_PROOF_SEAL
- protected $transType; // TRANS_TYPE (AUTH, SALE, REFUND, or CAPTURE)
- protected $payType; // PAYMENT_TYPE (CREDIT or ACH)
- protected $mode; // MODE (TEST or LIVE)
- protected $masterId; // MASTER_ID (optional)
- protected $secretKey; // used to generate the TPS
- /* customer supplied fields, (not required if MASTER_ID is set) */
- protected $account; // PAYMENT_ACCOUNT (i.e. credit card number)
- protected $cvv2; // CARD_CVVS
- protected $expire; // CARD_EXPIRE
- protected $amount; // AMOUNT
- protected $name1; // NAME1
- protected $name2; // NAME2
- protected $addr1; // ADDR1
- protected $addr2; // ADDR2 (optional)
- protected $city; // CITY
- protected $state; // STATE
- protected $zip; // ZIP
- protected $country = 'USA'; // COUNTRY
- protected $memo; // MEMO (optinal)
- /* additional fraud scrubbing for an AUTH */
- protected $autocap ; // DO_AUTOCAP
- protected $avsAllowed; // AVS_ALLOWED
- protected $cvv2Allowed; // CVV2_ALLOWED
- /* bluepay response output */
- public $response;
- /* constants */
- const MODE = 'TEST'; // either TEST or LIVE
- const POST_URL = 'https://secure.bluepay.com/interfaces/bp10emu'; // the url to post to
- const MERCHANT = '1000XXXXXX'; // the default account id
- const SECRET_KEY = 'TXXXXXXXXXXXXXXXXXXXXXX'; // the default secret key
- const TRANSACTION_TYPE = 'SALE';
- const PAYMENT_TYPE = 'CREDIT';
- const AUTOCAP = '0';
- const RESPONSEVERSION = '2'; // to get back additional parameter on response
- const MISSING_URL = 'http://mywebsite.com/missing.php';
- const APPROVED_URL ='http://mywebsite.com/success.php';
- const DECLINED_URL = 'http://mywebsite.com/badpay.php';
- /***
- * __construct()
- *
- * Constructor method, sets the account, secret key,
- * and the mode properties. These will default to
- * the constant values if not specified.
- */
- public function __construct()
- {
- $this->secretKey = self::SECRET_KEY; // SECRET_KEY
- $this->merchant = self::MERCHANT; // MERCHANT
- $this->transType = self::TRANSACTION_TYPE;
- $this->autocap = self::AUTOCAP;
- $this->mode = self::MODE;
- }
- /***
- * process()
- *
- * Will first generate the tamper proof seal, then
- * populate the POST query, then send it, and store
- * the response, and finally parse the response.
- */
- public function process($post) {
- $hash = $this->secretKey . $this->merchant . $this->transType.
- $post['AMOUNT'] . $this->autocap . $this->mode;
- $post['TAMPER_PROOF_SEAL'] = bin2hex( md5($hash, true) );
- // make an array of all constants
- $ref = new ReflectionClass(__CLASS__);
- $arr_const = $ref->getConstants();
- // merge constant array and post array
- $curl_post = array_merge($arr_const,$post);
- //var_dump($curl_post);
- /* perform the transaction via curl */
- /* perform the transaction via curl */
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, self::POST_URL); // Set the URL
- curl_setopt($ch, CURLOPT_USERAGENT, "BluepayPHP SDK/2.0"); // Cosmetic
- curl_setopt($ch, CURLOPT_POST, true); // Perform a POST
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate.
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // If not set, curl prints output to the browser
- curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($curl_post));
- $this->response = curl_exec($ch);
- //$info = curl_getinfo($ch);
- curl_close($ch);
- return $this->response;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement