e2-consult /
dnb-laravel-client
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace E2Consult\DNBApiClient; |
||||||
| 4 | |||||||
| 5 | use GuzzleHttp\HandlerStack; |
||||||
| 6 | use Illuminate\Support\Carbon; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 7 | use Aws\Credentials\Credentials; |
||||||
| 8 | use GuzzleHttp\Handler\CurlHandler; |
||||||
| 9 | use GuzzleHttp\Client as GuzzleClient; |
||||||
| 10 | |||||||
| 11 | class Client |
||||||
| 12 | { |
||||||
| 13 | protected $customerId; |
||||||
| 14 | protected $client; |
||||||
| 15 | |||||||
| 16 | public function __construct($customerId = null) |
||||||
| 17 | { |
||||||
| 18 | $this->customerId = $customerId; |
||||||
| 19 | $this->client = new GuzzleClient([ |
||||||
| 20 | 'base_uri' => config('services.dnb.endpoint'), |
||||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 21 | 'handler' => tap(HandlerStack::create(new CurlHandler()), function ($stack) { |
||||||
|
0 ignored issues
–
show
The function
tap was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 22 | $stack->push(new DNBRequestHandler( |
||||||
| 23 | new Credentials( |
||||||
| 24 | config('services.dnb.client_id'), |
||||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 25 | config('services.dnb.client_secret') |
||||||
| 26 | ), |
||||||
| 27 | config('services.dnb.api_key'), |
||||||
| 28 | $this->customerId |
||||||
| 29 | )); |
||||||
| 30 | }) |
||||||
| 31 | ]); |
||||||
| 32 | } |
||||||
| 33 | |||||||
| 34 | public function fetch($endpoint, $method = 'GET', $params = []) |
||||||
| 35 | { |
||||||
| 36 | return json_decode( |
||||||
| 37 | $this->client |
||||||
| 38 | ->request($method, $endpoint, $params) |
||||||
| 39 | ->getBody() |
||||||
| 40 | ); |
||||||
| 41 | } |
||||||
| 42 | |||||||
| 43 | public function getCustomerDetails() |
||||||
| 44 | { |
||||||
| 45 | return $this->fetch('/customers/current'); |
||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | public function getAccounts() |
||||||
| 49 | { |
||||||
| 50 | return $this->fetch('/accounts'); |
||||||
| 51 | } |
||||||
| 52 | |||||||
| 53 | public function getAccountDetails($accountNumber) |
||||||
| 54 | { |
||||||
| 55 | return $this->fetch("/accounts/{$accountNumber}"); |
||||||
| 56 | } |
||||||
| 57 | |||||||
| 58 | public function getAccountBalance($accountNumber) |
||||||
| 59 | { |
||||||
| 60 | return $this->fetch("/accounts/{$accountNumber}/balance"); |
||||||
| 61 | } |
||||||
| 62 | |||||||
| 63 | public function getAccountTransactions($accountNumber, $from = null, $to = null) |
||||||
| 64 | { |
||||||
| 65 | $from = $from ? Carbon::parse($from) : now()->subMonth(); |
||||||
|
0 ignored issues
–
show
The function
now was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 66 | $to = $to ? Carbon::parse($to) : now(); |
||||||
| 67 | |||||||
| 68 | return $this->fetch("/transactions/{$accountNumber}", 'GET', [ |
||||||
| 69 | 'query' => [ |
||||||
| 70 | 'fromDate' => $from->toDateString(), |
||||||
| 71 | 'toDate' => $to->toDateString() |
||||||
| 72 | ] |
||||||
| 73 | ]); |
||||||
| 74 | } |
||||||
| 75 | |||||||
| 76 | public function initiatePayment($debitAccountNumber, $creditAccountNumber, $amount, $requestedExecutionDate = null) |
||||||
| 77 | { |
||||||
| 78 | $requestedExecutionDate = Carbon::parse($requestedExecutionDate ?? now()); |
||||||
|
0 ignored issues
–
show
The function
now was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 79 | |||||||
| 80 | return $this->fetch('/payments', 'POST', [ |
||||||
| 81 | 'body' => json_encode([ |
||||||
| 82 | 'debitAccountNumber' => $debitAccountNumber, |
||||||
| 83 | 'creditAccountNumber' => $creditAccountNumber, |
||||||
| 84 | 'amount' => $amount, |
||||||
| 85 | 'requestedExecutionDate' => $requestedExecutionDate->toDateString() |
||||||
| 86 | ]) |
||||||
| 87 | ]); |
||||||
| 88 | } |
||||||
| 89 | |||||||
| 90 | public function updatePayment($accountNumber, $paymentId, $debitAccountNumber, $amount, $status, $requestedExecutionDate = null) |
||||||
| 91 | { |
||||||
| 92 | return $this->fetch("/payments/{$accountNumber}/pending-payments//$paymentId", 'PATCH', [ |
||||||
| 93 | 'body' => json_encode([ |
||||||
| 94 | 'debitAccountNumber' => $debitAccountNumber, |
||||||
| 95 | 'amount' => $amount, |
||||||
| 96 | 'status' => $status, |
||||||
| 97 | 'requestedExecutionDate' => $requestedExecutionDate->toDateString(), |
||||||
| 98 | ]) |
||||||
| 99 | ]); |
||||||
| 100 | } |
||||||
| 101 | |||||||
| 102 | public function deletePayment($accountNumber, $paymentId) |
||||||
| 103 | { |
||||||
| 104 | return $this->fetch("/payments/{$accountNumber}/pending-payments//$paymentId", 'DELETE'); |
||||||
| 105 | } |
||||||
| 106 | |||||||
| 107 | public function getDuePayments($accountNumber, $paymentId = null) |
||||||
| 108 | { |
||||||
| 109 | return $this->fetch("/payments/{$accountNumber}/due/$paymentId"); |
||||||
| 110 | } |
||||||
| 111 | |||||||
| 112 | public function getDuePayment($accountNumber, $paymentId) |
||||||
| 113 | { |
||||||
| 114 | return $this->getDuePayments($accountNumber, $paymentId); |
||||||
| 115 | } |
||||||
| 116 | |||||||
| 117 | public function getCurrencyRates() |
||||||
| 118 | { |
||||||
| 119 | return $this->fetch('currencies/NOK'); |
||||||
| 120 | } |
||||||
| 121 | |||||||
| 122 | public function convertCurrency($targetCurrency) |
||||||
| 123 | { |
||||||
| 124 | return $this->fetch("currencies/NOK/convert/{$targetCurrency}"); |
||||||
| 125 | } |
||||||
| 126 | |||||||
| 127 | public function getBranches($branchId = null) |
||||||
| 128 | { |
||||||
| 129 | return $this->fetch("/locations/branches/{$branchId}"); |
||||||
| 130 | } |
||||||
| 131 | |||||||
| 132 | public function getBranch($branchId) |
||||||
| 133 | { |
||||||
| 134 | return $this->getBranches($branchId); |
||||||
| 135 | } |
||||||
| 136 | |||||||
| 137 | public function getATMs() |
||||||
| 138 | { |
||||||
| 139 | return $this->fetch('/locations/atms'); |
||||||
| 140 | } |
||||||
| 141 | |||||||
| 142 | public function getNearestBranch($location = null) |
||||||
| 143 | { |
||||||
| 144 | if (is_string($location)) { |
||||||
| 145 | return $this->fetch('/locations/branches/findbyaddress', 'GET', [ |
||||||
| 146 | 'query' => [ |
||||||
| 147 | 'address' => $location |
||||||
| 148 | ] |
||||||
| 149 | ]); |
||||||
| 150 | } |
||||||
| 151 | |||||||
| 152 | if (is_array($location)) { |
||||||
| 153 | return $this->fetch('/locations/branches/coordinates', 'GET', [ |
||||||
| 154 | 'query' => [ |
||||||
| 155 | 'latitude' => $location[0], |
||||||
| 156 | 'longitude' => $location[1] |
||||||
| 157 | ] |
||||||
| 158 | ]); |
||||||
| 159 | } |
||||||
| 160 | } |
||||||
| 161 | |||||||
| 162 | public function getNearestATM($latitude = 0, $longitude = 0) |
||||||
| 163 | { |
||||||
| 164 | return $this->fetch('/locations/atms/coordinates', 'GET', [ |
||||||
| 165 | 'query' => [ |
||||||
| 166 | 'latitude' => $latitude, |
||||||
| 167 | 'longitude' => $longitude |
||||||
| 168 | ] |
||||||
| 169 | ]); |
||||||
| 170 | } |
||||||
| 171 | } |
||||||
| 172 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths