Index: civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm.module |
— | — | @@ -37,13 +37,6 @@ |
38 | 38 | 'weight' => 10, |
39 | 39 | ); |
40 | 40 | |
41 | | - $items['admin/settings/queue2civicrm/payflow'] = array( |
42 | | - 'title' => 'Payflow Settings', |
43 | | - 'access arguments' => array('administer queue2civicrm'), |
44 | | - 'page callback' => 'drupal_get_form', |
45 | | - 'page arguments' => array('queue2civicrm_payflow'), |
46 | | - ); |
47 | | - |
48 | 41 | $items['queue2civicrm'] = array( |
49 | 42 | 'access callback' => TRUE, |
50 | 43 | 'type' => MENU_CALLBACK, |
— | — | @@ -70,37 +63,6 @@ |
71 | 64 | return implode("\n", $content); |
72 | 65 | } |
73 | 66 | |
74 | | -function queue2civicrm_payflow() { |
75 | | - |
76 | | -$form = array(); |
77 | | - |
78 | | - $form['queue2civicrm_pfp_partner'] = array( |
79 | | - '#type' => 'textfield', |
80 | | - '#title' => t('Payflow Partner'), |
81 | | - '#required' => FALSE, |
82 | | - ); |
83 | | - |
84 | | - $form['queue2civicrm_pfp_vendor'] = array( |
85 | | - '#type' => 'textfield', |
86 | | - '#title' => t('Payflow Vendor'), |
87 | | - '#required' => FALSE, |
88 | | - ); |
89 | | - |
90 | | - $form['queue2civicrm_pfp_user'] = array( |
91 | | - '#type' => 'textfield', |
92 | | - '#title' => t('Payflow User'), |
93 | | - '#required' => FALSE, |
94 | | - ); |
95 | | - |
96 | | - $form['queue2civicrm_pfp_password'] = array( |
97 | | - '#type' => 'textfield', |
98 | | - '#title' => t('Payflow Password'), |
99 | | - '#required' => FALSE, |
100 | | - ); |
101 | | - |
102 | | - return system_settings_form($form); |
103 | | -} |
104 | | - |
105 | 67 | /** |
106 | 68 | * Implementation of hook_perm(). |
107 | 69 | */ |
— | — | @@ -128,14 +90,6 @@ |
129 | 91 | '#default_value' => variable_get('queue2civicrm_subscription', '/queue/test'), |
130 | 92 | ); |
131 | 93 | |
132 | | - $form['queue2civicrm_pending'] = array( |
133 | | - '#type' => 'textfield', |
134 | | - '#title' => t('Pending subscription path'), |
135 | | - '#required' => TRUE, |
136 | | - '#default_value' => variable_get('queue2civicrm_pending', '/queue/pending'), |
137 | | - ); |
138 | | - |
139 | | - |
140 | 94 | $form['queue2civicrm_batch'] = array( |
141 | 95 | '#type' => 'select', |
142 | 96 | '#title' => t('Cron batch size'), |
— | — | @@ -153,67 +107,9 @@ |
154 | 108 | ), |
155 | 109 | ); |
156 | 110 | |
157 | | - $form['queue2civicrm_batch_pending'] = array( |
158 | | - '#type' => 'select', |
159 | | - '#title' => t('Cron batch size for PENDING queue'), |
160 | | - '#required' => TRUE, |
161 | | - '#default_value' => variable_get('queue2civicrm_batch_pending', 0), |
162 | | - '#options' => array( |
163 | | - 0 => '0 (Disable)', |
164 | | - 1 => 1, |
165 | | - 5 => 5, |
166 | | - 10 => 10, |
167 | | - 20 => 20, |
168 | | - 30 => 30, |
169 | | - 40 => 40, |
170 | | - 50 => 50, |
171 | | - ), |
172 | | - ); |
173 | | - |
174 | 111 | return system_settings_form($form); |
175 | 112 | } |
176 | 113 | |
177 | | -/** |
178 | | - * Callback for menu path "admin/settings/queue2civicrm/payflow". |
179 | | - */ |
180 | | -function queue2civicrm_settings_pfp() { |
181 | | - $item = array(); |
182 | | - |
183 | | - $item['queue2civicrm_pfp_partner'] = array( |
184 | | - '#type' => 'textfield', |
185 | | - '#title' => t('Payflow Partner'), |
186 | | - '#required' => FALSE, |
187 | | - ); |
188 | | - |
189 | | - $item['queue2civicrm_pfp_vendor'] = array( |
190 | | - '#type' => 'textfield', |
191 | | - '#title' => t('Payflow Vendor'), |
192 | | - '#required' => FALSE, |
193 | | - ); |
194 | | - |
195 | | - $item['queue2civicrm_pfp_user'] = array( |
196 | | - '#type' => 'textfield', |
197 | | - '#title' => t('Payflow User'), |
198 | | - '#required' => FALSE, |
199 | | - ); |
200 | | - |
201 | | - $item['queue2civicrm_pfp_password'] = array( |
202 | | - '#type' => 'textfield', |
203 | | - '#title' => t('Payflow Password'), |
204 | | - '#required' => FALSE, |
205 | | - ); |
206 | | - |
207 | | - return system_settings_form($item); |
208 | | -} |
209 | | - |
210 | | -/** |
211 | | - * Implementation of hook_cron(). |
212 | | - */ |
213 | | -function queue2civicrm_cron() { |
214 | | - queue2civicrm_batch_process(); |
215 | | - queue2civicrm_batch_process_pending(); |
216 | | -} |
217 | | - |
218 | 114 | function queue2civicrm_batch_process() { |
219 | 115 | set_time_limit(10); |
220 | 116 | |
— | — | @@ -237,32 +133,6 @@ |
238 | 134 | } |
239 | 135 | } |
240 | 136 | |
241 | | -/* |
242 | | - * Gets pending transactions off the queue |
243 | | - */ |
244 | | -function queue2civicrm_batch_process_pending() { |
245 | | - set_time_limit(10); |
246 | | - |
247 | | - $processed = 0; |
248 | | - |
249 | | - watchdog('queue2civicrm', 'Attempting to process up to ' . variable_get('queue2civicrm_batch_pending', 0) . ' pending contribution(s).'); |
250 | | - |
251 | | - // Attempt to dequeue items for the batch |
252 | | - for ($i = 0; $i < variable_get('queue2civicrm_batch_pending', 0); ++$i) { |
253 | | - $success = queue2civicrm_dequeue_pending(); |
254 | | - if ($success) { |
255 | | - ++$processed; |
256 | | - } |
257 | | - } |
258 | | - |
259 | | - if ($processed > 0) { |
260 | | - watchdog('queue2civicrm', 'Successfully processed ' . $processed . ' pending contribution(s).'); |
261 | | - } |
262 | | - else { |
263 | | - watchdog('queue2civicrm', 'No pending contributions processed.'); |
264 | | - } |
265 | | -} |
266 | | - |
267 | 137 | /** |
268 | 138 | * Connect using the Stomp library. |
269 | 139 | */ |
— | — | @@ -330,40 +200,6 @@ |
331 | 201 | } |
332 | 202 | |
333 | 203 | /** |
334 | | - * Remove one item from the queue and process it. |
335 | | - */ |
336 | | -function queue2civicrm_dequeue_pending() { |
337 | | - $con = _queue2civicrm_stomp_connection(); |
338 | | - |
339 | | - if ($con) { |
340 | | - $con->subscribe(variable_get('queue2civicrm_pending', '/queue/pending')); |
341 | | - |
342 | | - $msg = $con->readFrame(); |
343 | | - |
344 | | - // Skip processing if no message to process. |
345 | | - if ($msg !== FALSE) { |
346 | | - watchdog('queue2civicrm', 'Read frame:<pre>' . check_plain(print_r($msg, TRUE)) . '</pre>'); |
347 | | - set_time_limit(60); |
348 | | - try { |
349 | | - // find out what we should do with this transaction |
350 | | - queue2civicrm_inquire_pending($msg); |
351 | | - // Confirm successful processing of message. |
352 | | - $con->ack($msg); |
353 | | - return TRUE; |
354 | | - } |
355 | | - catch (Exception $e) { |
356 | | - watchdog('queue2civicrm', 'Could not process frame from pending queue.', array(), WATCHDOG_ERROR); |
357 | | - } |
358 | | - } |
359 | | - else { |
360 | | - watchdog('queue2civicrm', 'Nothing to process on pending queue.'); |
361 | | - } |
362 | | - } |
363 | | - |
364 | | - return FALSE; |
365 | | -} |
366 | | - |
367 | | -/** |
368 | 204 | * Process one contribution from the queue to CiviCRM. |
369 | 205 | */ |
370 | 206 | function queue2civicrm_import( $msg ) { |
— | — | @@ -465,207 +301,23 @@ |
466 | 302 | } |
467 | 303 | |
468 | 304 | /** |
469 | | - * Process one contribution from the pending queue |
470 | | - * run an Inquiry transaction to Payflow |
471 | | - * deletes, ignores, or stores in to CiviCRM. |
472 | | - */ |
473 | | -function queue2civicrm_inquire_pending($msg) { |
474 | | - // Decode the message body. |
475 | | - $contribution = (array) json_decode($msg->body); |
476 | | - |
477 | | - watchdog('queue2civicrm', 'Pending contribution (pre-conversion):<pre>' . check_plain(print_r($contribution, TRUE)) . '</pre>'); |
478 | | - |
479 | | - $payflow_data['partner'] = variable_get('queue2civicrm_pfp_partner', 'PayPal'); |
480 | | - $payflow_data['vendor'] = variable_get('queue2civicrm_pfp_vendor', NULL); |
481 | | - $payflow_data['user'] = variable_get('queue2civicrm_pfp_user', NULL); |
482 | | - $payflow_data['password'] = variable_get('queue2civicrm_pfp_password', NULL); |
483 | | - |
484 | | - if ( ($payflow_data['partner'] == '') || ($payflow_data['vendor'] == '') || ($payflow_data['user'] == '') || ($payflow_data['password'] == '') ) |
485 | | - { |
486 | | - |
487 | | - queue2civicrm_requeue( $contribution ); |
488 | | - watchdog('queue2civicrm', 'Missing Payflow User Information. Enter Payflow Settings to process pending transactions'); |
489 | | - return; |
490 | | - } |
491 | | - |
492 | | - /** |
493 | | - * if the gateway is set to insert test, import the pending contribution, otherwise follow normal flow |
494 | | - * |
495 | | - * Conditional added by Arthur Richards |
496 | | - */ |
497 | | - if ($contribution['gateway'] != 'insert_test') { |
498 | | - $origid = $contribution['gateway_txn_id']; |
499 | | - |
500 | | - $result = queue2civicrm_payflow_inquiry( $origid, $payflow_data ); |
501 | | - |
502 | | - watchdog('queue2civicrm', 'Result from PFP :<pre>' . check_plain(print_r($result, TRUE)) . '</pre>'); |
503 | | - |
504 | | - $success = queue2civicrm_payflow_result( $result, $contribution ); |
505 | | - } else { |
506 | | - queue2civicrm_import_pending( $contribution ); |
507 | | - } |
508 | | - |
509 | | - watchdog('queue2civicrm', 'The pending transaction result:<pre>' . check_plain(print_r($success, TRUE)) . '</pre>'); |
510 | | -} |
511 | | - |
512 | | -/** |
513 | | - * Sends a name-value pair Inquiry Transaction to Payflow gateway |
514 | | - * |
515 | | - */ |
516 | | -function queue2civicrm_payflow_inquiry( $origid, $payflow_data ) { |
517 | | - |
518 | | - // create payflow query string, include string lengths |
519 | | - $queryArray = array( |
520 | | - 'TRXTYPE' => 'I', |
521 | | - 'TENDER' => 'C', |
522 | | - 'USER' => $payflow_data['user'], |
523 | | - 'VENDOR' => $payflow_data['vendor'], |
524 | | - 'PARTNER' => $payflow_data['partner'], |
525 | | - 'PWD' => $payflow_data['password'], |
526 | | - 'ORIGID' => $origid, |
527 | | - ); |
528 | | - |
529 | | - foreach( $queryArray as $name => $value ) { |
530 | | - $query[] = $name . '[' . strlen( $value ) . ']=' . $value; |
531 | | - } |
532 | | - |
533 | | - $queryString = implode( '&', $query ); |
534 | | - |
535 | | - $payflow_query = $queryString; |
536 | | - |
537 | | - // assign header data necessary for the curl_setopt() function |
538 | | - $order_id = date( 'ymdH' ) . rand( 1000, 9999 ); |
539 | | - $user_agent = $_SERVER['HTTP_USER_AGENT']; |
540 | | - $headers[] = 'Content-Type: text/namevalue'; |
541 | | - $headers[] = 'Content-Length : ' . strlen( $payflow_query ); |
542 | | - $headers[] = 'X-VPS-Client-Timeout: 45'; |
543 | | - $headers[] = 'X-VPS-Request-ID:' . $order_id; |
544 | | - $ch = curl_init(); |
545 | | - //CHANGE TO LIVE URL |
546 | | - curl_setopt( $ch, CURLOPT_URL, 'https://pilot-payflowpro.paypal.com' ); |
547 | | - curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); |
548 | | - curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent ); |
549 | | - curl_setopt( $ch, CURLOPT_HEADER, 1 ); |
550 | | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
551 | | - curl_setopt( $ch, CURLOPT_TIMEOUT, 90 ); |
552 | | - curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0 ); |
553 | | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
554 | | - curl_setopt( $ch, CURLOPT_POSTFIELDS, $payflow_query ); |
555 | | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 ); |
556 | | - curl_setopt( $ch, CURLOPT_FORBID_REUSE, true ); |
557 | | - curl_setopt( $ch, CURLOPT_POST, 1 ); |
558 | | - |
559 | | - // As suggested in the PayPal developer forum sample code, try more than once to get a response |
560 | | - // in case there is a general network issue |
561 | | - $i = 1; |
562 | | - |
563 | | - while( $i++ <= 3 ) { |
564 | | - $result = curl_exec( $ch ); |
565 | | - $headers = curl_getinfo( $ch ); |
566 | | - |
567 | | - if( $headers['http_code'] != 200 && $headers['http_code'] != 403 ) { |
568 | | - sleep( 5 ); |
569 | | - } elseif( $headers['http_code'] == 200 || $headers['http_code'] == 403 ) { |
570 | | - break; |
571 | | - } |
572 | | - } |
573 | | - |
574 | | - if( $headers['http_code'] != 200 ) { |
575 | | - watchdog('queue2civicrm', 'No response from credit card processor'); |
576 | | - curl_close( $ch ); |
577 | | - exit; |
578 | | - } |
579 | | - |
580 | | - curl_close( $ch ); |
581 | | - |
582 | | - // get result string |
583 | | - $result = strstr( $result, 'RESULT' ); |
584 | | - |
585 | | - return $result; |
586 | | - |
587 | | -} |
588 | | - |
589 | | - /** |
590 | | - * "Reads" the name-value pair result string returned by Payflow |
591 | | - * then decide what to do based on that result |
592 | | - * |
593 | | - */ |
594 | | -function queue2civicrm_payflow_result( $result, $contribution ) { |
595 | | - |
596 | | - // prepare NVP response for sorting and outputting |
597 | | - $responseArray = array(); |
598 | | - |
599 | | - while( strlen( $result ) ) { |
600 | | - // name |
601 | | - $namepos = strpos( $result, '=' ); |
602 | | - $nameval = substr( $result, 0, $namepos ); |
603 | | - // value |
604 | | - $valuepos = strpos( $result, '&' ) ? strpos( $result, '&' ) : strlen( $result ); |
605 | | - $valueval = substr( $result, $namepos + 1, $valuepos - $namepos - 1 ); |
606 | | - // decoding the respose |
607 | | - $responseArray[$nameval] = $valueval; |
608 | | - $result = substr( $result, $valuepos + 1, strlen( $result ) ); |
609 | | - } |
610 | | - |
611 | | - // we will process the transaction, ignore it because it was declined |
612 | | - // or put it back on the queue |
613 | | - $resultCode = $responseArray['RESULT']; |
614 | | - |
615 | | - // if approved, display results and send transaction to the queue |
616 | | - |
617 | | - if( $resultCode == '0' ) { |
618 | | - $approved = queue2civicrm_import_pending( $contribution ); |
619 | | - return "Contribution was changed to approved"; |
620 | | - // give user a second chance to enter incorrect data |
621 | | - } elseif ( $resultCode == '126' ) { |
622 | | - // put the transaction back on the queue |
623 | | - $requeued = queue2civicrm_requeue( $contribution ); |
624 | | - if ($requeued) { |
625 | | - return "Contribution has not changed and was put back on the queue"; |
626 | | - } |
627 | | - } elseif ( $resultCode == '26' ) { |
628 | | - // put the transaction back on the queue |
629 | | - $requeued = queue2civicrm_requeue( $contribution ); |
630 | | - if ($requeued) { |
631 | | - return "Payflow User Account settings are invalid. Please input account info."; |
632 | | - } |
633 | | - } else { return "Contribution was ignored, it was neither approved nor still a 126"; } |
634 | | - |
635 | | - |
636 | | -}// end display results |
637 | | - |
638 | | -/** |
639 | | - * Process one contribution from the queue to CiviCRM. |
640 | | - */ |
641 | | -function queue2civicrm_import_pending( $contribution ) { |
642 | | - queue2civicrm_import( $contribution ); |
643 | | -} |
644 | | - |
645 | | -function queue2civicrm_requeue( $contribution ) { |
646 | | - $transaction = json_encode($contribution); |
647 | | - |
648 | | - $con = _queue2civicrm_stomp_connection(); |
649 | | - |
650 | | - if ( $con ) { |
651 | | - // send the message back to the queue |
652 | | - $queue = variable_get('queue2civicrm_pending', '/queue/pending'); |
653 | | - $result = $con->send($queue, $transaction, array('persistent' => 'true')); |
654 | | - } |
655 | | - |
656 | | - if (!$result) { |
657 | | - watchdog('queue2civicrm', 'Could not return message to the queue!:<pre>' . check_plain(print_r($contribution, TRUE)) . '</pre>'); |
658 | | - return false; |
659 | | - } |
660 | | - else { |
661 | | - watchdog('queue2civicrm', 'Message put back on the queue'); |
662 | | - return true; |
663 | | - } |
664 | | - |
665 | | -} |
666 | | - |
| 305 | + * Make the form to insert a test message into the queue |
| 306 | + */ |
667 | 307 | function queue2civicrm_insertmq_form() { |
668 | 308 | $message = queue2civicrm_generate_message(); |
669 | 309 | |
| 310 | + $form['submit1'] = array( |
| 311 | + '#value' => 'Insert into queue', |
| 312 | + '#type' => 'submit' |
| 313 | + ); |
| 314 | + |
| 315 | + $form['queue'] = array( |
| 316 | + '#type' => 'textfield', |
| 317 | + '#title' => 'Queue to submit to', |
| 318 | + '#default_value' => '/queue/test_pending_pfp', |
| 319 | + '#required' => TRUE |
| 320 | + ); |
| 321 | + |
670 | 322 | foreach ( $message as $key => $value ) { |
671 | 323 | $form[$key] = array( |
672 | 324 | '#type' => 'textfield', |
— | — | @@ -674,7 +326,7 @@ |
675 | 327 | ); |
676 | 328 | } |
677 | 329 | |
678 | | - $form['submit'] = array( |
| 330 | + $form['submit2'] = array( |
679 | 331 | '#value' => 'Insert into queue', |
680 | 332 | '#type' => 'submit' |
681 | 333 | ); |
— | — | @@ -682,9 +334,14 @@ |
683 | 335 | return $form; |
684 | 336 | } |
685 | 337 | |
| 338 | +/** |
| 339 | + * Implementation of hook_form_submit |
| 340 | + * |
| 341 | + * Submits a test message to the queue |
| 342 | + */ |
686 | 343 | function queue2civicrm_insertmq_form_submit($form, &$form_state) { |
687 | 344 | $con = _queue2civicrm_stomp_connection(); |
688 | | - $result = $con->send(variable_get('queue2civicrm_pending', '/queue/pending'), drupal_to_js($form_state['values']), array('persistent' => true)); |
| 345 | + $result = $con->send( $form_state['values']['queue'], drupal_to_js($form_state['values']), array('persistent' => true)); |
689 | 346 | $con->disconnect(); |
690 | 347 | if (!$result) { |
691 | 348 | watchdog('queue2civicrm','Send to queue failed for this message: <pre>' . check_plain(print_r($form_state['values'], TRUE)) . '</pre>'); |