3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Core_Payment_PayPalImpl
extends CRM_Core_Payment
{
36 const CHARSET
= 'iso-8859-1';
38 protected $_mode = NULL;
41 * We only need one instance of this object. So we use the singleton
42 * pattern and cache the instance in this variable
47 static private $_singleton = NULL;
53 * The mode of operation: live or test.
55 * @param $paymentProcessor
57 * @return \CRM_Core_Payment_PayPalImpl
59 public function __construct($mode, &$paymentProcessor) {
61 $this->_paymentProcessor
= $paymentProcessor;
62 $this->_processorName
= ts('PayPal Pro');
63 $paymentProcessorType = CRM_Core_PseudoConstant
::paymentProcessorType(FALSE, NULL, 'name');
65 if ($this->_paymentProcessor
['payment_processor_type_id'] == CRM_Utils_Array
::key('PayPal_Standard', $paymentProcessorType)) {
66 $this->_processorName
= ts('PayPal Standard');
69 elseif ($this->_paymentProcessor
['payment_processor_type_id'] == CRM_Utils_Array
::key('PayPal_Express', $paymentProcessorType)) {
70 $this->_processorName
= ts('PayPal Express');
73 if (!$this->_paymentProcessor
['user_name']) {
74 CRM_Core_Error
::fatal(ts('Could not find user name for payment processor'));
79 * Are back office payments supported - e.g paypal standard won't permit you to enter a credit card associated with someone else's login
82 protected function supportsBackOffice() {
83 if ($this->_processorName
== ts('PayPal Pro')) {
90 * Express checkout code. Check PayPal documentation for more information
92 * @param array $params
93 * Assoc array of input parameters for this transaction.
96 * the result in an nice formatted array (or an error object)
98 public function setExpressCheckOut(&$params) {
101 $this->initialize($args, 'SetExpressCheckout');
103 $args['paymentAction'] = $params['payment_action'];
104 $args['amt'] = $params['amount'];
105 $args['currencyCode'] = $params['currencyID'];
106 $args['desc'] = CRM_Utils_Array
::value('description', $params);
107 $args['invnum'] = $params['invoiceID'];
108 $args['returnURL'] = $params['returnURL'];
109 $args['cancelURL'] = $params['cancelURL'];
110 $args['version'] = '56.0';
112 //LCD if recurring, collect additional data and set some values
113 if (!empty($params['is_recur'])) {
114 $args['L_BILLINGTYPE0'] = 'RecurringPayments';
115 //$args['L_BILLINGAGREEMENTDESCRIPTION0'] = 'Recurring Contribution';
116 $args['L_BILLINGAGREEMENTDESCRIPTION0'] = $params['amount'] . " Per " . $params['frequency_interval'] . " " . $params['frequency_unit'];
117 $args['L_PAYMENTTYPE0'] = 'Any';
120 // Allow further manipulation of the arguments via custom hooks ..
121 CRM_Utils_Hook
::alterPaymentProcessorParams($this, $params, $args);
123 $result = $this->invokeAPI($args);
125 if (is_a($result, 'CRM_Core_Error')) {
131 return $result['token'];
135 * Get details from paypal. Check PayPal documentation for more information
137 * @param string $token
138 * The key associated with this transaction.
141 * the result in an nice formatted array (or an error object)
143 public function getExpressCheckoutDetails($token) {
146 $this->initialize($args, 'GetExpressCheckoutDetails');
147 $args['token'] = $token;
149 $args['method'] = 'GetExpressCheckoutDetails';
151 $result = $this->invokeAPI($args);
153 if (is_a($result, 'CRM_Core_Error')) {
160 $params['token'] = $result['token'];
161 $params['payer_id'] = $result['payerid'];
162 $params['payer_status'] = $result['payerstatus'];
163 $params['first_name'] = $result['firstname'];
164 $params['middle_name'] = CRM_Utils_Array
::value('middlename', $result);
165 $params['last_name'] = $result['lastname'];
166 $params['street_address'] = $result['shiptostreet'];
167 $params['supplemental_address_1'] = CRM_Utils_Array
::value('shiptostreet2', $result);
168 $params['city'] = $result['shiptocity'];
169 $params['state_province'] = $result['shiptostate'];
170 $params['postal_code'] = $result['shiptozip'];
171 $params['country'] = $result['shiptocountrycode'];
177 * Do the express checkout at paypal. Check PayPal documentation for more information
179 * @param array $params
181 * @internal param string $token the key associated with this transaction
184 * the result in an nice formatted array (or an error object)
186 public function doExpressCheckout(&$params) {
189 $this->initialize($args, 'DoExpressCheckoutPayment');
191 $args['token'] = $params['token'];
192 $args['paymentAction'] = $params['payment_action'];
193 $args['amt'] = $params['amount'];
194 $args['currencyCode'] = $params['currencyID'];
195 $args['payerID'] = $params['payer_id'];
196 $args['invnum'] = $params['invoiceID'];
197 $args['returnURL'] = CRM_Utils_Array
::value('returnURL', $params);
198 $args['cancelURL'] = CRM_Utils_Array
::value('cancelURL', $params);
199 $args['desc'] = $params['description'];
201 $result = $this->invokeAPI($args);
203 if (is_a($result, 'CRM_Core_Error')) {
209 $params['trxn_id'] = $result['transactionid'];
210 $params['gross_amount'] = $result['amt'];
211 $params['fee_amount'] = $result['feeamt'];
212 $params['net_amount'] = CRM_Utils_Array
::value('settleamt', $result);
213 if ($params['net_amount'] == 0 && $params['fee_amount'] != 0) {
214 $params['net_amount'] = $params['gross_amount'] - $params['fee_amount'];
216 $params['payment_status'] = $result['paymentstatus'];
217 $params['pending_reason'] = $result['pendingreason'];
222 //LCD add new function for handling recurring payments for PayPal Express
224 * @param array $params
228 public function createRecurringPayments(&$params) {
231 $this->initialize($args, 'CreateRecurringPaymentsProfile');
233 $start_time = strtotime(date('m/d/Y'));
234 $start_date = date('Y-m-d\T00:00:00\Z', $start_time);
236 $args['token'] = $params['token'];
237 $args['paymentAction'] = $params['payment_action'];
238 $args['amt'] = $params['amount'];
239 $args['currencyCode'] = $params['currencyID'];
240 $args['payerID'] = $params['payer_id'];
241 $args['invnum'] = $params['invoiceID'];
242 $args['returnURL'] = $params['returnURL'];
243 $args['cancelURL'] = $params['cancelURL'];
244 $args['profilestartdate'] = $start_date;
245 $args['method'] = 'CreateRecurringPaymentsProfile';
246 $args['billingfrequency'] = $params['frequency_interval'];
247 $args['billingperiod'] = ucwords($params['frequency_unit']);
248 $args['desc'] = $params['amount'] . " Per " . $params['frequency_interval'] . " " . $params['frequency_unit'];
249 //$args['desc'] = 'Recurring Contribution';
250 $args['totalbillingcycles'] = $params['installments'];
251 $args['version'] = '56.0';
252 $args['profilereference'] =
253 "i={$params['invoiceID']}" .
255 "&c={$params['contactID']}" .
256 "&r={$params['contributionRecurID']}" .
257 "&b={$params['contributionID']}" .
258 "&p={$params['contributionPageID']}";
260 $result = $this->invokeAPI($args);
262 if (is_a($result, 'CRM_Core_Error')) {
268 $params['trxn_id'] = $result['transactionid'];
269 $params['gross_amount'] = $result['amt'];
270 $params['fee_amount'] = $result['feeamt'];
271 $params['net_amount'] = $result['settleamt'];
272 if ($params['net_amount'] == 0 && $params['fee_amount'] != 0) {
273 $params['net_amount'] = $params['gross_amount'] - $params['fee_amount'];
275 $params['payment_status'] = $result['paymentstatus'];
276 $params['pending_reason'] = $result['pendingreason'];
285 public function initialize(&$args, $method) {
286 $args['user'] = $this->_paymentProcessor
['user_name'];
287 $args['pwd'] = $this->_paymentProcessor
['password'];
288 $args['version'] = 3.0;
289 $args['signature'] = $this->_paymentProcessor
['signature'];
290 $args['subject'] = CRM_Utils_Array
::value('subject', $this->_paymentProcessor
);
291 $args['method'] = $method;
295 * This function collects all the information from a web/api form and invokes
296 * the relevant payment processor specific functions to perform the transaction
298 * @param array $params
299 * Assoc array of input parameters for this transaction.
301 * @param string $component
303 * the result in an nice formatted array (or an error object)
305 public function doDirectPayment(&$params, $component = 'contribute') {
308 $this->initialize($args, 'DoDirectPayment');
310 $args['paymentAction'] = $params['payment_action'];
311 $args['amt'] = $params['amount'];
312 $args['currencyCode'] = $params['currencyID'];
313 $args['invnum'] = $params['invoiceID'];
314 $args['ipaddress'] = $params['ip_address'];
315 $args['creditCardType'] = $params['credit_card_type'];
316 $args['acct'] = $params['credit_card_number'];
317 $args['expDate'] = sprintf('%02d', $params['month']) . $params['year'];
318 $args['cvv2'] = $params['cvv2'];
319 $args['firstName'] = $params['first_name'];
320 $args['lastName'] = $params['last_name'];
321 $args['email'] = CRM_Utils_Array
::value('email', $params);
322 $args['street'] = $params['street_address'];
323 $args['city'] = $params['city'];
324 $args['state'] = $params['state_province'];
325 $args['countryCode'] = $params['country'];
326 $args['zip'] = $params['postal_code'];
327 $args['desc'] = substr(CRM_Utils_Array
::value('description', $params), 0, 127);
328 $args['custom'] = CRM_Utils_Array
::value('accountingCode', $params);
330 if (CRM_Utils_Array
::value('is_recur', $params) == 1) {
331 $start_time = strtotime(date('m/d/Y'));
332 $start_date = date('Y-m-d\T00:00:00\Z', $start_time);
334 $args['PaymentAction'] = 'Sale';
335 $args['billingperiod'] = ucwords($params['frequency_unit']);
336 $args['billingfrequency'] = $params['frequency_interval'];
337 $args['method'] = "CreateRecurringPaymentsProfile";
338 $args['profilestartdate'] = $start_date;
340 $params['description'] . ": " .
341 $params['amount'] . " Per " .
342 $params['frequency_interval'] . " " .
343 $params['frequency_unit'];
344 $args['amt'] = $params['amount'];
345 $args['totalbillingcycles'] = $params['installments'];
346 $args['version'] = 56.0;
347 $args['PROFILEREFERENCE'] =
348 "i=" . $params['invoiceID'] . "&m=" . $component .
349 "&c=" . $params['contactID'] . "&r=" . $params['contributionRecurID'] .
350 "&b=" . $params['contributionID'] . "&p=" . $params['contributionPageID'];
353 // Allow further manipulation of the arguments via custom hooks ..
354 CRM_Utils_Hook
::alterPaymentProcessorParams($this, $params, $args);
356 $result = $this->invokeAPI($args);
359 if (is_a($result, 'CRM_Core_Error')) {
363 $params['recurr_profile_id'] = NULL;
365 if (CRM_Utils_Array
::value('is_recur', $params) == 1) {
366 $params['recurr_profile_id'] = $result['profileid'];
371 $params['trxn_id'] = CRM_Utils_Array
::value('transactionid', $result);
372 $params['gross_amount'] = CRM_Utils_Array
::value('amt', $result);
377 * This function checks to see if we have the right config values
380 * the error message if any
382 public function checkConfig() {
384 $paymentProcessorType = CRM_Core_PseudoConstant
::paymentProcessorType(FALSE, NULL, 'name');
386 $this->_paymentProcessor
['payment_processor_type_id'] == CRM_Utils_Array
::key('PayPal_Standard', $paymentProcessorType) ||
387 $this->_paymentProcessor
['payment_processor_type_id'] == CRM_Utils_Array
::key('PayPal', $paymentProcessorType)
389 if (empty($this->_paymentProcessor
['user_name'])) {
390 $error[] = ts('User Name is not set in the Administer » System Settings » Payment Processors.');
394 if ($this->_paymentProcessor
['payment_processor_type_id'] != CRM_Utils_Array
::key('PayPal_Standard', $paymentProcessorType)) {
395 if (empty($this->_paymentProcessor
['signature'])) {
396 $error[] = ts('Signature is not set in the Administer » System Settings » Payment Processors.');
399 if (empty($this->_paymentProcessor
['password'])) {
400 $error[] = ts('Password is not set in the Administer » System Settings » Payment Processors.');
404 if (!empty($error)) {
405 return implode('<p>', $error);
413 * @return null|string
415 public function cancelSubscriptionURL() {
416 if ($this->_paymentProcessor
['payment_processor_type'] == 'PayPal_Standard') {
417 return "{$this->_paymentProcessor['url_site']}cgi-bin/webscr?cmd=_subscr-find&alias=" . urlencode($this->_paymentProcessor
['user_name']);
425 * Check whether a method is present ( & supported ) by the payment processor object.
427 * @param string $method
428 * Method to check for.
432 public function isSupported($method = 'cancelSubscription') {
433 if ($this->_paymentProcessor
['payment_processor_type'] != 'PayPal') {
434 // since subscription methods like cancelSubscription or updateBilling is not yet implemented / supported
435 // by standard or express.
438 return parent
::isSupported($method);
442 * @param string $message
443 * @param array $params
445 * @return array|bool|object
447 public function cancelSubscription(&$message = '', $params = array()) {
448 if ($this->_paymentProcessor
['payment_processor_type'] == 'PayPal') {
450 $this->initialize($args, 'ManageRecurringPaymentsProfileStatus');
452 $args['PROFILEID'] = CRM_Utils_Array
::value('subscriptionId', $params);
453 $args['ACTION'] = 'Cancel';
454 $args['NOTE'] = CRM_Utils_Array
::value('reason', $params);
456 $result = $this->invokeAPI($args);
457 if (is_a($result, 'CRM_Core_Error')) {
460 $message = "{$result['ack']}: profileid={$result['profileid']}";
467 * @param string $message
468 * @param array $params
470 * @return array|bool|object
472 public function updateSubscriptionBillingInfo(&$message = '', $params = array()) {
473 if ($this->_paymentProcessor
['payment_processor_type'] == 'PayPal') {
474 $config = CRM_Core_Config
::singleton();
476 $this->initialize($args, 'UpdateRecurringPaymentsProfile');
478 $args['PROFILEID'] = $params['subscriptionId'];
479 $args['AMT'] = $params['amount'];
480 $args['CURRENCYCODE'] = $config->defaultCurrency
;
481 $args['CREDITCARDTYPE'] = $params['credit_card_type'];
482 $args['ACCT'] = $params['credit_card_number'];
483 $args['EXPDATE'] = sprintf('%02d', $params['month']) . $params['year'];
484 $args['CVV2'] = $params['cvv2'];
486 $args['FIRSTNAME'] = $params['first_name'];
487 $args['LASTNAME'] = $params['last_name'];
488 $args['STREET'] = $params['street_address'];
489 $args['CITY'] = $params['city'];
490 $args['STATE'] = $params['state_province'];
491 $args['COUNTRYCODE'] = $params['postal_code'];
492 $args['ZIP'] = $params['country'];
494 $result = $this->invokeAPI($args);
495 if (is_a($result, 'CRM_Core_Error')) {
498 $message = "{$result['ack']}: profileid={$result['profileid']}";
505 * @param string $message
506 * @param array $params
508 * @return array|bool|object
510 public function changeSubscriptionAmount(&$message = '', $params = array()) {
511 if ($this->_paymentProcessor
['payment_processor_type'] == 'PayPal') {
512 $config = CRM_Core_Config
::singleton();
514 $this->initialize($args, 'UpdateRecurringPaymentsProfile');
516 $args['PROFILEID'] = $params['subscriptionId'];
517 $args['AMT'] = $params['amount'];
518 $args['CURRENCYCODE'] = $config->defaultCurrency
;
519 $args['BILLINGFREQUENCY'] = $params['installments'];
521 $result = $this->invokeAPI($args);
522 CRM_Core_Error
::debug_var('$result', $result);
523 if (is_a($result, 'CRM_Core_Error')) {
526 $message = "{$result['ack']}: profileid={$result['profileid']}";
533 * @param array $params
534 * @param string $component
538 public function doTransferCheckout(&$params, $component = 'contribute') {
539 $config = CRM_Core_Config
::singleton();
541 if ($component != 'contribute' && $component != 'event') {
542 CRM_Core_Error
::fatal(ts('Component is invalid'));
545 $notifyURL = $config->userFrameworkResourceURL
. "extern/ipn.php?reset=1&contactID={$params['contactID']}" . "&contributionID={$params['contributionID']}" . "&module={$component}";
547 if ($component == 'event') {
548 $notifyURL .= "&eventID={$params['eventID']}&participantID={$params['participantID']}";
551 $membershipID = CRM_Utils_Array
::value('membershipID', $params);
553 $notifyURL .= "&membershipID=$membershipID";
555 $relatedContactID = CRM_Utils_Array
::value('related_contact', $params);
556 if ($relatedContactID) {
557 $notifyURL .= "&relatedContactID=$relatedContactID";
559 $onBehalfDupeAlert = CRM_Utils_Array
::value('onbehalf_dupe_alert', $params);
560 if ($onBehalfDupeAlert) {
561 $notifyURL .= "&onBehalfDupeAlert=$onBehalfDupeAlert";
566 $url = ($component == 'event') ?
'civicrm/event/register' : 'civicrm/contribute/transact';
567 $cancel = ($component == 'event') ?
'_qf_Register_display' : '_qf_Main_display';
568 $returnURL = CRM_Utils_System
::url($url,
569 "_qf_ThankYou_display=1&qfKey={$params['qfKey']}",
573 $cancelUrlString = "$cancel=1&cancel=1&qfKey={$params['qfKey']}";
574 if (!empty($params['is_recur'])) {
575 $cancelUrlString .= "&isRecur=1&recurId={$params['contributionRecurID']}&contribId={$params['contributionID']}";
578 $cancelURL = CRM_Utils_System
::url(
584 // ensure that the returnURL is absolute.
585 if (substr($returnURL, 0, 4) != 'http') {
586 $fixUrl = CRM_Utils_System
::url("civicrm/admin/setting/url", '&reset=1');
587 CRM_Core_Error
::fatal(ts('Sending a relative URL to PayPalIPN is erroneous. Please make your resource URL (in <a href="%1">Administer » System Settings » Resource URLs</a> ) complete.', array(1 => $fixUrl)));
590 $paypalParams = array(
591 'business' => $this->_paymentProcessor
['user_name'],
592 'notify_url' => $notifyURL,
593 'item_name' => $params['item_name'],
595 'undefined_quantity' => 0,
596 'cancel_return' => $cancelURL,
599 'return' => $returnURL,
601 'currency_code' => $params['currencyID'],
602 'invoice' => $params['invoiceID'],
603 'lc' => substr($config->lcMessages
, -2),
604 'charset' => function_exists('mb_internal_encoding') ?
mb_internal_encoding() : 'UTF-8',
605 'custom' => CRM_Utils_Array
::value('accountingCode',
610 // add name and address if available, CRM-3130
612 'first_name' => 'first_name',
613 'last_name' => 'last_name',
614 'street_address' => 'address1',
615 'country' => 'country',
616 'preferred_language' => 'lc',
618 'state_province' => 'state',
619 'postal_code' => 'zip',
623 foreach (array_keys($params) as $p) {
624 // get the base name without the location type suffixed to it
625 $parts = explode('-', $p);
626 $name = count($parts) > 1 ?
$parts[0] : $p;
627 if (isset($otherVars[$name])) {
628 $value = $params[$p];
630 if ($name == 'state_province') {
631 $stateName = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value);
634 if ($name == 'country') {
635 $countryName = CRM_Core_PseudoConstant
::countryIsoCode($value);
636 $value = $countryName;
638 // ensure value is not an array
640 if (!is_array($value)) {
641 $paypalParams[$otherVars[$name]] = $value;
647 // if recurring donations, add a few more items
648 if (!empty($params['is_recur'])) {
649 if ($params['contributionRecurID']) {
650 $notifyURL .= "&contributionRecurID={$params['contributionRecurID']}&contributionPageID={$params['contributionPageID']}";
651 $paypalParams['notify_url'] = $notifyURL;
654 CRM_Core_Error
::fatal(ts('Recurring contribution, but no database id'));
657 $paypalParams +
= array(
658 'cmd' => '_xclick-subscriptions',
659 'a3' => $params['amount'],
660 'p3' => $params['frequency_interval'],
661 't3' => ucfirst(substr($params['frequency_unit'], 0, 1)),
664 'srt' => CRM_Utils_Array
::value('installments', $params),
670 $paypalParams +
= array(
672 'amount' => $params['amount'],
676 // Allow further manipulation of the arguments via custom hooks ..
677 CRM_Utils_Hook
::alterPaymentProcessorParams($this, $params, $paypalParams);
680 foreach ($paypalParams as $key => $value) {
681 if ($value === NULL) {
685 $value = urlencode($value);
686 if ($key == 'return' ||
687 $key == 'cancel_return' ||
690 $value = str_replace('%2F', '/', $value);
692 $uri .= "&{$key}={$value}";
695 $uri = substr($uri, 1);
696 $url = $this->_paymentProcessor
['url_site'];
697 $sub = empty($params['is_recur']) ?
'cgi-bin/webscr' : 'subscriptions';
698 $paypalURL = "{$url}{$sub}?$uri";
700 CRM_Utils_System
::redirect($paypalURL);
704 * Hash_call: Function to perform the API call to PayPal using API signature
705 * @methodName is name of API method.
706 * @nvpStr is nvp string.
707 * returns an associtive array containing the response from the server.
709 public function invokeAPI($args, $url = NULL) {
712 if (empty($this->_paymentProcessor
['url_api'])) {
713 CRM_Core_Error
::fatal(ts('Please set the API URL. Please refer to the documentation for more details'));
716 $url = $this->_paymentProcessor
['url_api'] . 'nvp';
719 if (!function_exists('curl_init')) {
720 CRM_Core_Error
::fatal("curl functions NOT available.");
723 //setting the curl parameters.
725 curl_setopt($ch, CURLOPT_URL
, $url);
726 curl_setopt($ch, CURLOPT_VERBOSE
, 1);
728 //turning off the server and peer verification(TrustManager Concept).
729 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL'));
730 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST
, CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL') ?
2 : 0);
732 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
733 curl_setopt($ch, CURLOPT_POST
, 1);
736 foreach ($args as $n => $v) {
737 $p[] = "$n=" . urlencode($v);
740 //NVPRequest for submitting to server
741 $nvpreq = implode('&', $p);
743 //setting the nvpreq as POST FIELD to curl
744 curl_setopt($ch, CURLOPT_POSTFIELDS
, $nvpreq);
746 //getting response from server
747 $response = curl_exec($ch);
749 //converting NVPResponse to an Associative Array
750 $result = self
::deformat($response);
752 if (curl_errno($ch)) {
753 $e = CRM_Core_Error
::singleton();
754 $e->push(curl_errno($ch),
764 if (strtolower($result['ack']) != 'success' &&
765 strtolower($result['ack']) != 'successwithwarning'
767 $e = CRM_Core_Error
::singleton();
768 $e->push($result['l_errorcode0'],
770 "{$result['l_shortmessage0']} {$result['l_longmessage0']}"
778 /** This function will take NVPString and convert it to an Associative Array and it will decode the response.
779 * It is usefull to search for a particular key and displaying arrays.
780 * @nvpstr is NVPString.
781 * @nvpArray is Associative Array.
783 public static function deformat($str) {
786 while (strlen($str)) {
788 $keyPos = strpos($str, '=');
791 $valPos = strpos($str, '&') ?
strpos($str, '&') : strlen($str);
793 /*getting the Key and Value values and storing in a Associative Array*/
795 $key = substr($str, 0, $keyPos);
796 $val = substr($str, $keyPos +
1, $valPos - $keyPos - 1);
798 //decoding the respose
799 $result[strtolower(urldecode($key))] = urldecode($val);
800 $str = substr($str, $valPos +
1, strlen($str));