Forum for discussing general topics related to Couch.
3 posts Page 1 of 1
Okay, this one is probably pretty simple and obvious, but I've been working non-stop for over 24 hours, and my brain is just about to turn to mush. I'll just post this here, and hope that by the time I wake up, some kind soul will have provided me with some guidance...

I am setting up a website, where the client wants to 'sell' yearly memberships. There will be 2 kinds of memberships: one for individual members, and one for organisations/companies. When a person or company signs up, they have to provide quite a bit of information about themselves, and that information has to be passed on to the client - preferably via email, after the payment for the membership has been accepted by PayPal.

I have gone through the docs about the PayPal Core Concepts and the PayPal tag, but there must be something I'm missing. It seems that the idea of the PayPal tag, is that it should be placed in a cloned page (which has pre-existing information taken directly from the database), and not in a form (which will have ad-hoc information provided by the visitor on-the-spot).

How can I process a payment, and attach information that must be provided by the user via a form?

Once again, I apologise, as the answer to this must be pretty obvious, but I'm just too tired to think straight! :(

Many thanks for any and all suggestions.
Hi,

As you have already gone through the PayPal button's docs, the following key point of how things interact must be clear to you -

When a visitor clicks the PayPal button he actually leaves the Couch managed site and moves over to PayPal. From this point onwards, how the transaction proceeds is a black box for Couch.
The visitor could simply abandon the transaction and disappear.

It is PayPal that informs back Couch that a transaction is complete by sending the IPN. This is the only point where we can be sure that a sale has gone through and take further action.

The point I am trying to make is this - suppose we provide a form on our site where the visitors 'provide quite a bit of information about themselves'. Now when they press the PayPal button they'll be moving off to a different site (and possibly never complete the transaction).

So, what do we do with the data that has been entered in the form?
One method could be to to send it along with the visitor to PayPal and ask PayPal to send it back to us with the IPN on successful transaction.

PayPal does provide a parameter named 'custom' that can be used for this purpose however it is limited to only 255 characters so would be useless in our case. (this works well for smaller amount of data e.g. the product page on this very site, where someone buys a commercial license, makes use of the 'custom' parameter to send the domain name of the licensed site to PayPal. PayPal then sends back this domain name with the IPN when the payment is complete)

The only other method left would be to temporarily save all the data on our site before sending the visitor off to PayPal. In the 'custom' parameter we simply send the identifier of where we saved the data so we can get back to it when required.

Assuming the transaction is complete and we get the IPN, we use the 'custom' parameter to retrieve the saved data and do whatever needs to be done (e.g. email the data in your case).

What happens if the transaction is aborted?
The IPN never arrives and we are stuck with the data we saved with such anticipation.

This is something that would be handled by regularly pruning saved data.

OK, I think you can see that things are lot more involved that what you might have anticipated.

Anyways, you should still be able to implement this in Couch if you are willing to mess a little with PHP coding.

We can use DataBound form to persist the form data and redirect the visitor to PayPal with id of the newly created page as the 'custom' parameter (the code for redirecting to PayPal is in the cart component). Make sure to set the 'notify_url' parameter to a template that'll process the IPN.

Code for processing the IPN can be culled from paypal_processor() in tags.php and validate_transaction() function in functions.php (will need just a bit of tweaking).
The logic would be to get the id from 'custom' param and fetch the cloned page with the id. We have all the inputted data at this point and can do further processing (email or whatever).
Can delete the page after processing is complete.

As for the 'abandoned' form submissions - the client can either manually delete those every few days or set up a cron job to do so.

In closing, the logic outlined above is very much what we'll have to do for implementing 'Sales orders' functionality in CouchCart - the form submissions would become the sales orders with a status of 'pending'. Incoming IPN would edit the orders to set the status to 'complete'.

Hope this helps.
KK, thank you very much for your very clear answer - it was very helpful, indeed.

This is quite a bit more complex than what I would like to implement for this particular client. It may be simpler to just get the new member to fill out a form on the website, and have them email them with a PayPal invoice. I'll have a talk to the client, and see.

Once again, many thanks for your always excellent support.
3 posts Page 1 of 1