Advertisement
xkeshav

bluepay.php

Sep 12th, 2012
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.78 KB | None | 0 0
  1. <?php
  2. class BluePayment {
  3.  
  4.  /* merchant supplied parameters */
  5.  protected $accountId; // ACCOUNT_ID Your 12-digit Bluepay Account ID.
  6.  protected $merchant; // MERCHANT similar to accountID ( not accountId)
  7.  protected $userId; // USER_ID (optional)
  8.  protected $tps; // TAMPER_PROOF_SEAL
  9.  protected $transType; // TRANS_TYPE (AUTH, SALE, REFUND, or CAPTURE)
  10.  protected $payType; // PAYMENT_TYPE (CREDIT or ACH)
  11.  protected $mode; // MODE (TEST or LIVE)
  12.  protected $masterId; // MASTER_ID (optional)
  13.  protected $secretKey; // used to generate the TPS
  14.  
  15.  
  16.  /* customer supplied fields, (not required if MASTER_ID is set) */
  17.  protected $account; // PAYMENT_ACCOUNT (i.e. credit card number)
  18.  protected $cvv2; // CARD_CVVS
  19.  protected $expire; // CARD_EXPIRE
  20.  protected $amount; // AMOUNT
  21.  protected $name1; // NAME1
  22.  protected $name2; // NAME2
  23.  protected $addr1; // ADDR1
  24.  protected $addr2; // ADDR2 (optional)
  25.  protected $city; // CITY
  26.  protected $state; // STATE
  27.  protected $zip; // ZIP
  28.  protected $country = 'USA'; // COUNTRY
  29.  protected $memo; // MEMO (optinal)
  30.  
  31.  
  32.  /* additional fraud scrubbing for an AUTH */
  33.  protected $autocap ; // DO_AUTOCAP
  34.  protected $avsAllowed; // AVS_ALLOWED
  35.  protected $cvv2Allowed; // CVV2_ALLOWED
  36.  
  37.  /* bluepay response output */
  38.  public $response;
  39.  
  40.  /* constants */
  41.  const MODE = 'TEST'; // either TEST or LIVE
  42.  const POST_URL = 'https://secure.bluepay.com/interfaces/bp10emu'; // the url to post to
  43.  const MERCHANT = '1000XXXXXX'; // the default account id
  44.  const SECRET_KEY = 'TXXXXXXXXXXXXXXXXXXXXXX'; // the default secret key
  45.  const TRANSACTION_TYPE = 'SALE';
  46.  const PAYMENT_TYPE = 'CREDIT';
  47.  const AUTOCAP = '0';
  48.  const RESPONSEVERSION = '2'; // to get back additional parameter on response
  49.  const MISSING_URL  = 'http://mywebsite.com/missing.php';
  50.  const APPROVED_URL ='http://mywebsite.com/success.php';
  51.  const DECLINED_URL = 'http://mywebsite.com/badpay.php';
  52.  
  53. /***
  54.  * __construct()
  55.  *
  56.  * Constructor method, sets the account, secret key,
  57.  * and the mode properties. These will default to
  58.  * the constant values if not specified.
  59.  */
  60.  public function __construct()
  61.  {
  62.     $this->secretKey = self::SECRET_KEY; // SECRET_KEY
  63.     $this->merchant = self::MERCHANT; // MERCHANT
  64.     $this->transType = self::TRANSACTION_TYPE;     
  65.     $this->autocap = self::AUTOCAP;
  66.     $this->mode = self::MODE;
  67. }
  68.  
  69.  
  70.  /***
  71.  * process()
  72.  *
  73.  * Will first generate the tamper proof seal, then
  74.  * populate the POST query, then send it, and store
  75.  * the response, and finally parse the response.
  76.  */
  77.  public function process($post) {
  78.  
  79.         $hash = $this->secretKey . $this->merchant . $this->transType.
  80.             $post['AMOUNT'] . $this->autocap . $this->mode;
  81.  
  82.     $post['TAMPER_PROOF_SEAL'] = bin2hex( md5($hash, true) );
  83.     // make an array of all constants
  84.     $ref = new ReflectionClass(__CLASS__);
  85.     $arr_const = $ref->getConstants();
  86.     // merge constant array and post array
  87.     $curl_post = array_merge($arr_const,$post);
  88.     //var_dump($curl_post);
  89.  
  90.     /* perform the transaction via curl */
  91.     /* perform the transaction via curl */
  92.     $ch = curl_init();
  93.     curl_setopt($ch, CURLOPT_URL, self::POST_URL); // Set the URL
  94.     curl_setopt($ch, CURLOPT_USERAGENT, "BluepayPHP SDK/2.0"); // Cosmetic
  95.     curl_setopt($ch, CURLOPT_POST, true); // Perform a POST
  96.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate.
  97.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
  98.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1);
  99.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // If not set, curl prints output to the browser
  100.         curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
  101.     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($curl_post));
  102.     $this->response = curl_exec($ch);
  103.     //$info = curl_getinfo($ch);
  104.     curl_close($ch);
  105.     return $this->response;
  106. }
  107. }
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement