Merge pull request #4696 from colemanw/CRM-15669
[civicrm-core.git] / CRM / Core / Payment / GoogleIPN.php
1 <?php
2
3 /**
4 * Copyright (C) 2006 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 /* This is the response handler code that will be invoked every time
20 * a notification or request is sent by the Google Server
21 *
22 * To allow this code to receive responses, the url for this file
23 * must be set on the seller page under Settings->Integration as the
24 * "API Callback URL'
25 * Order processing commands can be sent automatically by placing these
26 * commands appropriately
27 *
28 * To use this code for merchant-calculated feedback, this url must be
29 * set also as the merchant-calculations-url when the cart is posted
30 * Depending on your calculations for shipping, taxes, coupons and gift
31 * certificates update parts of the code as required
32 *
33 */
34
35
36
37 define('GOOGLE_DEBUG_PP', 0);
38
39 /**
40 * Class CRM_Core_Payment_GoogleIPN
41 */
42 class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
43
44 /**
45 * We only need one instance of this object. So we use the singleton
46 * pattern and cache the instance in this variable
47 *
48 * @var object
49 * @static
50 */
51 static private $_singleton = NULL;
52
53 /**
54 * Mode of operation: live or test
55 *
56 * @var object
57 */
58 protected $_mode = NULL;
59
60 /**
61 * @param string $name
62 * @param $type
63 * @param $object
64 * @param bool $abort
65 *
66 * @return mixed
67 */
68 public static function retrieve($name, $type, $object, $abort = TRUE) {
69 $value = CRM_Utils_Array::value($name, $object);
70 if ($abort && $value === NULL) {
71 CRM_Core_Error::debug_log_message("Could not find an entry for $name");
72 echo "Failure: Missing Parameter<p>";
73 exit();
74 }
75
76 if ($value) {
77 if (!CRM_Utils_Type::validate($value, $type)) {
78 CRM_Core_Error::debug_log_message("Could not find a valid entry for $name");
79 echo "Failure: Invalid Parameter<p>";
80 exit();
81 }
82 }
83
84 return $value;
85 }
86
87 /**
88 * Constructor
89 *
90 * @param string $mode the mode of operation: live or test
91 *
92 * @param $paymentProcessor
93 *
94 * @return \CRM_Core_Payment_GoogleIPN
95 */
96 public function __construct($mode, &$paymentProcessor) {
97 parent::__construct();
98
99 $this->_mode = $mode;
100 $this->_paymentProcessor = $paymentProcessor;
101 }
102
103 /**
104 * The function gets called when a new order takes place.
105 *
106 * @param xml $dataRoot response send by google in xml format
107 * @param array $privateData contains the name value pair of <merchant-private-data>
108 *
109 * @param $component
110 *
111 * @return void
112 */
113 public function newOrderNotify($dataRoot, $privateData, $component) {
114 $ids = $input = $params = array();
115
116 $input['component'] = strtolower($component);
117
118 $ids['contact'] = self::retrieve('contactID', 'Integer', $privateData, TRUE);
119 $ids['contribution'] = self::retrieve('contributionID', 'Integer', $privateData, TRUE);
120
121 $ids['contributionRecur'] = $ids['contributionPage'] = NULL;
122 if ($input['component'] == "event") {
123 $ids['event'] = self::retrieve('eventID', 'Integer', $privateData, TRUE);
124 $ids['participant'] = self::retrieve('participantID', 'Integer', $privateData, TRUE);
125 $ids['membership'] = NULL;
126 }
127 else {
128 $ids['membership'] = self::retrieve('membershipID', 'Integer', $privateData, FALSE);
129 $ids['related_contact'] = self::retrieve('relatedContactID', 'Integer', $privateData, FALSE);
130 $ids['onbehalf_dupe_alert'] = self::retrieve('onBehalfDupeAlert', 'Integer', $privateData, FALSE);
131 $ids['contributionRecur'] = self::retrieve('contributionRecurID', 'Integer', $privateData, FALSE);
132 }
133
134 $paymentProcessorID = CRM_Core_DAO::getFieldValue(
135 'CRM_Financial_DAO_PaymentProcessorType',
136 'Google_Checkout',
137 'id',
138 'payment_processor_type'
139 );
140
141 if (!$this->validateData($input, $ids, $objects, TRUE, $paymentProcessorID)) {
142 return FALSE;
143 }
144
145 $input['invoice'] = $privateData['invoiceID'];
146 $input['newInvoice'] = $dataRoot['google-order-number']['VALUE'];
147
148 if ($ids['contributionRecur']) {
149 if ($objects['contributionRecur']->invoice_id == $dataRoot['serial-number']) {
150 CRM_Core_Error::debug_log_message("The new order notification already handled: {$dataRoot['serial-number']}.");
151 return;
152 }
153 else {
154 $transaction = new CRM_Core_Transaction();
155
156 CRM_Core_Error::debug_log_message("New order for an installment received.");
157 $recur = &$objects['contributionRecur'];
158
159 // fix dates that already exist
160 $dates = array('create', 'start', 'end', 'cancel', 'modified');
161 foreach ($dates as $date) {
162 $name = "{$date}_date";
163 if ($recur->$name) {
164 $recur->$name = CRM_Utils_Date::isoToMysql($recur->$name);
165 }
166 }
167 $recur->invoice_id = $dataRoot['serial-number'];
168 $recur->processor_id = $input['newInvoice'];
169 $recur->save();
170
171 if ($objects['contribution']->contribution_status_id == 1) {
172 // create a contribution and then get it processed
173 $contribution = new CRM_Contribute_DAO_Contribution();
174 $contribution->contact_id = $ids['contact'];
175 $contribution->financial_type_id = $objects['contributionType']->id;
176 $contribution->contribution_page_id = $objects['contribution']->contribution_page_id;
177 $contribution->contribution_recur_id = $ids['contributionRecur'];
178 $contribution->receive_date = date('YmdHis');
179 $contribution->currency = $objects['contribution']->currency;
180 $contribution->payment_instrument_id = $objects['contribution']->payment_instrument_id;
181 $contribution->amount_level = $objects['contribution']->amount_level;
182 $contribution->address_id = $objects['contribution']->address_id;
183 $contribution->invoice_id = $input['invoice'];
184 $contribution->total_amount = $dataRoot['order-total']['VALUE'];
185 $contribution->contribution_status_id = 2;
186 $contribution->campaign_id = $objects['contribution']->campaign_id;
187
188 $objects['contribution'] = $contribution;
189 }
190 $transaction->commit();
191 }
192 }
193
194 // make sure the invoice is valid and matches what we have in the contribution record
195 $contribution = &$objects['contribution'];
196
197 if ($contribution->invoice_id != $input['invoice']) {
198 CRM_Core_Error::debug_log_message("Invoice values dont match between database and IPN request");
199 return;
200 }
201
202 // lets replace invoice-id with google-order-number because thats what is common and unique
203 // in subsequent calls or notifications sent by google.
204 $contribution->invoice_id = $input['newInvoice'];
205
206 $input['amount'] = $dataRoot['order-total']['VALUE'];
207
208 if ($contribution->total_amount != $input['amount']) {
209 CRM_Core_Error::debug_log_message("Amount values dont match between database and IPN request");
210 return;
211 }
212
213 if (!$this->getInput($input, $ids, $dataRoot)) {
214 return FALSE;
215 }
216
217 $transaction = new CRM_Core_Transaction();
218
219 // check if contribution is already completed, if so we ignore this ipn
220 if ($contribution->contribution_status_id == 1) {
221 CRM_Core_Error::debug_log_message("returning since contribution has already been handled");
222 return;
223 }
224 else {
225 /* Since trxn_id hasn't got any use here,
226 * lets make use of it by passing the eventID/membershipTypeID to next level.
227 * And change trxn_id to google-order-number before finishing db update */
228
229 if (!empty($ids['event'])) {
230 $contribution->trxn_id = $ids['event'] . CRM_Core_DAO::VALUE_SEPARATOR . $ids['participant'];
231 }
232 elseif (!empty($ids['membership'])) {
233 $contribution->trxn_id = $ids['membership'][0] . CRM_Core_DAO::VALUE_SEPARATOR . $ids['related_contact'] . CRM_Core_DAO::VALUE_SEPARATOR . $ids['onbehalf_dupe_alert'];
234 }
235 }
236
237 $contribution->save();
238 $transaction->commit();
239
240 return TRUE;
241 }
242
243 /**
244 * The function gets called when the state(CHARGED, CANCELLED..) changes for an order
245 *
246 * @param string $status status of the transaction send by google
247 * @param $dataRoot
248 * @param array $privateData contains the name value pair of <merchant-private-data>
249 *
250 * @param $component
251 *
252 * @return void
253 */
254 public function orderStateChange($status, $dataRoot, $privateData, $component) {
255 $input = $objects = $ids = array();
256 $input['component'] = strtolower($component);
257
258 $ids['contributionRecur'] = self::retrieve('contributionRecurID', 'Integer', $privateData, FALSE);
259 $serial = $dataRoot['serial-number'];
260 $orderNo = $dataRoot['google-order-number']['VALUE'];
261
262 $contribution = new CRM_Contribute_BAO_Contribution();
263 $contribution->invoice_id = $orderNo;
264
265 if (!$contribution->find(TRUE)) {
266 CRM_Core_Error::debug_log_message("orderStateChange: Could not find contribution record with invoice id: $serial");
267 return;
268 }
269
270 // Google sends the charged notification twice.
271 // So to make sure, code is not executed again.
272 if ($contribution->contribution_status_id == 1) {
273 CRM_Core_Error::debug_log_message("Contribution already handled (ContributionID = {$contribution->id}).");
274 return;
275 }
276
277 // make sure invoice is set to serial no for recurring payments, to avoid violating uniqueness
278 $contribution->invoice_id = $ids['contributionRecur'] ? $serial : $orderNo;
279
280 $objects['contribution'] = &$contribution;
281 $ids['contribution'] = $contribution->id;
282 $ids['contact'] = $contribution->contact_id;
283
284 $ids['event'] = $ids['participant'] = $ids['membership'] = NULL;
285 $ids['contributionPage'] = NULL;
286
287 if ($input['component'] == "event") {
288 list($ids['event'], $ids['participant']) = explode(CRM_Core_DAO::VALUE_SEPARATOR,
289 $contribution->trxn_id
290 );
291 }
292 else {
293 $ids['related_contact'] = NULL;
294 $ids['onbehalf_dupe_alert'] = NULL;
295 if ($contribution->trxn_id) {
296 list($ids['membership'], $ids['related_contact'], $ids['onbehalf_dupe_alert']) = explode(CRM_Core_DAO::VALUE_SEPARATOR,
297 $contribution->trxn_id
298 );
299 }
300 foreach (array(
301 'membership', 'related_contact', 'onbehalf_dupe_alert') as $fld) {
302 if (!is_numeric($ids[$fld])) {
303 unset($ids[$fld]);
304 }
305 }
306 }
307
308 $paymentProcessorID = CRM_Core_DAO::getFieldValue(
309 'CRM_Financial_DAO_PaymentProcessorType',
310 'Google_Checkout',
311 'id',
312 'payment_processor_type'
313 );
314
315 $this->loadObjects($input, $ids, $objects, TRUE, $paymentProcessorID);
316
317 $transaction = new CRM_Core_Transaction();
318
319 if ($status == 'PAYMENT_DECLINED' ||
320 $status == 'CANCELLED_BY_GOOGLE' ||
321 $status == 'CANCELLED'
322 ) {
323 return $this->failed($objects, $transaction);
324 }
325
326 $input['amount'] = $contribution->total_amount;
327 $input['fee_amount'] = NULL;
328 $input['net_amount'] = NULL;
329 $input['trxn_id'] = $ids['contributionRecur'] ? $serial : $dataRoot['google-order-number']['VALUE'];
330 $input['is_test'] = $contribution->is_test;
331
332 $recur = NULL;
333 if ($ids['contributionRecur']) {
334 $recur = $objects['contributionRecur'];
335 }
336 $this->completeTransaction($input, $ids, $objects, $transaction, $recur);
337
338 $this->completeRecur($input, $ids, $objects);
339 }
340
341 /**
342 * @param $input
343 * @param $ids
344 * @param $objects
345 */
346 public function completeRecur($input, $ids, $objects) {
347 if ($ids['contributionRecur']) {
348 $recur = &$objects['contributionRecur'];
349 $contributionCount = CRM_Core_DAO::singleValueQuery("
350 SELECT count(*)
351 FROM civicrm_contribution
352 WHERE contribution_recur_id = {$ids['contributionRecur']}
353 ");
354 $autoRenewMembership = FALSE;
355 if ($recur->id &&
356 isset($ids['membership']) &&
357 $ids['membership']
358 ) {
359 $autoRenewMembership = TRUE;
360 }
361 if ($recur->installments && ($contributionCount >= $recur->installments)) {
362 $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
363
364 $recur->create_date = CRM_Utils_Date::isoToMysql($recur->create_date);
365 $recur->start_date = CRM_Utils_Date::isoToMysql($recur->start_date);
366 $recur->cancel_date = CRM_Utils_Date::isoToMysql($recur->cancel_date);
367 $recur->end_date = date('YmdHis');
368 $recur->modified_date = date('YmdHis');
369 $recur->contribution_status_id = array_search('Completed', $contributionStatus);
370 $recur->trnx_id = $dataRoot['google-order-number']['VALUE'];
371 $recur->save();
372
373 //send recurring Notification email for user
374 CRM_Contribute_BAO_ContributionPage::recurringNotify(
375 CRM_Core_Payment::RECURRING_PAYMENT_END,
376 $ids['contact'],
377 $ids['contributionPage'],
378 $recur,
379 $autoRenewMembership
380 );
381 }
382 elseif ($contributionCount == 1) {
383 CRM_Contribute_BAO_ContributionPage::recurringNotify(
384 CRM_Core_Payment::RECURRING_PAYMENT_START,
385 $ids['contact'],
386 $ids['contributionPage'],
387 $recur,
388 $autoRenewMembership
389 );
390 }
391 }
392 }
393
394 /**
395 * Singleton function used to manage this object
396 *
397 * @param string $mode the mode of operation: live or test
398 *
399 * @param $component
400 * @param $paymentProcessor
401 *
402 * @return object
403 * @static
404 */
405 public static function &singleton($mode, $component, &$paymentProcessor) {
406 if (self::$_singleton === NULL) {
407 self::$_singleton = new CRM_Core_Payment_GoogleIPN($mode, $paymentProcessor);
408 }
409 return self::$_singleton;
410 }
411
412 /**
413 * The function retrieves the amount the contribution is for, based on the order-no google sends
414 *
415 * @param int $orderNo <order-total> send by google
416 *
417 * @return amount
418 */
419 public function getAmount($orderNo) {
420 $contribution = new CRM_Contribute_DAO_Contribution();
421 $contribution->invoice_id = $orderNo;
422 if (!$contribution->find(TRUE)) {
423 CRM_Core_Error::debug_log_message("getAmount: Could not find contribution record with invoice id: $orderNo");
424 echo "Failure: Could not find contribution record with invoice id: $orderNo <p>";
425 exit();
426 }
427 return $contribution->total_amount;
428 }
429
430 /**
431 * The function returns the component(Event/Contribute..), given the google-order-no and merchant-private-data
432 *
433 * @param array $privateData contains the name value pair of <merchant-private-data>
434 * @param int $orderNo <order-total> send by google
435 * @param string $root root of xml-response
436 *
437 * @param $response
438 * @param $serial
439 * @internal param \xml $xml_response response send by google in xml format
440 * @return array context of this call (test, module, payment processor id)
441 * @static
442 */
443 public function getContext($privateData, $orderNo, $root, $response, $serial) {
444 $contributionID = CRM_Utils_Array::value('contributionID', $privateData);
445 $contribution = new CRM_Contribute_DAO_Contribution();
446 if ($root == 'new-order-notification') {
447 $contribution->id = $contributionID;
448 }
449 else {
450 $contribution->invoice_id = $orderNo;
451 }
452 if (!$contribution->find(TRUE)) {
453 CRM_Core_Error::debug_log_message("getContext: Could not find contribution record with invoice id: $orderNo");
454 $response->SendAck($serial);
455 }
456
457 $module = 'Contribute';
458 if (stristr($contribution->source, ts('Online Contribution'))) {
459 $module = 'Contribute';
460 }
461 elseif (stristr($contribution->source, ts('Online Event Registration'))) {
462 $module = 'Event';
463 }
464 $isTest = $contribution->is_test;
465
466 $ids = $input = $objects = array();
467 $objects['contribution'] = &$contribution;
468 $ids['contributionRecur'] = self::retrieve('contributionRecurID', 'Integer', $privateData, FALSE);
469 $input['component'] = strtolower($module);
470
471 if (!$ids['contributionRecur'] && $contribution->contribution_status_id == 1) {
472 CRM_Core_Error::debug_log_message("Contribution already handled (ContributionID = {$contribution->id}).");
473 // There is no point in going further. Return ack so we don't receive the same ipn.
474 $response->SendAck($serial);
475 }
476
477 if ($input['component'] == 'event') {
478 if ($root == 'new-order-notification') {
479 $ids['event'] = $privateData['eventID'];
480 }
481 else {
482 list($ids['event'], $ids['participant']) =
483 explode(CRM_Core_DAO::VALUE_SEPARATOR, $contribution->trxn_id);
484 }
485 }
486
487 $paymentProcessorID = CRM_Core_DAO::getFieldValue(
488 'CRM_Financial_DAO_PaymentProcessor',
489 'Google_Checkout',
490 'id',
491 'payment_processor_type'
492 );
493
494 $this->loadObjects($input, $ids, $objects, FALSE, $paymentProcessorID);
495
496 if (!$ids['paymentProcessor']) {
497 CRM_Core_Error::debug_log_message("Payment processor could not be retrieved.");
498 // There is no point in going further. Return ack so we don't receive the same ipn.
499 $response->SendAck($serial);
500 }
501
502 return array($isTest, $input['component'], $ids['paymentProcessor']);
503 }
504
505 /**
506 * This method is handles the response that will be invoked (from extern/googleNotify) every time
507 * a notification or request is sent by the Google Server.
508 *
509 */
510 public static function main($xml_response) {
511 require_once 'Google/library/googleresponse.php';
512 require_once 'Google/library/googlerequest.php';
513 require_once 'Google/library/googlemerchantcalculations.php';
514 require_once 'Google/library/googleresult.php';
515 require_once 'Google/library/xml-processing/gc_xmlparser.php';
516
517 $config = CRM_Core_Config::singleton();
518
519 // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
520 if (get_magic_quotes_gpc()) {
521 $xml_response = stripslashes($xml_response);
522 }
523
524 $headers = CRM_Utils_System::getAllHeaders();
525
526 if (GOOGLE_DEBUG_PP) {
527 CRM_Core_Error::debug_var('RESPONSE', $xml_response, TRUE, TRUE, 'Google');
528 }
529
530 // Retrieve the root and data from the xml response
531 $response = new GoogleResponse();
532 list($root, $data) = $response->GetParsedXML($xml_response);
533 // lets retrieve the private-data & order-no
534 $privateData = NULL;
535 if (array_key_exists('shopping-cart', $data[$root])) {
536 $privateData = $data[$root]['shopping-cart']['merchant-private-data']['VALUE'];
537 }
538 if (empty($privateData) && array_key_exists('order-summary', $data[$root])
539 && array_key_exists('shopping-cart', $data[$root]['order-summary'])) {
540 $privateData = $data[$root]['order-summary']['shopping-cart']['merchant-private-data']['VALUE'];
541 }
542 $privateData = $privateData ? self::stringToArray($privateData) : '';
543 $orderNo = $data[$root]['google-order-number']['VALUE'];
544 $serial = $data[$root]['serial-number'];
545
546 // a dummy object to call get context and a parent function inside it.
547 $ipn = new CRM_Core_Payment_GoogleIPN('live', $dummyProcessor);
548 list($mode, $module, $paymentProcessorID) = $ipn->getContext($privateData, $orderNo, $root, $response, $serial);
549 $mode = $mode ? 'test' : 'live';
550
551 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode);
552 $merchant_id = $paymentProcessor['user_name'];
553 $merchant_key = $paymentProcessor['password'];
554 $response->SetMerchantAuthentication($merchant_id, $merchant_key);
555
556 $server_type = ($mode == 'test') ? 'sandbox' : 'production';
557 $request = new GoogleRequest($merchant_id, $merchant_key, $server_type);
558
559 $ipn = self::singleton($mode, $module, $paymentProcessor);
560
561 if (GOOGLE_DEBUG_PP) {
562 CRM_Core_Error::debug_var('RESPONSE-ROOT', $response->root, TRUE, TRUE, 'Google');
563 }
564
565 //Check status and take appropriate action
566 $status = $response->HttpAuthentication($headers);
567
568 switch ($root) {
569 case "request-received":
570 case "error":
571 case "diagnosis":
572 case "checkout-redirect":
573 case "merchant-calculation-callback":
574 break;
575
576 case "new-order-notification": {
577 $response->SendAck($serial, FALSE);
578 $ipn->newOrderNotify($data[$root], $privateData, $module);
579 break;
580 }
581
582 case "order-state-change-notification": {
583 $response->SendAck($serial, FALSE);
584 $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
585 $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];
586
587 switch ($new_financial_state) {
588 case 'CHARGEABLE':
589 break;
590
591 case 'CHARGED':
592 case 'PAYMENT_DECLINED':
593 case 'CANCELLED':
594 case 'CANCELLED_BY_GOOGLE':
595 $ipn->orderStateChange($new_financial_state, $data[$root], $privateData, $module);
596 break;
597
598 case 'REVIEWING':
599 case 'CHARGING':
600 break;
601
602 default:
603 break;
604 }
605 break;
606 }
607
608 case "authorization-amount-notification": {
609 $response->SendAck($serial, FALSE);
610 $new_financial_state = $data[$root]['order-summary']['financial-order-state']['VALUE'];
611 $new_fulfillment_order = $data[$root]['order-summary']['fulfillment-order-state']['VALUE'];
612
613 switch ($new_financial_state) {
614 case 'CHARGEABLE':
615 // For google-handled subscriptions chargeorder needn't be initiated,
616 // assuming auto-charging is turned on.
617 //$request->SendProcessOrder($data[$root]['google-order-number']['VALUE']);
618 //$request->SendChargeOrder($data[$root]['google-order-number']['VALUE'],'');
619 break;
620
621 case 'CHARGED':
622 case 'PAYMENT_DECLINED':
623 case 'CANCELLED':
624 break;
625
626 case 'REVIEWING':
627 case 'CHARGING':
628 case 'CANCELLED_BY_GOOGLE':
629 break;
630
631 default:
632 break;
633 }
634 break;
635 }
636
637 case "charge-amount-notification":
638 case "chargeback-amount-notification":
639 case "refund-amount-notification":
640 case "risk-information-notification":
641 $response->SendAck($serial);
642 break;
643
644 default:
645 break;
646 }
647 }
648
649 /**
650 * @param $input
651 * @param $ids
652 * @param $dataRoot
653 *
654 * @return bool
655 */
656 public function getInput(&$input, &$ids, $dataRoot) {
657 if (!$this->getBillingID($ids)) {
658 return FALSE;
659 }
660
661 $billingID = $ids['billing'];
662 $lookup = array(
663 "first_name" => 'contact-name',
664 // "last-name" not available with google (every thing in contact-name)
665 "last_name" => 'last_name',
666 "street_address-{$billingID}" => 'address1',
667 "city-{$billingID}" => 'city',
668 "state-{$billingID}" => 'region',
669 "postal_code-{$billingID}" => 'postal-code',
670 "country-{$billingID}" => 'country-code',
671 );
672
673 foreach ($lookup as $name => $googleName) {
674 if (array_key_exists($googleName, $dataRoot['buyer-billing-address'])) {
675 $value = $dataRoot['buyer-billing-address'][$googleName]['VALUE'];
676 }
677 $input[$name] = $value ? $value : NULL;
678 }
679 return TRUE;
680 }
681
682 /**
683 * Converts the comma separated name-value pairs in <merchant-private-data>
684 * to an array of name-value pairs.
685 */
686 public static function stringToArray($str) {
687 $vars = $labels = array();
688 $labels = explode(',', $str);
689 foreach ($labels as $label) {
690 $terms = explode('=', $label);
691 $vars[$terms[0]] = $terms[1];
692 }
693 return $vars;
694 }
695 }