Hello.
Assuming that I send data into PayPal (with the use of "HTML Variables for PayPal Payments Standard"):
var variables:URLVariables = new URLVariables();
variables.cmd = "_xclick";
variables.business = "A8AJGG5PS2GKE";
variables.upload = "1";
variables.item_name = "some item";
variables.amount = "123";
variables.currency_code = "USD";
variables.lc = "pl";
variables.page_style = "PayPal";
variables.return = "my site";
variables.re = 2;
variables.no_note = 1;
variables.no_shipping = 1;
variables.notify_url = "some_mail@wp.com";
var request:URLRequest = new URLRequest("https://www.paypal.com/cgi-bin/webscr");
request.method = URLRequestMethod.POST;
request.data = variables;
navigateToURL(request, "_blank");
Does anyone managed to integrate PayPal IPN - "Instant Payment Notification"-
(https://www.paypal.com/ipn/) with AS3 in order to receive data from PayPal?
Could you please show any example of using it.
My idea is as follow:
1. .swf on you page sends variables into PayPal
2. After finishing the payment on PayPal, the customer is auto-redirected to your page ("return" variable)
3. Customer returns to your page. PayPal does NOT send any payment data there.
Separately in the background, you receive a form POST from PayPal at a different URL (notify_url variable) - (here resides the php that I added below).
4. You post back a form with cmd=_notify-validate and all fields you received from PayPal. PayPal responds with a single word VERIFIED or INVALID
5. If you receive VERIFIED, you can process payment
This method means that you can easily update for example your MySQL database but unfortunately you have to reload .swf file each time - and that's why it is not a perfect solution in my opinion;
PS:
- variables.return and variables.notify_url must be absolute urls
- notify_url must also allow anonymous access from outside of your network
- firewall must be opened to host: notify.paypal.com
- in your business PayPal account:
- php file:
<?php// read the post from PayPal system and add 'cmd'$req = 'cmd=' . urlencode('_notify-validate');
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value)); $req .= "&$key=$value";} $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_POSTFIELDS, $req);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com'));$res = curl_exec($ch);
curl_close($ch); // 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'];
if (strcmp ($res, "VERIFIED") == 0) {
// process payment}else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation}?>
I am not completzely following this: once paypal tells you that customer paid, you ask them whether he really paid?
About swf reloading: of course a swf can call the server repeatedly, without reloading itself every time.
This is just a thought experiment: visitor clicks on checkout button and will see paypal in a new tab (window). When the payment is settled, paypal redirects the visitor to another page of yours, still in the new tab. This page could cause your server to go to verify (or collect express checkout data) and then close the tab. At the next poll attempt your swf would see that the transaction has finished
North America
Europe, Middle East and Africa
Asia Pacific