/usr/share/php/kohana2/modules/payment/libraries/drivers/Payment/Paypalpro.php is in libkohana2-modules-php 2.3.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | <?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Paypay (website payments pro) Payment Driver
*
*
* @package Payment
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*/
class Payment_Paypalpro_Driver implements Payment_Driver
{
// Fields required to do a transaction
/**
* these are the required fields for the API method DoDirectPayment
* other API methods and the associated fields required are listed here: http://tinyurl.com/2cffgr
*
* *note - paypalpro API field names are not case sensitive
*/
private $required_fields = array
(
'ENDPOINT' => FALSE,
'USER' => FALSE,
'PWD' => FALSE,
'SIGNATURE' => FALSE,
'VERSION' => FALSE,
'METHOD' => FALSE,
'PAYMENTACTION' => FALSE,
'CURRENCYCODE' => FALSE, // default is USD - only required if other currency needed
'AMT' => FALSE, // payment amount
'IPADDRESS' => FALSE,
'FIRSTNAME' => FALSE,
'LASTNAME' => FALSE,
'CREDITCARDTYPE' => FALSE,
'ACCT' => FALSE, // card number
'EXPDATE' => FALSE,
'CVV2' => FALSE
);
private $fields = array
(
'ENDPOINT' => '',
'USER' => '',
'PWD' => '',
'SIGNATURE' => '',
'VERSION' => '',
'METHOD' => '',
/* some possible values for METHOD :
'DoDirectPayment',
'RefundTransaction',
'DoAuthorization',
'DoReauthorization',
'DoCapture',
'DoVoid'
*/
'PAYMENTACTION' => '',
'CURRENCYCODE' => '',
'AMT' => 0, // payment amount
'IPADDRESS' => '',
'FIRSTNAME' => '',
'LASTNAME' => '',
'CREDITCARDTYPE' => '',
'ACCT' => '', // card number
'EXPDATE' => '', // Format: MMYYYY
'CVV2' => '', // security code
// -- OPTIONAL FIELDS --
'STREET' => '',
'STREET2' => '',
'CITY' => '',
'STATE' => '',
'ZIP' => '',
'COUNTRYCODE' => '',
'SHIPTONAME' => '',
'SHIPTOSTREET' => '',
'SHIPTOSTREET2' => '',
'SHIPTOCITY' => '',
'SHIPTOSTATE' => '',
'SHIPTOZIP' => '',
'SHIPTOCOUNTRYCODE' => '',
'INVNUM' => '' // your internal order id / transaction id
// other optional fields listed here:
// https://www.paypal.com/en_US/ebook/PP_NVPAPI_DeveloperGuide/Appx_fieldreference.html#2145100
);
private $test_mode = TRUE;
/**
* Sets the config for the class.
*
* @param : array - config passed from the payment library constructor
*/
public function __construct($config)
{
$this->test_mode = $config['test_mode'];
if ($this->test_mode)
{
$this->fields['USER'] = $config['SANDBOX_USER'];
$this->fields['PWD'] = $config['SANDBOX_PWD'];
$this->fields['SIGNATURE'] = $config['SANDBOX_SIGNATURE'];
$this->fields['ENDPOINT'] = $config['SANDBOX_ENDPOINT'];
}
else
{
$this->fields['USER'] = $config['USER'];
$this->fields['PWD'] = $config['PWD'];
$this->fields['SIGNATURE'] = $config['SIGNATURE'];
$this->fields['ENDPOINT'] = $config['ENDPOINT'];
}
$this->fields['VERSION'] = $config['VERSION'];
$this->fields['CURRENCYCODE'] = $config['CURRENCYCODE'];
$this->required_fields['USER'] = !empty($config['USER']);
$this->required_fields['PWD'] = !empty($config['PWD']);
$this->required_fields['SIGNATURE'] = !empty($config['SIGNATURE']);
$this->required_fields['ENDPOINT'] = !empty($config['ENDPOINT']);
$this->required_fields['VERSION'] = !empty($config['VERSION']);
$this->required_fields['CURRENCYCODE'] = !empty($config['CURRENCYCODE']);
$this->curl_config = $config['curl_config'];
Kohana::log('debug', 'Paypalpro Payment Driver Initialized');
}
/**
*@desc set fields for nvp string
*/
public function set_fields($fields)
{
foreach ((array) $fields as $key => $value)
{
$this->fields[$key] = $value;
if (array_key_exists($key, $this->required_fields) and !empty($value))
{
$this->required_fields[$key] = TRUE;
}
}
}
/**
*@desc process PayPal Website Payments Pro transaction
*/
public function process()
{
// Check for required fields
if (in_array(FALSE, $this->required_fields))
{
$fields = array();
foreach ($this->required_fields as $key => $field)
{
if (!$field) $fields[] = $key;
}
throw new Kohana_Exception('payment.required', implode(', ', $fields));
}
// Instantiate curl and pass the API post url
$ch = curl_init($this->fields['ENDPOINT']);
foreach ($this->fields as $key => $val)
{
// don't include unset optional fields in the name-value pair request string
if ($val==='' OR $key=='ENDPOINT') unset($this->fields[$key]);
}
$nvp_qstr = http_build_query($this->fields);
// Set custom curl options
curl_setopt_array($ch, $this->curl_config);
// Set the curl POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp_qstr);
// Execute post and get results
$response = curl_exec($ch);
if (curl_errno($ch))
{
$curl_error_no = curl_errno($ch);
$curl_error_msg = curl_error($ch);
throw new Kohana_Exception('curl.error:'.$curl_error_no.' - '.$curl_error_msg);
}
curl_close ($ch);
if (!$response)
throw new Kohana_Exception('payment.gateway_connection_error');
$nvp_res_array = array();
parse_str(urldecode($response),$nvp_res_array);
return ($nvp_res_array['ACK'] == TRUE);
}
} // End Payment_Paypalpro_Driver Class
|