Forums

Redirect (with Paypal)

jessica 29 Jul, 2009
I'm using the redirect plugin to forward the user to paypal after filling out the form. I store the form data. Now, how would I link up the paypal and form? I saw on here about a transaction id but I think that's just with paypal api? I'm using a basic paypal account and not the fancy pro level. Or maybe it would be better to onsubmit grab the id from the table and pass that to paypal? But I'm not sure when the table inserts happen.

This is for a non-profit conference registration form and my first time doing this with paypal🙂

Suggestions?

Thank you!
Jessica
GreyHead 29 Jul, 2009
Hi Jessica,

I pass a unique ID to PayPal, you can either grab the Uid or the record number from the Autogenerated code or create one of your own as long as it's saved in the DB table. If you use the UID you'll need to set the flow sequence so that the ReDirect Plugin runs after the Auogenerated code.

You an use one of the PayPal fields as a transaction ID - I forget the field name but it's in the Web-forms API description.

Bob
jessica 29 Jul, 2009
Hi Bob,

Thank you for the suggestions. Right now I'm using item_name and can append an ID to that like "Registration for Name (ID)" or such. But if there's another field that might be better. I'll look into it! Thank you!

~Jessica
GreyHead 29 Jul, 2009
Hi Jessica,

Just stumbled across mu PayPal docs in a heap on my desk here.

There's an optional 'invoice' parameter that is good to use for a transaction identifier.

Bob
jtatum 29 Jul, 2009
I noticed the invoice parameter as well - it seems ideal. cf_id would make the perfect invoice number for paypal.

Currently plugins are set to run last and redirect is the only plugin, so it should have access to cf_id... However, without stepping through a lot of code, it's not obvious to me where cf_id would be.

For reference, the autogenerated code is:
<?php
		$MyForm =& CFChronoForm::getInstance("fall09Registration");
		if($MyForm->formparams("dbconnection") == "Yes"){
			$user = JFactory::getUser();			
			$row =& JTable::getInstance("chronoforms_fall09Registration", "Table");
			srand((double)microtime()*10000);
			$inum	=	"I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
			JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
			JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
			JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
			JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
			$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );			
			if (!$row->bind( $post )) {
				JError::raiseWarning(100, $row->getError());
			}				
			if (!$row->store()) {
				JError::raiseWarning(100, $row->getError());
			}
			$MyForm->tablerow["jos_chronoforms_fall09Registration"] = $row;
		}
		?>

I suppose it would be available somewhere after store() is invoked? A lot of objects flying around here. This seems like an obvious thing to do so I'm surprised the redirect plugin doesn't expose cf_id actually. Is getInstance() documented somewhere? If I invoke this in the extra code of the redirect plugin to pull the tablerow variable, can I get at cf_id that way?
GreyHead 30 Jul, 2009
Hi Jessica,

The Autogenerated code leaves all of the data in the $MyForm->tablerow["jos_table_name"] object so you can use this to access the current cf_id. (Replace jos_table_name with the name of your table though.)

Bob
jtatum 30 Jul, 2009
Hi Bob,

Is the $MyForm instance available in the "extra code" section of the redirect plugin?

James
jessica 30 Jul, 2009
Hello Bob,

Thank you. I was tinkering a little yesterday and was having the dickens. I'll try again unless James beats me to it.

~Jessica

James,

It may depend on the run order.

~Jessica
GreyHead 30 Jul, 2009
Hi James,

It should be available - though, as Jessica says, it will depend on the run order.

Bob
jessica 30 Jul, 2009
Hi Bob,

I think I have the order right. I've tried this code with me hard coding a number and that worked. It's when I try to pull it from the myForm->tablerow that it nulls out. RunOrder on the form is: 1: plugins block, 2: Order of OnSubmit block, 3: Order of Autogenerated block

The following is in the extra code part of the redirect. The form's zid field becomes "invoice" on paypal. Like I said, that part is fine. But I'm getting nothing in $myId.

<?php

$info =& $MyForm->tablerow["jos_chronoforms_fall09Registration"];

$myId = $info["cf_id"];

JRequest::setVar('zid', $myId, 'post');
?>


Thank you,
Jessica
jtatum 30 Jul, 2009
After playing with this forever, it seems that redirect runs very early in the submission chain and can't be moved. Changing the runorder of plugins vs. autogenerated vs. onsubmit does not modify the order of the redirect plugin.

There is a setting in redirect under url parameters, "before email" vs. "after email." It seems to be stuck on before email and changing it doesn't work. Looking at the debug output, indeed, redir is called before emails and probably before data is submitted to the database.

First, we used the onsubmit after email block to implement the code. Next, Jessica hacked the db using phpmyadmin to change redirect to run after email. That worked.

Long story short - there's a UI bug in selecting before email or after email in the redirect plugin, and doing this pretty much depends on it being after the emails, or at least after the data is committed (obviously).

Thanks for all the help, Bob🙂
GreyHead 30 Jul, 2009
Hi Jamie,

Midnight here - I'll check that in the morning.

Bob
jtatum 04 Aug, 2009
Just sending a ping to remind on this one🙂 Thanks
wimprovoost 07 Aug, 2009
Hello,

was struggling with the same, found this workaround somewhere that at least for me works fine:

Since Paypal doesn't actually do anything with the invoice number, you could retrieve the cf_id when you're on the next form after the form that does the database insert, and communicate the invoice number to your user when they have returned from Paypal.

The retrieval itself is the workaround: you probably have a field that is unique to a user, like the email field that Paypal returns or mobile phone nr.
Use this to select the latest record for this user:

$query="SELECT cf_id FROM jos_chronoforms_yourtable WHERE email='$_POST[payer_email]' ORDER BY cf_id DESC LIMIT 1";

and you're done!

Wim
Max_admin 07 Aug, 2009
Hi Jessica,

a late fix for your code:


$info = $MyForm->tablerow["jos_chronoforms_fall09Registration"]; // this is an object not array!

$myId = $info->cf_id;


I'm not sure if your sorted this out, but I know the run order is not very flexible, a complete events system need to be done and its already in my todo list, when it will be available I don't know! 😑

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.