Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers\Muamalat;
- use App\Http\Controllers\Controller;
- use Carbon\Carbon;
- use App\Models\TransactionDetail;
- use GuzzleHttp\Client;
- class PaymentController extends Controller
- {
- protected $mitraName = "MUMTAZ";
- public function post(Request $request)
- {
- $jwtBody = $this->jwtRequest();
- if (empty($jwtBody) || !$jwtBody) {
- return response()->json([
- "ERR" => "30",
- "METHOD" => "UNKNOWN",
- "MESSAGE" => "FORMAT ERROR",
- ]);
- }
- if ($jwtBody['USERNAME'] != "bmi_for_classid" || $jwtBody['PASSWORD'] != "Bismillah#classId@bmi%2019") {
- return response()->json([
- "ERR" => "401",
- "METHOD" => $jwtBody['METHOD'],
- "MESSAGE" => "WRONG CREDENTIAL",
- ]);
- }
- return $this->{strtolower($jwtBody['METHOD'])}($jwtBody);
- }
- public function inquiry($jwtBody)
- {
- if (!app('cache')->has('muamalat-system')) {
- return response()->json([
- "ERR" => "12",
- "METHOD" => "INQUIRY",
- "MESSAGE" => "SYSTEM NOT SIGNON",
- ]);
- }
- $res = $this->client()->request('GET', 'virtual-payment/inquiry', [
- 'query' => ['vano' => $jwtBody['VANO']],
- ]);
- $body = $res->getBody();
- if ($res->getStatusCode() == 200) {
- $trans = TransactionDetail::create([
- 'order_id' => $body->order_id,
- 'order_ref' => $jwtBody['REFNO'],
- 'va_no' => $jwtBody['VANO'],
- 'customer_name' => $body->custname,
- 'institute_name' => $body->description,
- 'institute_id' => $body->institute_id,
- 'gross_amount' => $body->bill / 100, //contain 00 decimal on end
- 'channel_id' => $jwtBody['CHANNELID'],
- 'body' => json_encode($jwtBody),
- 'trx_date' => Carbon::createFromFormat("YmdHis", $jwtBody['TRXDATE']),
- 'user_id' => 1,
- ]);
- $trans->items()->create([
- 'price' => $body['BILL'] / 100,
- 'quantity' => 1,
- 'name' => $body['DESCRIPTION2'],
- ]);
- }
- return response()->body($body);
- }
- public function payment($jwtBody)
- {
- if (!app('cache')->has('muamalat-system')) {
- return response()->json([
- "ERR" => "12",
- "METHOD" => "PAYMENT",
- "MESSAGE" => "SYSTEM NOT SIGNON",
- ]);
- }
- $res = $this->client()->request('POST', 'virtual-payment/create', [
- 'form_params' => [
- 'vano' => $jwtBody['VANO'],
- 'amount' => $jwtBody['PAYMENT'],
- ],
- ]);
- $body = $res->getBody();
- if ($res->getStatusCode() == 200) {
- $trans = TransactionDetail::where('order_ref', $jwtBody['REFNO'])->first();
- if ($trans instanceof TransactionDetail == false) {
- return response()->json([
- "ERR" => "15", //Bill ID not found
- "METHOD" => "INQUIRY",
- "MESSAGE" => "BILL NOT FOUND",
- ]);
- }
- $trans->update([
- 'payment_amount' => $jwtBody['PAYMENT'] / 100, //contain 00 decimal on end
- 'body' => json_encode($jwtBody),
- 'trx_date' => Carbon::createFromFormat("YmdHis", $jwtBody['TRXDATE']),
- 'status' => 'PAYMENT',
- ])
- }
- return response()->body($body);
- }
- public function reversal($jwtBody)
- {
- if (!app('cache')->has('muamalat-system')) {
- return response()->json([
- "ERR" => "12",
- "METHOD" => "INQUIRY",
- "MESSAGE" => "SYSTEM NOT SIGNON",
- ]);
- }
- $trans = TransactionDetail::where('order_ref', $jwtBody['REFNO'])->first();
- if ($trans instanceof TransactionDetail == false) {
- return response()->json([
- "ERR" => "15", //Bill ID not found
- "METHOD" => "REVERSAL",
- "MESSAGE" => "BILL NOT FOUND",
- ]);
- }
- if ($trans->status == 'REVERSAL') {
- return response()->json([
- "ERR" => "12", //Bill ID not found
- "METHOD" => "REVERSAL",
- "MESSAGE" => "BILL ALREADY REVERSED",
- ]);
- }
- $res = $this->client()->request('POST', 'virtual-payment/reversal', [
- 'form_params' => [
- 'order_id' => $trans->order_id,
- ],
- ]);
- $body = $res->getBody();
- if ($res->getStatusCode() == 200) {
- $trans->update([
- 'payment_amount' => $jwtBody['PAYMENT'] / 100, //contain 00 decimal on end
- 'body' => json_encode($jwtBody),
- 'status' => 'REVERSAL',
- ]);
- }
- return response()->body([
- "ERR" => "00",
- "METHOD" => "REVERSAL",
- ]);
- }
- public function signon($jwtBody)
- {
- $infos = explode(";", $jwtBody['SIGNONINFO']);
- if ($infos[1] != $this->mitraName) {
- return response()->json([
- "ERR" => "401",
- "METHOD" => $jwtBody['METHOD'],
- "MESSAGE" => "WRONG CREDENTIAL",
- ]);
- }
- $response = $infos[0] . ";00;{$this->mitraName}";
- app('cache')->rememberForever('muamalat-system', function () use ($jwtBody) {
- return $jwtBody;
- });
- return response()->body([
- "ERR" => $response,
- "METHOD" => "SIGNON",
- ]);
- }
- public function signoff($jwtBody)
- {
- $infos = explode(";", $jwtBody['SIGNOFFINFO']);
- if ($infos[1] != $this->mitraName) {
- return response()->json([
- "ERR" => "401",
- "METHOD" => $jwtBody['METHOD'],
- "MESSAGE" => "WRONG CREDENTIAL",
- ]);
- }
- $response = $infos[0] . ";00;{$this->mitraName}";
- app('cache')->forget('muamalat-system');
- return response()->body([
- "ERR" => $response,
- "METHOD" => "SIGNOFF",
- ]);
- }
- function echo ($jwtBody) {
- return response()->body([
- "ERR" => "00",
- "METHOD" => "ECHO",
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement