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 TIMEZONE
= 'America/Denver';
28 protected $_mode = NULL;
30 protected $_params = array();
33 * We only need one instance of this object. So we use the singleton
34 * pattern and cache the instance in this variable
38 static private $_singleton = NULL;
44 * The mode of operation: live or test.
46 * @param $paymentProcessor
48 * @return \CRM_Core_Payment_AuthorizeNet
50 public function __construct($mode, &$paymentProcessor) {
52 $this->_paymentProcessor
= $paymentProcessor;
53 $this->_processorName
= ts('Authorize.net');
55 $config = CRM_Core_Config
::singleton();
56 $this->_setParam('apiLogin', $paymentProcessor['user_name']);
57 $this->_setParam('paymentKey', $paymentProcessor['password']);
58 $this->_setParam('paymentType', 'AIM');
59 $this->_setParam('md5Hash', $paymentProcessor['signature']);
61 $this->_setParam('emailCustomer', 'TRUE');
62 $this->_setParam('timestamp', time());
64 $this->_setParam('sequence', rand(1, 1000));
68 * Should the first payment date be configurable when setting up back office recurring payments.
69 * In the case of Authorize.net this is an option
72 protected function supportsFutureRecurStartDate() {
77 * Can recurring contributions be set against pledges.
79 * In practice all processors that use the baseIPN function to finish transactions or
80 * call the completetransaction api support this by looking up previous contributions in the
81 * series and, if there is a prior contribution against a pledge, and the pledge is not complete,
82 * adding the new payment to the pledge.
84 * However, only enabling for processors it has been tested against.
88 protected function supportsRecurContributionsForPledges() {
93 * Submit a payment using Advanced Integration Method.
95 * @param array $params
96 * Assoc array of input parameters for this transaction.
99 * the result in a nice formatted array (or an error object)
101 public function doDirectPayment(&$params) {
102 if (!defined('CURLOPT_SSLCERT')) {
103 return self
::error(9001, 'Authorize.Net requires curl with SSL support');
107 * recurpayment function does not compile an array & then proces it -
108 * - the tpl does the transformation so adding call to hook here
109 * & giving it a change to act on the params array
111 $newParams = $params;
112 if (!empty($params['is_recur']) && !empty($params['contributionRecurID'])) {
113 CRM_Utils_Hook
::alterPaymentProcessorParams($this,
118 foreach ($newParams as $field => $value) {
119 $this->_setParam($field, $value);
122 if (!empty($params['is_recur']) && !empty($params['contributionRecurID'])) {
123 $result = $this->doRecurPayment();
124 if (is_a($result, 'CRM_Core_Error')) {
130 $postFields = array();
131 $authorizeNetFields = $this->_getAuthorizeNetFields();
133 // Set up our call for hook_civicrm_paymentProcessor,
134 // since we now have our parameters as assigned for the AIM back end.
135 CRM_Utils_Hook
::alterPaymentProcessorParams($this,
140 foreach ($authorizeNetFields as $field => $value) {
141 // CRM-7419, since double quote is used as enclosure while doing csv parsing
142 $value = ($field == 'x_description') ?
str_replace('"', "'", $value) : $value;
143 $postFields[] = $field . '=' . urlencode($value);
146 // Authorize.Net will not refuse duplicates, so we should check if the user already submitted this transaction
147 if ($this->_checkDupe($authorizeNetFields['x_invoice_num'])) {
148 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.');
151 $submit = curl_init($this->_paymentProcessor
['url_site']);
154 return self
::error(9002, 'Could not initiate connection to payment gateway');
157 curl_setopt($submit, CURLOPT_POST
, TRUE);
158 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, TRUE);
159 curl_setopt($submit, CURLOPT_POSTFIELDS
, implode('&', $postFields));
160 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
162 $response = curl_exec($submit);
165 return self
::error(curl_errno($submit), curl_error($submit));
170 $response_fields = $this->explode_csv($response);
172 // check gateway MD5 response
173 if (!$this->checkMD5($response_fields[37], $response_fields[6], $response_fields[9])) {
174 return self
::error(9003, 'MD5 Verification failed');
177 // check for application errors
179 // AVS, CVV2, CAVV, and other verification results
180 if ($response_fields[0] != self
::AUTH_APPROVED
) {
181 $errormsg = $response_fields[2] . ' ' . $response_fields[3];
182 return self
::error($response_fields[1], $errormsg);
187 // test mode always returns trxn_id = 0
188 // also live mode in CiviCRM with test mode set in
189 // Authorize.Net return $response_fields[6] = 0
190 // hence treat that also as test mode transaction
192 if (($this->_mode
== 'test') ||
$response_fields[6] == 0) {
193 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id RLIKE 'test[0-9]+'";
195 $trxn_id = strval(CRM_Core_DAO
::singleValueQuery($query, $p));
196 $trxn_id = str_replace('test', '', $trxn_id);
197 $trxn_id = intval($trxn_id) +
1;
198 $params['trxn_id'] = sprintf('test%08d', $trxn_id);
201 $params['trxn_id'] = $response_fields[6];
203 $params['gross_amount'] = $response_fields[9];
204 // TODO: include authorization code?
210 * Submit an Automated Recurring Billing subscription.
212 public function doRecurPayment() {
213 $template = CRM_Core_Smarty
::singleton();
215 $intervalLength = $this->_getParam('frequency_interval');
216 $intervalUnit = $this->_getParam('frequency_unit');
217 if ($intervalUnit == 'week') {
218 $intervalLength *= 7;
219 $intervalUnit = 'days';
221 elseif ($intervalUnit == 'year') {
222 $intervalLength *= 12;
223 $intervalUnit = 'months';
225 elseif ($intervalUnit == 'day') {
226 $intervalUnit = 'days';
228 elseif ($intervalUnit == 'month') {
229 $intervalUnit = 'months';
232 // interval cannot be less than 7 days or more than 1 year
233 if ($intervalUnit == 'days') {
234 if ($intervalLength < 7) {
235 return self
::error(9001, 'Payment interval must be at least one week');
237 elseif ($intervalLength > 365) {
238 return self
::error(9001, 'Payment interval may not be longer than one year');
241 elseif ($intervalUnit == 'months') {
242 if ($intervalLength < 1) {
243 return self
::error(9001, 'Payment interval must be at least one week');
245 elseif ($intervalLength > 12) {
246 return self
::error(9001, 'Payment interval may not be longer than one year');
250 $template->assign('intervalLength', $intervalLength);
251 $template->assign('intervalUnit', $intervalUnit);
253 $template->assign('apiLogin', $this->_getParam('apiLogin'));
254 $template->assign('paymentKey', $this->_getParam('paymentKey'));
255 $template->assign('refId', substr($this->_getParam('invoiceID'), 0, 20));
257 //for recurring, carry first contribution id
258 $template->assign('invoiceNumber', $this->_getParam('contributionID'));
259 $firstPaymentDate = $this->_getParam('receive_date');
260 if (!empty($firstPaymentDate)) {
261 //allow for post dated payment if set in form
262 $startDate = date_create($firstPaymentDate);
265 $startDate = date_create();
267 /* Format start date in Mountain Time to avoid Authorize.net error E00017
268 * we do this only if the day we are setting our start time to is LESS than the current
269 * day in mountaintime (ie. the server time of the A-net server). A.net won't accept a date
270 * earlier than the current date on it's server so if we are in PST we might need to use mountain
271 * time to bring our date forward. But if we are submitting something future dated we want
272 * the date we entered to be respected
274 $minDate = date_create('now', new DateTimeZone(self
::TIMEZONE
));
275 if (strtotime($startDate->format('Y-m-d')) < strtotime($minDate->format('Y-m-d'))) {
276 $startDate->setTimezone(new DateTimeZone(self
::TIMEZONE
));
279 $template->assign('startDate', $startDate->format('Y-m-d'));
281 $installments = $this->_getParam('installments');
283 // for open ended subscription totalOccurrences has to be 9999
284 $installments = empty($installments) ?
9999 : $installments;
285 $template->assign('totalOccurrences', $installments);
287 $template->assign('amount', $this->_getParam('amount'));
289 $template->assign('cardNumber', $this->_getParam('credit_card_number'));
290 $exp_month = str_pad($this->_getParam('month'), 2, '0', STR_PAD_LEFT
);
291 $exp_year = $this->_getParam('year');
292 $template->assign('expirationDate', $exp_year . '-' . $exp_month);
294 // name rather than description is used in the tpl - see http://www.authorize.net/support/ARB_guide.pdf
295 $template->assign('name', $this->_getParam('description', TRUE));
297 $template->assign('email', $this->_getParam('email'));
298 $template->assign('contactID', $this->_getParam('contactID'));
299 $template->assign('billingFirstName', $this->_getParam('billing_first_name'));
300 $template->assign('billingLastName', $this->_getParam('billing_last_name'));
301 $template->assign('billingAddress', $this->_getParam('street_address', TRUE));
302 $template->assign('billingCity', $this->_getParam('city', TRUE));
303 $template->assign('billingState', $this->_getParam('state_province'));
304 $template->assign('billingZip', $this->_getParam('postal_code', TRUE));
305 $template->assign('billingCountry', $this->_getParam('country'));
307 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
308 // submit to authorize.net
310 $submit = curl_init($this->_paymentProcessor
['url_recur']);
312 return self
::error(9002, 'Could not initiate connection to payment gateway');
314 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
315 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
316 curl_setopt($submit, CURLOPT_HEADER
, 1);
317 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
318 curl_setopt($submit, CURLOPT_POST
, 1);
319 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
321 $response = curl_exec($submit);
324 return self
::error(curl_errno($submit), curl_error($submit));
328 $responseFields = $this->_ParseArbReturn($response);
330 if ($responseFields['resultCode'] == 'Error') {
331 return self
::error($responseFields['code'], $responseFields['text']);
334 // update recur processor_id with subscriptionId
335 CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_ContributionRecur', $this->_getParam('contributionRecurID'),
336 'processor_id', $responseFields['subscriptionId']
338 //only impact of assigning this here is is can be used to cancel the subscription in an automated test
339 // if it isn't cancelled a duplicate transaction error occurs
340 if (!empty($responseFields['subscriptionId'])) {
341 $this->_setParam('subscriptionId', $responseFields['subscriptionId']);
348 public function _getAuthorizeNetFields() {
349 $amount = $this->_getParam('total_amount');//Total amount is from the form contribution field
350 if (empty($amount)) {//CRM-9894 would this ever be the case??
351 $amount = $this->_getParam('amount');
354 $fields['x_login'] = $this->_getParam('apiLogin');
355 $fields['x_tran_key'] = $this->_getParam('paymentKey');
356 $fields['x_email_customer'] = $this->_getParam('emailCustomer');
357 $fields['x_first_name'] = $this->_getParam('billing_first_name');
358 $fields['x_last_name'] = $this->_getParam('billing_last_name');
359 $fields['x_address'] = $this->_getParam('street_address');
360 $fields['x_city'] = $this->_getParam('city');
361 $fields['x_state'] = $this->_getParam('state_province');
362 $fields['x_zip'] = $this->_getParam('postal_code');
363 $fields['x_country'] = $this->_getParam('country');
364 $fields['x_customer_ip'] = $this->_getParam('ip_address');
365 $fields['x_email'] = $this->_getParam('email');
366 $fields['x_invoice_num'] = substr($this->_getParam('invoiceID'), 0, 20);
367 $fields['x_amount'] = $amount;
368 $fields['x_currency_code'] = $this->_getParam('currencyID');
369 $fields['x_description'] = $this->_getParam('description');
370 $fields['x_cust_id'] = $this->_getParam('contactID');
371 if ($this->_getParam('paymentType') == 'AIM') {
372 $fields['x_relay_response'] = 'FALSE';
373 // request response in CSV format
374 $fields['x_delim_data'] = 'TRUE';
375 $fields['x_delim_char'] = ',';
376 $fields['x_encap_char'] = '"';
378 $fields['x_card_num'] = $this->_getParam('credit_card_number');
379 $fields['x_card_code'] = $this->_getParam('cvv2');
380 $exp_month = str_pad($this->_getParam('month'), 2, '0', STR_PAD_LEFT
);
381 $exp_year = $this->_getParam('year');
382 $fields['x_exp_date'] = "$exp_month/$exp_year";
385 if ($this->_mode
!= 'live') {
386 $fields['x_test_request'] = 'TRUE';
393 * Checks to see if invoice_id already exists in db.
395 * @param int $invoiceId
399 * True if ID exists, else false
401 public function _checkDupe($invoiceId) {
402 $contribution = new CRM_Contribute_DAO_Contribution();
403 $contribution->invoice_id
= $invoiceId;
404 return $contribution->find();
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 public function _substring_between(&$haystack, $start, $end) {
559 if (strpos($haystack, $start) === FALSE ||
strpos($haystack, $end) === FALSE) {
563 $start_position = strpos($haystack, $start) +
strlen($start);
564 $end_position = strpos($haystack, $end);
565 return substr($haystack, $start_position, $end_position - $start_position);
570 * Get the value of a field if set.
572 * @param string $field
575 * @param bool $xmlSafe
577 * value of the field, or empty string if the field is
580 public function _getParam($field, $xmlSafe = FALSE) {
581 $value = CRM_Utils_Array
::value($field, $this->_params
, '');
583 $value = str_replace(array('&', '"', "'", '<', '>'), '', $value);
589 * @param null $errorCode
590 * @param null $errorMessage
594 public function &error($errorCode = NULL, $errorMessage = NULL) {
595 $e = CRM_Core_Error
::singleton();
597 $e->push($errorCode, 0, array(), $errorMessage);
600 $e->push(9001, 0, array(), 'Unknown System Error.');
606 * Set a field to the specified value. Value must be a scalar (int,
607 * float, string, or boolean)
609 * @param string $field
610 * @param mixed $value
613 * false if value is not a scalar, true if successful
615 public function _setParam($field, $value) {
616 if (!is_scalar($value)) {
620 $this->_params
[$field] = $value;
625 * This function checks to see if we have the right config values.
628 * the error message if any
630 public function checkConfig() {
632 if (empty($this->_paymentProcessor
['user_name'])) {
633 $error[] = ts('APILogin is not set for this payment processor');
636 if (empty($this->_paymentProcessor
['password'])) {
637 $error[] = ts('Key is not set for this payment processor');
640 if (!empty($error)) {
641 return implode('<p>', $error);
651 public function accountLoginURL() {
652 return ($this->_mode
== 'test') ?
'https://test.authorize.net' : 'https://authorize.net';
656 * @param string $message
657 * @param array $params
659 * @return bool|object
661 public function cancelSubscription(&$message = '', $params = array()) {
662 $template = CRM_Core_Smarty
::singleton();
664 $template->assign('subscriptionType', 'cancel');
666 $template->assign('apiLogin', $this->_getParam('apiLogin'));
667 $template->assign('paymentKey', $this->_getParam('paymentKey'));
668 $template->assign('subscriptionId', CRM_Utils_Array
::value('subscriptionId', $params));
670 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
672 // submit to authorize.net
673 $submit = curl_init($this->_paymentProcessor
['url_recur']);
675 return self
::error(9002, 'Could not initiate connection to payment gateway');
678 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
679 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
680 curl_setopt($submit, CURLOPT_HEADER
, 1);
681 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
682 curl_setopt($submit, CURLOPT_POST
, 1);
683 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
685 $response = curl_exec($submit);
688 return self
::error(curl_errno($submit), curl_error($submit));
693 $responseFields = $this->_ParseArbReturn($response);
694 $message = "{$responseFields['code']}: {$responseFields['text']}";
696 if ($responseFields['resultCode'] == 'Error') {
697 return self
::error($responseFields['code'], $responseFields['text']);
703 * @param string $message
704 * @param array $params
706 * @return bool|object
708 public function updateSubscriptionBillingInfo(&$message = '', $params = array()) {
709 $template = CRM_Core_Smarty
::singleton();
710 $template->assign('subscriptionType', 'updateBilling');
712 $template->assign('apiLogin', $this->_getParam('apiLogin'));
713 $template->assign('paymentKey', $this->_getParam('paymentKey'));
714 $template->assign('subscriptionId', $params['subscriptionId']);
716 $template->assign('cardNumber', $params['credit_card_number']);
717 $exp_month = str_pad($params['month'], 2, '0', STR_PAD_LEFT
);
718 $exp_year = $params['year'];
719 $template->assign('expirationDate', $exp_year . '-' . $exp_month);
721 $template->assign('billingFirstName', $params['first_name']);
722 $template->assign('billingLastName', $params['last_name']);
723 $template->assign('billingAddress', $params['street_address']);
724 $template->assign('billingCity', $params['city']);
725 $template->assign('billingState', $params['state_province']);
726 $template->assign('billingZip', $params['postal_code']);
727 $template->assign('billingCountry', $params['country']);
729 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
731 // submit to authorize.net
732 $submit = curl_init($this->_paymentProcessor
['url_recur']);
734 return self
::error(9002, 'Could not initiate connection to payment gateway');
737 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
738 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
739 curl_setopt($submit, CURLOPT_HEADER
, 1);
740 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
741 curl_setopt($submit, CURLOPT_POST
, 1);
742 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
744 $response = curl_exec($submit);
747 return self
::error(curl_errno($submit), curl_error($submit));
752 $responseFields = $this->_ParseArbReturn($response);
753 $message = "{$responseFields['code']}: {$responseFields['text']}";
755 if ($responseFields['resultCode'] == 'Error') {
756 return self
::error($responseFields['code'], $responseFields['text']);
762 * Process incoming notification.
764 static public function handlePaymentNotification() {
765 $ipnClass = new CRM_Core_Payment_AuthorizeNetIPN(array_merge($_GET, $_REQUEST));
770 * @param string $message
771 * @param array $params
773 * @return bool|object
775 public function changeSubscriptionAmount(&$message = '', $params = array()) {
776 $template = CRM_Core_Smarty
::singleton();
778 $template->assign('subscriptionType', 'update');
780 $template->assign('apiLogin', $this->_getParam('apiLogin'));
781 $template->assign('paymentKey', $this->_getParam('paymentKey'));
783 $template->assign('subscriptionId', $params['subscriptionId']);
785 // for open ended subscription totalOccurrences has to be 9999
786 $installments = empty($params['installments']) ?
9999 : $params['installments'];
787 $template->assign('totalOccurrences', $installments);
789 $template->assign('amount', $params['amount']);
791 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
793 // submit to authorize.net
794 $submit = curl_init($this->_paymentProcessor
['url_recur']);
796 return self
::error(9002, 'Could not initiate connection to payment gateway');
799 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
800 curl_setopt($submit, CURLOPT_HTTPHEADER
, array("Content-Type: text/xml"));
801 curl_setopt($submit, CURLOPT_HEADER
, 1);
802 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
803 curl_setopt($submit, CURLOPT_POST
, 1);
804 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
806 $response = curl_exec($submit);
809 return self
::error(curl_errno($submit), curl_error($submit));
814 $responseFields = $this->_ParseArbReturn($response);
815 $message = "{$responseFields['code']}: {$responseFields['text']}";
817 if ($responseFields['resultCode'] == 'Error') {
818 return self
::error($responseFields['code'], $responseFields['text']);