Jump to content


Photo

$pages scope

solved ipn paypal

  • Please log in to reply
3 replies to this topic

#1 fnode

fnode

    Jr. Member

  • Members
  • PipPip
  • 16 posts
  • 3

Posted 06 August 2012 - 09:41 AM

Hello Community,

I have a directory structure like this:

[website]
|- libs // This folder is not part of PW
|- paypal
|- ipn.php
|- site
|- wire

The problem is that I cannot access $pages inside /website/libs/paypal/ipn.php.

Paypal IPN will point to this file: http://mysite.com/libs/paypal/ipn.php

<?php

$productid = $pages->get(1332);
var_dump($productid);


// 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) {
   // 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
}
else if (strcmp ($res, "INVALID") == 0) {
   // log for manual investigation
}
?>

Thanks!

#2 Pete

Pete

    Administrator

  • Administrators
  • 1,756 posts
  • 658

  • LocationChester, England

Posted 06 August 2012 - 09:45 AM

You'll want to bootstrap PW in that file - see this page for instructions to do this and it should work fine: http://processwire.com/api/include/

#3 fnode

fnode

    Jr. Member

  • Members
  • PipPip
  • 16 posts
  • 3

Posted 06 August 2012 - 09:49 AM

Thank you Pete!

#4 fnode

fnode

    Jr. Member

  • Members
  • PipPip
  • 16 posts
  • 3

Posted 06 August 2012 - 10:04 AM

Code is working now! Thanks!

libs/paypal/ipn.php

<?php
include ("../../index.php");

$productid = $wire->pages->get(1332);

var_dump($productid);
?>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users