From e2f734043ad80827142b4603f0ec3217cb1f10fa Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Sun, 23 Jun 2024 22:06:05 +0500 Subject: [PATCH] Update doc blocks & return types. Signed-off-by: Raza Mehdi --- src/Facades/PayPal.php | 7 +- src/PayPalFacadeAccessor.php | 12 +-- src/Providers/PayPalServiceProvider.php | 10 +- src/Services/VerifyDocuments.php | 14 +-- src/Traits/PayPalAPI.php | 27 ++--- src/Traits/PayPalAPI/BillingPlans.php | 45 ++++---- .../PayPalAPI/BillingPlans/PricingSchemes.php | 12 ++- src/Traits/PayPalAPI/CatalogProducts.php | 27 ++--- src/Traits/PayPalAPI/Disputes.php | 21 ++-- src/Traits/PayPalAPI/DisputesActions.php | 58 +++++----- src/Traits/PayPalAPI/Identity.php | 51 ++++----- .../PayPalAPI/InvoiceSearch/Filters.php | 63 +++++------ src/Traits/PayPalAPI/Invoices.php | 87 +++++++-------- src/Traits/PayPalAPI/InvoicesSearch.php | 8 +- src/Traits/PayPalAPI/InvoicesTemplates.php | 33 +++--- src/Traits/PayPalAPI/Orders.php | 39 +++---- src/Traits/PayPalAPI/Orders/Helpers.php | 5 +- src/Traits/PayPalAPI/PartnerReferrals.php | 33 +++--- .../PayPalAPI/PaymentAuthorizations.php | 27 ++--- src/Traits/PayPalAPI/PaymentCaptures.php | 15 +-- .../PaymentExperienceWebProfiles.php | 39 +++---- src/Traits/PayPalAPI/PaymentMethodsTokens.php | 39 ++++--- .../PaymentMethodsTokens/Helpers.php | 36 ++++--- src/Traits/PayPalAPI/PaymentRefunds.php | 9 +- src/Traits/PayPalAPI/Payouts.php | 27 ++--- src/Traits/PayPalAPI/ReferencedPayouts.php | 27 ++--- src/Traits/PayPalAPI/Reporting.php | 14 +-- src/Traits/PayPalAPI/Subscriptions.php | 65 +++++------ .../PayPalAPI/Subscriptions/Helpers.php | 102 +++++++++--------- src/Traits/PayPalAPI/Trackers.php | 37 ++++--- src/Traits/PayPalAPI/WebHooks.php | 39 +++---- src/Traits/PayPalAPI/WebHooksEvents.php | 27 ++--- src/Traits/PayPalAPI/WebHooksVerification.php | 9 +- src/Traits/PayPalExperienceContext.php | 2 +- src/Traits/PayPalHttpClient.php | 34 +++--- src/Traits/PayPalRequest.php | 35 +++--- src/Traits/PayPalVerifyIPN.php | 2 +- 37 files changed, 615 insertions(+), 522 deletions(-) diff --git a/src/Facades/PayPal.php b/src/Facades/PayPal.php index 0ea2417a..8e4975eb 100644 --- a/src/Facades/PayPal.php +++ b/src/Facades/PayPal.php @@ -5,10 +5,11 @@ /* * Class Facade * @package Srmklive\PayPal\Facades - * @see Srmklive\PayPal\ExpressCheckout + * @see Srmklive\PayPal\Services\PayPal */ use Illuminate\Support\Facades\Facade; +use Srmklive\PayPal\PayPalFacadeAccessor; class PayPal extends Facade { @@ -17,8 +18,8 @@ class PayPal extends Facade * * @return string */ - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { - return 'Srmklive\PayPal\PayPalFacadeAccessor'; + return PayPalFacadeAccessor::class; } } diff --git a/src/PayPalFacadeAccessor.php b/src/PayPalFacadeAccessor.php index dee1f220..ded0f17e 100644 --- a/src/PayPalFacadeAccessor.php +++ b/src/PayPalFacadeAccessor.php @@ -10,18 +10,18 @@ class PayPalFacadeAccessor /** * PayPal API provider object. * - * @var + * @var PayPalClient */ - public static $provider; + public static PayPalClient $provider; /** * Get specific PayPal API provider object to use. * * @throws Exception * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public static function getProvider() + public static function getProvider(): PayPalClient { return self::$provider; } @@ -31,9 +31,9 @@ public static function getProvider() * * @throws \Exception * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public static function setProvider() + public static function setProvider(): PayPalClient { // Set default provider. Defaults to ExpressCheckout self::$provider = new PayPalClient(); diff --git a/src/Providers/PayPalServiceProvider.php b/src/Providers/PayPalServiceProvider.php index 4573e8f3..ac11e663 100644 --- a/src/Providers/PayPalServiceProvider.php +++ b/src/Providers/PayPalServiceProvider.php @@ -17,14 +17,14 @@ class PayPalServiceProvider extends ServiceProvider * * @var bool */ - protected $defer = false; + protected bool $defer = false; /** * Bootstrap the application events. * * @return void */ - public function boot() + public function boot(): void { // Publish config files $this->publishes([ @@ -40,7 +40,7 @@ public function boot() * * @return void */ - public function register() + public function register(): void { $this->registerPayPal(); @@ -52,7 +52,7 @@ public function register() * * @return void */ - private function registerPayPal() + private function registerPayPal(): void { $this->app->singleton('paypal_client', static function () { return new PayPalClient(); @@ -64,7 +64,7 @@ private function registerPayPal() * * @return void */ - private function mergeConfig() + private function mergeConfig(): void { $this->mergeConfigFrom( __DIR__.'/../../config/config.php', diff --git a/src/Services/VerifyDocuments.php b/src/Services/VerifyDocuments.php index 624687f9..87548d1d 100644 --- a/src/Services/VerifyDocuments.php +++ b/src/Services/VerifyDocuments.php @@ -9,7 +9,7 @@ class VerifyDocuments /** * @var array */ - protected static $dispute_evidence_types = [ + protected static array $dispute_evidence_types = [ 'application/pdf', 'image/gif', 'image/jpeg', @@ -19,12 +19,12 @@ class VerifyDocuments /** * @var string */ - protected static $dispute_evidence_file_size = 10; + protected static string|int $dispute_evidence_file_size = 10; /** * @var string */ - protected static $dispute_evidences_size = 50; + protected static string|int $dispute_evidences_size = 50; /** * Get Mime type from filename. @@ -33,7 +33,7 @@ class VerifyDocuments * * @return string */ - public static function getMimeType($file) + public static function getMimeType(string $file): string { return MimeType::fromFilename($file); } @@ -45,7 +45,7 @@ public static function getMimeType($file) * * @return bool */ - public static function isValidEvidenceFile(array $files) + public static function isValidEvidenceFile(array $files): bool { $validFile = true; $validSize = true; @@ -58,7 +58,7 @@ public static function isValidEvidenceFile(array $files) foreach ($files as $file) { $mime_type = self::getMimeType($file); - if (!in_array($mime_type, self::$dispute_evidence_types)) { + if (!in_array($mime_type, self::$dispute_evidence_types, true)) { $validFile = false; break; } @@ -73,6 +73,6 @@ public static function isValidEvidenceFile(array $files) $total_size += $size; } - return (($validFile === false) || ($validSize === false)) || ($total_size > $overall_size) ? false : true; + return !((($validFile === false) || ($validSize === false)) || ($total_size > $overall_size)); } } diff --git a/src/Traits/PayPalAPI.php b/src/Traits/PayPalAPI.php index 6168b459..f6aeb63e 100644 --- a/src/Traits/PayPalAPI.php +++ b/src/Traits/PayPalAPI.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits; +use Psr\Http\Message\StreamInterface; +use Srmklive\PayPal\Services\PayPal as PayPalClient; + trait PayPalAPI { use PayPalAPI\Trackers; @@ -31,14 +34,14 @@ trait PayPalAPI /** * Login through PayPal API to get access token. * - * @throws \Throwable + * @return array|StreamInterface|string * - * @return array|\Psr\Http\Message\StreamInterface|string + * @throws \Throwable * * @see https://developer.paypal.com/docs/api/get-an-access-token-curl/ * @see https://developer.paypal.com/docs/api/get-an-access-token-postman/ */ - public function getAccessToken() + public function getAccessToken(): StreamInterface|array|string { $this->apiEndPoint = 'v1/oauth2/token'; @@ -66,7 +69,7 @@ public function getAccessToken() * * @return void */ - public function setAccessToken(array $response) + public function setAccessToken(array $response): void { $this->access_token = $response['access_token']; @@ -82,7 +85,7 @@ public function setAccessToken(array $response) * * @return void */ - private function setPayPalAppId(array $response) + private function setPayPalAppId(array $response): void { $app_id = empty($response['app_id']) ? $this->config['app_id'] : $response['app_id']; @@ -94,9 +97,9 @@ private function setPayPalAppId(array $response) * * @param int $size * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function setPageSize(int $size): \Srmklive\PayPal\Services\PayPal + public function setPageSize(int $size): PayPalClient { $this->page_size = $size; @@ -106,11 +109,11 @@ 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 + * @return PayPalClient */ - public function setCurrentPage(int $page): \Srmklive\PayPal\Services\PayPal + public function setCurrentPage(int $page): PayPalClient { $this->current_page = $page; @@ -122,9 +125,9 @@ public function setCurrentPage(int $page): \Srmklive\PayPal\Services\PayPal * * @param bool $totals * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function showTotals(bool $totals): \Srmklive\PayPal\Services\PayPal + public function showTotals(bool $totals): PayPalClient { $this->show_totals = var_export($totals, true); diff --git a/src/Traits/PayPalAPI/BillingPlans.php b/src/Traits/PayPalAPI/BillingPlans.php index 63a3ef25..3c4f16c6 100644 --- a/src/Traits/PayPalAPI/BillingPlans.php +++ b/src/Traits/PayPalAPI/BillingPlans.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait BillingPlans { use BillingPlans\PricingSchemes; @@ -11,13 +14,13 @@ trait BillingPlans * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create */ - public function createPlan(array $data) + public function createPlan(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/billing/plans'; @@ -31,13 +34,13 @@ public function createPlan(array $data) /** * List all billing plans. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list */ - public function listPlans() + public function listPlans(): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/plans?page={$this->current_page}&page_size={$this->page_size}&total_required={$this->show_totals}"; @@ -52,13 +55,13 @@ public function listPlans() * @param string $plan_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update */ - public function updatePlan(string $plan_id, array $data) + public function updatePlan(string $plan_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/plans/{$plan_id}"; @@ -74,13 +77,13 @@ public function updatePlan(string $plan_id, array $data) * * @param string $plan_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get */ - public function showPlanDetails(string $plan_id) + public function showPlanDetails(string $plan_id): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/plans/{$plan_id}"; @@ -94,13 +97,13 @@ public function showPlanDetails(string $plan_id) * * @param string $plan_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate */ - public function activatePlan(string $plan_id) + public function activatePlan(string $plan_id): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/plans/{$plan_id}/activate"; @@ -114,13 +117,13 @@ public function activatePlan(string $plan_id) * * @param string $plan_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate */ - public function deactivatePlan(string $plan_id) + public function deactivatePlan(string $plan_id): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/plans/{$plan_id}/deactivate"; @@ -135,13 +138,13 @@ public function deactivatePlan(string $plan_id) * @param string $plan_id * @param array $pricing * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes */ - public function updatePlanPricing(string $plan_id, array $pricing) + public function updatePlanPricing(string $plan_id, array $pricing): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/plans/{$plan_id}/update-pricing-schemes"; diff --git a/src/Traits/PayPalAPI/BillingPlans/PricingSchemes.php b/src/Traits/PayPalAPI/BillingPlans/PricingSchemes.php index 393ebaa4..9dc0146e 100644 --- a/src/Traits/PayPalAPI/BillingPlans/PricingSchemes.php +++ b/src/Traits/PayPalAPI/BillingPlans/PricingSchemes.php @@ -2,11 +2,13 @@ namespace Srmklive\PayPal\Traits\PayPalAPI\BillingPlans; +use Psr\Http\Message\StreamInterface; +use Srmklive\PayPal\Services\PayPal as PayPalClient; use Throwable; trait PricingSchemes { - protected $pricing_schemes = []; + protected array $pricing_schemes = []; /** * Add pricing scheme for the billing plan. @@ -18,9 +20,9 @@ trait PricingSchemes * * @throws Throwable * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addPricingScheme(string $interval_unit, int $interval_count, float $price, bool $trial = false): \Srmklive\PayPal\Services\PayPal + public function addPricingScheme(string $interval_unit, int $interval_count, float $price, bool $trial = false): PayPalClient { $this->pricing_schemes[] = $this->addPlanBillingCycle($interval_unit, $interval_count, $price, $trial); @@ -32,9 +34,9 @@ public function addPricingScheme(string $interval_unit, int $interval_count, flo * * @throws \Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string */ - public function processBillingPlanPricingUpdates() + public function processBillingPlanPricingUpdates(): StreamInterface|array|string { return $this->updatePlanPricing($this->billing_plan['id'], $this->pricing_schemes); } diff --git a/src/Traits/PayPalAPI/CatalogProducts.php b/src/Traits/PayPalAPI/CatalogProducts.php index f044b7a7..cb77ad40 100644 --- a/src/Traits/PayPalAPI/CatalogProducts.php +++ b/src/Traits/PayPalAPI/CatalogProducts.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait CatalogProducts { /** @@ -9,13 +12,13 @@ trait CatalogProducts * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_create */ - public function createProduct(array $data) + public function createProduct(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/catalogs/products'; @@ -29,13 +32,13 @@ public function createProduct(array $data) /** * List products. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_list */ - public function listProducts() + public function listProducts(): StreamInterface|array|string { $this->apiEndPoint = "v1/catalogs/products?page={$this->current_page}&page_size={$this->page_size}&total_required={$this->show_totals}"; @@ -50,13 +53,13 @@ public function listProducts() * @param string $product_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch */ - public function updateProduct(string $product_id, array $data) + public function updateProduct(string $product_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v1/catalogs/products/{$product_id}"; @@ -72,13 +75,13 @@ public function updateProduct(string $product_id, array $data) * * @param string $product_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_get */ - public function showProductDetails(string $product_id) + public function showProductDetails(string $product_id): StreamInterface|array|string { $this->apiEndPoint = "v1/catalogs/products/{$product_id}"; diff --git a/src/Traits/PayPalAPI/Disputes.php b/src/Traits/PayPalAPI/Disputes.php index 22250bac..e32a003c 100644 --- a/src/Traits/PayPalAPI/Disputes.php +++ b/src/Traits/PayPalAPI/Disputes.php @@ -2,18 +2,21 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait Disputes { /** * List disputes. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_list */ - public function listDisputes() + public function listDisputes(): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes?page_size={$this->page_size}"; @@ -28,13 +31,13 @@ public function listDisputes() * @param string $dispute_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_patch */ - public function updateDispute(string $dispute_id, array $data) + public function updateDispute(string $dispute_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}"; @@ -50,13 +53,13 @@ public function updateDispute(string $dispute_id, array $data) * * @param string $dispute_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_get */ - public function showDisputeDetails(string $dispute_id) + public function showDisputeDetails(string $dispute_id): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}"; diff --git a/src/Traits/PayPalAPI/DisputesActions.php b/src/Traits/PayPalAPI/DisputesActions.php index 10613667..2c85ef4e 100644 --- a/src/Traits/PayPalAPI/DisputesActions.php +++ b/src/Traits/PayPalAPI/DisputesActions.php @@ -3,7 +3,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; use GuzzleHttp\Psr7; +use Psr\Http\Message\StreamInterface; use Srmklive\PayPal\Services\VerifyDocuments; +use Throwable; trait DisputesActions { @@ -14,13 +16,13 @@ trait DisputesActions * @param string $dispute_note * @param string $acknowledgement_type * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_acknowledge-return-item */ - public function acknowledgeItemReturned(string $dispute_id, string $dispute_note, string $acknowledgement_type) + public function acknowledgeItemReturned(string $dispute_id, string $dispute_note, string $acknowledgement_type): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/acknowledge-return-item"; @@ -38,15 +40,15 @@ 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 + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_provide-evidence */ - public function provideDisputeEvidence(string $dispute_id, array $files) + public function provideDisputeEvidence(string $dispute_id, array $files): StreamInterface|array|string { if (VerifyDocuments::isValidEvidenceFile($files) === false) { $this->throwInvalidEvidenceFileException(); @@ -78,13 +80,13 @@ public function provideDisputeEvidence(string $dispute_id, array $files) * @param float $amount * @param string $refund_type * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_make-offer */ - public function makeOfferToResolveDispute(string $dispute_id, string $dispute_note, float $amount, string $refund_type) + public function makeOfferToResolveDispute(string $dispute_id, string $dispute_note, float $amount, string $refund_type): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/make-offer"; @@ -108,13 +110,13 @@ public function makeOfferToResolveDispute(string $dispute_id, string $dispute_no * @param string $dispute_id * @param string $dispute_note * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_escalate */ - public function escalateDisputeToClaim(string $dispute_id, string $dispute_note) + public function escalateDisputeToClaim(string $dispute_id, string $dispute_note): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/escalate"; @@ -133,13 +135,13 @@ public function escalateDisputeToClaim(string $dispute_id, string $dispute_note) * @param string $dispute_id * @param string $dispute_note * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-offer */ - public function acceptDisputeOfferResolution(string $dispute_id, string $dispute_note) + public function acceptDisputeOfferResolution(string $dispute_id, string $dispute_note): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-offer"; @@ -159,13 +161,13 @@ public function acceptDisputeOfferResolution(string $dispute_id, string $dispute * @param string $dispute_note * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-claim */ - public function acceptDisputeClaim(string $dispute_id, string $dispute_note, array $data = []) + public function acceptDisputeClaim(string $dispute_id, string $dispute_note, array $data = []): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-claim"; @@ -185,13 +187,13 @@ public function acceptDisputeClaim(string $dispute_id, string $dispute_note, arr * @param string $dispute_id * @param bool $merchant * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_require-evidence */ - public function updateDisputeStatus(string $dispute_id, bool $merchant = true) + public function updateDisputeStatus(string $dispute_id, bool $merchant = true): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/require-evidence"; @@ -210,13 +212,13 @@ public function updateDisputeStatus(string $dispute_id, bool $merchant = true) * @param string $dispute_id * @param bool $merchant * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_adjudicate */ - public function settleDispute(string $dispute_id, bool $merchant = true) + public function settleDispute(string $dispute_id, bool $merchant = true): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/adjudicate"; @@ -235,13 +237,13 @@ public function settleDispute(string $dispute_id, bool $merchant = true) * @param string $dispute_id * @param string $dispute_note * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_deny-offer */ - public function declineDisputeOfferResolution(string $dispute_id, string $dispute_note) + public function declineDisputeOfferResolution(string $dispute_id, string $dispute_note): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/deny-offer"; diff --git a/src/Traits/PayPalAPI/Identity.php b/src/Traits/PayPalAPI/Identity.php index aaf36035..95aa794f 100644 --- a/src/Traits/PayPalAPI/Identity.php +++ b/src/Traits/PayPalAPI/Identity.php @@ -2,18 +2,21 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait Identity { /** * Get user profile information. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v1/#userinfo_get */ - public function showProfileInfo() + public function showProfileInfo(): StreamInterface|array|string { $this->apiEndPoint = 'v1/identity/openidconnect/userinfo?schema=openid'; @@ -29,13 +32,13 @@ public function showProfileInfo() * * @param string $field * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v2/#users_list */ - public function listUsers(string $field = 'userName') + public function listUsers(string $field = 'userName'): StreamInterface|array|string { $this->apiEndPoint = "v2/scim/Users?filter={$field}"; @@ -51,13 +54,13 @@ public function listUsers(string $field = 'userName') * * @param string $user_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v2/#users_get */ - public function showUserDetails(string $user_id) + public function showUserDetails(string $user_id): StreamInterface|array|string { $this->apiEndPoint = "v2/scim/Users/{$user_id}"; @@ -73,13 +76,13 @@ public function showUserDetails(string $user_id) * * @param string $user_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v2/#users_get */ - public function deleteUser(string $user_id) + public function deleteUser(string $user_id): StreamInterface|array|string { $this->apiEndPoint = "v2/scim/Users/{$user_id}"; @@ -101,13 +104,13 @@ public function deleteUser(string $user_id) * @param string $application_type * @param string $logo_url * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v1/#applications_post */ - public function createMerchantApplication(string $client_name, array $redirect_uris, array $contacts, string $payer_id, string $migrated_app, string $application_type = 'web', string $logo_url = '') + public function createMerchantApplication(string $client_name, array $redirect_uris, array $contacts, string $payer_id, string $migrated_app, string $application_type = 'web', string $logo_url = ''): StreamInterface|array|string { $this->apiEndPoint = 'v1/identity/applications'; @@ -132,13 +135,13 @@ public function createMerchantApplication(string $client_name, array $redirect_u * @param array $features * @param string $account_property * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_post */ - public function setAccountProperties(array $features, string $account_property = 'BRAINTREE_MERCHANT') + public function setAccountProperties(array $features, string $account_property = 'BRAINTREE_MERCHANT'): StreamInterface|array|string { $this->apiEndPoint = 'v1/identity/account-settings'; @@ -157,13 +160,13 @@ public function setAccountProperties(array $features, string $account_property = * * @param string $account_property * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_deactivate */ - public function disableAccountProperties(string $account_property = 'BRAINTREE_MERCHANT') + public function disableAccountProperties(string $account_property = 'BRAINTREE_MERCHANT'): StreamInterface|array|string { $this->apiEndPoint = 'v1/identity/account-settings/deactivate'; @@ -179,13 +182,13 @@ public function disableAccountProperties(string $account_property = 'BRAINTREE_M /** * Get a client token. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/multiparty/checkout/advanced/integrate/#link-sampleclienttokenrequest */ - public function getClientToken() + public function getClientToken(): StreamInterface|array|string { $this->apiEndPoint = 'v1/identity/generate-token'; diff --git a/src/Traits/PayPalAPI/InvoiceSearch/Filters.php b/src/Traits/PayPalAPI/InvoiceSearch/Filters.php index 6160e980..86ec4db5 100644 --- a/src/Traits/PayPalAPI/InvoiceSearch/Filters.php +++ b/src/Traits/PayPalAPI/InvoiceSearch/Filters.php @@ -3,18 +3,19 @@ namespace Srmklive\PayPal\Traits\PayPalAPI\InvoiceSearch; use Carbon\Carbon; +use Srmklive\PayPal\Services\PayPal as PayPalClient; trait Filters { /** * @var array */ - protected $invoice_search_filters = []; + protected array $invoice_search_filters = []; /** * @var array */ - protected $invoices_date_types = [ + protected array $invoices_date_types = [ 'invoice_date', 'due_date', 'payment_date', @@ -24,7 +25,7 @@ trait Filters /** * @var array */ - protected $invoices_status_types = [ + protected array $invoices_status_types = [ 'DRAFT', 'SENT', 'SCHEDULED', @@ -42,9 +43,9 @@ trait Filters /** * @param string $email * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByRecipientEmail(string $email): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByRecipientEmail(string $email): PayPalClient { $this->invoice_search_filters['recipient_email'] = $email; @@ -54,9 +55,9 @@ public function addInvoiceFilterByRecipientEmail(string $email): \Srmklive\PayPa /** * @param string $name * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByRecipientFirstName(string $name): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByRecipientFirstName(string $name): PayPalClient { $this->invoice_search_filters['recipient_first_name'] = $name; @@ -66,9 +67,9 @@ public function addInvoiceFilterByRecipientFirstName(string $name): \Srmklive\Pa /** * @param string $name * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByRecipientLastName(string $name): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByRecipientLastName(string $name): PayPalClient { $this->invoice_search_filters['recipient_last_name'] = $name; @@ -78,9 +79,9 @@ public function addInvoiceFilterByRecipientLastName(string $name): \Srmklive\Pay /** * @param string $name * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByRecipientBusinessName(string $name): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByRecipientBusinessName(string $name): PayPalClient { $this->invoice_search_filters['recipient_business_name'] = $name; @@ -90,9 +91,9 @@ public function addInvoiceFilterByRecipientBusinessName(string $name): \Srmklive /** * @param string $invoice_number * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByInvoiceNumber(string $invoice_number): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByInvoiceNumber(string $invoice_number): PayPalClient { $this->invoice_search_filters['invoice_number'] = $invoice_number; @@ -104,16 +105,16 @@ public function addInvoiceFilterByInvoiceNumber(string $invoice_number): \Srmkli * * @throws \Exception * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient * * @see https://developer.paypal.com/docs/api/invoicing/v2/#definition-invoice_status */ - public function addInvoiceFilterByInvoiceStatus(array $status): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByInvoiceStatus(array $status): PayPalClient { $invalid_status = false; foreach ($status as $item) { - if (!in_array($item, $this->invoices_status_types)) { + if (!in_array($item, $this->invoices_status_types, true)) { $invalid_status = true; } } @@ -131,9 +132,9 @@ public function addInvoiceFilterByInvoiceStatus(array $status): \Srmklive\PayPal * @param string $reference * @param bool $memo * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByReferenceorMemo(string $reference, bool $memo = false): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByReferenceorMemo(string $reference, bool $memo = false): PayPalClient { $field = ($memo === false) ? 'reference' : 'memo'; @@ -145,11 +146,11 @@ public function addInvoiceFilterByReferenceorMemo(string $reference, bool $memo /** * @param string $currency_code * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByCurrencyCode(string $currency_code = ''): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByCurrencyCode(string $currency_code = ''): PayPalClient { - $currency = !isset($currency_code) ? $this->getCurrency() : $currency_code; + $currency = $currency_code ?? $this->getCurrency(); $this->invoice_search_filters['currency_code'] = $currency; @@ -163,9 +164,9 @@ public function addInvoiceFilterByCurrencyCode(string $currency_code = ''): \Srm * * @throws \Exception * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByAmountRange(float $start_amount, float $end_amount, string $amount_currency = ''): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByAmountRange(float $start_amount, float $end_amount, string $amount_currency = ''): PayPalClient { if ($start_amount > $end_amount) { throw new \Exception('Starting amount should always be less than end amount!'); @@ -194,19 +195,19 @@ public function addInvoiceFilterByAmountRange(float $start_amount, float $end_am * * @throws \Exception * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByDateRange(string $start_date, string $end_date, string $date_type): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByDateRange(string $start_date, string $end_date, string $date_type): PayPalClient { $start_date_obj = Carbon::parse($start_date); $end_date_obj = Carbon::parse($end_date); if ($start_date_obj->gt($end_date_obj)) { - throw new \Exception('Starting date should always be less than the end date!'); + throw new \RuntimeException('Starting date should always be less than the end date!'); } if (!in_array($date_type, $this->invoices_date_types)) { - throw new \Exception('date type should be always one of these: '.implode(',', $this->invoices_date_types)); + throw new \RuntimeException('date type should be always one of these: '.implode(',', $this->invoices_date_types)); } $this->invoice_search_filters["{$date_type}_range"] = [ @@ -220,9 +221,9 @@ public function addInvoiceFilterByDateRange(string $start_date, string $end_date /** * @param bool $archived * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addInvoiceFilterByArchivedStatus(bool $archived = null): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByArchivedStatus(bool $archived = null): PayPalClient { $this->invoice_search_filters['archived'] = $archived; @@ -232,11 +233,11 @@ public function addInvoiceFilterByArchivedStatus(bool $archived = null): \Srmkli /** * @param array $fields * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient * * @see https://developer.paypal.com/docs/api/invoicing/v2/#definition-field */ - public function addInvoiceFilterByFields(array $fields): \Srmklive\PayPal\Services\PayPal + public function addInvoiceFilterByFields(array $fields): PayPalClient { $this->invoice_search_filters['status'] = $fields; diff --git a/src/Traits/PayPalAPI/Invoices.php b/src/Traits/PayPalAPI/Invoices.php index 8c7ae132..55135ba2 100644 --- a/src/Traits/PayPalAPI/Invoices.php +++ b/src/Traits/PayPalAPI/Invoices.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait Invoices { /** @@ -9,13 +12,13 @@ trait Invoices * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_create */ - public function createInvoice(array $data) + public function createInvoice(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v2/invoicing/invoices'; @@ -31,13 +34,13 @@ public function createInvoice(array $data) * * @param array $fields * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list */ - public function listInvoices(array $fields = []) + public function listInvoices(array $fields = []): StreamInterface|array|string { $fields_list = collect($fields); @@ -60,13 +63,13 @@ public function listInvoices(array $fields = []) * @param bool $send_merchant * @param array $recipients * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_send */ - public function sendInvoice(string $invoice_id, string $subject = '', string $note = '', bool $send_recipient = true, bool $send_merchant = false, array $recipients = []) + public function sendInvoice(string $invoice_id, string $subject = '', string $note = '', bool $send_recipient = true, bool $send_merchant = false, array $recipients = []): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/send"; @@ -87,13 +90,13 @@ public function sendInvoice(string $invoice_id, string $subject = '', string $no * @param bool $send_merchant * @param array $recipients * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_remind */ - public function sendInvoiceReminder(string $invoice_id, string $subject = '', string $note = '', bool $send_recipient = true, bool $send_merchant = false, array $recipients = []) + public function sendInvoiceReminder(string $invoice_id, string $subject = '', string $note = '', bool $send_recipient = true, bool $send_merchant = false, array $recipients = []): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/remind"; @@ -114,13 +117,13 @@ public function sendInvoiceReminder(string $invoice_id, string $subject = '', st * @param bool $send_merchant * @param array $recipients * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_cancel */ - public function cancelInvoice(string $invoice_id, string $subject = '', string $note = '', bool $send_recipient = true, bool $send_merchant = false, array $recipients = []) + public function cancelInvoice(string $invoice_id, string $subject = '', string $note = '', bool $send_recipient = true, bool $send_merchant = false, array $recipients = []): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/cancel"; @@ -141,13 +144,13 @@ public function cancelInvoice(string $invoice_id, string $subject = '', string $ * @param string $payment_note * @param string $payment_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments */ - public function registerPaymentInvoice(string $invoice_id, string $payment_date, string $payment_method, float $amount, string $payment_note = '', string $payment_id = '') + public function registerPaymentInvoice(string $invoice_id, string $payment_date, string $payment_method, float $amount, string $payment_note = '', string $payment_id = ''): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/payments"; @@ -175,13 +178,13 @@ public function registerPaymentInvoice(string $invoice_id, string $payment_date, * @param string $invoice_id * @param string $transaction_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments-delete */ - public function deleteExternalPaymentInvoice(string $invoice_id, string $transaction_id) + public function deleteExternalPaymentInvoice(string $invoice_id, string $transaction_id): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/payments/{$transaction_id}"; @@ -198,13 +201,13 @@ public function deleteExternalPaymentInvoice(string $invoice_id, string $transac * @param string $payment_method * @param float $amount * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_refunds */ - public function refundInvoice(string $invoice_id, string $payment_date, string $payment_method, float $amount) + public function refundInvoice(string $invoice_id, string $payment_date, string $payment_method, float $amount): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/refunds"; @@ -230,13 +233,13 @@ public function refundInvoice(string $invoice_id, string $payment_date, string $ * @param string $invoice_id * @param string $transaction_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_refunds-delete */ - public function deleteRefundInvoice(string $invoice_id, string $transaction_id) + public function deleteRefundInvoice(string $invoice_id, string $transaction_id): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/refunds/{$transaction_id}"; @@ -252,13 +255,13 @@ public function deleteRefundInvoice(string $invoice_id, string $transaction_id) * @param int $width * @param int $height * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-qr-code */ - public function generateQRCodeInvoice(string $invoice_id, int $width = 100, int $height = 100) + public function generateQRCodeInvoice(string $invoice_id, int $width = 100, int $height = 100): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/generate-qr-code"; @@ -274,13 +277,13 @@ public function generateQRCodeInvoice(string $invoice_id, int $width = 100, int /** * Generate the next invoice number. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-next-invoice-number */ - public function generateInvoiceNumber() + public function generateInvoiceNumber(): StreamInterface|array|string { $this->apiEndPoint = 'v2/invoicing/generate-next-invoice-number'; @@ -294,13 +297,13 @@ public function generateInvoiceNumber() * * @param string $invoice_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_get */ - public function showInvoiceDetails(string $invoice_id) + public function showInvoiceDetails(string $invoice_id): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}"; @@ -315,13 +318,13 @@ public function showInvoiceDetails(string $invoice_id) * @param string $invoice_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update */ - public function updateInvoice(string $invoice_id, array $data) + public function updateInvoice(string $invoice_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}"; @@ -337,13 +340,13 @@ public function updateInvoice(string $invoice_id, array $data) * * @param string $invoice_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list */ - public function deleteInvoice(string $invoice_id) + public function deleteInvoice(string $invoice_id): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}"; diff --git a/src/Traits/PayPalAPI/InvoicesSearch.php b/src/Traits/PayPalAPI/InvoicesSearch.php index 213e3dac..d689ef7f 100644 --- a/src/Traits/PayPalAPI/InvoicesSearch.php +++ b/src/Traits/PayPalAPI/InvoicesSearch.php @@ -2,7 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; use Srmklive\PayPal\Traits\PayPalAPI\InvoiceSearch\Filters; +use Throwable; trait InvoicesSearch { @@ -11,13 +13,13 @@ trait InvoicesSearch /** * Search and return existing invoices. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list */ - public function searchInvoices() + public function searchInvoices(): StreamInterface|array|string { if (collect($this->invoice_search_filters)->count() < 1) { $this->invoice_search_filters = [ diff --git a/src/Traits/PayPalAPI/InvoicesTemplates.php b/src/Traits/PayPalAPI/InvoicesTemplates.php index 0eea0fa7..2ffd973f 100644 --- a/src/Traits/PayPalAPI/InvoicesTemplates.php +++ b/src/Traits/PayPalAPI/InvoicesTemplates.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait InvoicesTemplates { /** @@ -9,13 +12,13 @@ trait InvoicesTemplates * * @param string $fields * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_list */ - public function listInvoiceTemplates(string $fields = 'all') + public function listInvoiceTemplates(string $fields = 'all'): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/templates?page={$this->current_page}&page_size={$this->page_size}&fields={$fields}"; @@ -29,13 +32,13 @@ public function listInvoiceTemplates(string $fields = 'all') * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_create */ - public function createInvoiceTemplate(array $data) + public function createInvoiceTemplate(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v2/invoicing/templates'; @@ -51,13 +54,13 @@ public function createInvoiceTemplate(array $data) * * @param string $template_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_get */ - public function showInvoiceTemplateDetails(string $template_id) + public function showInvoiceTemplateDetails(string $template_id): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/templates/{$template_id}"; @@ -72,13 +75,13 @@ public function showInvoiceTemplateDetails(string $template_id) * @param string $template_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_update */ - public function updateInvoiceTemplate(string $template_id, array $data) + public function updateInvoiceTemplate(string $template_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/templates/{$template_id}"; @@ -94,13 +97,13 @@ public function updateInvoiceTemplate(string $template_id, array $data) * * @param string $template_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_delete */ - public function deleteInvoiceTemplate(string $template_id) + public function deleteInvoiceTemplate(string $template_id): StreamInterface|array|string { $this->apiEndPoint = "v2/invoicing/templates/{$template_id}"; diff --git a/src/Traits/PayPalAPI/Orders.php b/src/Traits/PayPalAPI/Orders.php index afcff5ec..d232de4d 100644 --- a/src/Traits/PayPalAPI/Orders.php +++ b/src/Traits/PayPalAPI/Orders.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait Orders { use Orders\Helpers; @@ -11,13 +14,13 @@ trait Orders * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/orders/v2/#orders_create */ - public function createOrder(array $data) + public function createOrder(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v2/checkout/orders'; @@ -33,13 +36,13 @@ public function createOrder(array $data) * * @param string $order_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/orders/v2/#orders_get */ - public function showOrderDetails(string $order_id) + public function showOrderDetails(string $order_id): StreamInterface|array|string { $this->apiEndPoint = "v2/checkout/orders/{$order_id}"; @@ -54,13 +57,13 @@ public function showOrderDetails(string $order_id) * @param string $order_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/orders/v2/#orders_patch */ - public function updateOrder(string $order_id, array $data) + public function updateOrder(string $order_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v2/checkout/orders/{$order_id}"; @@ -77,11 +80,11 @@ public function updateOrder(string $order_id, array $data) * @param string $order_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string */ - public function confirmOrder(string $order_id, array $data) + public function confirmOrder(string $order_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v2/checkout/orders/{$order_id}/confirm-payment-source"; @@ -98,13 +101,13 @@ public function confirmOrder(string $order_id, array $data) * @param string $order_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/orders/v2/#orders_authorize */ - public function authorizePaymentOrder(string $order_id, array $data = []) + public function authorizePaymentOrder(string $order_id, array $data = []): StreamInterface|array|string { $this->apiEndPoint = "v2/checkout/orders/{$order_id}/authorize"; @@ -121,13 +124,13 @@ public function authorizePaymentOrder(string $order_id, array $data = []) * @param string $order_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture */ - public function capturePaymentOrder(string $order_id, array $data = []) + public function capturePaymentOrder(string $order_id, array $data = []): StreamInterface|array|string { $this->apiEndPoint = "v2/checkout/orders/{$order_id}/capture"; diff --git a/src/Traits/PayPalAPI/Orders/Helpers.php b/src/Traits/PayPalAPI/Orders/Helpers.php index 61ec59ad..af5d7dc7 100644 --- a/src/Traits/PayPalAPI/Orders/Helpers.php +++ b/src/Traits/PayPalAPI/Orders/Helpers.php @@ -2,6 +2,7 @@ namespace Srmklive\PayPal\Traits\PayPalAPI\Orders; +use Psr\Http\Message\StreamInterface; use Throwable; trait Helpers @@ -14,9 +15,9 @@ trait Helpers * * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string */ - public function setupOrderConfirmation(string $order_id, string $processing_instruction = '') + public function setupOrderConfirmation(string $order_id, string $processing_instruction = ''): StreamInterface|array|string { $body = [ 'processing_instruction' => $processing_instruction, diff --git a/src/Traits/PayPalAPI/PartnerReferrals.php b/src/Traits/PayPalAPI/PartnerReferrals.php index 9d1cc17c..0268c2ce 100644 --- a/src/Traits/PayPalAPI/PartnerReferrals.php +++ b/src/Traits/PayPalAPI/PartnerReferrals.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait PartnerReferrals { /** @@ -9,13 +12,13 @@ trait PartnerReferrals * * @param array $partner_data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/partner-referrals/v2/#partner-referrals_create */ - public function createPartnerReferral(array $partner_data) + public function createPartnerReferral(array $partner_data): StreamInterface|array|string { $this->apiEndPoint = 'v2/customer/partner-referrals'; @@ -31,13 +34,13 @@ public function createPartnerReferral(array $partner_data) * * @param string $partner_referral_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/partner-referrals/v2/#partner-referrals_read */ - public function showReferralData(string $partner_referral_id) + public function showReferralData(string $partner_referral_id): StreamInterface|array|string { $this->apiEndPoint = "v2/customer/partner-referrals/{$partner_referral_id}"; @@ -52,13 +55,13 @@ public function showReferralData(string $partner_referral_id) * @param string $partner_id * @param string $tracking_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/partner-referrals/v1/#merchant-integration_find */ - public function listSellerTrackingInformation(string $partner_id, string $tracking_id) + public function listSellerTrackingInformation(string $partner_id, string $tracking_id): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/partners/{$partner_id}/merchant-integrations?tracking_id={$tracking_id}"; @@ -73,13 +76,13 @@ public function listSellerTrackingInformation(string $partner_id, string $tracki * @param string $partner_id * @param string $merchant_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/partner-referrals/v1/#merchant-integration_status */ - public function showSellerStatus(string $partner_id, string $merchant_id) + public function showSellerStatus(string $partner_id, string $merchant_id): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/partners/{$partner_id}/merchant-integrations/{$merchant_id}"; @@ -93,13 +96,13 @@ public function showSellerStatus(string $partner_id, string $merchant_id) * * @param string $partner_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/partner-referrals/v1/#merchant-integration_credentials */ - public function listMerchantCredentials(string $partner_id) + public function listMerchantCredentials(string $partner_id): StreamInterface|array|string { $this->apiEndPoint = "v1/customer/partners/{$partner_id}/merchant-integrations/credentials"; diff --git a/src/Traits/PayPalAPI/PaymentAuthorizations.php b/src/Traits/PayPalAPI/PaymentAuthorizations.php index 16288e1e..8cc7c002 100644 --- a/src/Traits/PayPalAPI/PaymentAuthorizations.php +++ b/src/Traits/PayPalAPI/PaymentAuthorizations.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait PaymentAuthorizations { /** @@ -9,13 +12,13 @@ trait PaymentAuthorizations * * @param string $authorization_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_get */ - public function showAuthorizedPaymentDetails(string $authorization_id) + public function showAuthorizedPaymentDetails(string $authorization_id): StreamInterface|array|string { $this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}"; @@ -32,13 +35,13 @@ public function showAuthorizedPaymentDetails(string $authorization_id) * @param float $amount * @param string $note * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture */ - public function captureAuthorizedPayment(string $authorization_id, string $invoice_id, float $amount, string $note) + public function captureAuthorizedPayment(string $authorization_id, string $invoice_id, float $amount, string $note): StreamInterface|array|string { $this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/capture"; @@ -63,13 +66,13 @@ public function captureAuthorizedPayment(string $authorization_id, string $invoi * @param string $authorization_id * @param float $amount * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_reauthorize */ - public function reAuthorizeAuthorizedPayment(string $authorization_id, float $amount) + public function reAuthorizeAuthorizedPayment(string $authorization_id, float $amount): StreamInterface|array|string { $this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/reauthorize"; @@ -90,13 +93,13 @@ public function reAuthorizeAuthorizedPayment(string $authorization_id, float $am * * @param string $authorization_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_void */ - public function voidAuthorizedPayment(string $authorization_id) + public function voidAuthorizedPayment(string $authorization_id): StreamInterface|array|string { $this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/void"; diff --git a/src/Traits/PayPalAPI/PaymentCaptures.php b/src/Traits/PayPalAPI/PaymentCaptures.php index a856cf9d..eb9ba7d6 100644 --- a/src/Traits/PayPalAPI/PaymentCaptures.php +++ b/src/Traits/PayPalAPI/PaymentCaptures.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait PaymentCaptures { /** @@ -9,13 +12,13 @@ trait PaymentCaptures * * @param string $capture_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#captures_get */ - public function showCapturedPaymentDetails(string $capture_id) + public function showCapturedPaymentDetails(string $capture_id): StreamInterface|array|string { $this->apiEndPoint = "v2/payments/captures/{$capture_id}"; @@ -32,13 +35,13 @@ public function showCapturedPaymentDetails(string $capture_id) * @param float $amount * @param string $note * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#captures_refund */ - public function refundCapturedPayment(string $capture_id, string $invoice_id, float $amount, string $note) + public function refundCapturedPayment(string $capture_id, string $invoice_id, float $amount, string $note): StreamInterface|array|string { $this->apiEndPoint = "v2/payments/captures/{$capture_id}/refund"; diff --git a/src/Traits/PayPalAPI/PaymentExperienceWebProfiles.php b/src/Traits/PayPalAPI/PaymentExperienceWebProfiles.php index 30736c69..d21270ef 100644 --- a/src/Traits/PayPalAPI/PaymentExperienceWebProfiles.php +++ b/src/Traits/PayPalAPI/PaymentExperienceWebProfiles.php @@ -2,18 +2,21 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait PaymentExperienceWebProfiles { /** * List Web Experience Profiles. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_get-list */ - public function listWebExperienceProfiles() + public function listWebExperienceProfiles(): StreamInterface|array|string { $this->apiEndPoint = 'v1/payment-experience/web-profiles'; @@ -27,13 +30,13 @@ public function listWebExperienceProfiles() * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_create */ - public function createWebExperienceProfile(array $data) + public function createWebExperienceProfile(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/payment-experience/web-profiles'; @@ -49,13 +52,13 @@ public function createWebExperienceProfile(array $data) * * @param string $profile_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_delete */ - public function deleteWebExperienceProfile(string $profile_id) + public function deleteWebExperienceProfile(string $profile_id): StreamInterface|array|string { $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}"; @@ -70,13 +73,13 @@ public function deleteWebExperienceProfile(string $profile_id) * @param string $profile_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_partial-update */ - public function patchWebExperienceProfile(string $profile_id, array $data) + public function patchWebExperienceProfile(string $profile_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}"; @@ -93,13 +96,13 @@ public function patchWebExperienceProfile(string $profile_id, array $data) * @param string $profile_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_update */ - public function updateWebExperienceProfile(string $profile_id, array $data) + public function updateWebExperienceProfile(string $profile_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}"; @@ -115,13 +118,13 @@ public function updateWebExperienceProfile(string $profile_id, array $data) * * @param string $profile_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_get */ - public function showWebExperienceProfileDetails(string $profile_id) + public function showWebExperienceProfileDetails(string $profile_id): StreamInterface|array|string { $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}"; diff --git a/src/Traits/PayPalAPI/PaymentMethodsTokens.php b/src/Traits/PayPalAPI/PaymentMethodsTokens.php index 19bd95e9..2c953c8c 100644 --- a/src/Traits/PayPalAPI/PaymentMethodsTokens.php +++ b/src/Traits/PayPalAPI/PaymentMethodsTokens.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait PaymentMethodsTokens { use PaymentMethodsTokens\Helpers; @@ -11,13 +14,13 @@ trait PaymentMethodsTokens * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_create */ - public function createPaymentSourceToken(array $data) + public function createPaymentSourceToken(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v3/vault/payment-tokens'; @@ -35,11 +38,13 @@ public function createPaymentSourceToken(array $data) * @param int $page_size * @param bool $totals * - * @return array|\Psr\Http\Message\StreamInterface|string + * @throws Throwable + * + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#customer_payment-tokens_get */ - public function listPaymentSourceTokens(int $page = 1, int $page_size = 10, bool $totals = true) + public function listPaymentSourceTokens(int $page = 1, int $page_size = 10, bool $totals = true): StreamInterface|array|string { $this->apiEndPoint = "v3/vault/payment-tokens?customer_id={$this->customer_source['id']}&page={$page}&page_size={$page_size}&total_required={$totals}"; @@ -53,11 +58,13 @@ public function listPaymentSourceTokens(int $page = 1, int $page_size = 10, bool * * @param string $token * - * @return array|\Psr\Http\Message\StreamInterface|string + * @throws Throwable + * + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_get */ - public function showPaymentSourceTokenDetails(string $token) + public function showPaymentSourceTokenDetails(string $token): StreamInterface|array|string { $this->apiEndPoint = "v3/vault/payment-tokens/{$token}"; @@ -71,11 +78,13 @@ public function showPaymentSourceTokenDetails(string $token) * * @param string $token * - * @return array|\Psr\Http\Message\StreamInterface|string + * @throws Throwable + * + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_delete */ - public function deletePaymentSourceToken(string $token) + public function deletePaymentSourceToken(string $token): StreamInterface|array|string { $this->apiEndPoint = "v3/vault/payment-tokens/{$token}"; @@ -89,13 +98,13 @@ public function deletePaymentSourceToken(string $token) * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#setup-tokens_create */ - public function createPaymentSetupToken(array $data) + public function createPaymentSetupToken(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v3/vault/setup-tokens'; @@ -111,11 +120,13 @@ public function createPaymentSetupToken(array $data) * * @param string $token * - * @return array|\Psr\Http\Message\StreamInterface|string + * @throws Throwable + * + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#setup-tokens_get */ - public function showPaymentSetupTokenDetails(string $token) + public function showPaymentSetupTokenDetails(string $token): StreamInterface|array|string { $this->apiEndPoint = "v3/vault/setup-tokens/{$token}"; diff --git a/src/Traits/PayPalAPI/PaymentMethodsTokens/Helpers.php b/src/Traits/PayPalAPI/PaymentMethodsTokens/Helpers.php index 4b9483ea..ac17c7c2 100644 --- a/src/Traits/PayPalAPI/PaymentMethodsTokens/Helpers.php +++ b/src/Traits/PayPalAPI/PaymentMethodsTokens/Helpers.php @@ -2,17 +2,20 @@ namespace Srmklive\PayPal\Traits\PayPalAPI\PaymentMethodsTokens; +use Psr\Http\Message\StreamInterface; +use Srmklive\PayPal\Services\PayPal as PayPalClient; + trait Helpers { /** * @var array */ - protected $payment_source = []; + protected array $payment_source = []; /** * @var array */ - protected $customer_source = []; + protected array $customer_source = []; /** * Set payment method token by token id. @@ -20,9 +23,9 @@ trait Helpers * @param string $id * @param string $type * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function setTokenSource(string $id, string $type): \Srmklive\PayPal\Services\PayPal + public function setTokenSource(string $id, string $type): PayPalClient { $token_source = [ 'id' => $id, @@ -37,9 +40,9 @@ public function setTokenSource(string $id, string $type): \Srmklive\PayPal\Servi * * @param string $id * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function setCustomerSource(string $id): \Srmklive\PayPal\Services\PayPal + public function setCustomerSource(string $id): PayPalClient { $this->customer_source = [ 'id' => $id, @@ -53,9 +56,9 @@ public function setCustomerSource(string $id): \Srmklive\PayPal\Services\PayPal * * @param array $data * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function setPaymentSourceCard(array $data): \Srmklive\PayPal\Services\PayPal + public function setPaymentSourceCard(array $data): PayPalClient { return $this->setPaymentSourceDetails('card', $data); } @@ -65,9 +68,9 @@ public function setPaymentSourceCard(array $data): \Srmklive\PayPal\Services\Pay * * @param array $data * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function setPaymentSourcePayPal(array $data): \Srmklive\PayPal\Services\PayPal + public function setPaymentSourcePayPal(array $data): PayPalClient { return $this->setPaymentSourceDetails('paypal', $data); } @@ -77,9 +80,9 @@ public function setPaymentSourcePayPal(array $data): \Srmklive\PayPal\Services\P * * @param array $data * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function setPaymentSourceVenmo(array $data): \Srmklive\PayPal\Services\PayPal + public function setPaymentSourceVenmo(array $data): PayPalClient { return $this->setPaymentSourceDetails('venmo', $data); } @@ -90,9 +93,9 @@ public function setPaymentSourceVenmo(array $data): \Srmklive\PayPal\Services\Pa * @param string $source * @param array $data * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - protected function setPaymentSourceDetails(string $source, array $data): \Srmklive\PayPal\Services\PayPal + protected function setPaymentSourceDetails(string $source, array $data): PayPalClient { $this->payment_source[$source] = $data; @@ -106,9 +109,10 @@ protected function setPaymentSourceDetails(string $source, array $data): \Srmkli * * @throws \Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string + * */ - public function sendPaymentMethodRequest(bool $create_source = false) + public function sendPaymentMethodRequest(bool $create_source = false): StreamInterface|array|string { $token_payload = ['payment_source' => $this->payment_source]; diff --git a/src/Traits/PayPalAPI/PaymentRefunds.php b/src/Traits/PayPalAPI/PaymentRefunds.php index 1e557637..6dcd433d 100644 --- a/src/Traits/PayPalAPI/PaymentRefunds.php +++ b/src/Traits/PayPalAPI/PaymentRefunds.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait PaymentRefunds { /** @@ -9,13 +12,13 @@ trait PaymentRefunds * * @param string $refund_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_get */ - public function showRefundDetails(string $refund_id) + public function showRefundDetails(string $refund_id): StreamInterface|array|string { $this->apiEndPoint = "v2/payments/refunds/{$refund_id}"; diff --git a/src/Traits/PayPalAPI/Payouts.php b/src/Traits/PayPalAPI/Payouts.php index 13af7b9d..1bff7282 100644 --- a/src/Traits/PayPalAPI/Payouts.php +++ b/src/Traits/PayPalAPI/Payouts.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait Payouts { /** @@ -9,13 +12,13 @@ trait Payouts * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts_post */ - public function createBatchPayout(array $data) + public function createBatchPayout(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/payments/payouts'; @@ -31,13 +34,13 @@ public function createBatchPayout(array $data) * * @param string $payout_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts_get */ - public function showBatchPayoutDetails(string $payout_id) + public function showBatchPayoutDetails(string $payout_id): StreamInterface|array|string { $this->apiEndPoint = "v1/payments/payouts/{$payout_id}"; @@ -51,13 +54,13 @@ public function showBatchPayoutDetails(string $payout_id) * * @param string $payout_item_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_get */ - public function showPayoutItemDetails(string $payout_item_id) + public function showPayoutItemDetails(string $payout_item_id): StreamInterface|array|string { $this->apiEndPoint = "v1/payments/payouts-item/{$payout_item_id}"; @@ -71,13 +74,13 @@ public function showPayoutItemDetails(string $payout_item_id) * * @param string $payout_item_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_cancel */ - public function cancelUnclaimedPayoutItem(string $payout_item_id) + public function cancelUnclaimedPayoutItem(string $payout_item_id): StreamInterface|array|string { $this->apiEndPoint = "v1/payments/payouts-item/{$payout_item_id}/cancel"; diff --git a/src/Traits/PayPalAPI/ReferencedPayouts.php b/src/Traits/PayPalAPI/ReferencedPayouts.php index ee998fed..e4ffbdc4 100644 --- a/src/Traits/PayPalAPI/ReferencedPayouts.php +++ b/src/Traits/PayPalAPI/ReferencedPayouts.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait ReferencedPayouts { /** @@ -9,13 +12,13 @@ trait ReferencedPayouts * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts_create_batch */ - public function createReferencedBatchPayout(array $data) + public function createReferencedBatchPayout(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/payments/referenced-payouts'; @@ -31,13 +34,13 @@ public function createReferencedBatchPayout(array $data) * * @param string $batch_payout_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts_get_batch_details */ - public function listItemsReferencedInBatchPayout(string $batch_payout_id) + public function listItemsReferencedInBatchPayout(string $batch_payout_id): StreamInterface|array|string { $this->apiEndPoint = "v1/payments/referenced-payouts/{$batch_payout_id}"; @@ -51,13 +54,13 @@ public function listItemsReferencedInBatchPayout(string $batch_payout_id) * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts-items_create */ - public function createReferencedBatchPayoutItem(array $data) + public function createReferencedBatchPayoutItem(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/payments/referenced-payouts-items'; @@ -73,13 +76,13 @@ public function createReferencedBatchPayoutItem(array $data) * * @param string $payout_item_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts-items_get */ - public function showReferencedPayoutItemDetails(string $payout_item_id) + public function showReferencedPayoutItemDetails(string $payout_item_id): StreamInterface|array|string { $this->apiEndPoint = "v1/payments/referenced-payouts-items/{$payout_item_id}"; diff --git a/src/Traits/PayPalAPI/Reporting.php b/src/Traits/PayPalAPI/Reporting.php index 3ae76bc7..8b8b1b43 100644 --- a/src/Traits/PayPalAPI/Reporting.php +++ b/src/Traits/PayPalAPI/Reporting.php @@ -3,6 +3,8 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; use Carbon\Carbon; +use Psr\Http\Message\StreamInterface; +use Throwable; trait Reporting { @@ -12,13 +14,13 @@ trait Reporting * @param array $filters * @param string $fields * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/transaction-search/v1/#transactions_get */ - public function listTransactions(array $filters, string $fields = 'all') + public function listTransactions(array $filters, string $fields = 'all'): StreamInterface|array|string { $filters_list = collect($filters)->isEmpty() ? '' : collect($filters)->map(function ($value, $key) { @@ -38,13 +40,13 @@ public function listTransactions(array $filters, string $fields = 'all') * @param string $date * @param string $balance_currency * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/transaction-search/v1/#balances_get */ - public function listBalances(string $date = '', string $balance_currency = '') + public function listBalances(string $date = '', string $balance_currency = ''): StreamInterface|array|string { $date = empty($date) ? Carbon::now()->toIso8601String() : Carbon::parse($date)->toIso8601String(); $currency = empty($balance_currency) ? $this->getCurrency() : $balance_currency; diff --git a/src/Traits/PayPalAPI/Subscriptions.php b/src/Traits/PayPalAPI/Subscriptions.php index a43fb374..d5837077 100644 --- a/src/Traits/PayPalAPI/Subscriptions.php +++ b/src/Traits/PayPalAPI/Subscriptions.php @@ -3,6 +3,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; use Carbon\Carbon; +use DateTimeInterface; +use Psr\Http\Message\StreamInterface; +use Throwable; trait Subscriptions { @@ -13,13 +16,13 @@ trait Subscriptions * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create */ - public function createSubscription(array $data) + public function createSubscription(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/billing/subscriptions'; @@ -36,13 +39,13 @@ public function createSubscription(array $data) * @param string $subscription_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_patch */ - public function updateSubscription(string $subscription_id, array $data) + public function updateSubscription(string $subscription_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}"; @@ -58,13 +61,13 @@ public function updateSubscription(string $subscription_id, array $data) * * @param string $subscription_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get */ - public function showSubscriptionDetails(string $subscription_id) + public function showSubscriptionDetails(string $subscription_id): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}"; @@ -79,13 +82,13 @@ public function showSubscriptionDetails(string $subscription_id) * @param string $subscription_id * @param string $reason * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_activate */ - public function activateSubscription(string $subscription_id, string $reason) + public function activateSubscription(string $subscription_id, string $reason): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/activate"; @@ -102,13 +105,13 @@ public function activateSubscription(string $subscription_id, string $reason) * @param string $subscription_id * @param string $reason * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel */ - public function cancelSubscription(string $subscription_id, string $reason) + public function cancelSubscription(string $subscription_id, string $reason): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/cancel"; @@ -125,13 +128,13 @@ public function cancelSubscription(string $subscription_id, string $reason) * @param string $subscription_id * @param string $reason * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_suspend */ - public function suspendSubscription(string $subscription_id, string $reason) + public function suspendSubscription(string $subscription_id, string $reason): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/suspend"; @@ -149,13 +152,13 @@ public function suspendSubscription(string $subscription_id, string $reason) * @param string $note * @param float $amount * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_capture */ - public function captureSubscriptionPayment(string $subscription_id, string $note, float $amount) + public function captureSubscriptionPayment(string $subscription_id, string $note, float $amount): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/capture"; @@ -179,13 +182,13 @@ public function captureSubscriptionPayment(string $subscription_id, string $note * @param string $subscription_id * @param array $items * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_revise */ - public function reviseSubscription(string $subscription_id, array $items) + public function reviseSubscription(string $subscription_id, array $items): StreamInterface|array|string { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/revise"; @@ -200,22 +203,22 @@ public function reviseSubscription(string $subscription_id, array $items) * List transactions for an existing subscription. * * @param string $subscription_id - * @param \DateTimeInterface|string $start_date - * @param \DateTimeInterface|string $end_date + * @param DateTimeInterface|string $start_date + * @param DateTimeInterface|string $end_date * - * @throws \Throwable + * @return array|StreamInterface|string * - * @return array|\Psr\Http\Message\StreamInterface|string + * @throws Throwable * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions */ - public function listSubscriptionTransactions(string $subscription_id, $start_date = '', $end_date = '') + public function listSubscriptionTransactions(string $subscription_id, DateTimeInterface|string $start_date = '', DateTimeInterface|string $end_date = ''): StreamInterface|array|string { - if (($start_date instanceof \DateTimeInterface) === false) { + if (($start_date instanceof DateTimeInterface) === false) { $start_date = Carbon::parse($start_date); } - if (($end_date instanceof \DateTimeInterface) === false) { + if (($end_date instanceof DateTimeInterface) === false) { $end_date = Carbon::parse($end_date); } diff --git a/src/Traits/PayPalAPI/Subscriptions/Helpers.php b/src/Traits/PayPalAPI/Subscriptions/Helpers.php index 3bc60833..7860e509 100644 --- a/src/Traits/PayPalAPI/Subscriptions/Helpers.php +++ b/src/Traits/PayPalAPI/Subscriptions/Helpers.php @@ -4,6 +4,8 @@ use Carbon\Carbon; use Illuminate\Support\Str; +use Psr\Http\Message\StreamInterface; +use Srmklive\PayPal\Services\PayPal as PayPalClient; use Throwable; trait Helpers @@ -11,47 +13,47 @@ trait Helpers /** * @var array */ - protected $trial_pricing = []; + protected array $trial_pricing = []; /** * @var int */ - protected $payment_failure_threshold = 3; + protected int $payment_failure_threshold = 3; /** * @var array */ - protected $product; + protected array $product; /** * @var array */ - protected $billing_plan; + protected array $billing_plan; /** * @var array */ - protected $shipping_address; + protected array $shipping_address; /** * @var array */ - protected $payment_preferences; + protected array $payment_preferences; /** * @var bool */ - protected $has_setup_fee = false; + protected bool $has_setup_fee = false; /** * @var array */ - protected $taxes; + protected array $taxes; /** * @var string */ - protected $custom_id; + protected string $custom_id; /** * Setup a subscription. @@ -62,9 +64,9 @@ trait Helpers * * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string */ - public function setupSubscription(string $customer_name, string $customer_email, string $start_date = '') + public function setupSubscription(string $customer_name, string $customer_email, string $start_date = ''): StreamInterface|array|string { $body = [ 'plan_id' => $this->billing_plan['id'], @@ -107,11 +109,13 @@ public function setupSubscription(string $customer_name, string $customer_email, $subscription['billing_plan_id'] = $this->billing_plan['id']; $subscription['product_id'] = $this->product['id']; - unset($this->product); - unset($this->billing_plan); - unset($this->trial_pricing); - unset($this->return_url); - unset($this->cancel_url); + unset( + $this->product, + $this->billing_plan, + $this->trial_pricing, + $this->return_url, + $this->cancel_url + ); return $subscription; } @@ -121,12 +125,12 @@ 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 + * @return PayPalClient */ - public function addPlanTrialPricing(string $interval_type, int $interval_count, float $price = 0, int $total_cycles = 1): \Srmklive\PayPal\Services\PayPal + public function addPlanTrialPricing(string $interval_type, int $interval_count, float $price = 0, int $total_cycles = 1): PayPalClient { $this->trial_pricing = $this->addPlanBillingCycle($interval_type, $interval_count, $price, $total_cycles, true); @@ -138,14 +142,14 @@ 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 * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addDailyPlan(string $name, string $description, float $price, int $total_cycles = 0): \Srmklive\PayPal\Services\PayPal + public function addDailyPlan(string $name, string $description, float $price, int $total_cycles = 0): PayPalClient { if (isset($this->billing_plan)) { return $this; @@ -164,14 +168,14 @@ 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 * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addWeeklyPlan(string $name, string $description, float $price, int $total_cycles = 0): \Srmklive\PayPal\Services\PayPal + public function addWeeklyPlan(string $name, string $description, float $price, int $total_cycles = 0): PayPalClient { if (isset($this->billing_plan)) { return $this; @@ -190,14 +194,14 @@ 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 * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addMonthlyPlan(string $name, string $description, float $price, int $total_cycles = 0): \Srmklive\PayPal\Services\PayPal + public function addMonthlyPlan(string $name, string $description, float $price, int $total_cycles = 0): PayPalClient { if (isset($this->billing_plan)) { return $this; @@ -216,14 +220,14 @@ 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 * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addAnnualPlan(string $name, string $description, float $price, int $total_cycles = 0): \Srmklive\PayPal\Services\PayPal + public function addAnnualPlan(string $name, string $description, float $price, int $total_cycles = 0): PayPalClient { if (isset($this->billing_plan)) { return $this; @@ -242,16 +246,16 @@ 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 * * @throws Throwable * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addCustomPlan(string $name, string $description, float $price, string $interval_unit, int $interval_count, int $total_cycles = 0): \Srmklive\PayPal\Services\PayPal + public function addCustomPlan(string $name, string $description, float $price, string $interval_unit, int $interval_count, int $total_cycles = 0): PayPalClient { $billing_intervals = ['DAY', 'WEEK', 'MONTH', 'YEAR']; @@ -319,9 +323,9 @@ protected function addPlanBillingCycle(string $interval_unit, int $interval_coun * * @throws Throwable * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addProduct(string $name, string $description, string $type, string $category): \Srmklive\PayPal\Services\PayPal + public function addProduct(string $name, string $description, string $type, string $category): PayPalClient { if (isset($this->product)) { return $this; @@ -349,9 +353,9 @@ public function addProduct(string $name, string $description, string $type, stri * * @param string $product_id * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addProductById(string $product_id): \Srmklive\PayPal\Services\PayPal + public function addProductById(string $product_id): PayPalClient { $this->product = [ 'id' => $product_id, @@ -365,9 +369,9 @@ public function addProductById(string $product_id): \Srmklive\PayPal\Services\Pa * * @param string $plan_id * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addBillingPlanById(string $plan_id): \Srmklive\PayPal\Services\PayPal + public function addBillingPlanById(string $plan_id): PayPalClient { $this->billing_plan = [ 'id' => $plan_id, @@ -416,9 +420,9 @@ protected function addBillingPlan(string $name, string $description, array $bill * * @param int $threshold * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addPaymentFailureThreshold(int $threshold): \Srmklive\PayPal\Services\PayPal + public function addPaymentFailureThreshold(int $threshold): PayPalClient { $this->payment_failure_threshold = $threshold; @@ -430,9 +434,9 @@ public function addPaymentFailureThreshold(int $threshold): \Srmklive\PayPal\Ser * * @param float $price * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addSetupFee(float $price): \Srmklive\PayPal\Services\PayPal + public function addSetupFee(float $price): PayPalClient { $this->has_setup_fee = true; $this->payment_preferences = [ @@ -459,9 +463,9 @@ public function addSetupFee(float $price): \Srmklive\PayPal\Services\PayPal * @param string $postal_code * @param string $country_code * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addShippingAddress(string $full_name, string $address_line_1, string $address_line_2, string $admin_area_2, string $admin_area_1, string $postal_code, string $country_code): \Srmklive\PayPal\Services\PayPal + public function addShippingAddress(string $full_name, string $address_line_1, string $address_line_2, string $admin_area_2, string $admin_area_1, string $postal_code, string $country_code): PayPalClient { $this->shipping_address = [ 'name' => [ @@ -485,9 +489,9 @@ public function addShippingAddress(string $full_name, string $address_line_1, st * * @param float $percentage * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function addTaxes(float $percentage) + public function addTaxes(float $percentage): PayPalClient { $this->taxes = [ 'percentage' => $percentage, @@ -502,7 +506,7 @@ public function addTaxes(float $percentage) * * @param string $custom_id * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ public function addCustomId(string $custom_id) { diff --git a/src/Traits/PayPalAPI/Trackers.php b/src/Traits/PayPalAPI/Trackers.php index 036b1d6c..e2a99cc2 100644 --- a/src/Traits/PayPalAPI/Trackers.php +++ b/src/Traits/PayPalAPI/Trackers.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait Trackers { /** @@ -9,13 +12,13 @@ trait Trackers * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/tracking/v1/#trackers-batch_post */ - public function addBatchTracking(array $data) + public function addBatchTracking(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/shipping/trackers-batch'; @@ -31,13 +34,13 @@ public function addBatchTracking(array $data) * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_post */ - public function addTracking(array $data) + public function addTracking(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/shipping/trackers'; @@ -51,16 +54,16 @@ public function addTracking(array $data) /** * List tracking information based on Transaction ID or tracking number. * - * @param string $transaction_id - * @param string $tracking_number + * @param string $transaction_id + * @param string|null $tracking_number * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @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): StreamInterface|array|string { $this->apiEndPoint = "v1/shipping/trackers?transaction_id={$transaction_id}".!empty($tracking_number) ? "&tracking_number={$tracking_number}" : ''; @@ -75,13 +78,13 @@ public function listTrackingDetails(string $transaction_id, string $tracking_num * @param string $tracking_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_put */ - public function updateTrackingDetails(string $tracking_id, array $data) + public function updateTrackingDetails(string $tracking_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v1/shipping/trackers/{$tracking_id}"; @@ -97,13 +100,13 @@ public function updateTrackingDetails(string $tracking_id, array $data) * * @param string $tracking_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_get */ - public function showTrackingDetails(string $tracking_id) + public function showTrackingDetails(string $tracking_id): StreamInterface|array|string { $this->apiEndPoint = "v1/shipping/trackers/{$tracking_id}"; diff --git a/src/Traits/PayPalAPI/WebHooks.php b/src/Traits/PayPalAPI/WebHooks.php index a5e82ad1..2577db4f 100644 --- a/src/Traits/PayPalAPI/WebHooks.php +++ b/src/Traits/PayPalAPI/WebHooks.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait WebHooks { /** @@ -10,13 +13,13 @@ trait WebHooks * @param string $url * @param array $events * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_post */ - public function createWebHook(string $url, array $events) + public function createWebHook(string $url, array $events): StreamInterface|array|string { $this->apiEndPoint = 'v1/notifications/webhooks'; @@ -35,13 +38,13 @@ public function createWebHook(string $url, array $events) /** * List all web hooks. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_list */ - public function listWebHooks() + public function listWebHooks(): StreamInterface|array|string { $this->apiEndPoint = 'v1/notifications/webhooks'; @@ -55,13 +58,13 @@ public function listWebHooks() * * @param string $web_hook_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_delete */ - public function deleteWebHook(string $web_hook_id) + public function deleteWebHook(string $web_hook_id): StreamInterface|array|string { $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}"; @@ -76,13 +79,13 @@ public function deleteWebHook(string $web_hook_id) * @param string $web_hook_id * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_update */ - public function updateWebHook(string $web_hook_id, array $data) + public function updateWebHook(string $web_hook_id, array $data): StreamInterface|array|string { $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}"; @@ -98,13 +101,13 @@ public function updateWebHook(string $web_hook_id, array $data) * * @param string $web_hook_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_get */ - public function showWebHookDetails(string $web_hook_id) + public function showWebHookDetails(string $web_hook_id): StreamInterface|array|string { $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}"; @@ -118,13 +121,13 @@ public function showWebHookDetails(string $web_hook_id) * * @param string $web_hook_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_get */ - public function listWebHookEvents($web_hook_id) + public function listWebHookEvents($web_hook_id): StreamInterface|array|string { $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}/event-types"; diff --git a/src/Traits/PayPalAPI/WebHooksEvents.php b/src/Traits/PayPalAPI/WebHooksEvents.php index 47713dda..489bcb74 100644 --- a/src/Traits/PayPalAPI/WebHooksEvents.php +++ b/src/Traits/PayPalAPI/WebHooksEvents.php @@ -2,18 +2,21 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait WebHooksEvents { /** * List all events types for web hooks. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-event-types_list */ - public function listEventTypes() + public function listEventTypes(): StreamInterface|array|string { $this->apiEndPoint = 'v1/notifications/webhooks-event-types'; @@ -25,13 +28,13 @@ public function listEventTypes() /** * List all events notifications for web hooks. * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-events_list */ - public function listEvents() + public function listEvents(): StreamInterface|array|string { $this->apiEndPoint = 'v1/notifications/webhooks-events'; @@ -45,13 +48,13 @@ public function listEvents() * * @param string $event_id * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-events_get */ - public function showEventDetails(string $event_id) + public function showEventDetails(string $event_id): StreamInterface|array|string { $this->apiEndPoint = "v1/notifications/webhooks-events/{$event_id}"; @@ -66,13 +69,13 @@ public function showEventDetails(string $event_id) * @param string $event_id * @param array $items * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-events_resend */ - public function resendEventNotification(string $event_id, array $items) + public function resendEventNotification(string $event_id, array $items): StreamInterface|array|string { $this->apiEndPoint = "v1/notifications/webhooks-events/{$event_id}/resend"; diff --git a/src/Traits/PayPalAPI/WebHooksVerification.php b/src/Traits/PayPalAPI/WebHooksVerification.php index 4a936f2c..52a5a221 100644 --- a/src/Traits/PayPalAPI/WebHooksVerification.php +++ b/src/Traits/PayPalAPI/WebHooksVerification.php @@ -2,6 +2,9 @@ namespace Srmklive\PayPal\Traits\PayPalAPI; +use Psr\Http\Message\StreamInterface; +use Throwable; + trait WebHooksVerification { /** @@ -9,13 +12,13 @@ trait WebHooksVerification * * @param array $data * - * @throws \Throwable + * @throws Throwable * - * @return array|\Psr\Http\Message\StreamInterface|string + * @return array|StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#verify-webhook-signature_post */ - public function verifyWebHook(array $data) + public function verifyWebHook(array $data): StreamInterface|array|string { $this->apiEndPoint = 'v1/notifications/verify-webhook-signature'; diff --git a/src/Traits/PayPalExperienceContext.php b/src/Traits/PayPalExperienceContext.php index d1db77a2..c3bc092e 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 8c030a97..5a1377c2 100644 --- a/src/Traits/PayPalHttpClient.php +++ b/src/Traits/PayPalHttpClient.php @@ -16,77 +16,77 @@ trait PayPalHttpClient * * @var HttpClient */ - private $client; + private HttpClient $client; /** * Http Client configuration. * * @var array */ - private $httpClientConfig; + private array $httpClientConfig; /** * PayPal API Endpoint. * * @var string */ - private $apiUrl; + private string $apiUrl; /** * PayPal API Endpoint. * * @var string */ - private $apiEndPoint; + private string $apiEndPoint; /** * IPN notification url for PayPal. * * @var string */ - private $notifyUrl; + private string $notifyUrl; /** * Http Client request body parameter name. * * @var string */ - private $httpBodyParam; + private string $httpBodyParam; /** * Default payment action for PayPal. * * @var string */ - private $paymentAction; + private string $paymentAction; /** * Default locale for PayPal. * * @var string */ - private $locale; + private string $locale; /** * Validate SSL details when creating HTTP client. * * @var bool */ - private $validateSSL; + private bool $validateSSL; /** * Request type. * * @var string */ - protected $verb = 'post'; + protected string $verb = 'post'; /** * Set curl constants if not defined. * * @return void */ - protected function setCurlConstants() + protected function setCurlConstants(): void { $constants = [ 'CURLOPT_SSLVERSION' => 32, @@ -106,9 +106,9 @@ protected function setCurlConstants() * @param string $key * @param string $value * - * @return bool + * @return bool|string */ - protected function defineCurlConstant(string $key, string $value) + protected function defineCurlConstant(string $key, string $value): bool|string { return defined($key) ? true : define($key, $value); } @@ -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): void { if ($client instanceof HttpClient) { $this->client = $client; @@ -138,7 +138,7 @@ public function setClient(HttpClient $client = null) * * @return void */ - protected function setHttpClientConfiguration() + protected function setHttpClientConfiguration(): void { $this->setCurlConstants(); @@ -162,7 +162,7 @@ protected function setHttpClientConfiguration() * * @return void */ - private function setDefaultValues() + private function setDefaultValues(): void { $paymentAction = empty($this->paymentAction) ? 'Sale' : $this->paymentAction; $this->paymentAction = $paymentAction; @@ -204,7 +204,7 @@ private function makeHttpRequest(): StreamInterface * * @return array|StreamInterface|string */ - private function doPayPalRequest(bool $decode = true) + private function doPayPalRequest(bool $decode = true): StreamInterface|array|string { try { $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/'); diff --git a/src/Traits/PayPalRequest.php b/src/Traits/PayPalRequest.php index bb1ce3f5..82b92946 100644 --- a/src/Traits/PayPalRequest.php +++ b/src/Traits/PayPalRequest.php @@ -3,6 +3,7 @@ namespace Srmklive\PayPal\Traits; use RuntimeException; +use Srmklive\PayPal\Services\PayPal as PayPalClient; trait PayPalRequest { @@ -15,14 +16,14 @@ trait PayPalRequest * * @var string */ - public $mode; + public string $mode; /** * PayPal access token. * * @var string */ - protected $access_token; + protected mixed $access_token; /** * PayPal API configuration. @@ -36,35 +37,35 @@ trait PayPalRequest * * @var string */ - protected $currency; + protected string $currency; /** * Additional options for PayPal API request. * * @var array */ - protected $options; + protected array $options; /** * Set limit to total records per API call. * * @var int */ - protected $page_size = 20; + protected int $page_size = 20; /** * Set the current page for list resources API calls. * - * @var bool + * @var int */ - protected $current_page = 1; + protected int $current_page = 1; /** * Toggle whether totals for list resources are returned after every API call. * * @var bool */ - protected $show_totals = true; + protected bool $show_totals = true; /** * Set PayPal API Credentials. @@ -99,9 +100,9 @@ public function setApiCredentials(array $credentials): void * * @throws \RuntimeException * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function setCurrency(string $currency = 'USD'): \Srmklive\PayPal\Services\PayPal + public function setCurrency(string $currency = 'USD'): PayPalClient { // Check if provided currency is valid. if (!in_array($currency, $this->allowedCurrencies(), true)) { @@ -164,9 +165,9 @@ public function getCurrency(): string * @param string $key * @param string $value * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function setRequestHeader(string $key, string $value): \Srmklive\PayPal\Services\PayPal + public function setRequestHeader(string $key, string $value): PayPalClient { $this->options['headers'][$key] = $value; @@ -178,9 +179,9 @@ public function setRequestHeader(string $key, string $value): \Srmklive\PayPal\S * * @param array $headers * - * @return \Srmklive\PayPal\Services\PayPal + * @return PayPalClient */ - public function setRequestHeaders(array $headers): \Srmklive\PayPal\Services\PayPal + public function setRequestHeaders(array $headers): PayPalClient { foreach ($headers as $key=>$value) { $this->setRequestHeader($key, $value); @@ -286,9 +287,11 @@ private function setApiProviderConfiguration(array $credentials): void } /** + * Function to send invalid configuration exception. + * * @throws RuntimeException */ - private function throwConfigurationException() + private function throwConfigurationException(): void { throw new RuntimeException('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.'); } @@ -296,7 +299,7 @@ private function throwConfigurationException() /** * @throws RuntimeException */ - private function throwInvalidEvidenceFileException() + private function throwInvalidEvidenceFileException(): void { throw new RuntimeException('Invalid evidence file type provided. 1. The party can upload up to 50 MB of files per request. diff --git a/src/Traits/PayPalVerifyIPN.php b/src/Traits/PayPalVerifyIPN.php index 63478683..48bdc868 100644 --- a/src/Traits/PayPalVerifyIPN.php +++ b/src/Traits/PayPalVerifyIPN.php @@ -20,7 +20,7 @@ public function setWebHookID(string $webhook_id): \Srmklive\PayPal\Services\PayP * * @return array|\Psr\Http\Message\StreamInterface|string */ - public function verifyIPN(\Illuminate\Http\Request $request) + public function verifyIPN(\Illuminate\Http\Request $request): array|\Psr\Http\Message\StreamInterface|string { $headers = array_change_key_case($request->headers->all(), CASE_UPPER);