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>
18 * When looking up response codes in the Authorize.Net API, they
19 * begin at one, so always delete one from the "Position in Response"
21 class CRM_Core_Payment_AuthorizeNet
extends CRM_Core_Payment
{
22 const CHARSET
= 'iso-8859-1';
23 const AUTH_APPROVED
= 1;
24 const AUTH_DECLINED
= 2;
26 const AUTH_REVIEW
= 4;
27 const TIMEZONE
= 'America/Denver';
29 protected $_mode = NULL;
31 protected $_params = array();
34 * We only need one instance of this object. So we use the singleton
35 * pattern and cache the instance in this variable
39 static private $_singleton = NULL;
45 * The mode of operation: live or test.
47 * @param $paymentProcessor
49 * @return \CRM_Core_Payment_AuthorizeNet
51 public function __construct($mode, &$paymentProcessor) {
53 $this->_paymentProcessor
= $paymentProcessor;
54 $this->_processorName
= ts('Authorize.net');
56 $this->_setParam('apiLogin', $paymentProcessor['user_name']);
57 $this->_setParam('paymentKey', $paymentProcessor['password']);
58 $this->_setParam('paymentType', 'AIM');
59 $this->_setParam('md5Hash', CRM_Utils_Array
::value('signature', $paymentProcessor));
61 $this->_setParam('timestamp', time());
63 $this->_setParam('sequence', rand(1, 1000));
67 * Should the first payment date be configurable when setting up back office recurring payments.
68 * In the case of Authorize.net this is an option
71 protected function supportsFutureRecurStartDate() {
76 * Can recurring contributions be set against pledges.
78 * In practice all processors that use the baseIPN function to finish transactions or
79 * call the completetransaction api support this by looking up previous contributions in the
80 * series and, if there is a prior contribution against a pledge, and the pledge is not complete,
81 * adding the new payment to the pledge.
83 * However, only enabling for processors it has been tested against.
87 protected function supportsRecurContributionsForPledges() {
92 * Submit a payment using Advanced Integration Method.
94 * @param array $params
95 * Assoc array of input parameters for this transaction.
98 * the result in a nice formatted array (or an error object)
100 public function doDirectPayment(&$params) {
101 if (!defined('CURLOPT_SSLCERT')) {
102 return self
::error(9001, 'Authorize.Net requires curl with SSL support');
106 * recurpayment function does not compile an array & then process it -
107 * - the tpl does the transformation so adding call to hook here
108 * & giving it a change to act on the params array
110 $newParams = $params;
111 if (!empty($params['is_recur']) && !empty($params['contributionRecurID'])) {
112 CRM_Utils_Hook
::alterPaymentProcessorParams($this,
117 foreach ($newParams as $field => $value) {
118 $this->_setParam($field, $value);
121 if (!empty($params['is_recur']) && !empty($params['contributionRecurID'])) {
122 $result = $this->doRecurPayment();
123 if (is_a($result, 'CRM_Core_Error')) {
129 $postFields = array();
130 $authorizeNetFields = $this->_getAuthorizeNetFields();
132 // Set up our call for hook_civicrm_paymentProcessor,
133 // since we now have our parameters as assigned for the AIM back end.
134 CRM_Utils_Hook
::alterPaymentProcessorParams($this,
139 foreach ($authorizeNetFields as $field => $value) {
140 // CRM-7419, since double quote is used as enclosure while doing csv parsing
141 $value = ($field == 'x_description') ?
str_replace('"', "'", $value) : $value;
142 $postFields[] = $field . '=' . urlencode($value);
145 // Authorize.Net will not refuse duplicates, so we should check if the user already submitted this transaction
146 if ($this->checkDupe($authorizeNetFields['x_invoice_num'], CRM_Utils_Array
::value('contributionID', $params))) {
147 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.');
150 $submit = curl_init($this->_paymentProcessor
['url_site']);
153 return self
::error(9002, 'Could not initiate connection to payment gateway');
156 curl_setopt($submit, CURLOPT_POST
, TRUE);
157 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, TRUE);
158 curl_setopt($submit, CURLOPT_POSTFIELDS
, implode('&', $postFields));
159 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, Civi
::settings()->get('verifySSL'));
161 $response = curl_exec($submit);
164 return self
::error(curl_errno($submit), curl_error($submit));
169 $response_fields = $this->explode_csv($response);
171 // fetch available contribution statuses
172 $contributionStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
174 // check gateway MD5 response
175 if (!$this->checkMD5($response_fields[37], $response_fields[6], $response_fields[9])) {
176 $params['payment_status_id'] = array_search('Failed', $contributionStatus);
177 return self
::error(9003, 'MD5 Verification failed');
180 // check for application errors
182 // AVS, CVV2, CAVV, and other verification results
183 switch ($response_fields[0]) {
184 case self
::AUTH_REVIEW
:
185 $params['payment_status_id'] = array_search('Pending', $contributionStatus);
188 case self
::AUTH_ERROR
:
189 $params['payment_status_id'] = array_search('Failed', $contributionStatus);
190 $errormsg = $response_fields[2] . ' ' . $response_fields[3];
191 return self
::error($response_fields[1], $errormsg);
193 case self
::AUTH_DECLINED
:
194 $errormsg = $response_fields[2] . ' ' . $response_fields[3];
195 return self
::error($response_fields[1], $errormsg);
200 // test mode always returns trxn_id = 0
201 // also live mode in CiviCRM with test mode set in
202 // Authorize.Net return $response_fields[6] = 0
203 // hence treat that also as test mode transaction
205 if (($this->_mode
== 'test') ||
$response_fields[6] == 0) {
206 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id RLIKE 'test[0-9]+'";
208 $trxn_id = strval(CRM_Core_DAO
::singleValueQuery($query, $p));
209 $trxn_id = str_replace('test', '', $trxn_id);
210 $trxn_id = intval($trxn_id) +
1;
211 $params['trxn_id'] = sprintf('test%08d', $trxn_id);
214 $params['trxn_id'] = $response_fields[6];
216 $params['gross_amount'] = $response_fields[9];
219 // TODO: include authorization code?
225 * Submit an Automated Recurring Billing subscription.
227 public function doRecurPayment() {
228 $template = CRM_Core_Smarty
::singleton();
230 $intervalLength = $this->_getParam('frequency_interval');
231 $intervalUnit = $this->_getParam('frequency_unit');
232 if ($intervalUnit == 'week') {
233 $intervalLength *= 7;
234 $intervalUnit = 'days';
236 elseif ($intervalUnit == 'year') {
237 $intervalLength *= 12;
238 $intervalUnit = 'months';
240 elseif ($intervalUnit == 'day') {
241 $intervalUnit = 'days';
243 elseif ($intervalUnit == 'month') {
244 $intervalUnit = 'months';
247 // interval cannot be less than 7 days or more than 1 year
248 if ($intervalUnit == 'days') {
249 if ($intervalLength < 7) {
250 return self
::error(9001, 'Payment interval must be at least one week');
252 elseif ($intervalLength > 365) {
253 return self
::error(9001, 'Payment interval may not be longer than one year');
256 elseif ($intervalUnit == 'months') {
257 if ($intervalLength < 1) {
258 return self
::error(9001, 'Payment interval must be at least one week');
260 elseif ($intervalLength > 12) {
261 return self
::error(9001, 'Payment interval may not be longer than one year');
265 $template->assign('intervalLength', $intervalLength);
266 $template->assign('intervalUnit', $intervalUnit);
268 $template->assign('apiLogin', $this->_getParam('apiLogin'));
269 $template->assign('paymentKey', $this->_getParam('paymentKey'));
270 $template->assign('refId', substr($this->_getParam('invoiceID'), 0, 20));
272 //for recurring, carry first contribution id
273 $template->assign('invoiceNumber', $this->_getParam('contributionID'));
274 $firstPaymentDate = $this->_getParam('receive_date');
275 if (!empty($firstPaymentDate)) {
276 //allow for post dated payment if set in form
277 $startDate = date_create($firstPaymentDate);
280 $startDate = date_create();
282 /* Format start date in Mountain Time to avoid Authorize.net error E00017
283 * we do this only if the day we are setting our start time to is LESS than the current
284 * day in mountaintime (ie. the server time of the A-net server). A.net won't accept a date
285 * earlier than the current date on it's server so if we are in PST we might need to use mountain
286 * time to bring our date forward. But if we are submitting something future dated we want
287 * the date we entered to be respected
289 $minDate = date_create('now', new DateTimeZone(self
::TIMEZONE
));
290 if (strtotime($startDate->format('Y-m-d')) < strtotime($minDate->format('Y-m-d'))) {
291 $startDate->setTimezone(new DateTimeZone(self
::TIMEZONE
));
294 $template->assign('startDate', $startDate->format('Y-m-d'));
296 $installments = $this->_getParam('installments');
298 // for open ended subscription totalOccurrences has to be 9999
299 $installments = empty($installments) ?
9999 : $installments;
300 $template->assign('totalOccurrences', $installments);
302 $template->assign('amount', $this->_getParam('amount'));
304 $template->assign('cardNumber', $this->_getParam('credit_card_number'));
305 $exp_month = str_pad($this->_getParam('month'), 2, '0', STR_PAD_LEFT
);
306 $exp_year = $this->_getParam('year');
307 $template->assign('expirationDate', $exp_year . '-' . $exp_month);
309 // name rather than description is used in the tpl - see http://www.authorize.net/support/ARB_guide.pdf
310 $template->assign('name', $this->_getParam('description', TRUE));
312 $template->assign('email', $this->_getParam('email'));
313 $template->assign('contactID', $this->_getParam('contactID'));
314 $template->assign('billingFirstName', $this->_getParam('billing_first_name'));
315 $template->assign('billingLastName', $this->_getParam('billing_last_name'));
316 $template->assign('billingAddress', $this->_getParam('street_address', TRUE));
317 $template->assign('billingCity', $this->_getParam('city', TRUE));
318 $template->assign('billingState', $this->_getParam('state_province'));
319 $template->assign('billingZip', $this->_getParam('postal_code', TRUE));
320 $template->assign('billingCountry', $this->_getParam('country'));
322 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
323 // submit to authorize.net
325 $submit = curl_init($this->_paymentProcessor
['url_recur']);
327 return self
::error(9002, 'Could not initiate connection to payment gateway');
329 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
330 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
331 curl_setopt($submit, CURLOPT_HEADER
, 1);
332 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
333 curl_setopt($submit, CURLOPT_POST
, 1);
334 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, Civi
::settings()->get('verifySSL'));
336 $response = curl_exec($submit);
339 return self
::error(curl_errno($submit), curl_error($submit));
343 $responseFields = $this->_ParseArbReturn($response);
345 if ($responseFields['resultCode'] == 'Error') {
346 return self
::error($responseFields['code'], $responseFields['text']);
349 // update recur processor_id with subscriptionId
350 CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_ContributionRecur', $this->_getParam('contributionRecurID'),
351 'processor_id', $responseFields['subscriptionId']
353 //only impact of assigning this here is is can be used to cancel the subscription in an automated test
354 // if it isn't cancelled a duplicate transaction error occurs
355 if (!empty($responseFields['subscriptionId'])) {
356 $this->_setParam('subscriptionId', $responseFields['subscriptionId']);
363 public function _getAuthorizeNetFields() {
364 $amount = $this->_getParam('total_amount');//Total amount is from the form contribution field
365 if (empty($amount)) {//CRM-9894 would this ever be the case??
366 $amount = $this->_getParam('amount');
369 $fields['x_login'] = $this->_getParam('apiLogin');
370 $fields['x_tran_key'] = $this->_getParam('paymentKey');
371 $fields['x_email_customer'] = $this->_getParam('emailCustomer');
372 $fields['x_first_name'] = $this->_getParam('billing_first_name');
373 $fields['x_last_name'] = $this->_getParam('billing_last_name');
374 $fields['x_address'] = $this->_getParam('street_address');
375 $fields['x_city'] = $this->_getParam('city');
376 $fields['x_state'] = $this->_getParam('state_province');
377 $fields['x_zip'] = $this->_getParam('postal_code');
378 $fields['x_country'] = $this->_getParam('country');
379 $fields['x_customer_ip'] = $this->_getParam('ip_address');
380 $fields['x_email'] = $this->_getParam('email');
381 $fields['x_invoice_num'] = $this->_getParam('invoiceID');
382 $fields['x_amount'] = $amount;
383 $fields['x_currency_code'] = $this->_getParam('currencyID');
384 $fields['x_description'] = $this->_getParam('description');
385 $fields['x_cust_id'] = $this->_getParam('contactID');
386 if ($this->_getParam('paymentType') == 'AIM') {
387 $fields['x_relay_response'] = 'FALSE';
388 // request response in CSV format
389 $fields['x_delim_data'] = 'TRUE';
390 $fields['x_delim_char'] = ',';
391 $fields['x_encap_char'] = '"';
393 $fields['x_card_num'] = $this->_getParam('credit_card_number');
394 $fields['x_card_code'] = $this->_getParam('cvv2');
395 $exp_month = str_pad($this->_getParam('month'), 2, '0', STR_PAD_LEFT
);
396 $exp_year = $this->_getParam('year');
397 $fields['x_exp_date'] = "$exp_month/$exp_year";
400 if ($this->_mode
!= 'live') {
401 $fields['x_test_request'] = 'TRUE';
411 * @param string $data
414 * the HMAC_MD5 encoding string
416 public function hmac($key, $data) {
417 if (function_exists('mhash')) {
418 // Use PHP mhash extension
419 return (bin2hex(mhash(MHASH_MD5
, $data, $key)));
422 // RFC 2104 HMAC implementation for php.
423 // Creates an md5 HMAC.
424 // Eliminates the need to install mhash to compute a HMAC
425 // Hacked by Lance Rushing
426 // byte length for md5
428 if (strlen($key) > $b) {
429 $key = pack("H*", md5($key));
431 $key = str_pad($key, $b, chr(0x00));
432 $ipad = str_pad('', $b, chr(0x36));
433 $opad = str_pad('', $b, chr(0x5c));
434 $k_ipad = $key ^
$ipad;
435 $k_opad = $key ^
$opad;
436 return md5($k_opad . pack("H*", md5($k_ipad . $data)));
441 * Check the gateway MD5 response to make sure that this is a proper
444 * @param string $responseMD5
445 * MD5 hash generated by the gateway.
446 * @param string $transaction_id
447 * Transaction id generated by the gateway.
448 * @param string $amount
455 public function checkMD5($responseMD5, $transaction_id, $amount, $ipn = FALSE) {
456 // cannot check if no MD5 hash
457 $md5Hash = $this->_getParam('md5Hash');
458 if (empty($md5Hash)) {
461 $loginid = $this->_getParam('apiLogin');
462 $hashString = $ipn ?
($md5Hash . $transaction_id . $amount) : ($md5Hash . $loginid . $transaction_id . $amount);
463 $result = strtoupper(md5($hashString));
465 if ($result == $responseMD5) {
474 * Calculate and return the transaction fingerprint.
479 public function CalculateFP() {
480 $x_tran_key = $this->_getParam('paymentKey');
481 $loginid = $this->_getParam('apiLogin');
482 $sequence = $this->_getParam('sequence');
483 $timestamp = $this->_getParam('timestamp');
484 $amount = $this->_getParam('amount');
485 $currency = $this->_getParam('currencyID');
486 $transaction = "$loginid^$sequence^$timestamp^$amount^$currency";
487 return $this->hmac($x_tran_key, $transaction);
491 * Split a CSV file. Requires , as delimiter and " as enclosure.
492 * Based off notes from http://php.net/fgetcsv
494 * @param string $data
500 public function explode_csv($data) {
502 //make it easier to parse fields with quotes in them
503 $data = str_replace('""', "''", $data);
506 while ($data != '') {
508 if ($data[0] == '"') {
509 // handle quoted fields
510 preg_match('/^"(([^"]|\\")*?)",?(.*)$/', $data, $matches);
512 $fields[] = str_replace("''", '"', $matches[1]);
516 preg_match('/^([^,]*),?(.*)$/', $data, $matches);
518 $fields[] = $matches[1];
526 * Extract variables from returned XML.
528 * Function is from Authorize.Net sample code, and used
529 * to prevent the requirement of XML functions.
531 * @param string $content
532 * XML reply from Authorize.Net.
535 * refId, resultCode, code, text, subscriptionId
537 public function _parseArbReturn($content) {
538 $refId = $this->_substring_between($content, '<refId>', '</refId>');
539 $resultCode = $this->_substring_between($content, '<resultCode>', '</resultCode>');
540 $code = $this->_substring_between($content, '<code>', '</code>');
541 $text = $this->_substring_between($content, '<text>', '</text>');
542 $subscriptionId = $this->_substring_between($content, '<subscriptionId>', '</subscriptionId>');
545 'resultCode' => $resultCode,
548 'subscriptionId' => $subscriptionId,
553 * Helper function for _parseArbReturn.
555 * Function is from Authorize.Net sample code, and used to avoid using
558 * @param string $haystack
559 * @param string $start
562 * @return bool|string
564 public function _substring_between(&$haystack, $start, $end) {
565 if (strpos($haystack, $start) === FALSE ||
strpos($haystack, $end) === FALSE) {
569 $start_position = strpos($haystack, $start) +
strlen($start);
570 $end_position = strpos($haystack, $end);
571 return substr($haystack, $start_position, $end_position - $start_position);
576 * Get the value of a field if set.
578 * @param string $field
581 * @param bool $xmlSafe
583 * value of the field, or empty string if the field is
586 public function _getParam($field, $xmlSafe = FALSE) {
587 $value = CRM_Utils_Array
::value($field, $this->_params
, '');
589 $value = str_replace(array('&', '"', "'", '<', '>'), '', $value);
595 * @param null $errorCode
596 * @param null $errorMessage
600 public function &error($errorCode = NULL, $errorMessage = NULL) {
601 $e = CRM_Core_Error
::singleton();
603 $e->push($errorCode, 0, array(), $errorMessage);
606 $e->push(9001, 0, array(), 'Unknown System Error.');
612 * Set a field to the specified value. Value must be a scalar (int,
613 * float, string, or boolean)
615 * @param string $field
616 * @param mixed $value
619 * false if value is not a scalar, true if successful
621 public function _setParam($field, $value) {
622 if (!is_scalar($value)) {
626 $this->_params
[$field] = $value;
631 * This function checks to see if we have the right config values.
634 * the error message if any
636 public function checkConfig() {
638 if (empty($this->_paymentProcessor
['user_name'])) {
639 $error[] = ts('APILogin is not set for this payment processor');
642 if (empty($this->_paymentProcessor
['password'])) {
643 $error[] = ts('Key is not set for this payment processor');
646 if (!empty($error)) {
647 return implode('<p>', $error);
657 public function accountLoginURL() {
658 return ($this->_mode
== 'test') ?
'https://test.authorize.net' : 'https://authorize.net';
662 * @param string $message
663 * @param array $params
665 * @return bool|object
667 public function cancelSubscription(&$message = '', $params = array()) {
668 $template = CRM_Core_Smarty
::singleton();
670 $template->assign('subscriptionType', 'cancel');
672 $template->assign('apiLogin', $this->_getParam('apiLogin'));
673 $template->assign('paymentKey', $this->_getParam('paymentKey'));
674 $template->assign('subscriptionId', CRM_Utils_Array
::value('subscriptionId', $params));
676 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
678 // submit to authorize.net
679 $submit = curl_init($this->_paymentProcessor
['url_recur']);
681 return self
::error(9002, 'Could not initiate connection to payment gateway');
684 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
685 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
686 curl_setopt($submit, CURLOPT_HEADER
, 1);
687 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
688 curl_setopt($submit, CURLOPT_POST
, 1);
689 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, Civi
::settings()->get('verifySSL'));
691 $response = curl_exec($submit);
694 return self
::error(curl_errno($submit), curl_error($submit));
699 $responseFields = $this->_ParseArbReturn($response);
700 $message = "{$responseFields['code']}: {$responseFields['text']}";
702 if ($responseFields['resultCode'] == 'Error') {
703 return self
::error($responseFields['code'], $responseFields['text']);
709 * @param string $message
710 * @param array $params
712 * @return bool|object
714 public function updateSubscriptionBillingInfo(&$message = '', $params = array()) {
715 $template = CRM_Core_Smarty
::singleton();
716 $template->assign('subscriptionType', 'updateBilling');
718 $template->assign('apiLogin', $this->_getParam('apiLogin'));
719 $template->assign('paymentKey', $this->_getParam('paymentKey'));
720 $template->assign('subscriptionId', $params['subscriptionId']);
722 $template->assign('cardNumber', $params['credit_card_number']);
723 $exp_month = str_pad($params['month'], 2, '0', STR_PAD_LEFT
);
724 $exp_year = $params['year'];
725 $template->assign('expirationDate', $exp_year . '-' . $exp_month);
727 $template->assign('billingFirstName', $params['first_name']);
728 $template->assign('billingLastName', $params['last_name']);
729 $template->assign('billingAddress', $params['street_address']);
730 $template->assign('billingCity', $params['city']);
731 $template->assign('billingState', $params['state_province']);
732 $template->assign('billingZip', $params['postal_code']);
733 $template->assign('billingCountry', $params['country']);
735 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
737 // submit to authorize.net
738 $submit = curl_init($this->_paymentProcessor
['url_recur']);
740 return self
::error(9002, 'Could not initiate connection to payment gateway');
743 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
744 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
745 curl_setopt($submit, CURLOPT_HEADER
, 1);
746 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
747 curl_setopt($submit, CURLOPT_POST
, 1);
748 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, Civi
::settings()->get('verifySSL'));
750 $response = curl_exec($submit);
753 return self
::error(curl_errno($submit), curl_error($submit));
758 $responseFields = $this->_ParseArbReturn($response);
759 $message = "{$responseFields['code']}: {$responseFields['text']}";
761 if ($responseFields['resultCode'] == 'Error') {
762 return self
::error($responseFields['code'], $responseFields['text']);
768 * Process incoming notification.
770 static public function handlePaymentNotification() {
771 $ipnClass = new CRM_Core_Payment_AuthorizeNetIPN(array_merge($_GET, $_REQUEST));
776 * @param string $message
777 * @param array $params
779 * @return bool|object
781 public function changeSubscriptionAmount(&$message = '', $params = array()) {
782 $template = CRM_Core_Smarty
::singleton();
784 $template->assign('subscriptionType', 'update');
786 $template->assign('apiLogin', $this->_getParam('apiLogin'));
787 $template->assign('paymentKey', $this->_getParam('paymentKey'));
789 $template->assign('subscriptionId', $params['subscriptionId']);
791 // for open ended subscription totalOccurrences has to be 9999
792 $installments = empty($params['installments']) ?
9999 : $params['installments'];
793 $template->assign('totalOccurrences', $installments);
795 $template->assign('amount', $params['amount']);
797 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
799 // submit to authorize.net
800 $submit = curl_init($this->_paymentProcessor
['url_recur']);
802 return self
::error(9002, 'Could not initiate connection to payment gateway');
805 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
806 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
807 curl_setopt($submit, CURLOPT_HEADER
, 1);
808 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
809 curl_setopt($submit, CURLOPT_POST
, 1);
810 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, Civi
::settings()->get('verifySSL'));
812 $response = curl_exec($submit);
815 return self
::error(curl_errno($submit), curl_error($submit));
820 $responseFields = $this->_parseArbReturn($response);
821 $message = "{$responseFields['code']}: {$responseFields['text']}";
823 if ($responseFields['resultCode'] == 'Error') {
824 return self
::error($responseFields['code'], $responseFields['text']);