Forums

form results email only AFTER successful paypal payment

platipalapi 28 Mar, 2010
Hello everybody,

i think i should have read longer the forum before rushing to buy the Paypal API, because i think i actually don't need it for what i want to do (seems the redirect plugin can do it)

I have a form that is working "almost" perfectly, which leads to a Paypal payment page,
only that i would like me and user who fills the form, to receive the email confirmation (with the results of the form) only AFTER the payment has been successfully proceeded.

Is there a way to do so ?
I currently have a multi page form :
- First page, is the actual form which user has to fill in
- second page, is the confirmation page with "go back" and "submit" buttons.

I have found somewhere to start with, using the paypal api plugin, and this tutorial : http://www.chronoengine.com/tutorials/chronoforms-plugins/437-paid-registration-using-paypal-plugin.html.

it seems possible to use php and plugins to test if payment is successful, and if so, process to sending emails, but is there a way to use the API while not using credit cart information fields (i.e letting the user who fills the form decide to log into paypal with his account or fill his credit card information directly on paypal payment page) ? Because i tried to use the plugin, but it seems mandatory to have Credit cart information fields to sumbit to Paypal.

Also, users can upload up to 4 images in the form (to photofield_1, photofield_2, etc...)
i've set the email templates in the mother form, so it displays the pictures that have been sent through the form, with this line:
<img src="http://mysite.com/uploaded_pictures/{photofield_1}>


When i have a single form, it works, but when using multi-page plugin, since the pictures fields are set in the first form, the mother form sends email, and it actually doesn't display (because it tries to show http://mysite.com/uploaded_pictures/{photofield_1} litteraly, like it forgot what {photofield_1} corresponds to.
I think this is part of the problem that has been exposed in another topic, about the multi-page plugin use along with the redirect plugin to Paypal, and not being able to recall the fields in the child forms, so the mother form can submit them all to Paypal or any other redirect page.
The weirdest thing, is that i also use in this very email template other field names, like {user_email}, {user_phone}, etc. All these fields are filled in the first child form, and they are correctly displayed in the emails. Only the pictures are not shown. Any idea why ?

that's a pretty long post, so thanks in advance to whoever answers, even to bring partial information.
platipalapi 29 Mar, 2010
there are really no people here that have any idea on how to do this ? (at least the mail after payment only thing)
i've mailed the admins but no answers; that's a little frustrating, especially right after buying a subscription, get no support....
GreyHead 30 Mar, 2010
Hi platipalapi,

Sorry that I didn't get up in the night to reply to your posts. Haven't seen your email yet.

By all means ask Max for a refund for the PayPal API plugin if you don't need it. You can send a message to him through the Contact Us form here.

The ReDirect plugin does a very simple redirection of the user and some information to another site - PayPal in this case. If you want to get the user back and continue the processing afterwards then you'll need to use the PayPal 'return' and 'cancel_return' parameters and build the code to do whatever you need to do when they come back. If you return them to a ChronoForm and include &task=send in the URL then you may be able to use ChronoForms to continue the processing. I say 'may' becasue there are some security checks that may prevent this. There has been another thread about this in the last week or so that you'll want to read.

The PayPal API plugin lets you keep the user on your site but has some other requirements that may not suit your work-flow.

Alternatively you can build your own process to work with the PayPal IPN process.

Bob
platipalapi 31 Mar, 2010
ok, Max have been very kind and understanding, thanks to him. I actually didn't need the Paypal plugin at all, since i was interested in having users enter their credit card information directly on my site.

i don't understand in the process you explained, how a user could be sent to paypal, and when completed the payment, have him redirect to a thank page with confirmation mails sent JUST then.
i've been searching for the topic your talking about but i didn't find it 😶
clinton 04 Apr, 2010
Hi,
I am having the same problem, what i can help you with tho is geting to the payment gateway,
putting this code in the motherform will get you variables in the redirect plugin, witch u just have to specify.
<!-- <input type="text" name="cmd">
<input type="text" name="business">
<input type="text" name="return">
<input type="text" name="item_name">
<input type="text" name="item_number">
<input type="text" name="amount">
<input type="text" name="no_shipping">
<input type="text" name="cancel_return">
<input type="text" name="no_note">
<input type="hidden" name="currencyCode"/>
<input type="hidden" name="countryCode"/> -->

Obviously putting this in the last page of you multi page form with there variables specified must also be done.
Setting the "return" to whatever your website name is redirects you back to the page you specified.

The email only sending after you have been redirected back is the part im strugling with😟.

To GreyHead,
Do you have any idea how this can be done? Mabey redirecting form data to multiple pages? or somthing.
GreyHead 05 Apr, 2010
Hi Clinton,

For the variables with variable data this approach will work well.

You may not need to have those all hidden variables in the Form HTML. If they are truly fixed data (like 'business') then you can put them directly into the 'Extra Inputs data' box in the plugin.

In the current development version you can put name={input_name} into the Extra Inputs data box which gets round this problem.

I've delayed emails before by saving the html_message into the database along with the other email info before the ReDirect and then getting it back out again when the form is returned from PayPal and hand-coding the email send.

Bob
platipalapi 06 Apr, 2010

...
I've delayed emails before by saving the html_message into the database along with the other email info before the ReDirect and then getting it back out again when the form is returned from PayPal and hand-coding the email send.

Bob



Are you giving the solution here ? it's midnight, i'm tired >_< i don't understand a thing. Is this the way to proceed so mails are sent AFTER payment is made on paypal ?
GreyHead 07 Apr, 2010
Hi platipalapi,

Well, a solution.

The problem is that while you can track a user and a transaction while they are on your site once you send them to PayPal to make the payment you lose track*.

So when you get the payment confirmation you need to look up the transaction records and take whatever action is necessary. You'll need to update the databse to record the sale and you can create emails at that point. Alternatively, you can pull up an email that you saved earlier and use that for the text.

Bob

* The exception to this is if you use the PayPal API when the user never leaves your site. But this requires a different setup at PayPal and may well require more security on your site.
platipalapi 07 Apr, 2010
but the Paypal API requires the user to give his credit card information right ?
isn't there a way to use the paypal api so user has to provide only his paypal credentials ?
GreyHead 07 Apr, 2010
Hi platipalapi,

Not that I know of but the PayPal docs is the place to check that out.

Bob
platipalapi 09 Apr, 2010
Ok after digging for some time, i've found a way to have either buyer, website admin or both to receive an email once the payment is successful.

this is not really a chronoform based solution, since it doesn't imply a configuration of it.

For the ones interested, here is a code you have to paste in your favorite text file editor, save it under whateveryouwant.php (i simply named it notify.php) :

<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
	
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
 
	// If testing on Sandbox use: 
	// $header .= "Host: www.sandbox.paypal.com:443\r\n";
$header .= "Host: www.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

	// If testing on Sandbox use:
	//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

//set email variables
$From_email = "From: your@email.com";
$Subject_line = "Successful Payment";

$email_msg = "Thanks for your payment. It has been successfully proceeded. We'll send you a message for further information.";
$email_msg .= "\n\nThe details of your order are as follows:";
$email_msg .= "\n\n" . "Transaction ID: " .  $txn_id ;
$email_msg .= "\n" . "Payment Date: " . $payment_date;

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment

$mail_From = $From_email;
$mail_To = $payer_email;
$mail_Subject = $Subject_line;
$mail_Body = $email_msg;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);


}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

$mail_From = $From_email;
$mail_To = $receiver_email;
$mail_Subject = "INVALID IPN POST";
$mail_Body = "INVALID IPN POST. The raw POST string is below.\n\n" . $req;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

}
}
fclose ($fp);
}
?>


then place that file anywhere on your website hosting. Just make sure it's accessible from an url of your domain (http://www.yourdomain.com/notify.php for instance).

Then, in your Paypal preferences, set the IPN notification url to the url of your just-made script.
When a payment is successful, it will execude the code within the notify.php file and thus send email to whoever your specified in the script (here by default is the paypal buyer's email address).
Of course this is a paypal-based solution, but i think it could work with other payment platforms, if they have something similar to IPN.

The interesting thing here is that you can send dynamic emails : just customize the script to your convenience.
The main use of this is basically to know when a payment is successful.
You CAN'T (or at least not that i know) get back the variables of the forms other than the ones that were submitted to paypal.
You can just use the 'custom' variable to pass to paypal to put whatever you want in it (but it's only for one field...)

credits : thanks to paypaltech.com for the php code
This topic is locked and no more replies can be posted.