diff --git a/app/Filters/CreditFilters.php b/app/Filters/CreditFilters.php index 74465a466f1b..482e5376a3ef 100644 --- a/app/Filters/CreditFilters.php +++ b/app/Filters/CreditFilters.php @@ -30,7 +30,7 @@ class CreditFilters extends QueryFilters * @param string $value The credit status as seen by the client * @return Builder */ - public function credit_status(string $value = ''): Builder + public function client_status(string $value = ''): Builder { if (strlen($value) == 0) { return $this->builder; diff --git a/app/Http/Requests/Import/ImportRequest.php b/app/Http/Requests/Import/ImportRequest.php index 73ee49b25116..4cc8ff93489c 100644 --- a/app/Http/Requests/Import/ImportRequest.php +++ b/app/Http/Requests/Import/ImportRequest.php @@ -37,6 +37,7 @@ class ImportRequest extends Request 'column_map' => 'required_with:hash|array', 'skip_header' => 'required_with:hash|boolean', 'files.*' => 'file|mimes:csv,txt', + 'bank_integration_id' => 'bail|required_if:column_map,bank_transaction|min:2' ]; } } diff --git a/app/Http/Requests/Import/PreImportRequest.php b/app/Http/Requests/Import/PreImportRequest.php index 9e959ac882db..fa2aa52c891a 100644 --- a/app/Http/Requests/Import/PreImportRequest.php +++ b/app/Http/Requests/Import/PreImportRequest.php @@ -22,7 +22,10 @@ class PreImportRequest extends Request */ public function authorize() : bool { - return auth()->user()->isAdmin(); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + return $user->isAdmin(); } public function rules() diff --git a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php index 3eb17d91769e..118e02bb3d77 100644 --- a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php +++ b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php @@ -139,9 +139,8 @@ class PayPalPPCPPaymentDriver extends BaseDriver public function init(): self { - // $this->api_endpoint_url = $this->company_gateway->getConfigField('testMode') ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com'; $this->api_endpoint_url = 'https://api-m.paypal.com'; - + // $this->api_endpoint_url = 'https://api-m.sandbox.paypal.com'; $secret = config('ninja.paypal.secret'); $client_id = config('ninja.paypal.client_id'); @@ -238,30 +237,23 @@ class PayPalPPCPPaymentDriver extends BaseDriver } - private function getClientToken(): string - { - - $r = $this->gatewayRequest('/v1/identity/generate-token', 'post', ['body' => '']); - - if($r->successful()) { - return $r->json()['client_token']; - } - - throw new PaymentFailed('Unable to gain client token from Paypal. Check your configuration', 401); - - } - public function processPaymentResponse($request) { - + $request['gateway_response'] = str_replace("Error: ", "", $request['gateway_response']); $response = json_decode($request['gateway_response'], true); + //capture + $orderID = $response['orderID']; + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); + + $response = $r; + if(isset($response['status']) && $response['status'] == 'COMPLETED' && isset($response['purchase_units'])) { $data = [ 'payment_type' => $this->getPaymentMethod($request->gateway_type_id), - 'amount' => $response['purchase_units'][0]['amount']['value'], + 'amount' => $response['purchase_units'][0]['payments']['captures'][0]['amount']['value'], 'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'], 'gateway_type_id' => GatewayType::PAYPAL, ]; @@ -300,6 +292,21 @@ class PayPalPPCPPaymentDriver extends BaseDriver } } + + + private function getClientToken(): string + { + + $r = $this->gatewayRequest('/v1/identity/generate-token', 'post', ['body' => '']); + + if($r->successful()) { + return $r->json()['client_token']; + } + + throw new PaymentFailed('Unable to gain client token from Paypal. Check your configuration', 401); + + } + private function paymentSource(): array { /** we only need to support paypal as payment source until as we are only using hosted payment buttons */ @@ -307,36 +314,6 @@ class PayPalPPCPPaymentDriver extends BaseDriver } - /**@deprecated v5.7.54 */ - private function injectVenmoPaymentSource(): array - { - - return [ - "venmo" => [ - "email_address" => $this->client->present()->email(), - ], - ]; - - } - - /**@deprecated v5.7.54 */ - private function injectCardPaymentSource(): array - { - - return [ - "card" => [ - - "name" => $this->client->present()->name(), - "email_address" => $this->client->present()->email(), - "billing_address" => $this->getBillingAddress(), - "experience_context"=> [ - "user_action" => "PAY_NOW" - ], - ], - ]; - - } - private function injectPayPalPaymentSource(): array { @@ -462,10 +439,23 @@ class PayPalPPCPPaymentDriver extends BaseDriver ->withHeaders($this->getHeaders($headers)) ->{$verb}("{$this->api_endpoint_url}{$uri}", $data); + nlog($r); + nlog($r->json()); + if($r->successful()) { return $r; } + + SystemLogger::dispatch( + ['response' => $r->body()], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_FAILURE, + SystemLog::TYPE_PAYPAL, + $this->client, + $this->client->company, + ); + throw new PaymentFailed("Gateway failure - {$r->body()}", 401); } diff --git a/composer.json b/composer.json index ee36a096afcb..07e5149e7128 100644 --- a/composer.json +++ b/composer.json @@ -173,4 +173,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} +} \ No newline at end of file diff --git a/resources/views/portal/ninja2020/gateways/paypal/ppcp/pay.blade.php b/resources/views/portal/ninja2020/gateways/paypal/ppcp/pay.blade.php index 4de9e9d96755..eddd97098102 100644 --- a/resources/views/portal/ninja2020/gateways/paypal/ppcp/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/paypal/ppcp/pay.blade.php @@ -53,10 +53,11 @@ return actions.restart(); } - return actions.order.capture().then(function(details) { - document.getElementById("gateway_response").value =JSON.stringify( details ); + // return actions.order.capture().then(function(details) { + document.getElementById("gateway_response").value =JSON.stringify( data ); + // document.getElementById("gateway_response").value =JSON.stringify( details ); document.getElementById("server_response").submit(); - }); + // }); }, onCancel: function() { window.location.href = "/client/invoices/";