PageRenderTime 68ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/parent/Payu.php

https://bitbucket.org/Beingvinaygupta/attendenceschool
PHP | 140 lines | 119 code | 19 blank | 2 comment | 18 complexity | 15929eff0f287e578c97b88835c57838 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, MPL-2.0-no-copyleft-exception
  1. <?php
  2. if (!defined('BASEPATH'))
  3. exit('No direct script access allowed');
  4. class Payu extends CI_Controller {
  5. function __construct() {
  6. parent::__construct();
  7. $this->load->helper('file');
  8. $this->lang->load('message', 'english');
  9. $this->load->library('auth');
  10. $this->auth->is_logged_in_parent();
  11. }
  12. public function index() {
  13. $this->session->set_userdata('top_menu', 'Library');
  14. $this->session->set_userdata('sub_menu', 'book/index');
  15. $pre_session_data = $this->session->userdata('params');
  16. $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
  17. $pre_session_data['txn_id'] = $txnid;
  18. $this->session->set_userdata("params", $pre_session_data);
  19. $session_data = $this->session->userdata('params');
  20. $session_data['name'] = ($session_data['name'] != "") ? $session_data['name'] : "noname";
  21. $session_data['email'] = ($session_data['email'] != "") ? $session_data['email'] : "noemail@gmail.com";
  22. $session_data['guardian_phone'] = ($session_data['guardian_phone'] != "") ? $session_data['guardian_phone'] : "0000000000";
  23. $session_data['address'] = ($session_data['address'] != "") ? $session_data['address'] : "noaddress";
  24. $pay_method = $this->paymentsetting_model->getActiveMethod();
  25. //payumoney details
  26. $amount = $session_data['payment_detail']->amount;
  27. $customer_name = $session_data['name'];
  28. $customer_emial = $session_data['email'];
  29. $customer_mobile = $session_data['guardian_phone'];
  30. $customer_address = $session_data['address'];
  31. $product_info = $session_data['payment_detail']->fee_group_name . " - " . $session_data['payment_detail']->code;
  32. $MERCHANT_KEY = $pay_method->api_secret_key;
  33. $SALT = $pay_method->salt;
  34. //optional udf values
  35. $udf1 = '';
  36. $udf2 = '';
  37. $udf3 = '';
  38. $udf4 = '';
  39. $udf5 = '';
  40. $hashstring = $MERCHANT_KEY . '|' . $txnid . '|' . $amount . '|' . $product_info . '|' . $customer_name . '|' . $customer_emial . '|' . $udf1 . '|' . $udf2 . '|' . $udf3 . '|' . $udf4 . '|' . $udf5 . '||||||' . $SALT;
  41. $hash = strtolower(hash('sha512', $hashstring));
  42. $success = base_url('parent/payu/success');
  43. $fail = base_url('parent/payu/success');
  44. $cancel = base_url('parent/payu/success');
  45. $data = array(
  46. 'mkey' => $MERCHANT_KEY,
  47. 'tid' => $txnid,
  48. 'hash' => $hash,
  49. 'amount' => $amount,
  50. 'fee_group_name' => $session_data['payment_detail']->fee_group_name,
  51. 'fee_code' => $session_data['payment_detail']->code,
  52. 'name' => $customer_name,
  53. 'productinfo' => $product_info,
  54. 'mailid' => $customer_emial,
  55. 'phoneno' => $customer_mobile,
  56. 'address' => $customer_address,
  57. 'action' => "https://secure.payu.in", //for live change action https://secure.payu.in
  58. 'sucess' => $success,
  59. 'failure' => $fail,
  60. 'cancel' => $cancel
  61. );
  62. $data['session_data'] = $session_data;
  63. $this->load->view('parent/payu', $data);
  64. }
  65. function checkout() {
  66. $this->form_validation->set_rules('firstname', 'Customer Name', 'required|trim|xss_clean');
  67. $this->form_validation->set_rules('phone', 'Mobile No', 'required|trim|xss_clean');
  68. $this->form_validation->set_rules('email', 'Email', 'required|valid_email|trim|xss_clean');
  69. $this->form_validation->set_rules('amount', 'Amount', 'required|trim|xss_clean');
  70. if ($this->form_validation->run() == false) {
  71. $data = array(
  72. 'firstname' => form_error('firstname'),
  73. 'phone' => form_error('phone'),
  74. 'email' => form_error('email'),
  75. 'amount' => form_error('amount'),
  76. );
  77. $array = array('status' => 'fail', 'error' => $data);
  78. echo json_encode($array);
  79. } else {
  80. $array = array('status' => 'success', 'error' => '');
  81. echo json_encode($array);
  82. }
  83. }
  84. public function success() {
  85. if ($this->input->server('REQUEST_METHOD') == 'POST') {
  86. $session_data = $this->session->userdata('params');
  87. if ($this->input->post('status') == "success") {
  88. $mihpayid = $this->input->post('mihpayid');
  89. $transactionid = $this->input->post('txnid');
  90. $txn_id = $session_data['txn_id'];
  91. if ($txn_id == $transactionid) {
  92. $params = $this->session->userdata('params');
  93. $json_array = array(
  94. 'amount' => $this->input->post('amount'),
  95. 'date' => date('Y-m-d'),
  96. 'amount_discount' => 0,
  97. 'amount_fine' => 0,
  98. 'description' => "Online fees deposit through PayU TXN ID: " . $txn_id . " PayU Ref ID: " . $mihpayid,
  99. 'payment_mode' => 'PayU',
  100. );
  101. $data = array(
  102. 'student_fees_master_id' => $params['student_fees_master_id'],
  103. 'fee_groups_feetype_id' => $params['fee_groups_feetype_id'],
  104. 'amount_detail' => $json_array
  105. );
  106. $send_to = $params['guardian_phone'];
  107. $inserted_id = $this->studentfeemaster_model->fee_deposit($data, $send_to);
  108. if ($inserted_id) {
  109. $invoice_detail = json_decode($inserted_id);
  110. redirect(base_url("parent/payment/successinvoice/" . $invoice_detail->invoice_id . "/" . $invoice_detail->sub_invoice_id));
  111. } else {
  112. }
  113. } else {
  114. redirect(site_url('parent/payment/paymentfailed'));
  115. }
  116. } else {
  117. redirect(site_url('parent/payment/paymentfailed'));
  118. }
  119. }
  120. }
  121. }