Answers.Body: <p>I would -</p>
  
  <ul>
  <li>make the return page a CiviCRM IPN callback - <code>civicrm/payment/ipn/XX</code> (where XX is the database ID of the payment processor in use).</li>
  <li>from this IPN callback, which is a method in your processor, return a 302 to the Thanks page if the transaction "checks out", and the Unsuccessful page if not</li>
  </ul>
  
  <p>Probably the best "reference" payment processors are NOT those in core, but those based on Omnipay.</p>
  
  <ul>
  <li>Hitting <code>civicrm/payment/ipn/XX</code> will land you in <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Payment.php#L1102" rel="nofollow"><code>CRM_Core_Payment::handleIPN()</code></a> which should in turn call your processor's <code>$processorInstance-&gt;$method();</code> determined via <code>CRM_Core_Payment::handlePaymentMethod()</code>.</li>
  <li><a href="https://github.com/eileenmcnaughton" rel="nofollow">Eileen's Github</a> probably has a few Omnipay based processors worth checking out.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-14T09:02:41.213Z
Answers.Text: Hope the above is helpful - it's been a while since I've touched any payment processor stuff in CiviCRM, but that's my best recollection of how you can handle this situation.
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-14T08:25:33.823Z
Answers.LastActivityDate: 2016-06-14T09:02:02.630Z
Answers.LastEditDate: 2016-06-14T09:02:02.630Z
Answers.UserDisplayName: Chris Burgess
Body: <p>I have implemented a payment gateway for SwipeHQ's 1-off payment mechanism. It's similar to PayPal's mechanism in that there's an LPN that notifies CiviCRM of the success/failure of the transaction, and also a callback URL.</p>
  
  <p>SwipeHQ adds a couple of URL parameters to the callback URL to notify of success/failure. These are in addition to the mechanisms in the LPN.</p>
  
  <p>e.g. &amp;user_data=619%2C7%2C5a00dbadde859a90b262eb532f863d98%2C%2C%2C2%2C%2C&amp;response_message=INVALID%20CARD%20NUMBER&amp;response_code=14&amp;result=declined</p>
  
  <p>My issue is that the standard Thankyou page in Civi has no way of picking up this important info and using it to instruct the user to try again. The message there is "Thank you for your payment" or whatever is set up as the thank you message.</p>
  
  <p>So what's the best/right way to handle this?</p>
  
  <ul>
  <li>is there a hook that could be used on the Thank you page to change the message?</li>
  <li>or might it be easiest to just override the Thank you php and tpl files in order to display appropriate messages? I'd rather that this could be integrated into the payment plugin rather than having to mess with overrides though.</li>
  <li>perhaps just some jQuery added to the page to do some dynamic HTML rewriting based on URL params?</li>
  <li>or as suggested in another question/answer, use the LPN trigger URL to give to the payment provider as the callback, and integrate the checking into that file. It would end with a redirect back to the thank you page on success.</li>
  </ul>
  
  <p>The latter seems like a possibility, but may have some issues:</p>
  
  <p>How would you handle HTML display in the case that it's not "success"? Just spit stuff out directly from the LPN? But this wouldn't have any other templating etc from the CMS. What other pages could be used to redirect to?</p>
  
  <p>Thanks in advance for any advice.</p>
  
Tags: <joomla><payment-processor><developer><swipehq>
Title: How to detect/handle card failure from Payment Provider's callback URL
ThreadText: # How to detect/handle card failure from Payment Provider's callback URL
  
  (Asked by: username_0 on 2015-11-09)
  
  I have implemented a payment gateway for SwipeHQ's 1-off payment mechanism. It's similar to PayPal's mechanism in that there's an LPN that notifies CiviCRM of the success/failure of the transaction, and also a callback URL.
  
  SwipeHQ adds a couple of URL parameters to the callback URL to notify of success/failure. These are in addition to the mechanisms in the LPN.
  
  e.g. &user\_data=619%2C7%2C5a00dbadde859a90b262eb532f863d98%2C%2C%2C2%2C%2C&response\_message=INVALID%20CARD%20NUMBER&response\_code=14&result=declined
  
  My issue is that the standard Thankyou page in Civi has no way of picking up this important info and using it to instruct the user to try again. The message there is "Thank you for your payment" or whatever is set up as the thank you message.
  
  So what's the best/right way to handle this?
  
  * is there a hook that could be used on the Thank you page to change the message?
  * or might it be easiest to just override the Thank you php and tpl files in order to display appropriate messages? I'd rather that this could be integrated into the payment plugin rather than having to mess with overrides though.
  * perhaps just some jQuery added to the page to do some dynamic HTML rewriting based on URL params?
  * or as suggested in another question/answer, use the LPN trigger URL to give to the payment provider as the callback, and integrate the checking into that file. It would end with a redirect back to the thank you page on success.
  
  The latter seems like a possibility, but may have some issues:
  
  How would you handle HTML display in the case that it's not "success"? Just spit stuff out directly from the LPN? But this wouldn't have any other templating etc from the CMS. What other pages could be used to redirect to?
  
  Thanks in advance for any advice.
  
  **Tags:** joomla, payment-processor, developer, swipehq
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-06-14. Score: 2
  
  I would -
  
  * make the return page a CiviCRM IPN callback - `civicrm/payment/ipn/XX` (where XX is the database ID of the payment processor in use).
  * from this IPN callback, which is a method in your processor, return a 302 to the Thanks page if the transaction "checks out", and the Unsuccessful page if not
  
  Probably the best "reference" payment processors are NOT those in core, but those based on Omnipay.
  
  * Hitting `civicrm/payment/ipn/XX` will land you in [`CRM_Core_Payment::handleIPN()`](https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Payment.php#L1102) which should in turn call your processor's `$processorInstance->$method();` determined via `CRM_Core_Payment::handlePaymentMethod()`.
  * [Eileen's Github](https://github.com/eileenmcnaughton) probably has a few Omnipay based processors worth checking out.
  
  > **Comments:**
  > **username_1**: Hope the above is helpful - it's been a while since I've touched any payment processor stuff in CiviCRM, but that's my best recollection of how you can handle this situation.  
  
  ---
  
  