2 /** @package verysimple::Payment */
5 * import supporting libraries
7 include_once("PaymentRequest.php");
8 include_once("PaymentResponse.php");
9 include_once("RefundRequest.php");
12 * PaymentProcessor is an abstract base class for processing PaymentRequest
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
23 abstract class PaymentProcessor
33 * @param bool $testmode
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);
46 * Init is called by the base object on construction
48 * @param bool $testmode
50 abstract function Init($testmode);
53 * Process a PaymentRequest
55 * @param PaymentRequest $req
56 * Request object to be processed
57 * @return PaymentResponse
59 abstract function Process(PaymentRequest
$req);
64 * @param RefundRequest $req
65 * object to be processed
66 * @return PaymentResponse
68 abstract function Refund(RefundRequest
$req);
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;
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
102 foreach (array_keys($data) as $key) {
103 $post_data .= $delim . $key . "=" . $data [$key];
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);
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);