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

/app/Http/Controllers/Payment/UnicreditController.php

https://bitbucket.org/vamosimilano/webshop
PHP | 204 lines | 144 code | 32 blank | 28 comment | 17 complexity | 249c51a6fe986cb607fb05bdaefbb039 MD5 | raw file
  1. <?php
  2. /**
  3. * UnicreditController class.
  4. *
  5. * @extends Controller
  6. */
  7. class UnicreditController extends BaseController {
  8. /**
  9. * fullStart function.
  10. * @TODO: hibakezelés
  11. *
  12. * @access public
  13. * @param mixed $order_number
  14. * @return void
  15. */
  16. public function fullStart($order_number){
  17. Session::forget('last_card_trans');
  18. $order = Order::where('order_number', $order_number)
  19. ->where('status', 'NEW')
  20. ->first();
  21. if (empty($order)) {
  22. return Redirect::action('CartController@error', $order_number)
  23. ->withErrors([t('Hiba történt a fizetés során, rendelése már fizetve lett, vagy nem létező rendelés!')]);
  24. }
  25. $tranzaction = new UniCredit();
  26. $url = $tranzaction->startPayment($order,'full');
  27. if ($url == false) {
  28. return Redirect::action('CartController@error', $order_number)
  29. ->withErrors([t('Hiba történt a fizetés során, kérjük próbálja újra!')]);
  30. }
  31. return Redirect::to($url);
  32. }
  33. public function advStart($order_number){
  34. Session::forget('last_card_trans');
  35. $order = Order::where('order_number', $order_number)
  36. ->where('status', 'NEW')
  37. ->first();
  38. if (empty($order)) {
  39. return Redirect::action('CartController@error', $order_number)
  40. ->withErrors([t('Hiba történt a fizetés során, rendelése már fizetve lett, vagy nem létező rendelés!')]);
  41. }
  42. $tranzaction = new UniCredit();
  43. $url = $tranzaction->startPayment($order,'advance');
  44. if ($url == false) {
  45. return Redirect::action('CartController@error', $order_number)
  46. ->withErrors([t('Hiba történt a fizetés során, kérjük próbálja újra!')]);
  47. }
  48. return Redirect::to($url);
  49. }
  50. public function diffStart($order_number){
  51. Session::forget('last_card_trans');
  52. $order = Order::where('order_number', $order_number)->first();
  53. if (empty($order)) {
  54. return Redirect::action('CartController@error', $order_number)
  55. ->withErrors([t('Hiba történt a fizetés során, rendelése már fizetve lett, vagy nem létező rendelés!')]);
  56. }
  57. $tranzaction = new UniCredit();
  58. $url = $tranzaction->startPayment($order,'different');
  59. if ($url == false) {
  60. return Redirect::action('CartController@error', $order_number)
  61. ->withErrors([t('Hiba történt a fizetés során, kérjük próbálja újra!')]);
  62. }
  63. return Redirect::to($url);
  64. }
  65. /**
  66. * successPayment function.
  67. * Sikeres oldalra irányítás
  68. *
  69. * @access public
  70. * @return void
  71. */
  72. public function successPayment() {
  73. $trans_id = Input::get('trans_id');
  74. $log = Payment::where('order_ref', $trans_id)
  75. ->where('status', 'START')
  76. ->orderBy('created_at', 'DESC')
  77. ->first();
  78. if (empty($log)) {
  79. return Redirect::action('CartController@error', '0')
  80. ->withErrors([t('Hiba történt a fizetés során, nem találunk ilyen tranzakciót!')]);
  81. }
  82. $result = UniCredit::CheckPayment($trans_id);
  83. $order = Order::where('order_number', $log->order_number)
  84. ->first();
  85. Session::put('last_card_trans', $result);
  86. if ($result['result'] == 'OK') {
  87. $order->status = 'PENDING';
  88. $order->save();
  89. $order->sendMail();
  90. $order->sendSuccessTransaction($result);
  91. return Redirect::action('CartController@success', $log->order_number)
  92. ->with('flash_success', t('Sikeres tranzakció!'));
  93. }else{
  94. $order->sendErrorTransaction($result);
  95. return Redirect::action('CartController@error', $log->order_number)
  96. ->withErrors([t('Hiba történt a fizetés során, kérjük próbálja újra!')]);
  97. }
  98. }
  99. /**
  100. * errorPayment function.
  101. * Sikertelen oldalra irányítás
  102. *
  103. * @access public
  104. * @return void
  105. */
  106. public function errorPayment() {
  107. $trans_id = Input::get('trans_id');
  108. $log = Payment::where('order_ref', $trans_id)
  109. ->where('status', 'START')
  110. ->orderBy('created_at', 'DESC')
  111. ->first();
  112. if (empty($log)) {
  113. return Redirect::action('CartController@error', '0')
  114. ->withErrors([t('Hiba történt a fizetés során, nem találunk ilyen tranzakciót!')]);
  115. }
  116. $result = Unicredit::CheckPayment($trans_id);
  117. //TODO - ERROR - EMAIL KÜLDÉS
  118. $order = Order::where('order_number', $log->order_number)->first();
  119. Session::put('last_card_trans', $result);
  120. $order->sendErrorTransaction($result);
  121. return Redirect::action('CartController@error', $log->order_number)
  122. ->withErrors([t('Hiba történt a fizetés során, kérjük próbálja újra!')]);
  123. }
  124. public function paymentcancel() {
  125. $trans_id = base64_encode(Input::get('orderID'));
  126. $log = Payment::where('order_ref', $trans_id)
  127. ->where('status', 'START')
  128. ->orderBy('created_at', 'DESC')
  129. ->first();
  130. if (empty($log)) {
  131. return Redirect::action('CartController@error', '0')
  132. ->withErrors([t('Hiba történt a fizetés során, nem találunk ilyen tranzakciót!')]);
  133. }
  134. $result = Input::all();
  135. $log->data = serialize($result);
  136. $log->status = 'CANCEL';
  137. $log->save();
  138. return Redirect::action('CartController@error', $log->order_number)
  139. ->withErrors([t('Hiba történt a fizetés során, kérjük próbálja újra!')]);
  140. }
  141. public function paymentaccept() {
  142. $trans_id = base64_encode(Input::get('orderID'));
  143. $log = Payment::where('order_ref', $trans_id)
  144. ->where('status', 'START')
  145. ->orderBy('created_at', 'DESC')
  146. ->first();
  147. if (empty($log)) {
  148. return Redirect::action('CartController@errorbarcley', '0')
  149. ->withErrors([t('Hiba történt a fizetés során, nem találunk ilyen tranzakciót!')]);
  150. }
  151. $result = Input::all();
  152. $log->data = serialize($result);
  153. $log->status = 'SUCCED';
  154. $log->save();
  155. $order = Order::where('order_number', $log->order_number)
  156. ->first();
  157. Session::put('last_card_trans', $result);
  158. if ($result['STATUS'] == '9') {
  159. $order->status = 'PENDING';
  160. $order->save();
  161. $order->sendMail();
  162. $result['trans_id'] = $result['PAYID'];
  163. $order->sendSuccessTransactionBarclay($result);
  164. return Redirect::action('CartController@successbarcley', $log->order_number)
  165. ->with('flash_success', t('Sikeres tranzakció!'));
  166. }else{
  167. $order->sendErrorTransaction($result);
  168. return Redirect::action('CartController@errorbarclay', $log->order_number)
  169. ->withErrors([t('Hiba történt a fizetés során, kérjük próbálja újra!')]);
  170. }
  171. }
  172. }