PageRenderTime 66ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/sites/all/modules/contrib/civicrm/packages/PayJunction/pjClasses.php

https://gitlab.com/virtualrealms/d7civicrm
PHP | 390 lines | 247 code | 68 blank | 75 comment | 8 complexity | 34dbd22aba48df3f1e1aefe04038fc7f MD5 | raw file
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 5 |
  5. +--------------------------------------------------------------------+
  6. | This file is a part of CiviCRM. |
  7. | |
  8. | CiviCRM is free software; you can copy, modify, and distribute it |
  9. | under the terms of the GNU Affero General Public License |
  10. | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
  11. | |
  12. | CiviCRM is distributed in the hope that it will be useful, but |
  13. | WITHOUT ANY WARRANTY; without even the implied warranty of |
  14. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
  15. | See the GNU Affero General Public License for more details. |
  16. | |
  17. | You should have received a copy of the GNU Affero General Public |
  18. | License and the CiviCRM Licensing Exception along |
  19. | with this program; if not, contact CiviCRM LLC |
  20. | at info[AT]civicrm[DOT]org. If you have questions about the |
  21. | GNU Affero General Public License or the licensing of CiviCRM, |
  22. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  23. +--------------------------------------------------------------------+
  24. */
  25. /**
  26. * Copyright (C) 2007
  27. * Licensed to CiviCRM under the Academic Free License version 3.0.
  28. *
  29. * Written and contributed by Phase2 Technology, LLC (http://www.phase2technology.com)
  30. *
  31. */
  32. /**
  33. *
  34. * @package CRM
  35. * @author Michael Morris and Gene Chi @ Phase2 Technology <mmorris@phase2technology.com>
  36. * $Id$
  37. *
  38. */
  39. /**
  40. *
  41. * This class sends requests and receives responses from PayJunction (http://www.payjunction.com)
  42. *
  43. */
  44. class pjpgHttpsPost
  45. {
  46. var $pjpgRequest;
  47. var $pjpgResponse;
  48. function __construct( $pjpgRequestOBJ )
  49. {
  50. $this->pjpgRequest=$pjpgRequestOBJ;
  51. // pjRequst
  52. $pjRequest = $this->pjpgRequest;
  53. // pjTxn
  54. $pjTxn = $pjRequest->txnArray[0]->txn;
  55. // pJCustInfo is pjpgCustInfo
  56. $pjCustInfo = $pjRequest->txnArray[0]->custInfo;
  57. // pjBilling
  58. $pjBilling = $pjCustInfo->level3data['billing'][0];
  59. // pjRecur
  60. $pjRecur = $pjRequest->txnArray[0]->recur->params;
  61. /*
  62. * Assign PayJunction post array variable
  63. * 1. authentication
  64. * 2. credit card
  65. * 3. transactioin
  66. * 4. billing address
  67. * 5. schedule
  68. */
  69. // login and password
  70. $dc_logon = $pjBilling['logon'];
  71. $dc_password = $pjBilling['password'];
  72. // credit card
  73. $dc_first_name = $pjBilling['first_name'];
  74. $dc_last_name = $pjBilling['last_name'];
  75. $dc_number = $pjTxn['pan'];
  76. $dc_expiration_month = substr($pjTxn['expdate'],4,2);
  77. $dc_expiration_year = substr($pjTxn['expdate'],0,4);
  78. $dc_verification_number = $pjTxn['cavv'];
  79. // transaction
  80. $dc_transaction_amount = $pjTxn['amount'];
  81. $dc_notes = "No Comment";
  82. $dc_transaction_type = "AUTHORIZATION_CAPTURE";
  83. $dc_version = "1.2";
  84. // billing address
  85. $dc_address = $pjBilling['address'];
  86. $dc_city = $pjBilling['city'];
  87. $dc_state = $pjBilling['province'];
  88. $dc_zipcode = $pjBilling['postal_code'];
  89. $dc_country = $pjBilling['country'];
  90. // schedule
  91. $dc_schedule_create = $pjRecur['dc_schedule_create'];
  92. $dc_schedule_limit = $pjRecur['num_recurs'];
  93. $dc_schedule_periodic_number = $pjRecur['period'];
  94. $dc_schedule_periodic_type = $pjRecur['recur_unit'];
  95. $dc_schedule_start = $pjRecur['dc_schedule_start'];
  96. /*
  97. * PayJunction service URL
  98. * https://payjunction.com:443/quick_link
  99. * https://payjunction.com/quick_link
  100. */
  101. $url = $pjBilling['url_site'];
  102. /*
  103. * Build PayJunction transaction post array
  104. */
  105. // recurring transaction
  106. if ($dc_schedule_create == true)
  107. {
  108. // assign to "true" value
  109. $dc_schedule_create = "true";
  110. $post_array = array(
  111. "dc_logon" => $dc_logon,
  112. "dc_password" => $dc_password,
  113. "dc_first_name" => $dc_first_name,
  114. "dc_last_name" => $dc_last_name,
  115. "dc_expiration_month" => $dc_expiration_month,
  116. "dc_expiration_year" => $dc_expiration_year,
  117. "dc_number" => $dc_number,
  118. "dc_verification_number" => $dc_verification_number,
  119. "dc_transaction_amount" => $dc_transaction_amount,
  120. "dc_transaction_type" => $dc_transaction_type,
  121. "dc_version" => $dc_version,
  122. "dc_address" => $dc_address,
  123. "dc_city" => $dc_city,
  124. "dc_state" => $dc_state,
  125. "dc_zipcode" => $dc_zipcode,
  126. "dc_country" => $dc_country,
  127. "dc_schedule_create" => $dc_schedule_create,
  128. "dc_schedule_limit" => $dc_schedule_limit,
  129. "dc_schedule_periodic_number" => $dc_schedule_periodic_number,
  130. "dc_schedule_periodic_type" => $dc_schedule_periodic_type,
  131. "dc_schedule_start" => $dc_schedule_start
  132. );
  133. }
  134. // one time transaction
  135. else
  136. {
  137. $post_array = array(
  138. "dc_logon" => $dc_logon,
  139. "dc_password" => $dc_password,
  140. "dc_first_name" => $dc_first_name,
  141. "dc_last_name" => $dc_last_name,
  142. "dc_expiration_month" => $dc_expiration_month,
  143. "dc_expiration_year" => $dc_expiration_year,
  144. "dc_number" => $dc_number,
  145. "dc_verification_number" => $dc_verification_number,
  146. "dc_transaction_amount" => $dc_transaction_amount,
  147. "dc_transaction_type" => $dc_transaction_type,
  148. "dc_version" => $dc_version,
  149. "dc_address" => $dc_address,
  150. "dc_city" => $dc_city,
  151. "dc_state" => $dc_state,
  152. "dc_zipcode" => $dc_zipcode,
  153. "dc_country" => $dc_country
  154. );
  155. }
  156. reset($post_array);
  157. $request = "";
  158. while (list ($key, $val) = each($post_array))
  159. {
  160. $request .= $key . "=" . urlencode($val) . "&";
  161. }
  162. /*
  163. * PayJunction service request and response
  164. */
  165. $ch = curl_init($url);
  166. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  167. curl_setopt($ch, CURLOPT_POST, TRUE);
  168. curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  169. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  170. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  171. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
  172. $content = curl_exec($ch);
  173. curl_close($ch);
  174. // Build response array
  175. $content = array_values (explode (chr (28), $content));
  176. while ($key_value = next ($content))
  177. {
  178. list ($key, $value) = explode ("=", $key_value);
  179. $response[$key] = $value;
  180. }
  181. $this->pjpgResponse = $response;
  182. }
  183. function getPJpgResponse()
  184. {
  185. return $this->pjpgResponse;
  186. }
  187. }//end class pjpgHttpsPost
  188. class pjpgRequest
  189. {
  190. var $txnTypes =array(purchase=> array('order_id','cust_id', 'amount', 'pan', 'expdate', 'crypt_type'),
  191. refund => array('order_id', 'amount', 'txn_number', 'crypt_type'),
  192. ind_refund => array('order_id','cust_id', 'amount','pan','expdate', 'crypt_type'),
  193. preauth =>array('order_id','cust_id', 'amount', 'pan', 'expdate', 'crypt_type'),
  194. completion => array('order_id', 'comp_amount','txn_number', 'crypt_type'),
  195. purchasecorrection => array('order_id', 'txn_number', 'crypt_type'),
  196. opentotals => array('ecr_number'),
  197. batchclose => array('ecr_number'),
  198. batchcloseall => array(),
  199. cavv_purchase=> array('order_id','cust_id', 'amount', 'pan',
  200. 'expdate', 'cavv'),
  201. cavv_preauth =>array('order_id','cust_id', 'amount', 'pan',
  202. 'expdate', 'cavv')
  203. );
  204. var $txnArray;
  205. function __construct($txn)
  206. {
  207. if(is_array($txn))
  208. {
  209. $this->txnArray = $txn;
  210. }
  211. else
  212. {
  213. $temp[0]=$txn;
  214. $this->txnArray=$temp;
  215. }
  216. }
  217. }//end class pjpgRequest
  218. class pjpgCustInfo
  219. {
  220. var $level3template = array(cust_info=>
  221. array('email','instructions',
  222. billing => array ('first_name', 'last_name', 'company_name', 'address',
  223. 'city', 'province', 'postal_code', 'country',
  224. 'phone_number', 'fax','tax1', 'tax2','tax3',
  225. 'shipping_cost'),
  226. shipping => array('first_name', 'last_name', 'company_name', 'address',
  227. 'city', 'province', 'postal_code', 'country',
  228. 'phone_number', 'fax','tax1', 'tax2', 'tax3',
  229. 'shipping_cost'),
  230. item => array ('name', 'quantity', 'product_code', 'extended_amount')
  231. )
  232. );
  233. var $level3data;
  234. var $email;
  235. var $instructions;
  236. function __construct($custinfo=0,$billing=0,$shipping=0,$items=0)
  237. {
  238. if($custinfo)
  239. {
  240. $this->setCustInfo($custinfo);
  241. }
  242. }
  243. function setCustInfo($custinfo)
  244. {
  245. $this->level3data['cust_info']=array($custinfo);
  246. }
  247. function setEmail($email)
  248. {
  249. $this->email=$email;
  250. $this->setCustInfo(array(email=>$email,instructions=>$this->instructions));
  251. }
  252. function setInstructions($instructions)
  253. {
  254. $this->instructions=$instructions;
  255. $this->setCustinfo(array(email=>$this->email,instructions=>$instructions));
  256. }
  257. function setShipping($shipping)
  258. {
  259. $this->level3data['shipping']=array($shipping);
  260. }
  261. function setBilling($billing)
  262. {
  263. $this->level3data['billing']=array($billing);
  264. }
  265. function setItems($items)
  266. {
  267. if(! $this->level3data['item'])
  268. {
  269. $this->level3data['item']=array($items);
  270. }
  271. else
  272. {
  273. $index=count($this->level3data['item']);
  274. $this->level3data['item'][$index]=$items;
  275. }
  276. }
  277. }//end class pjpgCustInfo
  278. class pjpgRecur{
  279. var $params;
  280. var $recurTemplate = array('recur_unit','start_now','start_date',
  281. 'num_recurs','period','recur_amount');
  282. function __construct($params)
  283. {
  284. $this->params = $params;
  285. if( (! $this->params['period']) )
  286. {
  287. $this->params['period'] = 1;
  288. }
  289. }
  290. }//end class pjpgRecur
  291. class pjpgTransaction
  292. {
  293. var $txn;
  294. var $custInfo = null;
  295. var $recur = null;
  296. function __construct($txn)
  297. {
  298. $this->txn=$txn;
  299. }
  300. function getCustInfo()
  301. {
  302. return $this->custInfo;
  303. }
  304. function setCustInfo($custInfo)
  305. {
  306. $this->custInfo = $custInfo;
  307. array_push($this->txn,$custInfo);
  308. }
  309. function getRecur()
  310. {
  311. return $this->recur;
  312. }
  313. function setRecur($recur)
  314. {
  315. $this->recur = $recur;
  316. }
  317. function getTransaction()
  318. {
  319. return $this->txn;
  320. }
  321. } //end class pjpgTransaction
  322. ?>