CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • New Payment Processor Redirect to Thank You problem
Pages: [1]

Author Topic: New Payment Processor Redirect to Thank You problem  (Read 4261 times)

simonium

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 2
New Payment Processor Redirect to Thank You problem
September 08, 2010, 05:11:28 am
Hi there,

I'm trying to write a new payment processor for Realex, which runs in Notify mode.  The processor redirects to the realex site where credit card details are entered and then redirects back to my civicrm.

everything works fine except the final redirect to thank you page.  it just isn't happening for me.

this is the code which handles the redirect:

Code: [Select]

        if ( $success == 1 ) {
            if ( $component == "event" ) {
                $finalURL = CRM_Utils_System::url( 'civicrm/event/register', "_qf_ThankYou_display=1&qfKey=$qfKey", false, null, false );
            }
            elseif ( $component == "contribute" ) {
                $finalURL = CRM_Utils_System::url( 'civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey=$qfKey", false, null, false );
            }
   
            CRM_Utils_System::redirect( $finalURL );
}
        else {
            if ( $component == "event" ) {
                $finalURL = CRM_Utils_System::url( 'civicrm/event/confirm', "reset=1&cc=fail&participantId=$privateData[participantID]", false, null, false );
            }
            elseif ( $component == "contribute" ) {
                $finalURL = CRM_Utils_System::url( 'civicrm/contribute/transact', "_qf_Main_display=1&cancel=1&qfKey=$qfKey", false, null, false );
            }

            CRM_Utils_System::redirect( $finalURL );
        }

does anyone know why this isn't working?  Also, what value should the qfKey parameter hold?  I'm almost finished and would like to post the code back up to the forums as I've had a hard time figuring out how to implement it, and I think it could be useful for others.  Though I just need to get this last part working.

Any help would be greatly appreciated.


simon

simonium

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 2
Re: New Payment Processor Redirect to Thank You problem
September 23, 2010, 04:08:54 am
Just an update . . . I managed to figure out what I needed to know from my last post, I still couldn't get the redirect to work but simply printed a html page with a redirect meta tag which works just as well.

However, I cant seem to find a "payment failed " page anywhere in civicrm, there must be page that handles a "declined" response from a payment processor in notify mode - does anybody know what it is?

thanks in advance . . .

Simon.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: New Payment Processor Redirect to Thank You problem
September 23, 2010, 10:16:48 am

for the declined page, we just take users back to the main page and display the payment processor message

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: New Payment Processor Redirect to Thank You problem
September 23, 2010, 01:29:24 pm
Hi simonium - I've started re-directing the person back to the pending payment page for events - look in the Payment Express code for that. It means they can try again against the same event registration. They do wind up with 2 contributions against the same event which we've found to be the lessor of 2 evils. Now that 3.2. has a better data structure for payments I'm hoping to look at it again at some point
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

simonium

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 2
Re: New Payment Processor Redirect to Thank You problem
September 24, 2010, 06:23:31 am
Thanks for getting back to me guys, I really appreciate the support.  Ok, so I've sorted out the problem of re-directing back to a payment declined page, but now it's not re-directing back to the thank you page.  I'm really stuck, totally hit a wall.

this my code:

realexRedirect.php:

Code: [Select]
function doTransferCheckout( &$params, $component ) {
       
        // here I prepare all the parameters for the form below:
       
        ?>
        <html>
            <head>
                <title>Redirecting . . .</title>
            </head>
            <body>
                Redirecting . . .
                <form name="mainform" action="https://epage.payandshop.com/epage.cgi" method="post">
                   
                    <input type=hidden name="MERCHANT_ID" value="<?=$args['MERCHANT_ID']?>">
                    <input type=hidden name="ORDER_ID" value="<?=$args['ORDER_ID']?>">
                    <input type=hidden name="CURRENCY" value="<?=$args['CURRENCY']?>">
                    <input type=hidden name="AMOUNT" value="<?=$args['AMOUNT']?>">
                    <input type=hidden name="TIMESTAMP" value="<?=$args['TIMESTAMP']?>">
                    <input type=hidden name="MD5HASH" value="<?=$args['MD5HASH']?>">
                    <input type=hidden name="AUTO_SETTLE_FLAG" value="1">
                   
                    <input type=hidden name="module" value="<?=$args['module']?>">
                    <input type=hidden name="participantID" value="<?=$args['participantID']?>">
                    <input type=hidden name="eventID" value="<?=$args['eventID']?>">
                    <input type=hidden name="contributionID" value="<?=$args['contributionID']?>">
                    <input type=hidden name="contactID" value="<?=$args['contactID']?>">
                    <input type=hidden name="qfKey" value="<?=$params['qfKey']?>">
                    <input type=hidden name="baseurl" value="<?=$GLOBALS['base_url']?>">
                   
                </form>
                <script type="text/javascript">document.mainform.submit();</script>
            </body>
        </html>
       
        <?php
        
        
if(!isset($args['eventID']) || $args['eventID'] == "") {
            die();   
//<-- so if this is commented out, the contribution is always marked as complete no matter what, if it is left in : no thank you page (for contributions)
        
}
        
    }

see the 'die()' statement at the end of the above function? that's where I'm stuck - just can't figure out what's happening at this point in the program.

realexRedirectIPN.php:   // this handles the response from the payment processor


Code: [Select]
        require_once 'CRM/Core/Transaction.php';
        $transaction = new CRM_Core_Transaction( );
       
        $participant =& $objects['participant'];
        $membership  =& $objects['membership' ];
       
        // check if contribution is already completed, if so we ignore this ipn
        if ( $contribution->contribution_status_id == 1 ) {
            $transaction->commit( );
            CRM_Core_Error::debug_log_message( "returning since contribution has already been handled" );
        }
       
        if ( $input['result'] = '00' ) { // payment accepted
           
            $this->completeTransaction( $input, $ids, $objects, $transaction, $recur );
            $component_page = ($component == "event") ? "event/register" : "contribute/transact";
            $absoluteURL = $input['baseurl'].'/civicrm/'.$component_page.'&_qf_ThankYou_display=1&qfKey='.$input['qfKey'];
           
            echo "
            <html>
                <head>
                    <meta http-equiv=\"refresh\" content=\"0;url=$absoluteURL\">
                </head>
                <body>
                    Redirecting . . .
                </body>
            </html>";
           
}
        else { // payment declined
           
            $display_error = "payment declined";
           
            if ( $component == "event" ) {
                $absoluteURL = $input['baseurl']."/civicrm/event/confirm&reset=1&cc=fail&participantId=".$input['participantID'];
            }
            elseif ( $component == "contribute" ) {
                $absoluteURL = $input['baseurl']."/civicrm/contribute/transact&_qf_Main_display=1&cancel=1&errorcode=".$display_error."&qfKey=".$input['qfKey'];
            }
           
            echo "
            <html>
                <head>
                    <meta http-equiv=\"refresh\" content=\"0;url=$absoluteURL\">
                </head>
                <body>
                    Redirecting . . .
                </body>
            </html>";
        }



Sorry about all the code, I'm not sure really how to explain it without posting the code, and thanks again for your help guys.

jimyhuang

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 3
Re: New Payment Processor Redirect to Thank You problem
November 15, 2010, 10:21:53 am
Did you guys have workaround for this?
I have the same problem when writing new payment method for civicrm.

I can't get the "Thank you page (Event/Form/Registeration/ThankYou.php)" in event page. I have correct url redirect to, but always show me the "Event Confirm Page(Event/Form/Registeration/Confirm.php)" event I have parameter "_qf_ThankYou_display".
The url is below:
Code: [Select]
civicrm/event/register?_qf_ThankYou_display=1&qfKey=73e8e314040d29f68eb81d6f69871ed8_6710
Seems quickForm have some handling there, and didn't resolve my parameter. But I can't find out where it is.
Any suggestion?
(My civicrm version is 3.2.3 Drupal PHP5 29586 )
« Last Edit: November 15, 2010, 10:27:08 am by jimyhuang »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: New Payment Processor Redirect to Thank You problem
November 15, 2010, 07:47:13 pm

can u try this url:

Code: [Select]
civicrm/event/register&_qf_ThankYou_display=1&qfKey=73e8e314040d29f68eb81d6f69871ed8_6710

Note the & instead of the ?

thanx

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jimyhuang

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 3
Re: New Payment Processor Redirect to Thank You problem
November 16, 2010, 12:45:32 am
hi lobo,

I tried the url you mention about, but still stuck there.  :'(
URL I tried list below, redirect by code in myIPN.php:
Code: [Select]
/index.php?q=civicrm/contribute/transact&_qf_ThankYou_display=true&qfKey=f92283d7606cbcd2ef9c1560f44572c9_1702
/civicrm/contribute/transact&_qf_ThankYou_display=true&qfKey=f92283d7606cbcd2ef9c1560f44572c9_1702
/civicrm/contribute/transact&_qf_ThankYou_display=true&qfKey=f92283d7606cbcd2ef9c1560f44572c9_1702

Could you help give me key-point how the parameter "_qf_ThankYou_display" handle generation of a form? Maybe I can find out what's going on here.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: New Payment Processor Redirect to Thank You problem
November 16, 2010, 06:38:48 am

jimmy:

can u describe the flow a bit more?

noticed the below in both your posts that the redirect was being tried from *IPN.php

In general the IPN is being triggered by an "anonymous" user, so doing any redirect there will not redirect the user

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jimyhuang

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 3
Re: New Payment Processor Redirect to Thank You problem
November 18, 2010, 03:00:06 am
hi Lobo,

Finally I found the situation there and bugs of my code.

As simonium mention about, he add die() or exit() at the end of function doTransferCheckout(). I made the same mistake.

It should be add redirect to another page, or complete the civicrm exit state. Or at least, I need to save session object using code below before exit. Because QuickForm stores the state to session, it will check state first, then guest the best step of form for us. If we don't save the session, when client hit "Confirm" button and QuickForm never know if client submitted.

Code: [Select]
  require_once 'CRM/Core/Session.php';
      CRM_Core_Session::storeSessionObjects( );

God I spent much time to track code, and made this simple mistake... Leave this for reference.
Now I can redirect the client correctly. And thanks for your support!

simonium

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 2
Re: New Payment Processor Redirect to Thank You problem
November 18, 2010, 09:58:21 am
Perfect, that makes so much sense. My workaround was to pass an extra url parameter to what was supposed to be the thank you page.  The problem was the confirm page was being shown instead, so I changed confirm page template (through override) to pick up the url parameter and display a custom thank you page instead. Definitely an ugly workaround.  Thanks for posting your solution!

This is the code in the template override:

Code: [Select]
{if $smarty.get.mode EQ "thankyou"} {* 'mode=thankyou' is the url parameter passed from the IPN *}

Thank You - Your payment was successful.  Here are the details of your payment:
<br /><br /><hr width="504"/><br />
<b>Name / Email:</b> {$smarty.get.contactname}<br /><br />
<b>Paid to:</b> {$smarty.get.source}<br /><br />
<b>Amount:</b> {$smarty.get.cur} {$smarty.get.amount}<br /><br />
<b>Date:</b> {$smarty.get.date}<br /><br />

{else}
// normal template after this . . . .

digitalhuman

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
    • Senior Software Engineer
  • CiviCRM version: 4.5.5
  • CMS version: CiviCRM
  • MySQL version: 10
  • PHP version: 5.5
Re: New Payment Processor Redirect to Thank You problem
January 09, 2015, 03:41:10 am
Quote from: jimyhuang on November 18, 2010, 03:00:06 am
hi Lobo,

Finally I found the situation there and bugs of my code.

As simonium mention about, he add die() or exit() at the end of function doTransferCheckout(). I made the same mistake.

It should be add redirect to another page, or complete the civicrm exit state. Or at least, I need to save session object using code below before exit. Because QuickForm stores the state to session, it will check state first, then guest the best step of form for us. If we don't save the session, when client hit "Confirm" button and QuickForm never know if client submitted.

Code: [Select]
  require_once 'CRM/Core/Session.php';
      CRM_Core_Session::storeSessionObjects( );

God I spent much time to track code, and made this simple mistake... Leave this for reference.
Now I can redirect the client correctly. And thanks for your support!

WOW! This is indeed working! THANK YOU! I was stuck on the same situation for days!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • New Payment Processor Redirect to Thank You problem

This forum was archived on 2017-11-26.