request = $request; } public function prepare(){ $payoutStatus = PayoutStatus::whereNotIn('status',['SUCCESS','FAILURE'])->get(); if(!count($payoutStatus)){ $this->can_disbursed = true; } return $this; } public function initiateDisbursement(){ if(!$this->can_disbursed) return false; /* initialize an array */ $paytmParams = array(); $walletConfiguration = WalletConfiguration::first(); /* Find Sub Wallet GUID in your Paytm Dashboard at https://dashboard.paytm.com */ $paytmParams["subwalletGuid"] = $walletConfiguration->subWalletGuid; /* Enter your order id which needs to be check disbursal status for */ $paytmParams["orderId"] = 'M'.$this->request->get('id').'|'.time(); /* Enter Beneficiary Account Number in which the disbursal needs to be made */ $paytmParams["beneficiaryAccount"] = _env('PAYOUT_PAYTM_ENVIRONMENT') == 'TEST' ? "918008484891" : $this->request->get('beneficiaryAccount'); /* Enter Beneficiary's Bank IFSC Code */ $paytmParams["beneficiaryIFSC"] = _env('PAYOUT_PAYTM_ENVIRONMENT') == 'TEST' ? "PYTM0123456" : $this->request->get('beneficiaryIFSC'); $paytmParams["beneficiaryName"] = _env('PAYOUT_PAYTM_ENVIRONMENT') == 'TEST' ? "PYTM0123456" : $this->request->get('beneficiaryName'); /*Merchant can use this field to specify the disbursal mode. pass anyone from below NEFT, IMPS, UPI*/ $paytmParams["transferMode"] = 'NEFT'; /* Amount in INR to transfer */ $paytmParams["amount"] = round($this->request->get('amount'), 2); /* Enter Purpose of transfer, possible values are: SALARY_DISBURSEMENT, REIMBURSEMENT, BONUS, INCENTIVE, OTHER */ $paytmParams["purpose"] = "REIMBURSEMENT"; /* Enter the date for which you wants to disburse the amount. Required if purpose is SALARY_DISBURSEMENT or REIMBURSEMENT */ $paytmParams["date"] = Carbon::now()->toDateString(); /* prepare JSON string for request body */ $this->payload = json_encode($paytmParams, JSON_UNESCAPED_SLASHES); /** * Generate checksum by parameters we have in body * Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */ $checksum = getChecksumFromString($this->payload, PAYOUT_PAYTM_MERCHANT_KEY); /* Find your MID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */ $x_mid = PAYOUT_PAYTM_MERCHANT_MID; /* put generated checksum value here */ $x_checksum = $checksum; /* for Staging */ $url = _env('PAYOUT_PAYTM_API')."disburse/order/bank"; /* for Production */ // $url = "https://dashboard.paytm.com/bpay/api/v1/disburse/order/bank"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->payload); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "x-mid: " . $x_mid, "x-checksum: " . $x_checksum)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $preserveID = $this->preserve(__FUNCTION__, $response); return ['response' => json_decode($response), 'id' => $preserveID]; } public function getDisbursementStatus($application_id){ /* initialize an array */ $paytmParams = array(); /* Enter your order id which needs to be check disbursal status for */ $paytmParams["orderId"] = $this->getOrderID($application_id); /* prepare JSON string for request body */ $this->payload = json_encode($paytmParams, JSON_UNESCAPED_SLASHES); /** * Generate checksum by parameters we have in body * Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */ $checksum = getChecksumFromString($this->payload, PAYOUT_PAYTM_MERCHANT_KEY); /* Find your MID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */ $x_mid = PAYOUT_PAYTM_MERCHANT_MID; /* put generated checksum value here */ $x_checksum = $checksum; /* for Staging */ $url = _env('PAYOUT_PAYTM_API')."disburse/order/query"; /* for Production */ // $url = "https://dashboard.paytm.com/bpay/api/v1/disburse/order/query"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->payload); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "x-mid: " . $x_mid, "x-checksum: " . $x_checksum)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $preserveID = $this->preserve(__FUNCTION__, $response); return ['response' => json_decode($response), 'id' => $preserveID]; } public function getDisbursalAccountLists(){ /** * import checksum generation utility * You can get this utility from https://developer.paytm.com/docs/checksum/ */ /* initialize an array */ $paytmParams = array('subwalletGuid' => ''); /* prepare JSON string for request body */ $this->payload = json_encode($paytmParams, JSON_UNESCAPED_SLASHES); /** * Generate checksum by parameters we have in body * Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */ $checksum = getChecksumFromString($this->payload, PAYOUT_PAYTM_MERCHANT_KEY); /* Find your MID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */ $x_mid = PAYOUT_PAYTM_MERCHANT_MID; /* put generated checksum value here */ $x_checksum = $checksum; /* for Staging */ $url = _env('PAYOUT_PAYTM_API')."account/list"; /* for Production */ // $url = "https://dashboard.paytm.com/bpay/api/v1/account/list"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->payload); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "x-mid: " . $x_mid, "x-checksum: " . $x_checksum)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $response = json_decode($response, 1); return isset($response['result']) ? $response['result'] : []; } public function preserve($api, $response){ $responseData = json_decode($response); $isExistingPayoutStatus = PayoutStatus::where('application_id', $this->request->get('id'))->first(['id']); if (isset($isExistingPayoutStatus->id)){ $payoutStatus = PayoutStatus::find($isExistingPayoutStatus->id); }else{ $payoutStatus = new PayoutStatus(); $payoutStatus->application_id = $this->request->get('id'); $payoutStatus->user_id = Auth::user() ? Auth::user()->id : (Input::has('auth_user_id') ? Input::get('auth_user_id') : 107); } $payoutStatus->status = $responseData->status; $payoutStatus->save(); $payoutPreserve = new PayoutPreserve(); $payoutPreserve->payout_status_id = $payoutStatus->id; $payoutPreserve->response = $response; $payoutPreserve->request = $this->payload; $payoutPreserve->user_id = Auth::user() ? Auth::user()->id : (Input::has('auth_user_id') ? Input::get('auth_user_id') : 107); $payoutPreserve->status = $responseData->status; $payoutPreserve->api = $api; $payoutPreserve->save(); $responseDataArray = json_decode($response, 1); $responseDataArray = array_merge($responseDataArray, ['application_id' => $this->request->get('id')]); (new Slack(new Request(['title' => 'Paytm Payout '.$api.' Update', 'fields' => $responseDataArray, 'group' => Slack::$loan_disbursement_grp])))->send(); return isset($payoutStatus->id) ? $payoutStatus->id : ''; } public function getOrderID($application_id){ $payout = PayoutStatus::where('application_id', $application_id)->first(['id']); if (isset($payout->id)){ $PayoutPreserve = PayoutPreserve::where('payout_status_id',$payout->id)->where('status','ACCEPTED')->where('api','initiateDisbursement')->orderBy('created_at','desc')->first(['request']); if (isset($PayoutPreserve->request)){ $PayoutPreserveResponse = json_decode($PayoutPreserve->request); if (isset($PayoutPreserveResponse->orderId)){ return $PayoutPreserveResponse->orderId; } } } return 'M'.$application_id; } }