psportal-murray/ipn/ipn.php

423 lines
13 KiB
PHP
Raw Normal View History

2019-02-18 02:40:33 +00:00
<?php
/*
Copyright 2018 Murray Hayes
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
namespace Listener;
include_once '../consts.php';
include_once '../database.php';
// Set this to true to use the sandbox endpoint during testing:
$enable_sandbox = true;
// Use this to specify all of the email addresses that you have attached to paypal:
// $my_email_addresses = array("my_email_address@gmail.com", "my_email_address2@gmail.com", "my_email_address3@gmail.com");
// Set this to true to send a confirmation email:
$send_confirmation_email = false;
$confirmation_email_address = "My Name <my_email_address@gmail.com>";
$from_email_address = "My Name <my_email_address@gmail.com>";
// Set this to true to save a log file:
$save_log_file = true;
$log_file_dir = __DIR__ . "/logs";
require('PaypalIPN.php');
use PaypalIPN;
$ipn = new PaypalIPN();
date_default_timezone_set($timeZone);
// Use the sandbox endpoint during testing.
if ($enable_sandbox)
$ipn->useSandbox();
//$verified = $ipn->verifyIPN();
$verified = TRUE;
if ($verified)
{
/*
* Process IPN
* A list of variables is available here:
* https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
*/
/*
if (isset($_POST['protection_eligibility']) && isset($_POST['payer_id']) &&
isset($_POST['payment_date']) && isset($_POST['payment_status']) &&
isset($_POST['first_name']) && isset($_POST['last_name']) &&
isset($_POST['notify_version']) && isset($_POST['verify_sign']) &&
isset($_POST['payer_email']) && isset($_POST['txn_id']) &&
isset($_POST['payment_type']) && isset($_POST['receiver_email']) &&
isset($_POST['receiver_id']) && isset($_POST['txn_type']))
{
if ($_POST['protection_eligibility'] === 'Eligible')
$protection_eligibility = TRUE;
else
$protection_eligibility = FALSE;
$payer_id = $_POST['payer_id'];
$payment_date = $_POST['payment_date'];
if ($_POST['payment_status'] === 'Completed')
$payment_status = TRUE;
else
$payment_status = FALSE;
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$notify_version = $_POST['notify_version'];
$verify_sign = $_POST['verify_sign'];
$payer_email = $_POST['payer_email'];
$txn_id = $_POST['txn_id'];
$payment_type = $_POST['payment_type'];
$receiver_email = $_POST['receiver_email'];
$receiver_id = $_POST['receiver_id'];
$txn_type = $_POST['txn_type'];
if (isset($_POST['mc_gross']))
$mc_gross = (float) $_POST['mc_gross'];
else
$mc_gross = (float) 0.0;
if (isset($_POST['address_status']) && $_POST['address_status'] === 'confirmed')
$address_status = TRUE;
else
$address_status = FALSE;
if (isset($_POST['tax']))
$tax = (float) $_POST['tax'];
else
$tax = (float) 0.00;
if (isset($_POST['address_street']))
$address_street = $_POST['address_street'];
else
$address_street = NULL;
if (isset($_POST['charset']))
$charset = $_POST['charset'];
else
$charset = 'utf-8';
if (isset($_POST['address_zip']))
$address_zip = $_POST['address_zip'];
else
$address_zip = NULL;
if (isset($_POST['mc_fee']))
$mc_fee = (float) $_POST['mc_fee'];
else
$mc_fee = (float) 0.0;
if (isset($_POST['address_country_code']))
$address_country_code = $_POST['address_country_code'];
else
$address_country_code = 'CA';
if (isset($_POST['address_name']))
$address_name = $_POST['address_name'];
else
$address_name = NULL;
if (isset($_POST['cusom']))
$custom = $_POST['custom'];
else
$custom = NULL;
if (isset($_POST['payer_satus']) && $_POST['payer_satus'] === 'verified')
$payer_status = TRUE;
else
$payer_status = FALSE;
if (isset($_POST['address_country']))
$address_country = $_POST['address_country'];
else
$address_country = NULL;
if (isset($_POST['address_city']))
$address_city = $_POST['address_city'];
else
$address_city = NULL;
if (isset($_POST['quantity']))
$quantity = (int) $_POST['quantity'];
else
$quantity = (int) -1;
if (isset($_POST['address_state']))
$address_state = $_POST['address_state'];
else
$address_state = NULL;
if (isset($_POST['payment_fee']))
$payment_fee = (float) $_POST['payment_fee'];
else
$payment_fee = (float) 0.00;
if (isset($_POST['item_name']))
$item_name = $_POST['item_name'];
else
$item_name = NULL;
if (isset($_POST['mc_currency']))
$mc_currency = $_POST['mc_currency'];
else
$mc_currency = 'CAD';
if (isset($_POST['item_number']))
$item_number = $_POST['item_number'];
else
$item_number = NULL;
if (isset($_POST['residence_country']))
$residence_country = $_POST['residence_country'];
else
$residence_country = 'CA';
if (isset($_POST['test_ipn']))
$test_ipn = $_POST['test_ipn'];
else
$test_ipn = NULL;
if (isset($_POST['handling_amount']))
$handling_amount = (float) $_POST['handling_amount'];
else
$handling_amount = (float) 0.00;
if (isset($_POST['transaction_subject']))
$transaction_subject = $_POST['transaction_subject'];
else
$transaction_subject = NULL;
if (isset($_POST['payment_gross']))
$payment_gross = (float) $_POST['payment_gross'];
else
$payment_gross = (float) 0.00;
if (isset($_POST['shipping']))
$shipping = $_POST['shipping'];
else
$shippling = (float) 0.00;
$ipnID = receiveInstantPaypalNotification($item_name, $item_number, (int) $quantity,
$mc_currency, $mc_gross, $mc_fee, $payment_type, $payment_date,
$payment_gross, $payment_fee, $shipping, $handling_amount, $tax,
$payment_status, $protection_eligibility, $payer_id, $payer_email,
$first_name, $last_name, $address_street, $address_city, $address_state,
$address_country, $address_country_code, $address_zip, $address_status,
$address_name, $payer_status, $residence_country, $receiver_id,
$receiver_email, $transaction_subject, $custom, $charset, $txn_id,
$txn_type, $notify_version, $verify_sign, $test_ipn);
processInstantPaypalNotification($ipnID);
}
*/
/*
* Attempt number 2
*/
$data = file_get_contents('php://input');
if (isset($_POST['txn_type']) && isset($_POST['verify_sign']) && ($data !== FALSE))
{
$txn_type = $_POST['txn_type'];
$verify_sign = $_POST['verify_sign'];
if (isset($_POST['txn_id']))
$txn_id = $_POST['txn_id'];
else
$txn_id = NULL;
$ipnID = receiveInstantPaypalNotification($txn_type, $txn_id, $verify_sign, $data);
//print ("ipnID: $ipnID");
if (isset($_POST['payer_id']))
$payer_id = $_POST['payer_id'];
else
$payer_id = NULL;
if (isset($_POST['payment_date']))
$payment_date = date_format(date_create($_POST['payment_date']), $dbDateTimeFormat);
else
$payment_date = NULL;
if (isset($_POST['payment_status']))
$payment_status = $_POST['payment_status'];
else
$payment_status = NULL;
if (isset($_POST['first_name']))
$first_name = $_POST['first_name'];
else
$first_name = NULL;
if (isset($_POST['last_name']))
$last_name = $_POST['last_name'];
else
$last_name = NULL;
if (isset($_POST['payer_email']))
$payer_email = $_POST['payer_email'];
else
$payer_email = NULL;
if (isset($_POST['mc_currency']))
$mc_currency = $_POST['mc_currency'];
else
$mc_currency = NULL;
if (isset($_POST['mc_gross']))
$mc_gross = $_POST['mc_gross'];
else
$mc_gross = NULL;
if (isset($_POST['mc_fee']))
$mc_fee = $_POST['mc_fee'];
else
$mc_fee = NULL;
if (isset($_POST['address_street']))
$address_street = $_POST['address_street'];
else
$address_street = NULL;
if (isset($_POST['address_city']))
$address_city = $_POST['address_city'];
else
$address_city = NULL;
if (isset($_POST['address_state']))
$address_state = $_POST['address_state'];
else
$address_state = NULL;
if (isset($_POST['address_country']))
$address_country = $_POST['address_country'];
else
$address_country = NULL;
if (isset($_POST['address_country_code']))
$address_country_code = $_POST['address_country_code'];
else
$address_country_code = NULL;
if (isset($_POST['address_zip']))
$address_zip = $_POST['address_zip'];
else
$address_zip = NULL;
if (isset($_POST['address_country']))
$address_country = $_POST['address_country'];
else
$address_country = NULL;
if (isset($_POST['contact_phone']))
$contact_phone = $_POST['contact_phone'];
else
$contact_phone = NULL;
if (isset($_POST['custom']))
$custom = $_POST['custom'];
else
$custom = NULL;
if (isset($_POST['receipt_id']))
$receipt_id = $_POST['receipt_id'];
else
$receipt_id = NULL;
if (isset($_POST['payer_status']))
$payer_status = $_POST['payer_status'];
else
$payer_status = NULL;
if (isset($_POST['quantity']))
$quantity = $_POST['quantity'];
else
$quantity = NULL;
if (isset($_POST['payment_type']))
$payment_type = $_POST['payment_type'];
else
$payment_type = NULL;
if (isset($_POST['receiver_email']))
$receiver_email = $_POST['receiver_email'];
else
$receiver_email = NULL;
if (isset($_POST['receiver_id']))
$receiver_id = $_POST['receiver_id'];
else
$receiver_id = NULL;
if (isset($_POST['item_name']))
$item_name = $_POST['item_name'];
else
$item_name = NULL;
if (isset($_POST['item_number']))
$item_number = $_POST['item_number'];
else
$item_number = NULL;
if (isset($_POST['residence_country']))
$residence_country = $_POST['residence_country'];
else
$residence_country = NULL;
if (isset($_POST['charset']))
$charset = $_POST['charset'];
else
$charset = NULL;
if (isset($_POST['transaction_subject']))
$transaction_subject = $_POST['transaction_subject'];
else
$transaction_subject = NULL;
if (isset($_POST['memo']))
$memo = $_POST['memo'];
else
$memo = NULL;
if (isset($_POST['test_ipn']))
$test_ipn = $_POST['test_ipn'];
else
$test_ipn = NULL;
if (isset($_POST['notify_version']))
$notify_version = $_POST['notify_version'];
else
$notify_version = NULL;
if (isset($_POST['parent_txn_id']))
$parent_txn_id = $_POST['parent_txn_id'];
else
$parent_txn_id = NULL;
if (isset($_POST['initial_payment_txn_id']))
$initial_payment_txn_id = $_POST['initial_payment_txn_id'];
else
$initial_payment_txn_id = NULL;
if (isset($_POST['recurring_payment_id']))
$recurring_payment_id = $_POST['recurring_payment_id'];
else
$recurring_payment_id = NULL;
/* if (isset($_POST['address_country']))
$address_country = $_POST['address_country'];
else
$address_country = NULL;*/
insertInstantPaypalNotificationData($ipnID, $payer_id, $payment_date,
$payment_status, $first_name, $last_name, $payer_email, $mc_currency,
$mc_gross, $mc_fee, $address_street, $address_city, $address_country,
$address_state, $address_country_code, $address_zip, $contact_phone,
$custom, $receipt_id, $payer_status, $quantity, $payment_type,
$receiver_email, $receiver_id, $item_name, $item_number,
$residence_country, $charset, $transaction_subject, $memo, $test_ipn,
$notify_version, $parent_txn_id, $initial_payment_txn_id, $recurring_payment_id);
}
}
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
header("HTTP/1.1 200 OK");
?>