INFRA-132 - Docblock formatting fixes
[civicrm-core.git] / CRM / Core / Payment / PayflowPro.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +----------------------------------------------------------------------------+
39de6fd5 4 | PayflowPro Core Payment Module for CiviCRM version 4.6 |
6a488035
TO
5 +----------------------------------------------------------------------------+
6 | Licensed to CiviCRM under the Academic Free License version 3.0 |
7 | |
8 | Written & Contributed by Eileen McNaughton - 2009 |
9 +---------------------------------------------------------------------------+
10 */
28518c90
EM
11
12/**
13 * Class CRM_Core_Payment_PayflowPro
14 */
6a488035
TO
15class CRM_Core_Payment_PayflowPro extends CRM_Core_Payment {
16 // (not used, implicit in the API, might need to convert?)
7da04cde 17 const
353ffa53 18 CHARSET = 'UFT-8';
6a488035
TO
19
20 /**
21 * We only need one instance of this object. So we use the singleton
22 * pattern and cache the instance in this variable
23 *
24 * @var object
25 * @static
26 */
27 static private $_singleton = NULL;
28
29 /*
30 * Constructor
31 *
6a0b768e
TO
32 * @param string $mode
33 * The mode of operation: live or test.
6a488035
TO
34 *
35 * @return void
36 */
6c786a9b
EM
37 /**
38 * @param $mode
39 * @param $paymentProcessor
40 */
00be9182 41 public function __construct($mode, &$paymentProcessor) {
6a488035
TO
42 // live or test
43 $this->_mode = $mode;
44 $this->_paymentProcessor = $paymentProcessor;
45 $this->_processorName = ts('Payflow Pro');
46 }
ceb10dc7 47
6a488035
TO
48 /*
49 * This function sends request and receives response from
50 * the processor. It is the main function for processing on-server
51 * credit card transactions
52 */
b5c2afd0
EM
53 /**
54 * This function collects all the information from a web/api form and invokes
55 * the relevant payment processor specific functions to perform the transaction
56 *
6a0b768e
TO
57 * @param array $params
58 * Assoc array of input parameters for this transaction.
b5c2afd0 59 *
a6c01b45
CW
60 * @return array
61 * the result in an nice formatted array (or an error object)
b5c2afd0
EM
62 * @abstract
63 */
00be9182 64 public function doDirectPayment(&$params) {
6a488035
TO
65 if (!defined('CURLOPT_SSLCERT')) {
66 CRM_Core_Error::fatal(ts('PayFlowPro requires curl with SSL support'));
67 }
68
69 /*
70 * define variables for connecting with the gateway
71 */
ceb10dc7 72
6a488035
TO
73 // Are you using the Payflow Fraud Protection Service?
74 // Default is YES, change to NO or blank if not.
75 //This has not been investigated as part of writing this payment processor
76 $fraud = 'NO';
77 //if you have not set up a separate user account the vendor name is used as the username
78 if (!$this->_paymentProcessor['subject']) {
79 $user = $this->_paymentProcessor['user_name'];
80 }
81 else {
82 $user = $this->_paymentProcessor['subject'];
83 }
84
85 // ideally this id would be passed through into this class as
86 // part of the paymentProcessor
87 //object with the other variables. It seems inefficient to re-query to get it.
88 //$params['processor_id'] = CRM_Core_DAO::getFieldValue(
89 // 'CRM_Contribute_DAO_ContributionP
90 //age',$params['contributionPageID'], 'payment_processor_id' );
91
92 /*
93 *Create the array of variables to be sent to the processor from the $params array
94 * passed into this function
95 *
96 */
97
98 $payflow_query_array = array(
99 'USER' => $user,
100 'VENDOR' => $this->_paymentProcessor['user_name'],
101 'PARTNER' => $this->_paymentProcessor['signature'],
102 'PWD' => $this->_paymentProcessor['password'],
103 // C - Direct Payment using credit card
104 'TENDER' => 'C',
105 // A - Authorization, S - Sale
106 'TRXTYPE' => 'S',
107 'ACCT' => urlencode($params['credit_card_number']),
108 'CVV2' => $params['cvv2'],
109 'EXPDATE' => urlencode(sprintf('%02d', (int) $params['month']) . substr($params['year'], 2, 2)),
110 'ACCTTYPE' => urlencode($params['credit_card_type']),
111 'AMT' => urlencode($params['amount']),
112 'CURRENCY' => urlencode($params['currency']),
113 'FIRSTNAME' => $params['billing_first_name'],
114 //credit card name
115 'LASTNAME' => $params['billing_last_name'],
116 //credit card name
117 'STREET' => $params['street_address'],
118 'CITY' => urlencode($params['city']),
119 'STATE' => urlencode($params['state_province']),
120 'ZIP' => urlencode($params['postal_code']),
121 'COUNTRY' => urlencode($params['country']),
122 'EMAIL' => $params['email'],
123 'CUSTIP' => urlencode($params['ip_address']),
124 'COMMENT1' => urlencode($params['contributionType_accounting_code']),
125 'COMMENT2' => $mode,
126 'INVNUM' => urlencode($params['invoiceID']),
127 'ORDERDESC' => urlencode($params['description']),
128 'VERBOSITY' => 'MEDIUM',
129 'BILLTOCOUNTRY' => urlencode($params['country']),
130 );
131
132 if ($params['installments'] == 1) {
133 $params['is_recur'] == FALSE;
134 }
135
136 if ($params['is_recur'] == TRUE) {
137
138 $payflow_query_array['TRXTYPE'] = 'R';
139 $payflow_query_array['OPTIONALTRX'] = 'S';
140 $payflow_query_array['OPTIONALTRXAMT'] = $params['amount'];
141 //Amount of the initial Transaction. Required
142 $payflow_query_array['ACTION'] = 'A';
143 //A for add recurring (M-modify,C-cancel,R-reactivate,I-inquiry,P-payment
144 $payflow_query_array['PROFILENAME'] = urlencode('RegularContribution');
145 //A for add recurring (M-modify,C-cancel,R-reactivate,I-inquiry,P-payment
146 if ($params['installments'] > 0) {
147 $payflow_query_array['TERM'] = $params['installments'] - 1;
148 //ie. in addition to the one happening with this transaction
149 }
150 // $payflow_query_array['COMPANYNAME']
151 // $payflow_query_array['DESC'] = not set yet Optional
152 // description of the goods or
153 //services being purchased.
154 //This parameter applies only for ACH_CCD accounts.
155 // The
156 // $payflow_query_array['MAXFAILPAYMENTS'] = 0;
157 // number of payment periods (as s
158 //pecified by PAYPERIOD) for which the transaction is allowed
159 //to fail before PayPal cancels a profile. the default
160 // value of 0 (zero) specifies no
161 //limit. Retry
162 //attempts occur until the term is complete.
163 // $payflow_query_array['RETRYNUMDAYS'] = (not set as can't assume business rule
164
165 switch ($params['frequency_unit']) {
166 case '1 week':
797b807e 167 $params['next_sched_contribution_date'] = mktime(0, 0, 0, date("m"), date("d") + 7,
6a488035
TO
168 date("Y")
169 );
170 $params['end_date'] = mktime(0, 0, 0, date("m"), date("d") + (7 * $payflow_query_array['TERM']),
171 date("Y")
172 );
797b807e 173 $payflow_query_array['START'] = date('mdY', $params['next_sched_contribution_date']);
6a488035
TO
174 $payflow_query_array['PAYPERIOD'] = "WEEK";
175 $params['frequency_unit'] = "week";
176 $params['frequency_interval'] = 1;
177 break;
178
179 case '2 weeks':
797b807e 180 $params['next_sched_contribution_date'] = mktime(0, 0, 0, date("m"), date("d") + 14, date("Y"));
2aa397bc 181 $params['end_date'] = mktime(0, 0, 0, date("m"), date("d") + (14 * $payflow_query_array['TERM']), date("Y ")
6a488035 182 );
797b807e 183 $payflow_query_array['START'] = date('mdY', $params['next_sched_contribution_date']);
6a488035
TO
184 $payflow_query_array['PAYPERIOD'] = "BIWK";
185 $params['frequency_unit'] = "week";
186 $params['frequency_interval'] = 2;
187 break;
188
189 case '4 weeks':
797b807e 190 $params['next_sched_contribution_date'] = mktime(0, 0, 0, date("m"), date("d") + 28, date("Y")
6a488035 191 );
2aa397bc 192 $params['end_date'] = mktime(0, 0, 0, date("m"), date("d") + (28 * $payflow_query_array['TERM']), date("Y")
6a488035 193 );
797b807e 194 $payflow_query_array['START'] = date('mdY', $params['next_sched_contribution_date']);
6a488035
TO
195 $payflow_query_array['PAYPERIOD'] = "FRWK";
196 $params['frequency_unit'] = "week";
197 $params['frequency_interval'] = 4;
198 break;
199
200 case '1 month':
797b807e 201 $params['next_sched_contribution_date'] = mktime(0, 0, 0, date("m") + 1,
6a488035
TO
202 date("d"), date("Y")
203 );
204 $params['end_date'] = mktime(0, 0, 0, date("m") +
205 (1 * $payflow_query_array['TERM']),
206 date("d"), date("Y")
207 );
797b807e 208 $payflow_query_array['START'] = date('mdY', $params['next_sched_contribution_date']);
6a488035
TO
209 $payflow_query_array['PAYPERIOD'] = "MONT";
210 $params['frequency_unit'] = "month";
211 $params['frequency_interval'] = 1;
212 break;
213
214 case '3 months':
2aa397bc 215 $params['next_sched_contribution_date'] = mktime(0, 0, 0, date("m") + 3, date("d"), date("Y")
6a488035
TO
216 );
217 $params['end_date'] = mktime(0, 0, 0, date("m") +
218 (3 * $payflow_query_array['TERM']),
219 date("d"), date("Y")
220 );
797b807e 221 $payflow_query_array['START'] = date('mdY', $params['next_sched_contribution_date']);
6a488035
TO
222 $payflow_query_array['PAYPERIOD'] = "QTER";
223 $params['frequency_unit'] = "month";
224 $params['frequency_interval'] = 3;
225 break;
226
227 case '6 months':
797b807e 228 $params['next_sched_contribution_date'] = mktime(0, 0, 0, date("m") + 6, date("d"),
6a488035
TO
229 date("Y")
230 );
231 $params['end_date'] = mktime(0, 0, 0, date("m") +
232 (6 * $payflow_query_array['TERM']),
233 date("d"), date("Y")
234 );
2aa397bc 235 $payflow_query_array['START'] = date('mdY', $params['next_sched_contribution_date']
6a488035
TO
236 );
237 $payflow_query_array['PAYPERIOD'] = "SMYR";
238 $params['frequency_unit'] = "month";
239 $params['frequency_interval'] = 6;
240 break;
241
242 case '1 year':
797b807e 243 $params['next_sched_contribution_date'] = mktime(0, 0, 0, date("m"), date("d"),
6a488035
TO
244 date("Y") + 1
245 );
246 $params['end_date'] = mktime(0, 0, 0, date("m"), date("d"),
247 date("Y") +
248 (1 * $payflow_query_array['TEM'])
249 );
797b807e 250 $payflow_query_array['START'] = date('mdY', $params['next_sched_contribution_date']);
6a488035
TO
251 $payflow_query_array['PAYPERIOD'] = "YEAR";
252 $params['frequency_unit'] = "year";
253 $params['frequency_interval'] = 1;
254 break;
255 }
256 }
257
258 CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $payflow_query_array);
259 $payflow_query = $this->convert_to_nvp($payflow_query_array);
260
261 /*
262 * Check to see if we have a duplicate before we send
263 */
264 if ($this->_checkDupe($params['invoiceID'])) {
265 return self::errorExit(9003, 'It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator.');
266 }
267
268 // ie. url at payment processor to submit to.
269 $submiturl = $this->_paymentProcessor['url_site'];
270
271 $responseData = self::submit_transaction($submiturl, $payflow_query);
272
273 /*
ceb10dc7 274 * Payment successfully sent to gateway - process the response now
6a488035
TO
275 */
276 $result = strstr($responseData, "RESULT");
277 $nvpArray = array();
278 while (strlen($result)) {
279 // name
280 $keypos = strpos($result, '=');
281 $keyval = substr($result, 0, $keypos);
282 // value
283 $valuepos = strpos($result, '&') ? strpos($result, '&') : strlen($result);
284 $valval = substr($result, $keypos + 1, $valuepos - $keypos - 1);
285 // decoding the respose
286 $nvpArray[$keyval] = $valval;
287 $result = substr($result, $valuepos + 1, strlen($result));
288 }
289 // get the result code to validate.
290 $result_code = $nvpArray['RESULT'];
291 /*debug
292 echo "<p>Params array</p><br>";
293 print_r($params);
294 echo "<p></p><br>";
295 echo "<p>Values to Payment Processor</p><br>";
296 print_r($payflow_query_array);
297 echo "<p></p><br>";
298 echo "<p>Results from Payment Processor</p><br>";
299 print_r($nvpArray);
300 echo "<p></p><br>";
301 */
302
303 switch ($result_code) {
304 case 0:
305
306 /*******************************************************
307 * Success !
308 * This is a successful transaction. PayFlow Pro does return further information
309 * about transactions to help you identify fraud including whether they pass
310 * the cvv check, the avs check. This is stored in
311 * CiviCRM as part of the transact
312 * but not further processing is done. Business rules would need to be defined
6a488035
TO
313 *******************************************************/
314 $params['trxn_id'] = $nvpArray['PNREF'] . $nvpArray['TRXPNREF'];
315 //'trxn_id' is varchar(255) field. returned value is length 12
316 $params['trxn_result_code'] = $nvpArray['AUTHCODE'] . "-Cvv2:" . $nvpArray['CVV2MATCH'] . "-avs:" . $nvpArray['AVSADDR'];
317
318 if ($params['is_recur'] == TRUE) {
319 $params['recur_trxn_id'] = $nvpArray['PROFILEID'];
320 //'trxn_id' is varchar(255) field. returned value is length 12
321 }
322 return $params;
323
324 case 1:
325 return self::errorExit(9008, "There is a payment processor configuration problem. This is usually due to invalid account information or ip restrictions on the account. You can verify ip restriction by logging // into Manager. See Service Settings >> Allowed IP Addresses. ");
326
327 case 12:
328 // Hard decline from bank.
329 return self::errorExit(9009, "Your transaction was declined ");
330
331 case 13:
332 // Voice authorization required.
333 return self::errorExit(9010, "Your Transaction is pending. Contact Customer Service to complete your order.");
334
335 case 23:
336 // Issue with credit card number or expiration date.
337 return self::errorExit(9011, "Invalid credit card information. Please re-enter.");
338
339 case 26:
340 return self::errorExit(9012, "You have not configured your payment processor with the correct credentials. Make sure you have provided both the <vendor> and the <user> variables ");
341
342 default:
343 return self::errorExit(9013, "Error - from payment processor: [" . $result_code . " " . $nvpArray['RESPMSG'] . "] ");
344 }
345
346 return self::errorExit(9014, "Check the code - all transactions should have been headed off before they got here. Something slipped through the net");
347 }
348
349 /**
350 * Checks to see if invoice_id already exists in db
351 *
6a0b768e
TO
352 * @param int $invoiceId
353 * The ID to check.
6a488035 354 *
a6c01b45
CW
355 * @return bool
356 * True if ID exists, else false
6a488035 357 */
00be9182 358 public function _checkDupe($invoiceId) {
6a488035
TO
359 //copied from Eway but not working and not really sure it should!
360 $contribution = new CRM_Contribute_DAO_Contribution();
361 $contribution->invoice_id = $invoiceId;
362 return $contribution->find();
363 }
364
365 /*
366 * Produces error message and returns from class
367 */
6c786a9b
EM
368 /**
369 * @param null $errorCode
370 * @param null $errorMessage
371 *
372 * @return object
373 */
00be9182 374 public function &errorExit($errorCode = NULL, $errorMessage = NULL) {
6a488035
TO
375 $e = CRM_Core_Error::singleton();
376 if ($errorCode) {
377 $e->push($errorCode, 0, NULL, $errorMessage);
378 }
379 else {
380 $e->push(9000, 0, NULL, 'Unknown System Error.');
381 }
382 return $e;
383 }
384
385
386 /*
387 * NOTE: 'doTransferCheckout' not implemented
388 */
6c786a9b 389 /**
c490a46a 390 * @param array $params
6c786a9b
EM
391 * @param $component
392 *
393 * @throws Exception
394 */
00be9182 395 public function doTransferCheckout(&$params, $component) {
6a488035
TO
396 CRM_Core_Error::fatal(ts('This function is not implemented'));
397 }
398
399 /*
400 * This public function checks to see if we have the right processor config values set
401 *
402 * NOTE: Called by Events and Contribute to check config params are set prior to trying
403 * register any credit card details
404 *
6a0b768e
TO
405 * @param string $mode
406 * The mode we are operating in (live or test) - not used.
6a488035
TO
407 *
408 * returns string $errorMsg if any errors found - null if OK
6a488035 409 */
ceb10dc7 410
6a488035
TO
411 // function checkConfig( $mode ) // CiviCRM V1.9 Declaration
412
413 // CiviCRM V2.0 Declaration
b5c2afd0
EM
414 /**
415 * This function checks to see if we have the right config values
416 *
417 * @internal param string $mode the mode we are operating in (live or test)
418 *
a6c01b45
CW
419 * @return string
420 * the error message if any
b5c2afd0 421 */
00be9182 422 public function checkConfig() {
6a488035
TO
423 $errorMsg = array();
424 if (empty($this->_paymentProcessor['user_name'])) {
425 $errorMsg[] = ' ' . ts('ssl_merchant_id is not set for this payment processor');
426 }
427
428 if (empty($this->_paymentProcessor['url_site'])) {
429 $errorMsg[] = ' ' . ts('URL is not set for %1', array(1 => $this->_paymentProcessor['name']));
430 }
431
432 if (!empty($errorMsg)) {
433 return implode('<p>', $errorMsg);
434 }
435 else {
436 return NULL;
437 }
438 }
439 //end check config
440
441 /*
442 * convert to a name/value pair (nvp) string
443 */
6c786a9b
EM
444 /**
445 * @param $payflow_query_array
446 *
447 * @return array|string
448 */
00be9182 449 public function convert_to_nvp($payflow_query_array) {
6a488035
TO
450 foreach ($payflow_query_array as $key => $value) {
451 $payflow_query[] = $key . '[' . strlen($value) . ']=' . $value;
452 }
453 $payflow_query = implode('&', $payflow_query);
454
455 return $payflow_query;
456 }
457
458 /*
459 * Submit transaction using CuRL
460 * @submiturl string Url to direct HTTPS GET to
461 * @payflow_query value string to be posted
6a488035 462 */
6c786a9b
EM
463 /**
464 * @param $submiturl
465 * @param $payflow_query
466 *
467 * @return mixed|object
468 */
00be9182 469 public function submit_transaction($submiturl, $payflow_query) {
6a488035
TO
470 /*
471 * Submit transaction using CuRL
472 */
ceb10dc7 473
6a488035
TO
474 // get data ready for API
475 $user_agent = $_SERVER['HTTP_USER_AGENT'];
476 // Here's your custom headers; adjust appropriately for your setup:
477 $headers[] = "Content-Type: text/namevalue";
478 //or text/xml if using XMLPay.
479 $headers[] = "Content-Length : " . strlen($data);
480 // Length of data to be passed
481 // Here the server timeout value is set to 45, but notice
482 // below in the cURL section, the timeout
483 // for cURL is 90 seconds. You want to make sure the server
484 // timeout is less, then the connection.
485 $headers[] = "X-VPS-Timeout: 45";
486 //random unique number - the transaction is retried using this transaction ID
487 // in this function but if that doesn't work and it is re- submitted
488 // it is treated as a new attempt. PayflowPro doesn't allow
489 // you to change details (e.g. card no) when you re-submit
490 // you can only try the same details
491 $headers[] = "X-VPS-Request-ID: " . rand(1, 1000000000);
492 // optional header field
493 $headers[] = "X-VPS-VIT-Integration-Product: CiviCRM";
494 // other Optional Headers. If used adjust as necessary.
495 // Name of your OS
496 //$headers[] = "X-VPS-VIT-OS-Name: Linux";
497 // OS Version
498 //$headers[] = "X-VPS-VIT-OS-Version: RHEL 4";
499 // What you are using
500 //$headers[] = "X-VPS-VIT-Client-Type: PHP/cURL";
501 // For your info
502 //$headers[] = "X-VPS-VIT-Client-Version: 0.01";
503 // For your info
504 //$headers[] = "X-VPS-VIT-Client-Architecture: x86";
505 // Application version
506 //$headers[] = "X-VPS-VIT-Integration-Version: 0.01";
507 $ch = curl_init();
508 curl_setopt($ch, CURLOPT_URL, $submiturl);
509 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
510 curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
511 curl_setopt($ch, CURLOPT_HEADER, 1);
512 // tells curl to include headers in response
513 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
514 // return into a variable
515 curl_setopt($ch, CURLOPT_TIMEOUT, 90);
516 // times out after 90 secs
439b9688
LS
517 if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
518 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
519 }
6a488035
TO
520 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'));
521 // this line makes it work under https
522 curl_setopt($ch, CURLOPT_POSTFIELDS, $payflow_query);
523 //adding POST data
17c04b52 524 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL') ? 2 : 0);
6a488035
TO
525 //verifies ssl certificate
526 curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
527 //forces closure of connection when done
528 curl_setopt($ch, CURLOPT_POST, 1);
529 //data sent as POST
530
531 // Try to submit the transaction up to 3 times with 5 second delay. This can be used
532 // in case of network issues. The idea here is since you are posting via HTTPS there
533 // could be general network issues, so try a few times before you tell customer there
534 // is an issue.
535
536 $i = 1;
537 while ($i++ <= 3) {
538 $responseData = curl_exec($ch);
539 $responseHeaders = curl_getinfo($ch);
540 if ($responseHeaders['http_code'] != 200) {
541 // Let's wait 5 seconds to see if its a temporary network issue.
542 sleep(5);
543 }
544 elseif ($responseHeaders['http_code'] == 200) {
545 // we got a good response, drop out of loop.
546 break;
547 }
548 }
549
550 /*
551 * Transaction submitted -
552 * See if we had a curl error - if so tell 'em and bail out
553 *
554 * NOTE: curl_error does not return a logical value (see its documentation), but
555 * a string, which is empty when there was no error.
556 */
557 if ((curl_errno($ch) > 0) || (strlen(curl_error($ch)) > 0)) {
558 curl_close($ch);
559 $errorNum = curl_errno($ch);
560 $errorDesc = curl_error($ch);
561
562 //Paranoia - in the unlikley event that 'curl' errno fails
2aa397bc
TO
563 if ($errorNum == 0) {
564 $errorNum = 9005;
565 }
6a488035
TO
566
567 // Paranoia - in the unlikley event that 'curl' error fails
2aa397bc
TO
568 if (strlen($errorDesc) == 0) {
569 $errorDesc = "Connection to payment gateway failed";
570 }
6a488035
TO
571 if ($errorNum = 60) {
572 return self::errorExit($errorNum, "Curl error - " . $errorDesc .
573 " Try this link for more information http://curl.haxx.se/d
574 ocs/sslcerts.html"
575 );
576 }
577
578 return self::errorExit($errorNum, "Curl error - " . $errorDesc .
579 " processor response = " . $processorResponse
580 );
581 }
582
583 /*
584 * If null data returned - tell 'em and bail out
585 *
586 * NOTE: You will not necessarily get a string back, if the request failed for
587 * any reason, the return value will be the boolean false.
588 */
589 if (($responseData === FALSE) || (strlen($responseData) == 0)) {
590 curl_close($ch);
591 return self::errorExit(9006, "Error: Connection to payment gateway failed - no data
592 returned. Gateway url set to $submiturl");
593 }
594
595 /*
596 * If gateway returned no data - tell 'em and bail out
597 */
598 if (empty($responseData)) {
599 curl_close($ch);
600 return self::errorExit(9007, "Error: No data returned from payment gateway.");
601 }
602
603 /*
604 * Success so far - close the curl and check the data
605 */
606 curl_close($ch);
607 return $responseData;
608 }
609 //end submit_transaction
610
6c786a9b 611 /**
100fef9d
CW
612 * @param int $recurringProfileID
613 * @param int $processorID
6c786a9b
EM
614 *
615 * @throws Exception
616 */
00be9182 617 public function getRecurringTransactionStatus($recurringProfileID, $processorID) {
6a488035
TO
618 if (!defined('CURLOPT_SSLCERT')) {
619 CRM_Core_Error::fatal(ts('PayFlowPro requires curl with SSL support'));
620 }
621
622 /*
623 * define variables for connecting with the gateway
624 */
ceb10dc7 625
6a488035
TO
626 //if you have not set up a separate user account the vendor name is used as the username
627 if (!$this->_paymentProcessor['subject']) {
628 $user = $this->_paymentProcessor['user_name'];
629 }
630 else {
631 $user = $this->_paymentProcessor['subject'];
632 }
633 //$recurringProfileID = "RT0000000001";
634 // c $trythis = $this->getRecurringTransactionStatus($recurringProfileID,17);
635
6a488035
TO
636 /*
637 *Create the array of variables to be sent to the processor from the $params array
638 * passed into this function
639 *
640 */
641
642 $payflow_query_array = array(
643 'USER' => $user,
644 'VENDOR' => $this->_paymentProcessor['user_name'],
645 'PARTNER' => $this->_paymentProcessor['signature'],
646 'PWD' => $this->_paymentProcessor['password'],
647 // C - Direct Payment using credit card
648 'TENDER' => 'C',
649 // A - Authorization, S - Sale
650 'TRXTYPE' => 'R',
651 'ACTION' => 'I',
652 //A for add recurring
653 //(M-modify,C-cancel,R-reactivate,
654 //I-inquiry,P-payment
655 'ORIGPROFILEID' => $recurringProfileID,
656 'PAYMENTHISTORY' => 'Y',
657 );
658
659 $payflow_query = $this->convert_to_nvp($payflow_query_array);
660 echo $payflow_query;
661 $submiturl = $this->_paymentProcessor['url_site'];
662 //ie. url at payment processor to submit to.
663 $responseData = self::submit_transaction($submiturl, $payflow_query);
664 /*
ceb10dc7 665 * Payment successfully sent to gateway - process the response now
6a488035 666 */
ceb10dc7 667
6a488035
TO
668 $result = strstr($responseData, "RESULT");
669 $nvpArray = array();
670 while (strlen($result)) {
671 // name
672 $keypos = strpos($result, '=');
673 $keyval = substr($result, 0, $keypos);
674 // value
675 $valuepos = strpos($result, '&') ? strpos($result, '&') : strlen($result);
676 $valval = substr($result, $keypos + 1, $valuepos - $keypos - 1);
677 // decoding the respose
678 $nvpArray[$keyval] = $valval;
679 $result = substr($result, $valuepos + 1, strlen($result));
680 }
681 // get the result code to validate.
682 $result_code = $nvpArray['RESULT'];
683 print_r($responseData);
684
685 //RESPMSG=Invalid Profile ID: Invalid recurring profile ID
686 //RT0000000001
687 }
688}