Esempio n. 1
0
<?php

/**
 * Created by PhpStorm.
 * User: Antonshell
 * Date: 11.08.2015
 * Time: 22:38
 */
require_once 'autoload.php';
$ipn = new PaypalIpn();
$ipn->createIpnListener();
Esempio n. 2
0
 /**
  * Catch IPN response from PayPal
  *
  * @access  public
  * @return  void
  */
 public function action_ipn()
 {
     \Package::load('paypalipn');
     $post = \Input::post();
     $admin_email = '*****@*****.**';
     if (isset($post['invoice']) || is_numeric($post['invoice'])) {
         if ($order = \Order\Model_Order::find_one_by_id($post['invoice'])) {
             $order_info = $this->order_info($post['invoice']);
             //$validate_order['mc_currency'] =  strtoupper($order['currency']);
             $validate_order['mc_currency'] = "AUD";
             $validate_order['mc_gross'] = $order_info['grand_total_price'];
             $response = \PaypalIpn::forge()->validate($validate_order);
             $response_check = $response !== false;
             //                @mail($admin_email, \Config::get('site_title', 'Giant Invitation Australia') . ' Pre response ' . $response['invoice'],
             //                    'Order id : ' . $response['invoice'] . "\n" .
             //                    'Response:' . print_r($response, true) . "\n" .
             //                    'Check:' . $response_check);
             $payment = \Payment\Model_Payment::forge();
             /*
             [mc_gross] => 527.00
             [invoice] => 9
             [protection_eligibility] => Eligible
             [address_status] => confirmed
             [item_number1] =>
             [tax] => 0.00
             [item_number2] =>
             [payer_id] => 2AY578XVRY42G
             [address_street] => 1 Main St
             [payment_date] => 05:19:51 Dec 20, 2012 PST
             [payment_status] => Completed
             [charset] => windows-1252
             [address_zip] => 95131
             [mc_shipping] => 0.00
             [mc_handling] => 0.00
             [first_name] => Djordje
             [mc_fee] => 20.90
             [address_country_code] => US
             [address_name] => Djordje Dimitrijev
             [notify_version] => 3.7
             [custom] =>
             [payer_status] => verified
             [business] => s01_1354717870_biz@eximius-solutions.com
             [address_country] => United States
             [num_cart_items] => 2
             [mc_handling1] => 0.00
             [mc_handling2] => 0.00
             [address_city] => San Jose
             [verify_sign] => Amjz0My6wXvXmjP5pfTStQO3QZ2QA4.Ti6ln42PKcmRKuS-ZegoVx6nF
             [payer_email] => b01_1354717574_per@eximius-solutions.com
             [mc_shipping1] => 0.00
             [mc_shipping2] => 0.00
             [tax1] => 0.00
             [tax2] => 0.00
             [txn_id] => 3AR12649JA9996934
             [payment_type] => instant
             [last_name] => Dimitrijev
             [address_state] => CA
             [item_name1] => Fujiyama
             [receiver_email] => s01_1354717870_biz@eximius-solutions.com
             [item_name2] => Musala
             [payment_fee] =>
             [quantity1] => 2
             [quantity2] => 1
             [receiver_id] => W4MYKU8N4SVHS
             [txn_type] => cart
             [mc_gross_1] => 398.00
             [mc_currency] => EUR
             [mc_gross_2] => 129.00
             [residence_country] => US
             [test_ipn] => 1
             [transaction_subject] => Shopping CartFujiyamaMusala
             [payment_gross] =>
             [ipn_track_id] => 72c4d71c8638a
             */
             if ($response !== false) {
                 $json_response = json_encode($response);
                 $payment->order_id = $response['invoice'];
                 $payment->total_price = $response['mc_gross'];
                 $payment->method = 'paypal';
                 $payment->status = $response['payment_status'];
                 $payment->response = $json_response;
                 if (isset($response['pending_reason'])) {
                     $payment->status_detail = $response['pending_reason'];
                 }
                 if (strtolower($response['payment_status']) == 'completed') {
                     // Send email
                     /*$emailer = new \PaymentProccess\PaymentEmailer($order);
                       $emailer->send();*/
                     $emailer = new \Autorespondertrigger\Trigger();
                     $emailer->sendOrderPaymentReceivedPaypalCredit($order);
                     $order->total_price = $order_info['total_price'];
                     $order->paymentmethod = 'N/A';
                     if (isset($order->payments[0]->method)) {
                         $order->paymentmethod = $order->payments[0]->method;
                     }
                     // Create redemption code ( if order is sample order - this will be checked in RedemptionCodeSaverClass)
                     $redemptionCodeSaver = new \DiscountCodeApplier\RedemptionCodeSaver($order);
                     $redemptionCodeSaver->save();
                 } else {
                     logger(\Fuel::L_INFO, 'PayPal IPN - Pending order. Order ID: ' . $response['invoice'] . '. - ' . $json_response);
                     @mail($admin_email, \Config::get('site_title', 'Giant Invitation Australia') . ' | PayPal IPN - Pending order. Order ID: ' . $response['invoice'], 'PayPal IPN - Pending order. Order ID: ' . $response['invoice'] . "\n" . print_r($response, true));
                 }
             } else {
                 $payment->order_id = $post['invoice'];
                 $payment->total_price = $post['mc_gross'];
                 $payment->method = 'paypal';
                 $payment->status = 'Pending';
                 $payment->response = json_encode($post);
                 // Log order as failed
                 logger(\Fuel::L_INFO, 'PayPal IPN - Failed order. Order ID: ' . $response['invoice'] . '. - ' . $json_response);
                 @mail($admin_email, \Config::get('site_title', 'Giant Invitation Australia') . ' | PayPal IPN - Failed order. Order ID: ' . $response['invoice'], 'PayPal IPN - Failed order. Order ID: ' . $response['invoice'] . "\n" . print_r($response, true));
             }
             // Save payment to database
             try {
                 $payment->save();
             } catch (\Database_Exception $e) {
                 logger(\Fuel::L_INFO, 'PayPal IPN - error during inserting data into the database. Order ID: ' . $response['invoice'] . '. - ' . $json_response);
                 @mail($admin_email, \Config::get('site_title', 'My Shortlist') . ' | PayPal IPN - DB error. Order ID: ' . $response['invoice'], 'PayPal IPN - error during inserting data into the database. Order ID: ' . $response['invoice'] . "\n" . print_r($response, true));
             }
         } else {
             logger(\Fuel::L_INFO, 'PayPal IPN - error. There is no order with ID: ' . $post['invoice'] . '. - ' . json_encode($post));
             @mail($admin_email, \Config::get('site_title', 'My Shortlist') . ' | PayPal IPN - error. There is no order with ID: ' . $post['invoice'], 'PayPal IPN - there is no order with ID: ' . $post['invoice'] . "\n" . print_r($post, true));
         }
     } else {
         logger(\Fuel::L_INFO, 'PayPal IPN - error. Missing Order ID. - ' . json_encode($post));
         @mail($admin_email, \Config::get('site_title', 'My Shortlist') . ' | PayPal IPN - error. Missing Order ID.', 'PayPal IPN - Missing Order ID.' . "\n" . print_r($post, true));
     }
 }
Esempio n. 3
0
<?php

error_reporting(-1);
ini_set('display_errors', 'On');
require_once 'classes/class.paypal_ipn.php';
$PL = new PaypalIpn();
// default values
//$PL->DEBUG = 1;
//$PL->USE_SANDBOX = 1;
//$->LOG_FILE = "./ipn.log";
$PL->processInput(file_get_contents('php://input'));
if ($PL->isValidated()) {
    // check whether the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your PayPal email
    // check that payment_amount/payment_currency are correct
    // process payment and mark item as paid.
    // 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'];
}