Forums

Chronoforms 6 Paypal Redirect

webix 31 Jul, 2018
Hi,

After I submit my form, it will save to DB.
I have a DB column flag for payment.

So my question is, how to update database after payment was made thru paypal?

Thank you in advance for your help.

Cheers!
GreyHead 01 Aug, 2018
Hi webix,

The most effective way to do this is to use the PayPal IPN (Instant Payment Notification) service. You can set up a separate form event to handle the interactions with PayPal - they will include a confirmation that the transaction is valid and notices of success (or not) of the payment.

There is a FAQ here it was written for an older version for ChronoForms but the same basic principles apply.

Bob
webix 01 Aug, 2018
Hi Bob,

i think this wasnt formulated good enought. I have already the form set and this working like a sharm. My concern is how to update the DB after PayPal transaction is complete. The issue is, that i cant understend how to recognise what record have to be updated.

I did try to debug the form after back from PayPal page, but there is only array below what i got:
Array
(
    [chronoform] => form
    [event] => complete
    [option] => com_chronoforms6
    [Itemid] => 
)
So i do not understand how i can get the info what record i have to update in my DB after payment is successfull.

Truying to add the code to the complete event and on IPN Verifier but there is no data delivered:
echo'<div>$form->data: '.print_r($form->data, true).'</div>';
Also i do not realy understend where exactly i have to place DB updater within setup.

Thank you in advance
Alex
GreyHead 01 Aug, 2018
Hi webix,

Are you using IPN or just a PayPal redirect?

Bob
webix 01 Aug, 2018
with IPN
GreyHead 01 Aug, 2018
Hi webix,

Then you need to save the data to a database table before directing the user to PayPal and include a record identifier in the data sent, You can use the record ID, though I prefer a short unique random string as that is more secure.

In the IPN action you can read the record identifier from the data returned by PayPal and use that to verify and update the same record to show 'paid'.

The IPN action is not visible to you as a user or admin - it just communicates with PayPal - so you can't use a Debugger or print_r to see the results. You can add the results to the body of an email action in the IPN form event to have them mailed to you.

Bob
webix 01 Aug, 2018
Thanks for quick reply , Bob.


The logic how it should work is clear. And im store already form data into dB. I’m using AI Id for record self and user_id to identify the user later for update.

however I do not understand how to update the record on IPN verifier. I did try to place an dB record on IPN verifier success section, but this didn’t update dB. So my concern is more technical implemetation and not logical process.

I will very appreciate any help you can provide at this point.

thank you in advance
Alex

Update: what I’m also not understand - how to use WHERE condition on update dB.
GreyHead 02 Aug, 2018
Hi webix,

The Where conditions for the Save Data action are the same as for the Load Data action - see Page 21 of the CFv6 manual for an example.

Please add an email action to the IPN verifier success section to make sure that is being executed. You can then add debug code to the email template to see what data is available,

Bob
webix 02 Aug, 2018
Hi Bob,

thanks for the answer. I did placed now the email action into success secction inside of IPN verifier and mail was send. Unfortunately it was send multiple times. And still sending around one mail per 4-6 minutes during im writting this message =) . Probably you can also adwise on this issue. However the IPN verifier success section seems to work.

I did tryed to paste PHP code for debugger into mail body with
<?php echo $this->data; ?> 
But in mails i recieved it was only "data); ?> " and not the array. So im still not understand how to do this on the right way.

After i did check that IPN verifier success section works , i did placed there an DB save data action with following settings:[ol][li]Database table: my_database_to_be_updated[/li][li]Write action: update[/li][li]Data override on update:
modified_at:{date:Y-m-d H:i:s} [br]is_paid:1[/li][li]Update conditions: user_id:{user:id}[/li][/ol]
Unfortunately DB wasnt updated. So im still expecting concerns how to set the db update action after payment is done on the right way.

Im realy sorry to concern you with this probably easy things, but as non developer, this is realy not obviously. I would be very grateful if you can post there some code snippet and exactly place where to use this.

Regards[br]Alex
webix 03 Aug, 2018
would it be possible you take a look into my admin setup? I can then send you credentials via PM or Mail.
healyhatman 03 Aug, 2018
1 Likes
Just put {debug:} in the body of the email.

And you can't use {user:id} in the IPN event because it's called by PayPal not the user, so there's no logged in user and no id. You need to generate a unique code with {uuid:} that gets saved to the database and sent to PP that PP sends back, then use that code in the where condition .
webix 03 Aug, 2018
Thanks for answer. It helped a lot. I got this work . I'll post later a solution if someone will run into same issue.

However i have now an other concern to fight with:

i would like on update decrase a numeric value in DB. I did truyed to add some rules to Special fields like
quantity/decrement:1
Next try was to add some math to Data override on Update like
quantity:quantity-1
Both without success.

How it is possible to decrase the value by Update DB on IPN success action?

Thanks
Alex
healyhatman 03 Aug, 2018
Read data. If found, use PHP action to do the math, then use a save data action to save the new value.
webix 03 Aug, 2018
Thank you for Quick reply.

If I understand you right, I have to add within IPN success event firstly Database Read data action. Then after this one add PHP code section to manipulate data and then Database Save data action to store new value?

Ill try this by tomorrow. But I’m wondering why I need to get data from dB via Data read action. I have already all information I need on the hand to manipulate. So probably only PHP section to manipulate data and Data save action to store required? Please correct if I’m wrong.

And another question - all actions in IPN successful_ running in some time interval again and again after user is back to website from PayPal. Means if there is email action placed, I get the emails every 2-5 minutes until this action is not removed from setup. Same for all other actions like Database Save data and others. Is this common behavior of CF or I did something wrong? It’s it ok to prevent repeatable triggering by adding stop action after each php, data read/save action I placed there?

Thank you
Alex
GreyHead 04 Aug, 2018
Hi Alex,

The only data that you have in the IPN action is the data sent back by PayPal. The IPN actions do not have automatic access to any form data. IMHO you should use the transaction identifier in the PayPal data to read and load the matching transaction record from the database table. For security you should then check that the key transaction details match up e.g. that the amount is the same.

Normally you will not get repeated emails from the IPN action, then should only be triggered when there is a new message from PayPal. PayPal can send multiple messages if there is a delay in approving the transaction - you can check for this by looking at the data received - but these do not usually come every few minutes. The more likely explanation is that there is a loop somewhere in the form process you have set up and one form event is loading another; it's also possible that the IPN URL is being polled by something, maybe a site security checker or a search engine bot and that is triggering the emails. The data received should give a clue,

Bob
webix 04 Aug, 2018
Hi Bob,

Thank for answer. I will check for some loops can triggering this.

I know that IPN have only data send back by PayPal. The array contains also product name that is unique in my case. So I’m truying to update the quantity of product with database Save data action. However I can’t get the math quantity - 1 worked in this action. This is my question how to do this.



thanks
Alex
GreyHead 04 Aug, 2018
Hi Alex,

I would probably use a PHP action to run the MySQL query to run
UPDATE `table_name` SET `quantity` = quantity - 1 WHERE `product` = 'product_name'
Bob
webix 04 Aug, 2018
Hi Bob,

i did now truyed your solution, but still no success. Please find my code below added as PHP action to IPN success_ action[pre]$db = JFactory::getDbo();
$query = $db->getQuery(true);[br]$fields = array([br] $db->quoteName("quantity") . " = quantity - 1"[br]);[br]$conditions = array([br] $db->quoteName("name") . " = '".$this->data['item_name']."'", [br]);[br]$query->update($db->quoteName("#__rewards"))->set($fields)->where($conditions);[br]$db->setQuery($query);[br]$result = $db->execute();[/pre]
This code works well by adding directly into joomla template file but wont be executed inside of IPN success_ section.

I did also tryed to set real name isteand of
$this->data['item_name']
Next codes was also truyed:
UPDATE ssi_rewards SET quantity = 'quantity - 1' WHERE name = '".$this->data['item_name']."';

UPDATE ssi_rewards SET quantity = 'quantity - 1' WHERE name = 'Aufkleber, rund, ca. 9,5 cm'";
$db->query("UPDATE ssi_rewards SET quantity = 'quantity - 1' WHERE name = 'Aufkleber, rund, ca. 9,5 cm'");
All didn't have success.

Any ideas what im doing wrong?

PS. My biggest problem is time pressure - this project have to go Live tomorrow...

Thanks[br]Alex
GreyHead 05 Aug, 2018
Hi Alex,

Please try adding the \ to the first line
$db = \JFactory::getDbo();
ChronoForms now uses a NameSpace and the Joomla methods are not inside it.

Bob
This topic is locked and no more replies can be posted.