Highway to PSR2
[openemr.git] / portal / patient / fwk / libs / verysimple / Payment / PaymentProcessor.php
blobcda917ae0220b9e4dead7cc123b9ce88babaed03
1 <?php
2 /** @package verysimple::Payment */
4 /**
5 * import supporting libraries
6 */
7 include_once("PaymentRequest.php");
8 include_once("PaymentResponse.php");
9 include_once("RefundRequest.php");
11 /**
12 * PaymentProcessor is an abstract base class for processing PaymentRequest
13 * objects.
14 * The purpose of this API is to allow a common PaymentRequest
15 * object to be processed by any class that extends PaymentProcessor
17 * @package verysimple::Payment
18 * @author VerySimple Inc.
19 * @copyright 1997-2012 VerySimple, Inc.
20 * @license http://www.gnu.org/licenses/lgpl.html LGPL
21 * @version 3.0
23 abstract class PaymentProcessor
25 public $Username;
26 public $Password;
27 public $Signature;
28 protected $_testMode;
30 /**
31 * Constructor
33 * @param bool $testmode
34 * default = false
36 final function __construct($testmode = false, $username = "", $password = "", $signature = "")
38 $this->Username = $username;
39 $this->Password = $password;
40 $this->Signature = $signature;
41 $this->_testMode = $testmode;
42 $this->Init($testmode);
45 /**
46 * Init is called by the base object on construction
48 * @param bool $testmode
50 abstract function Init($testmode);
52 /**
53 * Process a PaymentRequest
55 * @param PaymentRequest $req
56 * Request object to be processed
57 * @return PaymentResponse
59 abstract function Process(PaymentRequest $req);
61 /**
62 * Refund a Payment
64 * @param RefundRequest $req
65 * object to be processed
66 * @return PaymentResponse
68 abstract function Refund(RefundRequest $req);
70 /**
71 * Given a 2-digit year, return the full 4-digit year
73 * @param numeric $year
75 protected function GetFullYear($year)
77 if (strlen($year) < 4) {
78 // assume the current century (could be problematic around 2098, 2099, etc)
79 $century = substr(date("Y"), 0, 2);
80 $year = $century . $year;
83 return $year;
86 /**
88 * @param string $url
89 * url to post
90 * @param array $data
91 * array of arguments for post request
92 * @param bool $verify_cert
93 * whether to verify an SSL cert. default = false
94 * @param bool $use_cookies
95 * whether to store a cookie file. default = false
97 protected function CurlPost($url, $data, $verify_cert = false, $use_cookies = false)
99 // convert the data array into a url querystring
100 $post_data = "";
101 $delim = "";
102 foreach (array_keys($data) as $key) {
103 $post_data .= $delim . $key . "=" . $data [$key];
104 $delim = "&";
107 $agent = "curl_post.1";
108 // $header[] = "Accept: text/vnd.wap.wml,*.*";
109 $ch = curl_init($url);
111 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
112 curl_setopt($ch, CURLOPT_VERBOSE, 0); // ########## debug
113 curl_setopt($ch, CURLOPT_USERAGENT, $agent);
114 // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
115 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
117 if ($use_cookies) {
118 curl_setopt($ch, CURLOPT_COOKIEJAR, "cook");
119 curl_setopt($ch, CURLOPT_COOKIEFILE, "cook");
122 curl_setopt($ch, CURLOPT_POST, 1);
123 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
124 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_cert);
125 curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
127 $tmp = curl_exec($ch);
128 $error = curl_error($ch);
130 if ($error != "") {
131 $tmp .= $error;
134 curl_close($ch);
136 return $tmp;