Guest User

Untitled

a guest
May 31st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.13 KB | None | 0 0
  1. <?
  2.  
  3. define("APPROVED", 1);
  4. define("DECLINED", 2);
  5. define("ERROR", 3);
  6.  
  7. class gwapi
  8. {
  9.  
  10. // Initial Setting Functions
  11.  
  12. function setLogin($username, $password)
  13. {
  14. /*{{{*/
  15. $this->login['username'] = $username;
  16. $this->login['password'] = $password;
  17. }/*}}}*/
  18.  
  19. function setOrder(
  20. $orderid,
  21. $orderdescription,
  22. $tax,
  23. $shipping,
  24. $ponumber,
  25. $ipaddress
  26. ) {/*{{{*/
  27. $this->order['orderid'] = $orderid;
  28. $this->order['orderdescription'] = $orderdescription;
  29. $this->order['tax'] = $tax;
  30. $this->order['shipping'] = $shipping;
  31. $this->order['ponumber'] = $ponumber;
  32. $this->order['ipaddress'] = $ipaddress;
  33. }/*}}}*/
  34.  
  35. function setBilling(
  36. $firstname,
  37. $lastname,
  38. $company,
  39. $address1,
  40. $address2,
  41. $city,
  42. $state,
  43. $zip,
  44. $country,
  45. $phone,
  46. $fax,
  47. $email,
  48. $website
  49. ) {/*{{{*/
  50. $this->billing['firstname'] = $firstname;
  51. $this->billing['lastname'] = $lastname;
  52. $this->billing['company'] = $company;
  53. $this->billing['address1'] = $address1;
  54. $this->billing['address2'] = $address2;
  55. $this->billing['city'] = $city;
  56. $this->billing['state'] = $state;
  57. $this->billing['zip'] = $zip;
  58. $this->billing['country'] = $country;
  59. $this->billing['phone'] = $phone;
  60. $this->billing['fax'] = $fax;
  61. $this->billing['email'] = $email;
  62. $this->billing['website'] = $website;
  63. }/*}}}*/
  64.  
  65. function setShipping(
  66. $firstname,
  67. $lastname,
  68. $company,
  69. $address1,
  70. $address2,
  71. $city,
  72. $state,
  73. $zip,
  74. $country,
  75. $email
  76. ) {/*{{{*/
  77. $this->shipping['firstname'] = $firstname;
  78. $this->shipping['lastname'] = $lastname;
  79. $this->shipping['company'] = $company;
  80. $this->shipping['address1'] = $address1;
  81. $this->shipping['address2'] = $address2;
  82. $this->shipping['city'] = $city;
  83. $this->shipping['state'] = $state;
  84. $this->shipping['zip'] = $zip;
  85. $this->shipping['country'] = $country;
  86. $this->shipping['email'] = $email;
  87. }/*}}}*/
  88.  
  89. // Transaction Functions
  90.  
  91. function doSale($amount, $ccnumber, $ccexp, $cvv = "")
  92. {
  93. /*{{{*/
  94.  
  95. $query = "";
  96. // Login Information
  97. $query .= "username=" . urlencode($this->login['username']) . "&";
  98. $query .= "password=" . urlencode($this->login['password']) . "&";
  99. // Sales Information
  100. $query .= "ccnumber=" . urlencode($ccnumber) . "&";
  101. $query .= "ccexp=" . urlencode($ccexp) . "&";
  102. $query .= "amount=" . urlencode(number_format($amount, 2, ".", "")) . "&";
  103. $query .= "cvv=" . urlencode($cvv) . "&";
  104. // Order Information
  105. $query .= "ipaddress=" . urlencode($this->order['ipaddress']) . "&";
  106. $query .= "orderid=" . urlencode($this->order['orderid']) . "&";
  107. $query .= "orderdescription=" . urlencode($this->order['orderdescription']) . "&";
  108. $query .= "tax=" . urlencode(number_format($this->order['tax'], 2, ".", "")) . "&";
  109. $query .= "shipping=" . urlencode(number_format($this->order['shipping'], 2, ".", "")) . "&";
  110. $query .= "ponumber=" . urlencode($this->order['ponumber']) . "&";
  111. // Billing Information
  112. $query .= "firstname=" . urlencode($this->billing['firstname']) . "&";
  113. $query .= "lastname=" . urlencode($this->billing['lastname']) . "&";
  114. $query .= "company=" . urlencode($this->billing['company']) . "&";
  115. $query .= "address1=" . urlencode($this->billing['address1']) . "&";
  116. $query .= "address2=" . urlencode($this->billing['address2']) . "&";
  117. $query .= "city=" . urlencode($this->billing['city']) . "&";
  118. $query .= "state=" . urlencode($this->billing['state']) . "&";
  119. $query .= "zip=" . urlencode($this->billing['zip']) . "&";
  120. $query .= "country=" . urlencode($this->billing['country']) . "&";
  121. $query .= "phone=" . urlencode($this->billing['phone']) . "&";
  122. $query .= "fax=" . urlencode($this->billing['fax']) . "&";
  123. $query .= "email=" . urlencode($this->billing['email']) . "&";
  124. $query .= "website=" . urlencode($this->billing['website']) . "&";
  125. // Shipping Information
  126. $query .= "shipping_firstname=" . urlencode($this->shipping['firstname']) . "&";
  127. $query .= "shipping_lastname=" . urlencode($this->shipping['lastname']) . "&";
  128. $query .= "shipping_company=" . urlencode($this->shipping['company']) . "&";
  129. $query .= "shipping_address1=" . urlencode($this->shipping['address1']) . "&";
  130. $query .= "shipping_address2=" . urlencode($this->shipping['address2']) . "&";
  131. $query .= "shipping_city=" . urlencode($this->shipping['city']) . "&";
  132. $query .= "shipping_state=" . urlencode($this->shipping['state']) . "&";
  133. $query .= "shipping_zip=" . urlencode($this->shipping['zip']) . "&";
  134. $query .= "shipping_country=" . urlencode($this->shipping['country']) . "&";
  135. $query .= "shipping_email=" . urlencode($this->shipping['email']) . "&";
  136. $query .= "type=sale";
  137. return $this->_doPost($query);
  138.  
  139. }/*}}}*/
  140.  
  141. function doAuth($amount, $ccnumber, $ccexp, $cvv = "")
  142. {
  143. /*{{{*/
  144.  
  145. $query = "";
  146. // Login Information
  147. $query .= "username=" . urlencode($this->login['username']) . "&";
  148. $query .= "password=" . urlencode($this->login['password']) . "&";
  149. // Sales Information
  150. $query .= "ccnumber=" . urlencode($ccnumber) . "&";
  151. $query .= "ccexp=" . urlencode($ccexp) . "&";
  152. $query .= "amount=" . urlencode(number_format($amount, 2, ".", "")) . "&";
  153. $query .= "cvv=" . urlencode($cvv) . "&";
  154. // Order Information
  155. $query .= "ipaddress=" . urlencode($this->order['ipaddress']) . "&";
  156. $query .= "orderid=" . urlencode($this->order['orderid']) . "&";
  157. $query .= "orderdescription=" . urlencode($this->order['orderdescription']) . "&";
  158. $query .= "tax=" . urlencode(number_format($this->order['tax'], 2, ".", "")) . "&";
  159. $query .= "shipping=" . urlencode(number_format($this->order['shipping'], 2, ".", "")) . "&";
  160. $query .= "ponumber=" . urlencode($this->order['ponumber']) . "&";
  161. // Billing Information
  162. $query .= "firstname=" . urlencode($this->billing['firstname']) . "&";
  163. $query .= "lastname=" . urlencode($this->billing['lastname']) . "&";
  164. $query .= "company=" . urlencode($this->billing['company']) . "&";
  165. $query .= "address1=" . urlencode($this->billing['address1']) . "&";
  166. $query .= "address2=" . urlencode($this->billing['address2']) . "&";
  167. $query .= "city=" . urlencode($this->billing['city']) . "&";
  168. $query .= "state=" . urlencode($this->billing['state']) . "&";
  169. $query .= "zip=" . urlencode($this->billing['zip']) . "&";
  170. $query .= "country=" . urlencode($this->billing['country']) . "&";
  171. $query .= "phone=" . urlencode($this->billing['phone']) . "&";
  172. $query .= "fax=" . urlencode($this->billing['fax']) . "&";
  173. $query .= "email=" . urlencode($this->billing['email']) . "&";
  174. $query .= "website=" . urlencode($this->billing['website']) . "&";
  175. // Shipping Information
  176. $query .= "shipping_firstname=" . urlencode($this->shipping['firstname']) . "&";
  177. $query .= "shipping_lastname=" . urlencode($this->shipping['lastname']) . "&";
  178. $query .= "shipping_company=" . urlencode($this->shipping['company']) . "&";
  179. $query .= "shipping_address1=" . urlencode($this->shipping['address1']) . "&";
  180. $query .= "shipping_address2=" . urlencode($this->shipping['address2']) . "&";
  181. $query .= "shipping_city=" . urlencode($this->shipping['city']) . "&";
  182. $query .= "shipping_state=" . urlencode($this->shipping['state']) . "&";
  183. $query .= "shipping_zip=" . urlencode($this->shipping['zip']) . "&";
  184. $query .= "shipping_country=" . urlencode($this->shipping['country']) . "&";
  185. $query .= "shipping_email=" . urlencode($this->shipping['email']) . "&";
  186. $query .= "type=auth";
  187. return $this->_doPost($query);
  188.  
  189. }/*}}}*/
  190.  
  191. function doCredit($amount, $ccnumber, $ccexp)
  192. {
  193. /*{{{*/
  194.  
  195. $query = "";
  196. // Login Information
  197. $query .= "username=" . urlencode($this->login['username']) . "&";
  198. $query .= "password=" . urlencode($this->login['password']) . "&";
  199. // Sales Information
  200. $query .= "ccnumber=" . urlencode($ccnumber) . "&";
  201. $query .= "ccexp=" . urlencode($ccexp) . "&";
  202. $query .= "amount=" . urlencode(number_format($amount, 2, ".", "")) . "&";
  203. // Order Information
  204. $query .= "ipaddress=" . urlencode($this->order['ipaddress']) . "&";
  205. $query .= "orderid=" . urlencode($this->order['orderid']) . "&";
  206. $query .= "orderdescription=" . urlencode($this->order['orderdescription']) . "&";
  207. $query .= "tax=" . urlencode(number_format($this->order['tax'], 2, ".", "")) . "&";
  208. $query .= "shipping=" . urlencode(number_format($this->order['shipping'], 2, ".", "")) . "&";
  209. $query .= "ponumber=" . urlencode($this->order['ponumber']) . "&";
  210. // Billing Information
  211. $query .= "firstname=" . urlencode($this->billing['firstname']) . "&";
  212. $query .= "lastname=" . urlencode($this->billing['lastname']) . "&";
  213. $query .= "company=" . urlencode($this->billing['company']) . "&";
  214. $query .= "address1=" . urlencode($this->billing['address1']) . "&";
  215. $query .= "address2=" . urlencode($this->billing['address2']) . "&";
  216. $query .= "city=" . urlencode($this->billing['city']) . "&";
  217. $query .= "state=" . urlencode($this->billing['state']) . "&";
  218. $query .= "zip=" . urlencode($this->billing['zip']) . "&";
  219. $query .= "country=" . urlencode($this->billing['country']) . "&";
  220. $query .= "phone=" . urlencode($this->billing['phone']) . "&";
  221. $query .= "fax=" . urlencode($this->billing['fax']) . "&";
  222. $query .= "email=" . urlencode($this->billing['email']) . "&";
  223. $query .= "website=" . urlencode($this->billing['website']) . "&";
  224. $query .= "type=credit";
  225. return $this->_doPost($query);
  226.  
  227. }/*}}}*/
  228.  
  229. function doOffline($authorizationcode, $amount, $ccnumber, $ccexp)
  230. {
  231. /*{{{*/
  232.  
  233. $query = "";
  234. // Login Information
  235. $query .= "username=" . urlencode($this->login['username']) . "&";
  236. $query .= "password=" . urlencode($this->login['password']) . "&";
  237. // Sales Information
  238. $query .= "ccnumber=" . urlencode($ccnumber) . "&";
  239. $query .= "ccexp=" . urlencode($ccexp) . "&";
  240. $query .= "amount=" . urlencode(number_format($amount, 2, ".", "")) . "&";
  241. $query .= "authorizationcode=" . urlencode($authorizationcode) . "&";
  242. // Order Information
  243. $query .= "ipaddress=" . urlencode($this->order['ipaddress']) . "&";
  244. $query .= "orderid=" . urlencode($this->order['orderid']) . "&";
  245. $query .= "orderdescription=" . urlencode($this->order['orderdescription']) . "&";
  246. $query .= "tax=" . urlencode(number_format($this->order['tax'], 2, ".", "")) . "&";
  247. $query .= "shipping=" . urlencode(number_format($this->order['shipping'], 2, ".", "")) . "&";
  248. $query .= "ponumber=" . urlencode($this->order['ponumber']) . "&";
  249. // Billing Information
  250. $query .= "firstname=" . urlencode($this->billing['firstname']) . "&";
  251. $query .= "lastname=" . urlencode($this->billing['lastname']) . "&";
  252. $query .= "company=" . urlencode($this->billing['company']) . "&";
  253. $query .= "address1=" . urlencode($this->billing['address1']) . "&";
  254. $query .= "address2=" . urlencode($this->billing['address2']) . "&";
  255. $query .= "city=" . urlencode($this->billing['city']) . "&";
  256. $query .= "state=" . urlencode($this->billing['state']) . "&";
  257. $query .= "zip=" . urlencode($this->billing['zip']) . "&";
  258. $query .= "country=" . urlencode($this->billing['country']) . "&";
  259. $query .= "phone=" . urlencode($this->billing['phone']) . "&";
  260. $query .= "fax=" . urlencode($this->billing['fax']) . "&";
  261. $query .= "email=" . urlencode($this->billing['email']) . "&";
  262. $query .= "website=" . urlencode($this->billing['website']) . "&";
  263. // Shipping Information
  264. $query .= "shipping_firstname=" . urlencode($this->shipping['firstname']) . "&";
  265. $query .= "shipping_lastname=" . urlencode($this->shipping['lastname']) . "&";
  266. $query .= "shipping_company=" . urlencode($this->shipping['company']) . "&";
  267. $query .= "shipping_address1=" . urlencode($this->shipping['address1']) . "&";
  268. $query .= "shipping_address2=" . urlencode($this->shipping['address2']) . "&";
  269. $query .= "shipping_city=" . urlencode($this->shipping['city']) . "&";
  270. $query .= "shipping_state=" . urlencode($this->shipping['state']) . "&";
  271. $query .= "shipping_zip=" . urlencode($this->shipping['zip']) . "&";
  272. $query .= "shipping_country=" . urlencode($this->shipping['country']) . "&";
  273. $query .= "shipping_email=" . urlencode($this->shipping['email']) . "&";
  274. $query .= "type=offline";
  275. return $this->_doPost($query);
  276.  
  277. }/*}}}*/
  278.  
  279. function doCapture($transactionid, $amount = 0)
  280. {
  281. /*{{{*/
  282.  
  283. $query = "";
  284. // Login Information
  285. $query .= "username=" . urlencode($this->login['username']) . "&";
  286. $query .= "password=" . urlencode($this->login['password']) . "&";
  287. // Transaction Information
  288. $query .= "transactionid=" . urlencode($transactionid) . "&";
  289. if ($amount>0) {
  290. $query .= "amount=" . urlencode(number_format($amount, 2, ".", "")) . "&";
  291. }
  292. $query .= "type=capture";
  293. return $this->_doPost($query);
  294.  
  295. }/*}}}*/
  296.  
  297. function doVoid($transactionid)
  298. {
  299. /*{{{*/
  300.  
  301. $query = "";
  302. // Login Information
  303. $query .= "username=" . urlencode($this->login['username']) . "&";
  304. $query .= "password=" . urlencode($this->login['password']) . "&";
  305. // Transaction Information
  306. $query .= "transactionid=" . urlencode($transactionid) . "&";
  307. $query .= "type=void";
  308. return $this->_doPost($query);
  309.  
  310. }/*}}}*/
  311.  
  312. function doRefund($transactionid, $amount = 0)
  313. {
  314. /*{{{*/
  315.  
  316. $query = "";
  317. // Login Information
  318. $query .= "username=" . urlencode($this->login['username']) . "&";
  319. $query .= "password=" . urlencode($this->login['password']) . "&";
  320. // Transaction Information
  321. $query .= "transactionid=" . urlencode($transactionid) . "&";
  322. if ($amount>0) {
  323. $query .= "amount=" . urlencode(number_format($amount, 2, ".", "")) . "&";
  324. }
  325. $query .= "type=refund";
  326. return $this->_doPost($query);
  327.  
  328. }/*}}}*/
  329.  
  330. function _doPost($query)
  331. {
  332. /*{{{*/
  333. $ch = curl_init();
  334. curl_setopt($ch, CURLOPT_URL, "https://secure.embgateway.com/api/transact.php");
  335. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
  336. curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  337. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  338. curl_setopt($ch, CURLOPT_HEADER, 0);
  339. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  340.  
  341. curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
  342. curl_setopt($ch, CURLOPT_POST, 1);
  343.  
  344. if (!($data = curl_exec($ch))) {
  345. return ERROR;
  346. }
  347. curl_close($ch);
  348. unset($ch);
  349. print "n$datan";
  350. $data = explode("&", $data);
  351. for ($i=0; $i<count($data); $i++) {
  352. $rdata = explode("=", $data[$i]);
  353. $this->responses[$rdata[0]] = $rdata[1];
  354. }
  355. return $this->responses['response'];
  356. }/*}}}*/
  357. }
  358.  
  359. $gw = new gwapi;
  360. $gw->setLogin("demo", "password");
  361. $gw->setBilling(
  362. "John",
  363. "Smith",
  364. "Acme, Inc.",
  365. "123 Main St",
  366. "Suite 200",
  367. "Beverly Hills",
  368. "CA",
  369. "90210",
  370. "US",
  371. "555-555-5555",
  372. "555-555-5556",
  373. "support@example.com",
  374. "www.example.com"
  375. );
  376. $gw->setShipping(
  377. "Mary",
  378. "Smith",
  379. "na",
  380. "124 Shipping Main St",
  381. "Suite Ship",
  382. "Beverly Hills",
  383. "CA",
  384. "90210",
  385. "US",
  386. "support@example.com"
  387. );
  388. $gw->setOrder("1234", "Big Order", 1, 2, "PO1234", "65.192.14.10");
  389.  
  390. $r = $gw->doSale("50.00", "4111111111111111", "1010");
  391. print $gw->responses['responsetext'];
Add Comment
Please, Sign In to add comment