diff --git a/app/Http/Controllers/PurchaseOrderController.php b/app/Http/Controllers/PurchaseOrderController.php index 8fc2228d492f..c06fff041bd2 100644 --- a/app/Http/Controllers/PurchaseOrderController.php +++ b/app/Http/Controllers/PurchaseOrderController.php @@ -717,7 +717,7 @@ class PurchaseOrderController extends BaseController default: return response()->json(['message' => ctrans('texts.action_unavailable', ['action' => $action])], 400); - break; + } } diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index f3e8e33adfe8..f0e617a12eba 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -129,9 +129,9 @@ class StorePaymentRequest extends Request $input['date'] = now()->addSeconds($user->company()->utc_offset())->format('Y-m-d'); } - if (! isset($input['idempotency_key'])) { - $input['idempotency_key'] = substr(sha1(json_encode($input)).time()."{$input['date']}{$input['amount']}{$user->id}", 0, 64); - } + // if (! isset($input['idempotency_key'])) { + $input['idempotency_key'] = substr(time()."{$input['date']}{$input['amount']}{$credits_total}{$this->client_id}{$user->company()->company_key}", 0, 64); + // } $this->replace($input); } diff --git a/app/Import/Transformer/BaseTransformer.php b/app/Import/Transformer/BaseTransformer.php index dbaa16d75c22..45c7fd8fca0c 100644 --- a/app/Import/Transformer/BaseTransformer.php +++ b/app/Import/Transformer/BaseTransformer.php @@ -653,11 +653,11 @@ class BaseTransformer /** * @param $name * - * @return int|null + * @return int */ public function getExpenseCategoryId($name) { - /** @var \App\Models\ExpenseCategory $ec */ + /** @var ?\App\Models\ExpenseCategory $ec */ $ec = ExpenseCategory::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ @@ -673,7 +673,7 @@ class BaseTransformer $ec->name = $name; $ec->save(); - return $ec ? $ec->id : null; + return $ec->id; } public function getOrCreateExpenseCategry($name) diff --git a/app/Models/User.php b/app/Models/User.php index e3c03c63ebf5..c10132696530 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -264,6 +264,7 @@ class User extends Authenticatable implements MustVerifyEmail { $truth = app()->make(TruthSource::class); + // @phpstan-ignore-next-line if ($this->company) { return $this->company; } elseif ($truth->getCompany()) { diff --git a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php index 0db7ff2ac382..15b74889778c 100644 --- a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php +++ b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php @@ -194,7 +194,7 @@ class PayPalBasePaymentDriver extends BaseDriver { return ''; - /** @var \App\Models\ClientGatewayToken $cgt */ + /** @var ?\App\Models\ClientGatewayToken $cgt */ $cgt = ClientGatewayToken::where('company_gateway_id', $this->company_gateway->id) ->where('client_id', $this->client->id) ->first(); diff --git a/app/PaymentDrivers/Stripe/ACH.php b/app/PaymentDrivers/Stripe/ACH.php index b21641609476..2802835bc69e 100644 --- a/app/PaymentDrivers/Stripe/ACH.php +++ b/app/PaymentDrivers/Stripe/ACH.php @@ -344,8 +344,6 @@ class ACH return redirect()->route('client.payment_methods.verification', ['payment_method' => $cgt->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); - $data['message'] = 'Invalid parameters were supplied to Stripe\'s API'; - break; case $e instanceof AuthenticationException: $data['message'] = 'Authentication with Stripe\'s API failed'; break; diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 3b3a2047d4ef..cb3b0584d4e6 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -489,11 +489,7 @@ class StripePaymentDriver extends BaseDriver { $customer = Customer::retrieve($customer_id, $this->stripe_connect_auth); - if ($customer) { - return $customer; - } - - return null; + return $customer ?? null; } /** diff --git a/app/PaymentDrivers/WePayPaymentDriver.php b/app/PaymentDrivers/WePayPaymentDriver.php index 20daa4b410e1..2cf8fd4979a3 100644 --- a/app/PaymentDrivers/WePayPaymentDriver.php +++ b/app/PaymentDrivers/WePayPaymentDriver.php @@ -53,7 +53,7 @@ class WePayPaymentDriver extends BaseDriver throw new \Exception("Gateway no longer supported", 500); - return $this; + // return $this; } /** diff --git a/app/Services/Subscription/PaymentLinkService.php b/app/Services/Subscription/PaymentLinkService.php index 2d91260e7e2c..1c66db998ff4 100644 --- a/app/Services/Subscription/PaymentLinkService.php +++ b/app/Services/Subscription/PaymentLinkService.php @@ -117,7 +117,7 @@ class PaymentLinkService /* 06-04-2022 */ /* We may not be in a state where the user is present */ - if (auth()->guard('contact')) { + if (auth()->guard('contact')->user()) { return $this->handleRedirect('/client/invoices/' . $this->encodePrimaryKey($payment_hash->fee_invoice_id)); } } diff --git a/app/Services/Tax/Providers/TaxProvider.php b/app/Services/Tax/Providers/TaxProvider.php index 44585c75bb25..1a4b20736542 100644 --- a/app/Services/Tax/Providers/TaxProvider.php +++ b/app/Services/Tax/Providers/TaxProvider.php @@ -227,7 +227,7 @@ class TaxProvider // $this->provider = EuTax::class; - return $this; + // return $this; } /** diff --git a/resources/views/portal/ninja2020/gateways/paypal/ppcp/card.blade.php b/resources/views/portal/ninja2020/gateways/paypal/ppcp/card.blade.php index 38db67ac5138..b740e554157a 100644 --- a/resources/views/portal/ninja2020/gateways/paypal/ppcp/card.blade.php +++ b/resources/views/portal/ninja2020/gateways/paypal/ppcp/card.blade.php @@ -88,7 +88,7 @@ @if(isset($merchantId)) - + @else @endif diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index cf5816191f4d..696bf0b937e2 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -62,6 +62,38 @@ class PaymentTest extends TestCase ); } + public function testIdempotencyTrigger() + { + + $data = [ + 'amount' => 5, + 'client_id' => $this->client->hashed_id, + 'invoices' => [ + [ + 'invoice_id' => $this->invoice->hashed_id, + 'amount' => 5, + ], + ], + 'date' => '2020/12/11', + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/payments/', $data); + + $response->assertStatus(200); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/payments/', $data); + + $response->assertStatus(422); + + } + + public function testInvoicesValidationProp() {