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 = [];
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')) {
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 for application errors
176 // AVS, CVV2, CAVV, and other verification results
177 switch ($response_fields[0]) {
178 case self
::AUTH_REVIEW
:
179 $params['payment_status_id'] = array_search('Pending', $contributionStatus);
182 case self
::AUTH_ERROR
:
183 $params['payment_status_id'] = array_search('Failed', $contributionStatus);
184 $errormsg = $response_fields[2] . ' ' . $response_fields[3];
185 return self
::error($response_fields[1], $errormsg);
187 case self
::AUTH_DECLINED
:
188 $errormsg = $response_fields[2] . ' ' . $response_fields[3];
189 return self
::error($response_fields[1], $errormsg);
194 // test mode always returns trxn_id = 0
195 // also live mode in CiviCRM with test mode set in
196 // Authorize.Net return $response_fields[6] = 0
197 // hence treat that also as test mode transaction
199 if (($this->_mode
== 'test') ||
$response_fields[6] == 0) {
200 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id RLIKE 'test[0-9]+'";
202 $trxn_id = strval(CRM_Core_DAO
::singleValueQuery($query, $p));
203 $trxn_id = str_replace('test', '', $trxn_id);
204 $trxn_id = intval($trxn_id) +
1;
205 $params['trxn_id'] = sprintf('test%08d', $trxn_id);
208 $params['trxn_id'] = $response_fields[6];
210 $params['gross_amount'] = $response_fields[9];
213 // TODO: include authorization code?
219 * Submit an Automated Recurring Billing subscription.
221 public function doRecurPayment() {
222 $template = CRM_Core_Smarty
::singleton();
224 $intervalLength = $this->_getParam('frequency_interval');
225 $intervalUnit = $this->_getParam('frequency_unit');
226 if ($intervalUnit == 'week') {
227 $intervalLength *= 7;
228 $intervalUnit = 'days';
230 elseif ($intervalUnit == 'year') {
231 $intervalLength *= 12;
232 $intervalUnit = 'months';
234 elseif ($intervalUnit == 'day') {
235 $intervalUnit = 'days';
237 elseif ($intervalUnit == 'month') {
238 $intervalUnit = 'months';
241 // interval cannot be less than 7 days or more than 1 year
242 if ($intervalUnit == 'days') {
243 if ($intervalLength < 7) {
244 return self
::error(9001, 'Payment interval must be at least one week');
246 elseif ($intervalLength > 365) {
247 return self
::error(9001, 'Payment interval may not be longer than one year');
250 elseif ($intervalUnit == 'months') {
251 if ($intervalLength < 1) {
252 return self
::error(9001, 'Payment interval must be at least one week');
254 elseif ($intervalLength > 12) {
255 return self
::error(9001, 'Payment interval may not be longer than one year');
259 $template->assign('intervalLength', $intervalLength);
260 $template->assign('intervalUnit', $intervalUnit);
262 $template->assign('apiLogin', $this->_getParam('apiLogin'));
263 $template->assign('paymentKey', $this->_getParam('paymentKey'));
264 $template->assign('refId', substr($this->_getParam('invoiceID'), 0, 20));
266 //for recurring, carry first contribution id
267 $template->assign('invoiceNumber', $this->_getParam('contributionID'));
268 $firstPaymentDate = $this->_getParam('receive_date');
269 if (!empty($firstPaymentDate)) {
270 //allow for post dated payment if set in form
271 $startDate = date_create($firstPaymentDate);
274 $startDate = date_create();
276 /* Format start date in Mountain Time to avoid Authorize.net error E00017
277 * we do this only if the day we are setting our start time to is LESS than the current
278 * day in mountaintime (ie. the server time of the A-net server). A.net won't accept a date
279 * earlier than the current date on it's server so if we are in PST we might need to use mountain
280 * time to bring our date forward. But if we are submitting something future dated we want
281 * the date we entered to be respected
283 $minDate = date_create('now', new DateTimeZone(self
::TIMEZONE
));
284 if (strtotime($startDate->format('Y-m-d')) < strtotime($minDate->format('Y-m-d'))) {
285 $startDate->setTimezone(new DateTimeZone(self
::TIMEZONE
));
288 $template->assign('startDate', $startDate->format('Y-m-d'));
290 $installments = $this->_getParam('installments');
292 // for open ended subscription totalOccurrences has to be 9999
293 $installments = empty($installments) ?
9999 : $installments;
294 $template->assign('totalOccurrences', $installments);
296 $template->assign('amount', $this->_getParam('amount'));
298 $template->assign('cardNumber', $this->_getParam('credit_card_number'));
299 $exp_month = str_pad($this->_getParam('month'), 2, '0', STR_PAD_LEFT
);
300 $exp_year = $this->_getParam('year');
301 $template->assign('expirationDate', $exp_year . '-' . $exp_month);
303 // name rather than description is used in the tpl - see http://www.authorize.net/support/ARB_guide.pdf
304 $template->assign('name', $this->_getParam('description', TRUE));
306 $template->assign('email', $this->_getParam('email'));
307 $template->assign('contactID', $this->_getParam('contactID'));
308 $template->assign('billingFirstName', $this->_getParam('billing_first_name'));
309 $template->assign('billingLastName', $this->_getParam('billing_last_name'));
310 $template->assign('billingAddress', $this->_getParam('street_address', TRUE));
311 $template->assign('billingCity', $this->_getParam('city', TRUE));
312 $template->assign('billingState', $this->_getParam('state_province'));
313 $template->assign('billingZip', $this->_getParam('postal_code', TRUE));
314 $template->assign('billingCountry', $this->_getParam('country'));
316 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
317 // submit to authorize.net
319 $submit = curl_init($this->_paymentProcessor
['url_recur']);
321 return self
::error(9002, 'Could not initiate connection to payment gateway');
323 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
324 curl_setopt($submit, CURLOPT_HTTPHEADER
, ["Content-Type: text/xml"]);
325 curl_setopt($submit, CURLOPT_HEADER
, 1);
326 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
327 curl_setopt($submit, CURLOPT_POST
, 1);
328 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, Civi
::settings()->get('verifySSL'));
330 $response = curl_exec($submit);
333 return self
::error(curl_errno($submit), curl_error($submit));
337 $responseFields = $this->_ParseArbReturn($response);
339 if ($responseFields['resultCode'] == 'Error') {
340 return self
::error($responseFields['code'], $responseFields['text']);
343 // update recur processor_id with subscriptionId
344 CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_ContributionRecur', $this->_getParam('contributionRecurID'),
345 'processor_id', $responseFields['subscriptionId']
347 //only impact of assigning this here is is can be used to cancel the subscription in an automated test
348 // if it isn't cancelled a duplicate transaction error occurs
349 if (!empty($responseFields['subscriptionId'])) {
350 $this->_setParam('subscriptionId', $responseFields['subscriptionId']);
357 public function _getAuthorizeNetFields() {
358 //Total amount is from the form contribution field
359 $amount = $this->_getParam('total_amount');
360 //CRM-9894 would this ever be the case??
361 if (empty($amount)) {
362 $amount = $this->_getParam('amount');
365 $fields['x_login'] = $this->_getParam('apiLogin');
366 $fields['x_tran_key'] = $this->_getParam('paymentKey');
367 $fields['x_email_customer'] = $this->_getParam('emailCustomer');
368 $fields['x_first_name'] = $this->_getParam('billing_first_name');
369 $fields['x_last_name'] = $this->_getParam('billing_last_name');
370 $fields['x_address'] = $this->_getParam('street_address');
371 $fields['x_city'] = $this->_getParam('city');
372 $fields['x_state'] = $this->_getParam('state_province');
373 $fields['x_zip'] = $this->_getParam('postal_code');
374 $fields['x_country'] = $this->_getParam('country');
375 $fields['x_customer_ip'] = $this->_getParam('ip_address');
376 $fields['x_email'] = $this->_getParam('email');
377 $fields['x_invoice_num'] = $this->_getParam('invoiceID');
378 $fields['x_amount'] = $amount;
379 $fields['x_currency_code'] = $this->_getParam('currencyID');
380 $fields['x_description'] = $this->_getParam('description');
381 $fields['x_cust_id'] = $this->_getParam('contactID');
382 if ($this->_getParam('paymentType') == 'AIM') {
383 $fields['x_relay_response'] = 'FALSE';
384 // request response in CSV format
385 $fields['x_delim_data'] = 'TRUE';
386 $fields['x_delim_char'] = ',';
387 $fields['x_encap_char'] = '"';
389 $fields['x_card_num'] = $this->_getParam('credit_card_number');
390 $fields['x_card_code'] = $this->_getParam('cvv2');
391 $exp_month = str_pad($this->_getParam('month'), 2, '0', STR_PAD_LEFT
);
392 $exp_year = $this->_getParam('year');
393 $fields['x_exp_date'] = "$exp_month/$exp_year";
396 if ($this->_mode
!= 'live') {
397 $fields['x_test_request'] = 'TRUE';
407 * @param string $data
410 * the HMAC_MD5 encoding string
412 public function hmac($key, $data) {
413 if (function_exists('mhash')) {
414 // Use PHP mhash extension
415 return (bin2hex(mhash(MHASH_MD5
, $data, $key)));
418 // RFC 2104 HMAC implementation for php.
419 // Creates an md5 HMAC.
420 // Eliminates the need to install mhash to compute a HMAC
421 // Hacked by Lance Rushing
422 // byte length for md5
424 if (strlen($key) > $b) {
425 $key = pack("H*", md5($key));
427 $key = str_pad($key, $b, chr(0x00));
428 $ipad = str_pad('', $b, chr(0x36));
429 $opad = str_pad('', $b, chr(0x5c));
430 $k_ipad = $key ^
$ipad;
431 $k_opad = $key ^
$opad;
432 return md5($k_opad . pack("H*", md5($k_ipad . $data)));
437 * Calculate and return the transaction fingerprint.
442 public function CalculateFP() {
443 $x_tran_key = $this->_getParam('paymentKey');
444 $loginid = $this->_getParam('apiLogin');
445 $sequence = $this->_getParam('sequence');
446 $timestamp = $this->_getParam('timestamp');
447 $amount = $this->_getParam('amount');
448 $currency = $this->_getParam('currencyID');
449 $transaction = "$loginid^$sequence^$timestamp^$amount^$currency";
450 return $this->hmac($x_tran_key, $transaction);
454 * Split a CSV file. Requires , as delimiter and " as enclosure.
455 * Based off notes from http://php.net/fgetcsv
457 * @param string $data
463 public function explode_csv($data) {
465 //make it easier to parse fields with quotes in them
466 $data = str_replace('""', "''", $data);
469 while ($data != '') {
471 if ($data[0] == '"') {
472 // handle quoted fields
473 preg_match('/^"(([^"]|\\")*?)",?(.*)$/', $data, $matches);
475 $fields[] = str_replace("''", '"', $matches[1]);
479 preg_match('/^([^,]*),?(.*)$/', $data, $matches);
481 $fields[] = $matches[1];
489 * Extract variables from returned XML.
491 * Function is from Authorize.Net sample code, and used
492 * to prevent the requirement of XML functions.
494 * @param string $content
495 * XML reply from Authorize.Net.
498 * refId, resultCode, code, text, subscriptionId
500 public function _parseArbReturn($content) {
501 $refId = $this->_substring_between($content, '<refId>', '</refId>');
502 $resultCode = $this->_substring_between($content, '<resultCode>', '</resultCode>');
503 $code = $this->_substring_between($content, '<code>', '</code>');
504 $text = $this->_substring_between($content, '<text>', '</text>');
505 $subscriptionId = $this->_substring_between($content, '<subscriptionId>', '</subscriptionId>');
508 'resultCode' => $resultCode,
511 'subscriptionId' => $subscriptionId,
516 * Helper function for _parseArbReturn.
518 * Function is from Authorize.Net sample code, and used to avoid using
521 * @param string $haystack
522 * @param string $start
525 * @return bool|string
527 public function _substring_between(&$haystack, $start, $end) {
528 if (strpos($haystack, $start) === FALSE ||
strpos($haystack, $end) === FALSE) {
532 $start_position = strpos($haystack, $start) +
strlen($start);
533 $end_position = strpos($haystack, $end);
534 return substr($haystack, $start_position, $end_position - $start_position);
539 * Get the value of a field if set.
541 * @param string $field
544 * @param bool $xmlSafe
546 * value of the field, or empty string if the field is
549 public function _getParam($field, $xmlSafe = FALSE) {
550 $value = CRM_Utils_Array
::value($field, $this->_params
, '');
552 $value = str_replace(['&', '"', "'", '<', '>'], '', $value);
558 * @param null $errorCode
559 * @param null $errorMessage
563 public function &error($errorCode = NULL, $errorMessage = NULL) {
564 $e = CRM_Core_Error
::singleton();
566 $e->push($errorCode, 0, [], $errorMessage);
569 $e->push(9001, 0, [], 'Unknown System Error.');
575 * Set a field to the specified value. Value must be a scalar (int,
576 * float, string, or boolean)
578 * @param string $field
579 * @param mixed $value
582 * false if value is not a scalar, true if successful
584 public function _setParam($field, $value) {
585 if (!is_scalar($value)) {
589 $this->_params
[$field] = $value;
594 * This function checks to see if we have the right config values.
597 * the error message if any
599 public function checkConfig() {
601 if (empty($this->_paymentProcessor
['user_name'])) {
602 $error[] = ts('APILogin is not set for this payment processor');
605 if (empty($this->_paymentProcessor
['password'])) {
606 $error[] = ts('Key is not set for this payment processor');
609 if (!empty($error)) {
610 return implode('<p>', $error);
620 public function accountLoginURL() {
621 return ($this->_mode
== 'test') ?
'https://test.authorize.net' : 'https://authorize.net';
625 * @param string $message
626 * @param array $params
628 * @return bool|object
630 public function cancelSubscription(&$message = '', $params = []) {
631 $template = CRM_Core_Smarty
::singleton();
633 $template->assign('subscriptionType', 'cancel');
635 $template->assign('apiLogin', $this->_getParam('apiLogin'));
636 $template->assign('paymentKey', $this->_getParam('paymentKey'));
637 $template->assign('subscriptionId', CRM_Utils_Array
::value('subscriptionId', $params));
639 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
641 // submit to authorize.net
642 $submit = curl_init($this->_paymentProcessor
['url_recur']);
644 return self
::error(9002, 'Could not initiate connection to payment gateway');
647 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
648 curl_setopt($submit, CURLOPT_HTTPHEADER
, ["Content-Type: text/xml"]);
649 curl_setopt($submit, CURLOPT_HEADER
, 1);
650 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
651 curl_setopt($submit, CURLOPT_POST
, 1);
652 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, Civi
::settings()->get('verifySSL'));
654 $response = curl_exec($submit);
657 return self
::error(curl_errno($submit), curl_error($submit));
662 $responseFields = $this->_ParseArbReturn($response);
663 $message = "{$responseFields['code']}: {$responseFields['text']}";
665 if ($responseFields['resultCode'] == 'Error') {
666 return self
::error($responseFields['code'], $responseFields['text']);
672 * @param string $message
673 * @param array $params
675 * @return bool|object
677 public function updateSubscriptionBillingInfo(&$message = '', $params = []) {
678 $template = CRM_Core_Smarty
::singleton();
679 $template->assign('subscriptionType', 'updateBilling');
681 $template->assign('apiLogin', $this->_getParam('apiLogin'));
682 $template->assign('paymentKey', $this->_getParam('paymentKey'));
683 $template->assign('subscriptionId', $params['subscriptionId']);
685 $template->assign('cardNumber', $params['credit_card_number']);
686 $exp_month = str_pad($params['month'], 2, '0', STR_PAD_LEFT
);
687 $exp_year = $params['year'];
688 $template->assign('expirationDate', $exp_year . '-' . $exp_month);
690 $template->assign('billingFirstName', $params['first_name']);
691 $template->assign('billingLastName', $params['last_name']);
692 $template->assign('billingAddress', $params['street_address']);
693 $template->assign('billingCity', $params['city']);
694 $template->assign('billingState', $params['state_province']);
695 $template->assign('billingZip', $params['postal_code']);
696 $template->assign('billingCountry', $params['country']);
698 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
700 // submit to authorize.net
701 $submit = curl_init($this->_paymentProcessor
['url_recur']);
703 return self
::error(9002, 'Could not initiate connection to payment gateway');
706 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
707 curl_setopt($submit, CURLOPT_HTTPHEADER
, ["Content-Type: text/xml"]);
708 curl_setopt($submit, CURLOPT_HEADER
, 1);
709 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
710 curl_setopt($submit, CURLOPT_POST
, 1);
711 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, Civi
::settings()->get('verifySSL'));
713 $response = curl_exec($submit);
716 return self
::error(curl_errno($submit), curl_error($submit));
721 $responseFields = $this->_ParseArbReturn($response);
722 $message = "{$responseFields['code']}: {$responseFields['text']}";
724 if ($responseFields['resultCode'] == 'Error') {
725 return self
::error($responseFields['code'], $responseFields['text']);
731 * Process incoming notification.
733 public static function handlePaymentNotification() {
734 $ipnClass = new CRM_Core_Payment_AuthorizeNetIPN(array_merge($_GET, $_REQUEST));
739 * @param string $message
740 * @param array $params
742 * @return bool|object
744 public function changeSubscriptionAmount(&$message = '', $params = []) {
745 $template = CRM_Core_Smarty
::singleton();
747 $template->assign('subscriptionType', 'update');
749 $template->assign('apiLogin', $this->_getParam('apiLogin'));
750 $template->assign('paymentKey', $this->_getParam('paymentKey'));
752 $template->assign('subscriptionId', $params['subscriptionId']);
754 // for open ended subscription totalOccurrences has to be 9999
755 $installments = empty($params['installments']) ?
9999 : $params['installments'];
756 $template->assign('totalOccurrences', $installments);
758 $template->assign('amount', $params['amount']);
760 $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
762 // submit to authorize.net
763 $submit = curl_init($this->_paymentProcessor
['url_recur']);
765 return self
::error(9002, 'Could not initiate connection to payment gateway');
768 curl_setopt($submit, CURLOPT_RETURNTRANSFER
, 1);
769 curl_setopt($submit, CURLOPT_HTTPHEADER
, ["Content-Type: text/xml"]);
770 curl_setopt($submit, CURLOPT_HEADER
, 1);
771 curl_setopt($submit, CURLOPT_POSTFIELDS
, $arbXML);
772 curl_setopt($submit, CURLOPT_POST
, 1);
773 curl_setopt($submit, CURLOPT_SSL_VERIFYPEER
, Civi
::settings()->get('verifySSL'));
775 $response = curl_exec($submit);
778 return self
::error(curl_errno($submit), curl_error($submit));
783 $responseFields = $this->_parseArbReturn($response);
784 $message = "{$responseFields['code']}: {$responseFields['text']}";
786 if ($responseFields['resultCode'] == 'Error') {
787 return self
::error($responseFields['code'], $responseFields['text']);