diff --git a/phpstan.neon.dist b/phpstan.neon.dist index dfd417be..c1799961 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,9 +1,9 @@ parameters: paths: - src - level: 0 + level: 5 ignoreErrors: - "#Parameter#" - "#Call to static method error\\(\\)\\ on an unknown class Log.#" excludePaths: - - "src/Providers/PayPalServiceProvider.php" \ No newline at end of file + - "src/Providers/PayPalServiceProvider.php" diff --git a/src/PayPalFacadeAccessor.php b/src/PayPalFacadeAccessor.php index dee1f220..3c5307c3 100644 --- a/src/PayPalFacadeAccessor.php +++ b/src/PayPalFacadeAccessor.php @@ -10,7 +10,7 @@ class PayPalFacadeAccessor /** * PayPal API provider object. * - * @var + * @var \Srmklive\PayPal\Services\PayPal */ public static $provider; diff --git a/src/Services/Str.php b/src/Services/Str.php index 0fb4576f..15ac758e 100644 --- a/src/Services/Str.php +++ b/src/Services/Str.php @@ -20,14 +20,10 @@ public static function isJson($value): bool } if (function_exists('json_validate')) { - return json_validate($value, 512); + return json_validate($value); } - try { - Utils::jsonDecode($value, true, 512, 4194304); - } catch (\JsonException $jsonException) { - return false; - } + Utils::jsonDecode($value, true, 512, JSON_THROW_ON_ERROR); return true; } diff --git a/src/Services/VerifyDocuments.php b/src/Services/VerifyDocuments.php index 624687f9..ad815b54 100644 --- a/src/Services/VerifyDocuments.php +++ b/src/Services/VerifyDocuments.php @@ -17,12 +17,12 @@ class VerifyDocuments ]; /** - * @var string + * @var int */ protected static $dispute_evidence_file_size = 10; /** - * @var string + * @var int */ protected static $dispute_evidences_size = 50; diff --git a/src/Traits/PayPalAPI.php b/src/Traits/PayPalAPI.php index 8bde8e61..b065dbe5 100644 --- a/src/Traits/PayPalAPI.php +++ b/src/Traits/PayPalAPI.php @@ -107,7 +107,7 @@ public function setPageSize(int $size): \Srmklive\PayPal\Services\PayPal /** * Set the current page for list resources API calls. * - * @param int $size + * @param int $page * * @return \Srmklive\PayPal\Services\PayPal */ diff --git a/src/Traits/PayPalAPI/DisputesActions.php b/src/Traits/PayPalAPI/DisputesActions.php index 10613667..e7eac273 100644 --- a/src/Traits/PayPalAPI/DisputesActions.php +++ b/src/Traits/PayPalAPI/DisputesActions.php @@ -38,7 +38,7 @@ public function acknowledgeItemReturned(string $dispute_id, string $dispute_note * Providence evidence in support of a dispute. * * @param string $dispute_id - * @param array $file_path + * @param array $files * * @throws \Throwable * diff --git a/src/Traits/PayPalAPI/InvoiceSearch/Filters.php b/src/Traits/PayPalAPI/InvoiceSearch/Filters.php index 6160e980..e1a1e897 100644 --- a/src/Traits/PayPalAPI/InvoiceSearch/Filters.php +++ b/src/Traits/PayPalAPI/InvoiceSearch/Filters.php @@ -149,7 +149,15 @@ public function addInvoiceFilterByReferenceorMemo(string $reference, bool $memo */ public function addInvoiceFilterByCurrencyCode(string $currency_code = ''): \Srmklive\PayPal\Services\PayPal { - $currency = !isset($currency_code) ? $this->getCurrency() : $currency_code; + if (!empty($currency_code)) { + $currency = $currency_code; + } else { + try { + $currency = $this->getCurrency(); + } catch (\Throwable $e) { + $currency = 'USD'; + } + } $this->invoice_search_filters['currency_code'] = $currency; @@ -171,7 +179,15 @@ public function addInvoiceFilterByAmountRange(float $start_amount, float $end_am throw new \Exception('Starting amount should always be less than end amount!'); } - $currency = !isset($amount_currency) ? $this->getCurrency() : $amount_currency; + if (!empty($amount_currency)) { + $currency = $amount_currency; + } else { + try { + $currency = $this->getCurrency(); + } catch (\Throwable $e) { + $currency = 'USD'; + } + } $this->invoice_search_filters['total_amount_range'] = [ 'lower_amount' => [ diff --git a/src/Traits/PayPalAPI/Subscriptions.php b/src/Traits/PayPalAPI/Subscriptions.php index a43fb374..15e309b3 100644 --- a/src/Traits/PayPalAPI/Subscriptions.php +++ b/src/Traits/PayPalAPI/Subscriptions.php @@ -219,8 +219,8 @@ public function listSubscriptionTransactions(string $subscription_id, $start_dat $end_date = Carbon::parse($end_date); } - $start_date = $start_date->toIso8601ZuluString(); - $end_date = $end_date->toIso8601ZuluString(); + $start_date = $start_date->format('Y-m-d\TH:i:s\Z'); + $end_date = $end_date->format('Y-m-d\TH:i:s\Z'); $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/transactions?start_time={$start_date}&end_time={$end_date}"; diff --git a/src/Traits/PayPalAPI/Subscriptions/Helpers.php b/src/Traits/PayPalAPI/Subscriptions/Helpers.php index 3bc60833..d94dec86 100644 --- a/src/Traits/PayPalAPI/Subscriptions/Helpers.php +++ b/src/Traits/PayPalAPI/Subscriptions/Helpers.php @@ -19,19 +19,19 @@ trait Helpers protected $payment_failure_threshold = 3; /** - * @var array + * @var array|null */ - protected $product; + protected ?array $product = null; /** - * @var array + * @var array|null */ - protected $billing_plan; + protected ?array $billing_plan = null; /** - * @var array + * @var array|null */ - protected $shipping_address; + protected ?array $shipping_address = null; /** * @var array @@ -44,14 +44,19 @@ trait Helpers protected $has_setup_fee = false; /** - * @var array + * @var array|null + */ + protected ?array $taxes = null; + + /** + * @var string|null */ - protected $taxes; + protected ?string $custom_id = null; /** - * @var string + * @var array */ - protected $custom_id; + protected ?array $experience_context = []; /** * Setup a subscription. @@ -121,7 +126,7 @@ public function setupSubscription(string $customer_name, string $customer_email, * * @param string $interval_type * @param int $interval_count - * @param float|int $price + * @param float $price * @param int $total_cycles * * @return \Srmklive\PayPal\Services\PayPal @@ -138,7 +143,7 @@ public function addPlanTrialPricing(string $interval_type, int $interval_count, * * @param string $name * @param string $description - * @param float|int $price + * @param float $price * @param int $total_cycles * * @throws Throwable @@ -164,7 +169,7 @@ public function addDailyPlan(string $name, string $description, float $price, in * * @param string $name * @param string $description - * @param float|int $price + * @param float $price * @param int $total_cycles * * @throws Throwable @@ -190,7 +195,7 @@ public function addWeeklyPlan(string $name, string $description, float $price, i * * @param string $name * @param string $description - * @param float|int $price + * @param float $price * @param int $total_cycles * * @throws Throwable @@ -216,7 +221,7 @@ public function addMonthlyPlan(string $name, string $description, float $price, * * @param string $name * @param string $description - * @param float|int $price + * @param float $price * @param int $total_cycles * * @throws Throwable @@ -242,7 +247,7 @@ public function addAnnualPlan(string $name, string $description, float $price, i * * @param string $name * @param string $description - * @param float|int $price + * @param float $price * @param string $interval_unit * @param int $interval_count * @param int $total_cycles @@ -327,14 +332,12 @@ public function addProduct(string $name, string $description, string $type, stri return $this; } - $request_id = Str::random(); - $product = $this->createProduct([ 'name' => $name, 'description' => $description, 'type' => $type, 'category' => $category, - ], $request_id); + ]); if ($error = data_get($product, 'error', false)) { throw new \RuntimeException(data_get($error, 'details.0.description', 'Failed to add product')); @@ -389,8 +392,6 @@ public function addBillingPlanById(string $plan_id): \Srmklive\PayPal\Services\P */ protected function addBillingPlan(string $name, string $description, array $billing_cycles): void { - $request_id = Str::random(); - $plan_params = [ 'product_id' => $this->product['id'], 'name' => $name, @@ -404,7 +405,7 @@ protected function addBillingPlan(string $name, string $description, array $bill ], ]; - $billingPlan = $this->createPlan($plan_params, $request_id); + $billingPlan = $this->createPlan($plan_params); if ($error = data_get($billingPlan, 'error', false)) { throw new \RuntimeException(data_get($error, 'details.0.description', 'Failed to add billing plan')); } diff --git a/src/Traits/PayPalAPI/Trackers.php b/src/Traits/PayPalAPI/Trackers.php index 036b1d6c..4789b9f0 100644 --- a/src/Traits/PayPalAPI/Trackers.php +++ b/src/Traits/PayPalAPI/Trackers.php @@ -60,9 +60,9 @@ public function addTracking(array $data) * * @see https://developer.paypal.com/docs/api/tracking/v1/#trackers-batch_get */ - public function listTrackingDetails(string $transaction_id, string $tracking_number = null) + public function listTrackingDetails(string $transaction_id, ?string $tracking_number = null) { - $this->apiEndPoint = "v1/shipping/trackers?transaction_id={$transaction_id}".!empty($tracking_number) ? "&tracking_number={$tracking_number}" : ''; + $this->apiEndPoint = "v1/shipping/trackers?transaction_id={$transaction_id}".(!empty($tracking_number) ? "&tracking_number={$tracking_number}" : ''); $this->verb = 'get'; diff --git a/src/Traits/PayPalExperienceContext.php b/src/Traits/PayPalExperienceContext.php index d1db77a2..a0dbe634 100644 --- a/src/Traits/PayPalExperienceContext.php +++ b/src/Traits/PayPalExperienceContext.php @@ -7,7 +7,7 @@ trait PayPalExperienceContext /** * @var array */ - protected $experience_context = []; + protected ?array $experience_context = []; /** * Set Brand Name when setting experience context for payment. diff --git a/src/Traits/PayPalHttpClient.php b/src/Traits/PayPalHttpClient.php index 7723b66c..ab4b6cd0 100644 --- a/src/Traits/PayPalHttpClient.php +++ b/src/Traits/PayPalHttpClient.php @@ -120,7 +120,7 @@ protected function defineCurlConstant(string $key, string $value) * * @return void */ - public function setClient(HttpClient $client = null) + public function setClient(?HttpClient $client = null) { if ($client instanceof HttpClient) { $this->client = $client; diff --git a/src/Traits/PayPalRequest.php b/src/Traits/PayPalRequest.php index 362103cf..011b2a2c 100644 --- a/src/Traits/PayPalRequest.php +++ b/src/Traits/PayPalRequest.php @@ -55,7 +55,7 @@ trait PayPalRequest /** * Set the current page for list resources API calls. * - * @var bool + * @var int */ protected $current_page = 1; diff --git a/src/Traits/PayPalVerifyIPN.php b/src/Traits/PayPalVerifyIPN.php index 63478683..37bb6887 100644 --- a/src/Traits/PayPalVerifyIPN.php +++ b/src/Traits/PayPalVerifyIPN.php @@ -2,6 +2,8 @@ namespace Srmklive\PayPal\Traits; +use Illuminate\Http\Request; + trait PayPalVerifyIPN { protected $webhook_id; @@ -16,12 +18,16 @@ public function setWebHookID(string $webhook_id): \Srmklive\PayPal\Services\PayP /** * Verify incoming IPN through a web hook id. * + * @param \Illuminate\Http\Request $request Laravel HTTP request object * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string + * + * @phpstan-ignore-next-line */ - public function verifyIPN(\Illuminate\Http\Request $request) + public function verifyIPN(Request $request) { + /** @phpstan-ignore-next-line */ $headers = array_change_key_case($request->headers->all(), CASE_UPPER); if (!isset($headers['PAYPAL-AUTH-ALGO'][0]) || @@ -36,6 +42,7 @@ public function verifyIPN(\Illuminate\Http\Request $request) return ['error' => 'Invalid headers or webhook id provided']; } + /** @phpstan-ignore-next-line */ $params = json_decode($request->getContent()); $payload = [ diff --git a/tests/MockClientClasses.php b/tests/MockClientClasses.php index 109fe3fe..0a4d784d 100644 --- a/tests/MockClientClasses.php +++ b/tests/MockClientClasses.php @@ -117,14 +117,7 @@ private function getApiCredentials(): array protected function setMethodsFunction(): bool { - $useOnlyMethods = false; - - foreach (['8.1', '8.2', '8.3'] as $php_version) { - if (strpos(phpversion(), $php_version) !== false) { - $useOnlyMethods = true; - } - } - - return $useOnlyMethods; + // Always use onlyMethods as setMethods is deprecated in PHPUnit 8 and removed in PHPUnit 10 + return true; } }