コード例 #1
0
ファイル: payments.php プロジェクト: arp19690/newtravel
 public function paypal_success()
 {
     if ($this->input->get('trip_url_key') && $this->input->get('plan_key') && $this->input->get('id') && $this->input->post()) {
         if ($this->input->post('item_number1') == $this->input->get('trip_url_key')) {
             $user_id = $this->session->userdata['user_id'];
             $user_email = $this->session->userdata['user_email'];
             if ($user_id == getEncryptedString($this->input->get('id'), 'decode')) {
                 $model = new Common_model();
                 $redis_functions = new Redisfunctions();
                 $trip_url_key = $this->input->get('trip_url_key');
                 $featured_plan_key = $this->input->get('plan_key');
                 $post_details = $redis_functions->get_trip_details($trip_url_key);
                 $feature_plan_details = $model->fetchSelectedData('*', TABLE_FEATURED_MASTER, array('pfm_key' => $featured_plan_key));
                 if (!empty($post_details) && !empty($feature_plan_details)) {
                     if ($post_details['post_user_id'] == $user_id) {
                         $paypal_data = $this->input->post();
                         $payment_reference_number = getUniquePaymentReferenceNumber(getEncryptedString($paypal_data['txn_id']));
                         $payment_created_on = date('Y-m-d H:i:s');
                         $data_array = array('payment_reference_number' => $payment_reference_number, 'payment_user_id' => $user_id, 'payment_pfm_id' => $feature_plan_details[0]['pfm_id'], 'payment_post_id' => $post_details['post_id'], 'payment_txn_id' => $paypal_data['txn_id'], 'payment_amount' => $paypal_data['payment_gross'], 'payment_payer_email' => $paypal_data['payer_email'], 'payment_receiver_email' => $paypal_data['receiver_email'], 'payment_status' => '1', 'payment_json' => json_encode($paypal_data), 'payment_created_on' => $payment_created_on);
                         $is_exists = $model->fetchSelectedData('payment_id', TABLE_PAYMENTS, array('payment_post_id' => $post_details['post_id'], 'payment_txn_id' => $paypal_data['txn_id']));
                         if (empty($is_exists)) {
                             $model->insertData(TABLE_PAYMENTS, $data_array);
                             $this->session->set_flashdata('success', 'Payment successful');
                         } else {
                             $this->session->set_flashdata('error', 'Transaction ID already exists');
                             redirect(getTripUrl($trip_url_key));
                         }
                         // Adding post to featured table
                         if ($this->add_post_to_featured($post_details['post_id'], $feature_plan_details[0]['pfm_id']) == FALSE) {
                             $this->session->set_flashdata('error', 'Unauthorized access to post');
                             redirect(getTripUrl($trip_url_key));
                         }
                         // Updating redis table here
                         $redis_functions->set_trip_details($trip_url_key);
                         $redis_functions->set_featured_trips();
                         // Sending invoice email here
                         if (USER_IP != '127.0.0.1') {
                             $invoice_data_array = array('payment_reference_number' => $payment_reference_number, 'payment_created_on' => $payment_created_on, 'payer_user_fullname' => $this->session->userdata['user_fullname'], 'payer_user_email' => $user_email, 'payment_txn_id' => $paypal_data['txn_id'], 'post_title' => $post_details['post_title'], 'pfm_title' => $feature_plan_details['pfm_title'], 'payment_currency' => 'USD', 'payment_amount' => $paypal_data['payment_gross']);
                             $email_model = new Email_model();
                             $invoice_html_data = $email_model->invoice_template($invoice_data_array);
                             $email_model->sendMail($user_email, $invoice_html_data['email_subject'], $invoice_html_data['email_message']);
                         }
                         $page_title = 'Payment confirmed';
                         $input_arr = array(base_url() => 'Home', '#' => $page_title);
                         $breadcrumbs = get_breadcrumbs($input_arr);
                         $data["post_details"] = $post_details;
                         $data["feature_plan_details"] = $feature_plan_details[0];
                         $data["payment_reference_number"] = $payment_reference_number;
                         $data["breadcrumbs"] = $breadcrumbs;
                         $data["page_title"] = $page_title;
                         $data['meta_title'] = $data["page_title"] . ' - ' . $this->redis_functions->get_site_setting('SITE_NAME');
                         $this->template->write_view("content", "pages/payments/paypal-success", $data);
                         $this->template->render();
                     } else {
                         $this->session->set_flashdata('error', 'Unauthorized access');
                         display_404_page();
                     }
                 } else {
                     $this->session->set_flashdata('error', 'No such records found');
                     display_404_page();
                 }
             } else {
                 $this->session->set_flashdata('error', 'Invalid request');
                 display_404_page();
             }
         } else {
             $this->session->set_flashdata('error', 'Invalid request');
             display_404_page();
         }
     } else {
         $this->session->set_flashdata('error', 'Invalid request');
         display_404_page();
     }
 }