4 * Licensed to CiviCRM under the Academic Free License version 3.0.
6 * Written and contributed by Ideal Solution, LLC (http://www.idealso.com)
13 * @author Marshal Newrock <marshal@idealso.com>
17 * When looking up response codes in the Authorize.Net API, they
18 * begin at one, so always delete one from the "Position in Response"
20 class CRM_Core_Payment_AuthorizeNet
extends CRM_Core_Payment
{
21 CONST CHARSET
= 'iso-8859-1';
22 CONST AUTH_APPROVED
= 1;
23 CONST AUTH_DECLINED
= 2;
25 CONST TIMEZONE
= 'America/Denver';
27 protected $_mode = NULL;
29 protected $_params = array();
32 * We only need one instance of this object. So we use the singleton
33 * pattern and cache the instance in this variable
38 static private $_singleton = NULL;
43 * @param string $mode the mode of operation: live or test
45 * @param $paymentProcessor
47 * @return \CRM_Core_Payment_AuthorizeNet
49 function __construct($mode, &$paymentProcessor) {
51 $this->_paymentProcessor
= $paymentProcessor;
52 $this->_processorName
= ts('Authorize.net');
54 $config = CRM_Core_Config
::singleton();
55 $this->_setParam('apiLogin', $paymentProcessor['user_name']);
56 $this->_setParam('paymentKey', $paymentProcessor['password']);
57 $this->_setParam('paymentType', 'AIM');
58 $this->_setParam('md5Hash', $paymentProcessor['signature']);
60 $this->_setParam('emailCustomer', 'TRUE');
61 $this->_setParam('timestamp', time());
63 $this->_setParam('sequence', rand(1, 1000));
67 * singleton function used to manage this object
69 * @param string $mode the mode of operation: live or test
70 * @param object $paymentProcessor the details of the payment processor being invoked
71 * @param object $paymentForm reference to the form object if available
72 * @param boolean $force should we force a reload of this payment object
78 static function &singleton($mode, &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
79 $processorName = $paymentProcessor['name'];
80 if (!isset(self
::$_singleton[$processorName]) || self
::$_singleton[$processorName] === NULL) {
81 self
::$_singleton[$processorName] = new CRM_Core_Payment_AuthorizeNet($mode, $paymentProcessor);
83 return self
::$_singleton[$processorName];
87 * Submit a payment using Advanced Integration Method
89 * @param array $params assoc array of input parameters for this transaction
91 * @return array the result in a nice formatted array (or an error object)
94 function doDirectPayment(&$params) {
95 if (!defined('CURLOPT_SSLCERT')) {
96 return self
::error(9001, 'Authorize.Net requires curl with SSL support');
100 * recurpayment function does not compile an array & then proces it -
101 * - the tpl does the transformation so adding call to hook here
102 * & giving it a change to act on the params array
104 $newParams = $params;
105 if (!empty($params['is_recur']) && !empty($params['contributionRecurID'])) {
106 CRM_Utils_Hook
::alterPaymentProcessorParams($this,
111 foreach ($newParams as $field => $value) {
112 $this->_setParam($field, $value);
115 if (!empty($params['is_recur']) && !empty($params['contributionRecurID'])) {
116 $result = $this->doRecurPayment();
117 if (is_a($result, 'CRM_Core_Error')) {
123 $postFields = array();
124 $authorizeNetFields = $this->_getAuthorizeNetFields();
126 // Set up our call for hook_civicrm_paymentProcessor,
127 // since we now have our parameters as assigned for the AIM back end.
128 CRM_Utils_Hook
::alterPaymentProcessorParams($this,
133 foreach ($authorizeNetFields as $field => $value) {
134 // CRM-7419, since double quote is used as enclosure while doing csv parsing
135 $value = ($field == 'x_description') ?
str_replace('"', "'", $value) : $value;
136 $postFields[] = $field . '=' . urlencode($value);
139 // Authorize.Net will not refuse duplicates, so we should check if the user already submitted this transaction
140 if ($this->_checkDupe($authorizeNetFields['x_invoice_num'])) {
141 return self
::error(9004, '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 from Authorize.net. 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.');
144 $submit = curl_init($this->_paymentProcessor
['url_site']);
147 return self
::error(9002, 'Could not initiate connection to payment gateway');
150 curl_setopt($submit, CURLOPT_POST
, TRUE);
151 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, TRUE);
152 curl_setopt($submit, CURLOPT_POSTFIELDS
, implode('&', $postFields));
153 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
155 $response = curl_exec($submit);
158 return self
::error(curl_errno($submit), curl_error($submit));
163 $response_fields = $this->explode_csv($response);
165 // check gateway MD5 response
166 if (!$this->checkMD5($response_fields[37], $response_fields[6], $response_fields[9])) {
167 return self
::error(9003, 'MD5 Verification failed');
170 // check for application errors
172 // AVS, CVV2, CAVV, and other verification results
173 if ($response_fields[0] != self
::AUTH_APPROVED
) {
174 $errormsg = $response_fields[2] . ' ' . $response_fields[3];
175 return self
::error($response_fields[1], $errormsg);
180 // test mode always returns trxn_id = 0
181 // also live mode in CiviCRM with test mode set in
182 // Authorize.Net return $response_fields[6] = 0
183 // hence treat that also as test mode transaction
185 if (($this->_mode
== 'test') ||
$response_fields[6] == 0) {
186 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id RLIKE 'test[0-9]+'";
188 $trxn_id = strval(CRM_Core_DAO
::singleValueQuery($query, $p));
189 $trxn_id = str_replace('test', '', $trxn_id);
190 $trxn_id = intval($trxn_id) +
1;
191 $params['trxn_id'] = sprintf('test%08d', $trxn_id);
194 $params['trxn_id'] = $response_fields[6];
196 $params['gross_amount'] = $response_fields[9];
197 // TODO: include authorization code?
203 * Submit an Automated Recurring Billing subscription
207 function doRecurPayment() {
208 $template = CRM_Core_Smarty
::singleton();
210 $intervalLength = $this->_getParam('frequency_interval');
211 $intervalUnit = $this->_getParam('frequency_unit');
212 if ($intervalUnit == 'week') {
213 $intervalLength *= 7;
214 $intervalUnit = 'days';
216 elseif ($intervalUnit == 'year') {
217 $intervalLength *= 12;
218 $intervalUnit = 'months';
220 elseif ($intervalUnit == 'day') {
221 $intervalUnit = 'days';
223 elseif ($intervalUnit == 'month') {
224 $intervalUnit = 'months';
227 // interval cannot be less than 7 days or more than 1 year
228 if ($intervalUnit == 'days') {
229 if ($intervalLength < 7) {
230 return self
::error(9001, 'Payment interval must be at least one week');
232 elseif ($intervalLength > 365) {
233 return self
::error(9001, 'Payment interval may not be longer than one year');
236 elseif ($intervalUnit == 'months') {
237 if ($intervalLength < 1) {
238 return self
::error(9001, 'Payment interval must be at least one week');
240 elseif ($intervalLength > 12) {
241 return self
::error(9001, 'Payment interval may not be longer than one year');
245 $template->assign('intervalLength', $intervalLength);
246 $template->assign('intervalUnit', $intervalUnit);
248 $template->assign('apiLogin', $this->_getParam('apiLogin'));
249 $template->assign('paymentKey', $this->_getParam('paymentKey'));
250 $template->assign('refId', substr($this->_getParam('invoiceID'), 0, 20));
252 //for recurring, carry first contribution id
253 $template->assign('invoiceNumber', $this->_getParam('contributionID'));
254 $firstPaymentDate = $this->_getParam('receive_date');
255 if (!empty($firstPaymentDate)) {
256 //allow for post dated payment if set in form
257 $startDate = date_create($firstPaymentDate);
260 $startDate = date_create();
262 /* Format start date in Mountain Time to avoid Authorize.net error E00017
263 * we do this only if the day we are setting our start time to is LESS than the current
264 * day in mountaintime (ie. the server time of the A-net server). A.net won't accept a date
265 * earlier than the current date on it's server so if we are in PST we might need to use mountain
266 * time to bring our date forward. But if we are submitting something future dated we want
267 * the date we entered to be respected
269 $minDate = date_create('now', new DateTimeZone(self
::TIMEZONE
));
270 if(strtotime($startDate->format('Y-m-d')) < strtotime($minDate->format('Y-m-d'))){
271 $startDate->setTimezone(new DateTimeZone(self
::TIMEZONE
));
274 $template->assign( 'startDate', $startDate->format('Y-m-d') );
276 $installments = $this->_getParam('installments');
278 // for open ended subscription totalOccurrences has to be 9999
279 $installments = empty($installments) ?
9999 : $installments;
280 $template->assign('totalOccurrences', $installments);
282 $template->assign('amount', $this->_getParam('amount'));
284 $template->assign('cardNumber', $this->_getParam('credit_card_number'));
285 $exp_month = str_pad($this->_getParam('month'), 2, '0', STR_PAD_LEFT
);
286 $exp_year = $this->_getParam('year');
287 $template->assign('expirationDate', $exp_year . '-' . $exp_month);
289 // name rather than description is used in the tpl - see http://www.authorize.net/support/ARB_guide.pdf
290 $template->assign('name', $this->_getParam('description', TRUE));
292 $template->assign('email', $this->_getParam('email'));
293 $template->assign('contactID', $this->_getParam('contactID'));
294 $template->assign('billingFirstName', $this->_getParam('billing_first_name'));
295 $template->assign('billingLastName', $this->_getParam('billing_last_name'));
296 $template->assign('billingAddress', $this->_getParam('street_address', TRUE));
297 $template->assign('billingCity', $this->_getParam('city', TRUE));
298 $template->assign('billingState', $this->_getParam('state_province'));
299 $template->assign('billingZip', $this->_getParam('postal_code', TRUE));
300 $template->assign('billingCountry', $this->_getParam('country'));
302 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
303 // submit to authorize.net
305 $submit = curl_init($this->_paymentProcessor
['url_recur']);
307 return self
::error(9002, 'Could not initiate connection to payment gateway');
309 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
310 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
311 curl_setopt($submit, CURLOPT_HEADER
, 1);
312 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
313 curl_setopt($submit, CURLOPT_POST
, 1);
314 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
316 $response = curl_exec($submit);
319 return self
::error(curl_errno($submit), curl_error($submit));
323 $responseFields = $this->_ParseArbReturn($response);
325 if ($responseFields['resultCode'] == 'Error') {
326 return self
::error($responseFields['code'], $responseFields['text']);
329 // update recur processor_id with subscriptionId
330 CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_ContributionRecur', $this->_getParam('contributionRecurID'),
331 'processor_id', $responseFields['subscriptionId']
333 //only impact of assigning this here is is can be used to cancel the subscription in an automated test
334 // if it isn't cancelled a duplicate transaction error occurs
335 if (!empty($responseFields['subscriptionId'])) {
336 $this->_setParam('subscriptionId', $responseFields['subscriptionId']);
343 function _getAuthorizeNetFields() {
344 $amount = $this->_getParam('total_amount');//Total amount is from the form contribution field
345 if(empty($amount)){//CRM-9894 would this ever be the case??
346 $amount = $this->_getParam('amount');
349 $fields['x_login'] = $this->_getParam('apiLogin');
350 $fields['x_tran_key'] = $this->_getParam('paymentKey');
351 $fields['x_email_customer'] = $this->_getParam('emailCustomer');
352 $fields['x_first_name'] = $this->_getParam('billing_first_name');
353 $fields['x_last_name'] = $this->_getParam('billing_last_name');
354 $fields['x_address'] = $this->_getParam('street_address');
355 $fields['x_city'] = $this->_getParam('city');
356 $fields['x_state'] = $this->_getParam('state_province');
357 $fields['x_zip'] = $this->_getParam('postal_code');
358 $fields['x_country'] = $this->_getParam('country');
359 $fields['x_customer_ip'] = $this->_getParam('ip_address');
360 $fields['x_email'] = $this->_getParam('email');
361 $fields['x_invoice_num'] = substr($this->_getParam('invoiceID'), 0, 20);
362 $fields['x_amount'] = $amount;
363 $fields['x_currency_code'] = $this->_getParam('currencyID');
364 $fields['x_description'] = $this->_getParam('description');
365 $fields['x_cust_id'] = $this->_getParam('contactID');
366 if ($this->_getParam('paymentType') == 'AIM') {
367 $fields['x_relay_response'] = 'FALSE';
368 // request response in CSV format
369 $fields['x_delim_data'] = 'TRUE';
370 $fields['x_delim_char'] = ',';
371 $fields['x_encap_char'] = '"';
373 $fields['x_card_num'] = $this->_getParam('credit_card_number');
374 $fields['x_card_code'] = $this->_getParam('cvv2');
375 $exp_month = str_pad($this->_getParam('month'), 2, '0', STR_PAD_LEFT
);
376 $exp_year = $this->_getParam('year');
377 $fields['x_exp_date'] = "$exp_month/$exp_year";
380 if ($this->_mode
!= 'live') {
381 $fields['x_test_request'] = 'TRUE';
388 * Checks to see if invoice_id already exists in db
390 * @param int $invoiceId The ID to check
392 * @return bool True if ID exists, else false
394 function _checkDupe($invoiceId) {
395 $contribution = new CRM_Contribute_DAO_Contribution();
396 $contribution->invoice_id
= $invoiceId;
397 return $contribution->find();
404 * @param string $data
406 * @return string the HMAC_MD5 encoding string
408 function hmac($key, $data) {
409 if (function_exists('mhash')) {
410 // Use PHP mhash extension
411 return (bin2hex(mhash(MHASH_MD5
, $data, $key)));
414 // RFC 2104 HMAC implementation for php.
415 // Creates an md5 HMAC.
416 // Eliminates the need to install mhash to compute a HMAC
417 // Hacked by Lance Rushing
418 // byte length for md5
420 if (strlen($key) > $b) {
421 $key = pack("H*", md5($key));
423 $key = str_pad($key, $b, chr(0x00));
424 $ipad = str_pad('', $b, chr(0x36));
425 $opad = str_pad('', $b, chr(0x5c));
426 $k_ipad = $key ^
$ipad;
427 $k_opad = $key ^
$opad;
428 return md5($k_opad . pack("H*", md5($k_ipad . $data)));
433 * Check the gateway MD5 response to make sure that this is a proper
436 * @param string $responseMD5 MD5 hash generated by the gateway
437 * @param string $transaction_id Transaction id generated by the gateway
438 * @param string $amount Purchase amount
444 function checkMD5($responseMD5, $transaction_id, $amount, $ipn = FALSE) {
445 // cannot check if no MD5 hash
446 $md5Hash = $this->_getParam('md5Hash');
447 if (empty($md5Hash)) {
450 $loginid = $this->_getParam('apiLogin');
451 $hashString = $ipn ?
($md5Hash . $transaction_id . $amount) : ($md5Hash . $loginid . $transaction_id . $amount);
452 $result = strtoupper(md5($hashString));
454 if ($result == $responseMD5) {
463 * Calculate and return the transaction fingerprint
465 * @return string fingerprint
467 function CalculateFP() {
468 $x_tran_key = $this->_getParam('paymentKey');
469 $loginid = $this->_getParam('apiLogin');
470 $sequence = $this->_getParam('sequence');
471 $timestamp = $this->_getParam('timestamp');
472 $amount = $this->_getParam('amount');
473 $currency = $this->_getParam('currencyID');
474 $transaction = "$loginid^$sequence^$timestamp^$amount^$currency";
475 return $this->hmac($x_tran_key, $transaction);
479 * Split a CSV file. Requires , as delimiter and " as enclosure.
480 * Based off notes from http://php.net/fgetcsv
482 * @param string $data a single CSV line
484 * @return array CSV fields
486 function explode_csv($data) {
488 //make it easier to parse fields with quotes in them
489 $data = str_replace('""', "''", $data);
492 while ($data != '') {
494 if ($data[0] == '"') {
495 // handle quoted fields
496 preg_match('/^"(([^"]|\\")*?)",?(.*)$/', $data, $matches);
498 $fields[] = str_replace("''", '"', $matches[1]);
502 preg_match('/^([^,]*),?(.*)$/', $data, $matches);
504 $fields[] = $matches[1];
512 * Extract variables from returned XML
514 * Function is from Authorize.Net sample code, and used
515 * to prevent the requirement of XML functions.
517 * @param string $content XML reply from Authorize.Net
519 * @return array refId, resultCode, code, text, subscriptionId
521 function _parseArbReturn($content) {
522 $refId = $this->_substring_between($content, '<refId>', '</refId>');
523 $resultCode = $this->_substring_between($content, '<resultCode>', '</resultCode>');
524 $code = $this->_substring_between($content, '<code>', '</code>');
525 $text = $this->_substring_between($content, '<text>', '</text>');
526 $subscriptionId = $this->_substring_between($content, '<subscriptionId>', '</subscriptionId>');
529 'resultCode' => $resultCode,
532 'subscriptionId' => $subscriptionId,
537 * Helper function for _parseArbReturn
539 * Function is from Authorize.Net sample code, and used to avoid using
542 function _substring_between(&$haystack, $start, $end) {
543 if (strpos($haystack, $start) === FALSE ||
strpos($haystack, $end) === FALSE) {
547 $start_position = strpos($haystack, $start) +
strlen($start);
548 $end_position = strpos($haystack, $end);
549 return substr($haystack, $start_position, $end_position - $start_position);
554 * Get the value of a field if set
556 * @param string $field the field
558 * @param bool $xmlSafe
559 * @return mixed value of the field, or empty string if the field is
562 function _getParam($field, $xmlSafe = FALSE) {
563 $value = CRM_Utils_Array
::value($field, $this->_params
, '');
565 $value = str_replace(array( '&', '"', "'", '<', '>' ), '', $value);
571 * @param null $errorCode
572 * @param null $errorMessage
576 function &error($errorCode = NULL, $errorMessage = NULL) {
577 $e = CRM_Core_Error
::singleton();
579 $e->push($errorCode, 0, array( ), $errorMessage);
582 $e->push(9001, 0, array( ), 'Unknown System Error.');
588 * Set a field to the specified value. Value must be a scalar (int,
589 * float, string, or boolean)
591 * @param string $field
592 * @param mixed $value
594 * @return bool false if value is not a scalar, true if successful
596 function _setParam($field, $value) {
597 if (!is_scalar($value)) {
601 $this->_params
[$field] = $value;
606 * This function checks to see if we have the right config values
608 * @return string the error message if any
611 function checkConfig() {
613 if (empty($this->_paymentProcessor
['user_name'])) {
614 $error[] = ts('APILogin is not set for this payment processor');
617 if (empty($this->_paymentProcessor
['password'])) {
618 $error[] = ts('Key is not set for this payment processor');
621 if (!empty($error)) {
622 return implode('<p>', $error);
632 function accountLoginURL() {
633 return ($this->_mode
== 'test') ?
'https://test.authorize.net' : 'https://authorize.net';
637 * @param string $message
638 * @param array $params
640 * @return bool|object
642 function cancelSubscription(&$message = '', $params = array(
644 $template = CRM_Core_Smarty
::singleton();
646 $template->assign('subscriptionType', 'cancel');
648 $template->assign('apiLogin', $this->_getParam('apiLogin'));
649 $template->assign('paymentKey', $this->_getParam('paymentKey'));
650 $template->assign('subscriptionId', CRM_Utils_Array
::value('subscriptionId', $params));
652 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
654 // submit to authorize.net
655 $submit = curl_init($this->_paymentProcessor
['url_recur']);
657 return self
::error(9002, 'Could not initiate connection to payment gateway');
660 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
661 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
662 curl_setopt($submit, CURLOPT_HEADER
, 1);
663 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
664 curl_setopt($submit, CURLOPT_POST
, 1);
665 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
667 $response = curl_exec($submit);
670 return self
::error(curl_errno($submit), curl_error($submit));
675 $responseFields = $this->_ParseArbReturn($response);
676 $message = "{$responseFields['code']}: {$responseFields['text']}";
678 if ($responseFields['resultCode'] == 'Error') {
679 return self
::error($responseFields['code'], $responseFields['text']);
685 * @param string $message
686 * @param array $params
688 * @return bool|object
690 function updateSubscriptionBillingInfo(&$message = '', $params = array(
692 $template = CRM_Core_Smarty
::singleton();
693 $template->assign('subscriptionType', 'updateBilling');
695 $template->assign('apiLogin', $this->_getParam('apiLogin'));
696 $template->assign('paymentKey', $this->_getParam('paymentKey'));
697 $template->assign('subscriptionId', $params['subscriptionId']);
699 $template->assign('cardNumber', $params['credit_card_number']);
700 $exp_month = str_pad($params['month'], 2, '0', STR_PAD_LEFT
);
701 $exp_year = $params['year'];
702 $template->assign('expirationDate', $exp_year . '-' . $exp_month);
704 $template->assign('billingFirstName', $params['first_name']);
705 $template->assign('billingLastName', $params['last_name']);
706 $template->assign('billingAddress', $params['street_address']);
707 $template->assign('billingCity', $params['city']);
708 $template->assign('billingState', $params['state_province']);
709 $template->assign('billingZip', $params['postal_code']);
710 $template->assign('billingCountry', $params['country']);
712 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
714 // submit to authorize.net
715 $submit = curl_init($this->_paymentProcessor
['url_recur']);
717 return self
::error(9002, 'Could not initiate connection to payment gateway');
720 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
721 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
722 curl_setopt($submit, CURLOPT_HEADER
, 1);
723 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
724 curl_setopt($submit, CURLOPT_POST
, 1);
725 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
727 $response = curl_exec($submit);
730 return self
::error(curl_errno($submit), curl_error($submit));
735 $responseFields = $this->_ParseArbReturn($response);
736 $message = "{$responseFields['code']}: {$responseFields['text']}";
738 if ($responseFields['resultCode'] == 'Error') {
739 return self
::error($responseFields['code'], $responseFields['text']);
745 * @param string $message
746 * @param array $params
748 * @return bool|object
750 function changeSubscriptionAmount(&$message = '', $params = array(
752 $template = CRM_Core_Smarty
::singleton();
754 $template->assign('subscriptionType', 'update');
756 $template->assign('apiLogin', $this->_getParam('apiLogin'));
757 $template->assign('paymentKey', $this->_getParam('paymentKey'));
759 $template->assign('subscriptionId', $params['subscriptionId']);
760 $template->assign('totalOccurrences', $params['installments']);
761 $template->assign('amount', $params['amount']);
763 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
765 // submit to authorize.net
766 $submit = curl_init($this->_paymentProcessor
['url_recur']);
768 return self
::error(9002, 'Could not initiate connection to payment gateway');
771 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
772 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
773 curl_setopt($submit, CURLOPT_HEADER
, 1);
774 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
775 curl_setopt($submit, CURLOPT_POST
, 1);
776 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
778 $response = curl_exec($submit);
781 return self
::error(curl_errno($submit), curl_error($submit));
786 $responseFields = $this->_ParseArbReturn($response);
787 $message = "{$responseFields['code']}: {$responseFields['text']}";
789 if ($responseFields['resultCode'] == 'Error') {
790 return self
::error($responseFields['code'], $responseFields['text']);