diff --git a/src/Contracts/BankTransfer.php b/src/Contracts/BankTransfer.php index 76c312a..8468ba9 100644 --- a/src/Contracts/BankTransfer.php +++ b/src/Contracts/BankTransfer.php @@ -7,13 +7,13 @@ interface BankTransfer /** * Execute the transfer operation */ - public function makeTransfer(array $orderInfo): mixed; + public function makeTransfer(array $orderInfo = []): mixed; - public function transferStatus(array $orderInfo): mixed; + public function transferStatus(array $orderInfo = []): mixed; - public function cancelTransfer(array $orderInfo): mixed; + public function cancelTransfer(array $orderInfo = []): mixed; - public function verifyAccount(array $accountInfo): mixed; + public function verifyAccount(array $accountInfo = []): mixed; - public function vendorBalance(array $accountInfo): mixed; + public function vendorBalance(array $accountInfo = []): mixed; } diff --git a/src/Contracts/OrderQuotation.php b/src/Contracts/OrderQuotation.php new file mode 100644 index 0000000..b39ee20 --- /dev/null +++ b/src/Contracts/OrderQuotation.php @@ -0,0 +1,12 @@ +find($id); - if (! $order) { + if (!$order) { throw (new ModelNotFoundException)->setModel(config('fintech.transaction.order_model'), $id); } @@ -51,20 +53,34 @@ public function available(string $id): JsonResponse|AssignableVendorCollection */ public function vendor(AssignableVendorInfoRequest $request): JsonResponse { + $order_id = $request->input('order_id'); + + $service_vendor_slug = $request->input('vendor_slug'); + try { - $order = Transaction::order()->find($request->input('order_id')); + $order = Transaction::order()->find($order_id); - if (! $order) { - throw (new ModelNotFoundException)->setModel(config('fintech.transaction.order_model'), $request->input('order_id')); + if (!$order) { + throw (new ModelNotFoundException)->setModel(config('fintech.transaction.order_model'), $order_id); } $availableVendors = config('fintech.remit.providers'); - if (! array_key_exists($request->input('vendor_slug'), $availableVendors)) { + if (!isset($availableVendors[$service_vendor_slug])) { throw new \ErrorException('Service Vendor is not available on the configuration.'); } - $jsonResponse = []; + $vendor = $availableVendors[$service_vendor_slug]; + + $driverClass = $vendor['driver']; + + $instance = App::make($driverClass); + + if (!$instance instanceof OrderQuotation) { + throw new \ErrorException('Service Vendor Class is not instance of `Fintech\Remit\Contracts\OrderQuotation` interface.'); + } + + $jsonResponse = $instance->requestQuotation($order); return $this->success($jsonResponse); diff --git a/src/Vendors/CityBankApi.php b/src/Vendors/CityBankApi.php index a8b5839..61d2998 100644 --- a/src/Vendors/CityBankApi.php +++ b/src/Vendors/CityBankApi.php @@ -3,9 +3,10 @@ namespace Fintech\Remit\Vendors; use Fintech\Remit\Contracts\BankTransfer; +use Fintech\Remit\Contracts\OrderQuotation; use Illuminate\Support\Facades\Log; -class CityBankApi implements BankTransfer +class CityBankApi implements BankTransfer, OrderQuotation { /** * CityBank API configuration. @@ -31,11 +32,11 @@ public function __construct() $this->config = config('fintech.remit.providers.citybank'); if ($this->config['mode'] === 'sandbox') { - $this->apiUrl = 'https://'.$this->config[$this->status]['app_host'].'/nrb_api_test/dynamicApi.php?wsdl'; + $this->apiUrl = 'https://' . $this->config[$this->status]['app_host'] . '/nrb_api_test/dynamicApi.php?wsdl'; $this->status = 'sandbox'; } else { - $this->apiUrl = 'https://'.$this->config[$this->status]['app_host'].'/dynamicApi.php?wsdl'; + $this->apiUrl = 'https://' . $this->config[$this->status]['app_host'] . '/dynamicApi.php?wsdl'; $this->status = 'live'; } } @@ -52,9 +53,9 @@ private function doAuthenticate() $return = 'AUTH_FAILED'; $xml_string = ' - '.$this->config[$this->status]['username'].' - '.$this->config[$this->status]['password'].' - '.$this->config[$this->status]['exchange_company'].' + ' . $this->config[$this->status]['username'] . ' + ' . $this->config[$this->status]['password'] . ' + ' . $this->config[$this->status]['exchange_company'] . ' '; $soapMethod = 'doAuthenticate'; @@ -67,98 +68,6 @@ private function doAuthenticate() return $return; } - /** - * Do transfer service will help you to send a new transaction by providing following parameter value - * - * @return mixed - * - * @throws \Exception - */ - public function doTransfer($inputData) - { - $doAuthenticate = $this->doAuthenticate(); - if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - if ($inputData->bank_id == 17) { - $mode_of_payment = 'CBL Account'; - } else { - $mode_of_payment = 'Other Bank'; - } - if ($inputData->recipient_type_name == 'Cash') { - $mode_of_payment = 'Cash'; - } - if ($inputData->recipient_type_name == 'Cash Pickup') { - $mode_of_payment = 'Cash'; - } - $xml_string = ' - - '.$doAuthenticate.' - '.$inputData->reference_no.' - '.$inputData->sender_first_name.' - '.$inputData->sender_mobile.' - - '.$inputData->sender_id_number.' - '.$inputData->sender_id_issue_country.' - '.((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null).(isset($inputData->receiver_middle_name) ? ' '.$inputData->receiver_middle_name : null).(isset($inputData->receiver_last_name) ? ' '.$inputData->receiver_last_name : null)).' - '; - if ($mode_of_payment != 'Cash') { - $xml_string .= ' - '.$inputData->bank_account_number.' - Savings - '.$inputData->bank_name.' - '.$inputData->bank_branch_name.' - '.(isset($inputData->location_routing_id[1]->bank_branch_location_field_value) ? $inputData->location_routing_id[1]->bank_branch_location_field_value : null).' - '; - } - $xml_string .= ' - '.$inputData->transfer_amount.' - '.$inputData->purpose_of_remittance.' - '.$inputData->receiver_contact_number.' - - - '.$inputData->sender_address.' - '.$inputData->sender_mobile.' - '.$inputData->receiver_address.' - - NA - '.$mode_of_payment.' - '.date('Y-m-d', strtotime($inputData->created_date)).' - - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - - '; - $soapMethod = 'doTransfer'; - $response = $this->connectionCheck($xml_string, $soapMethod); - if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->doTransferResponse->Response, true); - } else { - $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; - } - } else { - $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; - } - - return $returnValue; - } - /** * Get transaction status service will help you to get the transaction status * @@ -170,93 +79,9 @@ public function doTransfer($inputData) */ public function getTnxStatus($inputs_data) { - $doAuthenticate = $this->doAuthenticate(); - if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - $xml_string = ' - - - '.$doAuthenticate.' - '.$inputs_data['reference_no'].' - - '; - $soapMethod = 'getTnxStatus'; - $response = $this->connectionCheck($xml_string, $soapMethod); - if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->getTnxStatusResponse->Response, true); - } else { - $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; - } - } else { - $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; - } - - return $returnValue; - } - - /** - * Do amendment or cancel service will help you to send the transaction cancel/amendment request - * - * @param $inputData - * reference_no like system transaction number, amend_query like cancel/amendment - * @return mixed - * - * @throws \Exception - */ - public function doAmendmentOrCancel($inputData) - { - $doAuthenticate = $this->doAuthenticate(); - if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - $xml_string = ' - - - '.$doAuthenticate.' - '.$inputData['reference_no'].' - '.$inputData['amend_query'].' - - '; - $soapMethod = 'doAmendmentOrCancel'; - $response = $this->connectionCheck($xml_string, $soapMethod); - if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->doAmendmentOrCancelResponse->Response, true); - } else { - $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; - } - } else { - $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; - } - return $returnValue; } - /** - * Get balance service will help to know the available balance - * - * @return mixed - * - * @throws \Exception - */ - public function getBalance() - { - $doAuthenticate = $this->doAuthenticate(); - if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { - $xml_string = ' - - '.$doAuthenticate.' - - '; - $soapMethod = 'getBalance'; - $response = $this->connectionCheck($xml_string, $soapMethod); - if (isset($response) && $response != false && $response != null) { - $returnValue = json_decode($response->getBalanceResponse->Response, true); - } else { - $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; - } - } else { - $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; - } - - return $returnValue; - } /** * bKash customer validation service will help you to validate the beneficiary bkash number before send the transaction @@ -275,9 +100,9 @@ public function bkashCustomerValidation($inputData) $xml_string = ' - '.$doAuthenticate.' - '.$inputData['receiver_first_name'].' - '.$inputData['bank_account_number'].' + ' . $doAuthenticate . ' + ' . $inputData['receiver_first_name'] . ' + ' . $inputData['bank_account_number'] . ' '; $soapMethod = 'bkashCustomerValidation'; @@ -310,8 +135,8 @@ public function bkashValidation($inputData) $xml_string = ' - '.$doAuthenticate.' - '.$inputData['bank_account_number'].' + ' . $doAuthenticate . ' + ' . $inputData['bank_account_number'] . ' '; $soapMethod = 'getBkashCustomerDetails'; @@ -343,39 +168,39 @@ public function doBkashTransfer($inputData) $xml_string = ' - '.$doAuthenticate.' - '.$inputData->transfer_amount.' - '.$inputData->reference_no.' - '.$inputData->sender_first_name.' - '.$inputData->sender_date_of_birth.' + ' . $doAuthenticate . ' + ' . $inputData->transfer_amount . ' + ' . $inputData->reference_no . ' + ' . $inputData->sender_first_name . ' + ' . $inputData->sender_date_of_birth . ' - '.$inputData->sender_id_number.' + ' . $inputData->sender_id_number . ' - '.$inputData->sender_address.' - '.$inputData->sender_mobile.' - '.$inputData->sender_id_issue_country.' + ' . $inputData->sender_address . ' + ' . $inputData->sender_mobile . ' + ' . $inputData->sender_id_issue_country . ' '; if (isset($inputData->wallet_account_actual_name) && $inputData->wallet_account_actual_name != '') { $xml_string .= ' - '.(isset($inputData->wallet_account_actual_name) ? $inputData->wallet_account_actual_name : null).' + ' . (isset($inputData->wallet_account_actual_name) ? $inputData->wallet_account_actual_name : null) . ' '; } else { $xml_string .= ' - '.((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null).(isset($inputData->receiver_middle_name) ? ' '.$inputData->receiver_middle_name : null).(isset($inputData->receiver_last_name) ? ' '.$inputData->receiver_last_name : null)).' + ' . ((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null) . (isset($inputData->receiver_middle_name) ? ' ' . $inputData->receiver_middle_name : null) . (isset($inputData->receiver_last_name) ? ' ' . $inputData->receiver_last_name : null)) . ' '; } $xml_string .= ' - '.(isset($inputData->receiver_city) ? $inputData->receiver_city : 'Dhaka').' + ' . (isset($inputData->receiver_city) ? $inputData->receiver_city : 'Dhaka') . ' - '.$inputData->purpose_of_remittance.' - '.$inputData->bank_account_number.' + ' . $inputData->purpose_of_remittance . ' + ' . $inputData->bank_account_number . ' - '.$inputData->receiver_address.' - '.date('Y-m-d', strtotime($inputData->created_date)).' + ' . $inputData->receiver_address . ' + ' . date('Y-m-d', strtotime($inputData->created_date)) . ' '; $soapMethod = 'doBkashTransfer'; @@ -408,8 +233,8 @@ public function getBkashTnxStatus($inputData) $xml_string = ' - '.$doAuthenticate.' - '.$inputData['reference_no'].' + ' . $doAuthenticate . ' + ' . $inputData['reference_no'] . ' '; $soapMethod = 'getBkashTransferStatus'; @@ -434,12 +259,12 @@ public function getBkashTnxStatus($inputData) private function connectionCheck($xml_post_string, $method) { $xml_string = $this->xmlGenerate($xml_post_string, $method); - Log::info($method.'
'.$xml_string); + Log::info($method . '
' . $xml_string); $headers = [ - 'Host: '.$this->config[$this->status]['app_host'], + 'Host: ' . $this->config[$this->status]['app_host'], 'Content-type: text/xml;charset="utf-8"', - 'Content-length: '.strlen($xml_string), - 'SOAPAction: '.$method, + 'Content-length: ' . strlen($xml_string), + 'SOAPAction: ' . $method, ]; // PHP cURL for connection @@ -454,7 +279,7 @@ private function connectionCheck($xml_post_string, $method) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // execution $response = curl_exec($ch); - Log::error($method.' CURL reported error: '); + Log::error($method . ' CURL reported error: '); if ($response === false) { throw new \Exception(curl_error($ch), curl_errno($ch)); } @@ -463,7 +288,7 @@ private function connectionCheck($xml_post_string, $method) $response2 = str_replace('', '', $response1); $response = str_replace('xmlns:ns1="urn:dynamicapi"', '', $response2); $response = str_replace('ns1:', '', $response); //dd($response); - Log::info($method.'
'.$response); + Log::info($method . '
' . $response); return simplexml_load_string($response); } @@ -477,9 +302,9 @@ public function xmlGenerate($string, $method) - - '.$string.' - + + ' . $string . ' + '; @@ -502,25 +327,7 @@ public function topUp($input) $returnValue = $this->doTransfer($input->transaction_json_data); } - return (object) $returnValue; - } - - /** - * @return object - * - * @throws \Exception - */ - public function queryTnxStatus($input) - { - if ($input['service_id'] == 15) { - $returnValue = $this->getBkashTnxStatus($input); - } elseif ($input['service_id'] == 36) { - $returnValue = $this->getNagadTnxStatus($input); - } else { - $returnValue = $this->getTnxStatus($input); - } - - return $returnValue; + return (object)$returnValue; } /** @@ -540,9 +347,9 @@ public function nagadCustomerValidation($inputData) $xml_string = ' - '.$doAuthenticate.' + ' . $doAuthenticate . ' 50 - '.$inputData['bank_account_number'].' + ' . $inputData['bank_account_number'] . ' N '; @@ -575,39 +382,39 @@ public function doNagadTransfer($inputData) $xml_string = ' - '.$doAuthenticate.' - '.$inputData->transfer_amount.' - '.$inputData->reference_no.' - '.$inputData->sender_first_name.' - '.$inputData->sender_date_of_birth.' + ' . $doAuthenticate . ' + ' . $inputData->transfer_amount . ' + ' . $inputData->reference_no . ' + ' . $inputData->sender_first_name . ' + ' . $inputData->sender_date_of_birth . ' - '.$inputData->sender_id_number.' + ' . $inputData->sender_id_number . ' - '.$inputData->sender_address.' - '.$inputData->sender_mobile.' - '.$inputData->sender_id_issue_country.' + ' . $inputData->sender_address . ' + ' . $inputData->sender_mobile . ' + ' . $inputData->sender_id_issue_country . ' '; if (isset($inputData->wallet_account_actual_name) && $inputData->wallet_account_actual_name != '') { $xml_string .= ' - '.(isset($inputData->wallet_account_actual_name) ? $inputData->wallet_account_actual_name : null).' + ' . (isset($inputData->wallet_account_actual_name) ? $inputData->wallet_account_actual_name : null) . ' '; } else { $xml_string .= ' - '.((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null).(isset($inputData->receiver_middle_name) ? ' '.$inputData->receiver_middle_name : null).(isset($inputData->receiver_last_name) ? ' '.$inputData->receiver_last_name : null)).' + ' . ((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null) . (isset($inputData->receiver_middle_name) ? ' ' . $inputData->receiver_middle_name : null) . (isset($inputData->receiver_last_name) ? ' ' . $inputData->receiver_last_name : null)) . ' '; } $xml_string .= ' - '.(isset($inputData->receiver_city) ? $inputData->receiver_city : 'Dhaka').' + ' . (isset($inputData->receiver_city) ? $inputData->receiver_city : 'Dhaka') . ' - '.$inputData->purpose_of_remittance.' - '.$inputData->bank_account_number.' + ' . $inputData->purpose_of_remittance . ' + ' . $inputData->bank_account_number . ' - '.$inputData->receiver_address.' - '.date('Y-m-d', strtotime($inputData->created_date)).' + ' . $inputData->receiver_address . ' + ' . date('Y-m-d', strtotime($inputData->created_date)) . ' '; @@ -641,8 +448,8 @@ public function getNagadTnxStatus($inputData) $xml_string = ' - '.$doAuthenticate.' - '.$inputData['reference_no'].' + ' . $doAuthenticate . ' + ' . $inputData['reference_no'] . ' '; $soapMethod = 'getNagadTransferStatus'; @@ -662,28 +469,184 @@ public function getNagadTnxStatus($inputData) /** * Execute the transfer operation */ - public function makeTransfer(array $orderInfo): mixed + public function makeTransfer(array $orderInfo = []): mixed { - // TODO: Implement makeTransfer() method. + $doAuthenticate = $this->doAuthenticate(); + if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { + if ($inputData->bank_id == 17) { + $mode_of_payment = 'CBL Account'; + } else { + $mode_of_payment = 'Other Bank'; + } + if ($inputData->recipient_type_name == 'Cash') { + $mode_of_payment = 'Cash'; + } + if ($inputData->recipient_type_name == 'Cash Pickup') { + $mode_of_payment = 'Cash'; + } + $xml_string = ' + + ' . $doAuthenticate . ' + ' . $inputData->reference_no . ' + ' . $inputData->sender_first_name . ' + ' . $inputData->sender_mobile . ' + + ' . $inputData->sender_id_number . ' + ' . $inputData->sender_id_issue_country . ' + ' . ((isset($inputData->receiver_first_name) ? $inputData->receiver_first_name : null) . (isset($inputData->receiver_middle_name) ? ' ' . $inputData->receiver_middle_name : null) . (isset($inputData->receiver_last_name) ? ' ' . $inputData->receiver_last_name : null)) . ' + '; + if ($mode_of_payment != 'Cash') { + $xml_string .= ' + ' . $inputData->bank_account_number . ' + Savings + ' . $inputData->bank_name . ' + ' . $inputData->bank_branch_name . ' + ' . (isset($inputData->location_routing_id[1]->bank_branch_location_field_value) ? $inputData->location_routing_id[1]->bank_branch_location_field_value : null) . ' + '; + } + $xml_string .= ' + ' . $inputData->transfer_amount . ' + ' . $inputData->purpose_of_remittance . ' + ' . $inputData->receiver_contact_number . ' + + + ' . $inputData->sender_address . ' + ' . $inputData->sender_mobile . ' + ' . $inputData->receiver_address . ' + + NA + ' . $mode_of_payment . ' + ' . date('Y-m-d', strtotime($inputData->created_date)) . ' + + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + + '; + $soapMethod = 'doTransfer'; + $response = $this->connectionCheck($xml_string, $soapMethod); + if (isset($response) && $response != false && $response != null) { + $returnValue = json_decode($response->doTransferResponse->Response, true); + } else { + $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; + } + } else { + $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + } + + return $returnValue; } - public function transferStatus(array $orderInfo): mixed + public function transferStatus(array $orderInfo = []): mixed { - // TODO: Implement transferStatus() method. + $doAuthenticate = $this->doAuthenticate(); + if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { + $xml_string = ' + + + ' . $doAuthenticate . ' + ' . $inputs_data['reference_no'] . ' + + '; + $soapMethod = 'getTnxStatus'; + $response = $this->connectionCheck($xml_string, $soapMethod); + if (isset($response) && $response != false && $response != null) { + $returnValue = json_decode($response->getTnxStatusResponse->Response, true); + } else { + $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; + } + } else { + $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + } + + return $returnValue; } - public function cancelTransfer(array $orderInfo): mixed + /** + * Do amendment or cancel service will help you to send the transaction cancel/amendment request + * reference_no like system transaction number, amend_query like cancel/amendment + * @param $orderInfo + * @return mixed + * + * @throws \Exception + */ + public function cancelTransfer(array $orderInfo = []): mixed { - // TODO: Implement cancelTransfer() method. + $doAuthenticate = $this->doAuthenticate(); + if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { + $xml_string = ' + + + ' . $doAuthenticate . ' + ' . $inputData['reference_no'] . ' + ' . $inputData['amend_query'] . ' + + '; + $soapMethod = 'doAmendmentOrCancel'; + $response = $this->connectionCheck($xml_string, $soapMethod); + if (isset($response) && $response != false && $response != null) { + $returnValue = json_decode($response->doAmendmentOrCancelResponse->Response, true); + } else { + $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; + } + } else { + $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + } + + return $returnValue; } - public function verifyAccount(array $accountInfo): mixed + public function verifyAccount(array $accountInfo = []): mixed { // TODO: Implement verifyAccount() method. } - public function vendorBalance(array $accountInfo): mixed + public function vendorBalance(array $accountInfo = []): mixed + { + $doAuthenticate = $this->doAuthenticate(); + if ($doAuthenticate != 'AUTH_FAILED' || $doAuthenticate != null) { + $xml_string = ' + + ' . $doAuthenticate . ' + + '; + $soapMethod = 'getBalance'; + $response = $this->connectionCheck($xml_string, $soapMethod); + if (isset($response) && $response != false && $response != null) { + $returnValue = json_decode($response->getBalanceResponse->Response, true); + } else { + $returnValue = ['message' => 'Transaction response Found', 'status' => 5000]; + } + } else { + $returnValue = ['message' => 'AUTH_FAILED INVALID USER INFORMATION', 'status' => 103]; + } + + return $returnValue; + } + + /** + * @param \Illuminate\Database\Eloquent\Model|\MongoDB\Laravel\Eloquent\Model $order + * @return mixed + */ + public function requestQuotation($order): mixed { - // TODO: Implement vendorBalance() method. + } }