/** * 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)); } }
public function action_credit() { if (!$this->check_logged()) { \Messages::error('You must be logged in if you want to continue with your order.'); \Response::redirect(\Uri::create('order/checkout/address')); } if (!\Input::post()) { throw new \HttpNotFoundException(); } if (\Input::post('order_type') == 'payment') { \Response::redirect(\Uri::create('order/checkout/payment')); } $credit_account = \Order\Model_Order::credit_account(null, \Cart::getTotal('price')); if (\Input::post('order_type') != 'credit') { \Messages::error('There was an error while trying to save your order.'); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost'))); } if (!$credit_account['credit'] || $credit_account['over_limit']) { \Messages::error("You don't have permission for this action."); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost'))); } $items = \Cart::items(); $user = \Sentry::user(); if ($order = $this->save_order()) { $payment = \Payment\Model_Payment::find_one_by_order_id($order->id); if (!isset($payment)) { $payment = \Payment\Model_Payment::forge(); } $total_price = $order->total_price ? $order->total_price + $order->shipping_price - $order->discount_amount : $order['total_price'] + $order['shipping_price'] - $order['discount_amount']; $payment->set(array('order_id' => $order->id, 'total_price' => $total_price, 'method' => 'credit', 'status' => 'ordered', 'status_detail' => 'Credit Account')); $payment->save(); $this->autoresponder($user, $order); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/complete/' . $order->id))); } \Messages::error('There was an error while trying to save your order.'); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost'))); }
public function action_credit() { if (!$this->check_logged()) { \Messages::error('You must be logged in if you want to continue with your order.'); \Response::redirect(\Uri::create('order/checkout/address')); } if (!\Input::post()) { throw new \HttpNotFoundException(); } if (\Input::post('order_type') == 'payment') { \Response::redirect(\Uri::create('order/checkout/payment')); } $credit_account = \Order\Model_Order::credit_account(null, \Cart::getTotal('price')); if (\Input::post('order_type') != 'credit') { \Messages::error('There was an error while trying to save your order.'); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost'))); } if (!$credit_account['credit'] || $credit_account['over_limit']) { \Messages::error("You don't have permission for this action."); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost'))); } $user = \Sentry::user(); if ($order = $this->save_order()) { $payment = \Payment\Model_Payment::forge(); $payment->order_id = $order->id; $payment->total_price = $order->total_price; $payment->method = 'credit'; $payment->status = 'ordered'; $payment->status_detail = 'Credit Account'; $payment->save(); $this->autoresponder($user, $order); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/complete/' . $order->id))); } \Messages::error('There was an error while trying to save your order.'); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost'))); }
public function __construct() { $this->payment = \Payment\Model_Payment::forge(); }