Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Muamalat;
  4.  
  5. use App\Http\Controllers\Controller;
  6. use Carbon\Carbon;
  7. use App\Models\TransactionDetail;
  8. use GuzzleHttp\Client;
  9.  
  10. class PaymentController extends Controller
  11. {
  12.  
  13. protected $mitraName = "MUMTAZ";
  14.  
  15. public function post(Request $request)
  16. {
  17. $jwtBody = $this->jwtRequest();
  18.  
  19. if (empty($jwtBody) || !$jwtBody) {
  20. return response()->json([
  21. "ERR" => "30",
  22. "METHOD" => "UNKNOWN",
  23. "MESSAGE" => "FORMAT ERROR",
  24. ]);
  25. }
  26.  
  27. if ($jwtBody['USERNAME'] != "bmi_for_classid" || $jwtBody['PASSWORD'] != "Bismillah#classId@bmi%2019") {
  28. return response()->json([
  29. "ERR" => "401",
  30. "METHOD" => $jwtBody['METHOD'],
  31. "MESSAGE" => "WRONG CREDENTIAL",
  32. ]);
  33. }
  34.  
  35. return $this->{strtolower($jwtBody['METHOD'])}($jwtBody);
  36.  
  37. }
  38.  
  39. public function inquiry($jwtBody)
  40. {
  41.  
  42. if (!app('cache')->has('muamalat-system')) {
  43. return response()->json([
  44. "ERR" => "12",
  45. "METHOD" => "INQUIRY",
  46. "MESSAGE" => "SYSTEM NOT SIGNON",
  47. ]);
  48. }
  49.  
  50. $res = $this->client()->request('GET', 'virtual-payment/inquiry', [
  51. 'query' => ['vano' => $jwtBody['VANO']],
  52. ]);
  53.  
  54. $body = $res->getBody();
  55. if ($res->getStatusCode() == 200) {
  56. $trans = TransactionDetail::create([
  57. 'order_id' => $body->order_id,
  58. 'order_ref' => $jwtBody['REFNO'],
  59. 'va_no' => $jwtBody['VANO'],
  60. 'customer_name' => $body->custname,
  61. 'institute_name' => $body->description,
  62. 'institute_id' => $body->institute_id,
  63. 'gross_amount' => $body->bill / 100, //contain 00 decimal on end
  64. 'channel_id' => $jwtBody['CHANNELID'],
  65. 'body' => json_encode($jwtBody),
  66. 'trx_date' => Carbon::createFromFormat("YmdHis", $jwtBody['TRXDATE']),
  67. 'user_id' => 1,
  68. ]);
  69.  
  70. $trans->items()->create([
  71. 'price' => $body['BILL'] / 100,
  72. 'quantity' => 1,
  73. 'name' => $body['DESCRIPTION2'],
  74. ]);
  75. }
  76.  
  77. return response()->body($body);
  78.  
  79. }
  80.  
  81. public function payment($jwtBody)
  82. {
  83. if (!app('cache')->has('muamalat-system')) {
  84. return response()->json([
  85. "ERR" => "12",
  86. "METHOD" => "PAYMENT",
  87. "MESSAGE" => "SYSTEM NOT SIGNON",
  88. ]);
  89. }
  90.  
  91. $res = $this->client()->request('POST', 'virtual-payment/create', [
  92. 'form_params' => [
  93. 'vano' => $jwtBody['VANO'],
  94. 'amount' => $jwtBody['PAYMENT'],
  95. ],
  96. ]);
  97.  
  98. $body = $res->getBody();
  99. if ($res->getStatusCode() == 200) {
  100. $trans = TransactionDetail::where('order_ref', $jwtBody['REFNO'])->first();
  101. if ($trans instanceof TransactionDetail == false) {
  102. return response()->json([
  103. "ERR" => "15", //Bill ID not found
  104. "METHOD" => "INQUIRY",
  105. "MESSAGE" => "BILL NOT FOUND",
  106. ]);
  107. }
  108.  
  109. $trans->update([
  110. 'payment_amount' => $jwtBody['PAYMENT'] / 100, //contain 00 decimal on end
  111. 'body' => json_encode($jwtBody),
  112. 'trx_date' => Carbon::createFromFormat("YmdHis", $jwtBody['TRXDATE']),
  113. 'status' => 'PAYMENT',
  114. ])
  115. }
  116.  
  117. return response()->body($body);
  118.  
  119. }
  120.  
  121. public function reversal($jwtBody)
  122. {
  123. if (!app('cache')->has('muamalat-system')) {
  124. return response()->json([
  125. "ERR" => "12",
  126. "METHOD" => "INQUIRY",
  127. "MESSAGE" => "SYSTEM NOT SIGNON",
  128. ]);
  129. }
  130.  
  131. $trans = TransactionDetail::where('order_ref', $jwtBody['REFNO'])->first();
  132. if ($trans instanceof TransactionDetail == false) {
  133. return response()->json([
  134. "ERR" => "15", //Bill ID not found
  135. "METHOD" => "REVERSAL",
  136. "MESSAGE" => "BILL NOT FOUND",
  137. ]);
  138. }
  139.  
  140. if ($trans->status == 'REVERSAL') {
  141. return response()->json([
  142. "ERR" => "12", //Bill ID not found
  143. "METHOD" => "REVERSAL",
  144. "MESSAGE" => "BILL ALREADY REVERSED",
  145. ]);
  146. }
  147.  
  148. $res = $this->client()->request('POST', 'virtual-payment/reversal', [
  149. 'form_params' => [
  150. 'order_id' => $trans->order_id,
  151. ],
  152. ]);
  153.  
  154. $body = $res->getBody();
  155. if ($res->getStatusCode() == 200) {
  156.  
  157. $trans->update([
  158. 'payment_amount' => $jwtBody['PAYMENT'] / 100, //contain 00 decimal on end
  159. 'body' => json_encode($jwtBody),
  160. 'status' => 'REVERSAL',
  161. ]);
  162. }
  163.  
  164. return response()->body([
  165. "ERR" => "00",
  166. "METHOD" => "REVERSAL",
  167. ]);
  168.  
  169. }
  170.  
  171. public function signon($jwtBody)
  172. {
  173. $infos = explode(";", $jwtBody['SIGNONINFO']);
  174. if ($infos[1] != $this->mitraName) {
  175. return response()->json([
  176. "ERR" => "401",
  177. "METHOD" => $jwtBody['METHOD'],
  178. "MESSAGE" => "WRONG CREDENTIAL",
  179. ]);
  180. }
  181.  
  182. $response = $infos[0] . ";00;{$this->mitraName}";
  183.  
  184. app('cache')->rememberForever('muamalat-system', function () use ($jwtBody) {
  185. return $jwtBody;
  186. });
  187.  
  188. return response()->body([
  189. "ERR" => $response,
  190. "METHOD" => "SIGNON",
  191. ]);
  192. }
  193.  
  194. public function signoff($jwtBody)
  195. {
  196.  
  197. $infos = explode(";", $jwtBody['SIGNOFFINFO']);
  198. if ($infos[1] != $this->mitraName) {
  199. return response()->json([
  200. "ERR" => "401",
  201. "METHOD" => $jwtBody['METHOD'],
  202. "MESSAGE" => "WRONG CREDENTIAL",
  203. ]);
  204. }
  205.  
  206. $response = $infos[0] . ";00;{$this->mitraName}";
  207.  
  208. app('cache')->forget('muamalat-system');
  209.  
  210. return response()->body([
  211. "ERR" => $response,
  212. "METHOD" => "SIGNOFF",
  213. ]);
  214. }
  215.  
  216. function echo ($jwtBody) {
  217.  
  218. return response()->body([
  219. "ERR" => "00",
  220. "METHOD" => "ECHO",
  221. ]);
  222. }
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement