Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
parameters:
paths:
- src
level: 0
level: 5
ignoreErrors:
- "#Parameter#"
- "#Call to static method error\\(\\)\\ on an unknown class Log.#"
excludePaths:
- "src/Providers/PayPalServiceProvider.php"
- "src/Providers/PayPalServiceProvider.php"
2 changes: 1 addition & 1 deletion src/PayPalFacadeAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PayPalFacadeAccessor
/**
* PayPal API provider object.
*
* @var
* @var \Srmklive\PayPal\Services\PayPal
*/
public static $provider;

Expand Down
8 changes: 2 additions & 6 deletions src/Services/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ public static function isJson($value): bool
}

if (function_exists('json_validate')) {
return json_validate($value, 512);
return json_validate($value);
}

try {
Utils::jsonDecode($value, true, 512, 4194304);
} catch (\JsonException $jsonException) {
return false;
}
Utils::jsonDecode($value, true, 512, JSON_THROW_ON_ERROR);

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Services/VerifyDocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class VerifyDocuments
];

/**
* @var string
* @var int
*/
protected static $dispute_evidence_file_size = 10;

/**
* @var string
* @var int
*/
protected static $dispute_evidences_size = 50;

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/PayPalAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function setPageSize(int $size): \Srmklive\PayPal\Services\PayPal
/**
* Set the current page for list resources API calls.
*
* @param int $size
* @param int $page
*
* @return \Srmklive\PayPal\Services\PayPal
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/PayPalAPI/DisputesActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function acknowledgeItemReturned(string $dispute_id, string $dispute_note
* Providence evidence in support of a dispute.
*
* @param string $dispute_id
* @param array $file_path
* @param array $files
*
* @throws \Throwable
*
Expand Down
20 changes: 18 additions & 2 deletions src/Traits/PayPalAPI/InvoiceSearch/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,15 @@ public function addInvoiceFilterByReferenceorMemo(string $reference, bool $memo
*/
public function addInvoiceFilterByCurrencyCode(string $currency_code = ''): \Srmklive\PayPal\Services\PayPal
{
$currency = !isset($currency_code) ? $this->getCurrency() : $currency_code;
if (!empty($currency_code)) {
$currency = $currency_code;
} else {
try {
$currency = $this->getCurrency();
} catch (\Throwable $e) {
$currency = 'USD';
}
}

$this->invoice_search_filters['currency_code'] = $currency;

Expand All @@ -171,7 +179,15 @@ public function addInvoiceFilterByAmountRange(float $start_amount, float $end_am
throw new \Exception('Starting amount should always be less than end amount!');
}

$currency = !isset($amount_currency) ? $this->getCurrency() : $amount_currency;
if (!empty($amount_currency)) {
$currency = $amount_currency;
} else {
try {
$currency = $this->getCurrency();
} catch (\Throwable $e) {
$currency = 'USD';
}
}

$this->invoice_search_filters['total_amount_range'] = [
'lower_amount' => [
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/PayPalAPI/Subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ public function listSubscriptionTransactions(string $subscription_id, $start_dat
$end_date = Carbon::parse($end_date);
}

$start_date = $start_date->toIso8601ZuluString();
$end_date = $end_date->toIso8601ZuluString();
$start_date = $start_date->format('Y-m-d\TH:i:s\Z');
$end_date = $end_date->format('Y-m-d\TH:i:s\Z');

$this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/transactions?start_time={$start_date}&end_time={$end_date}";

Expand Down
45 changes: 23 additions & 22 deletions src/Traits/PayPalAPI/Subscriptions/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ trait Helpers
protected $payment_failure_threshold = 3;

/**
* @var array
* @var array|null
*/
protected $product;
protected ?array $product = null;

/**
* @var array
* @var array|null
*/
protected $billing_plan;
protected ?array $billing_plan = null;

/**
* @var array
* @var array|null
*/
protected $shipping_address;
protected ?array $shipping_address = null;

/**
* @var array
Expand All @@ -44,14 +44,19 @@ trait Helpers
protected $has_setup_fee = false;

/**
* @var array
* @var array|null
*/
protected ?array $taxes = null;

/**
* @var string|null
*/
protected $taxes;
protected ?string $custom_id = null;

/**
* @var string
* @var array
*/
protected $custom_id;
protected ?array $experience_context = [];

/**
* Setup a subscription.
Expand Down Expand Up @@ -121,7 +126,7 @@ public function setupSubscription(string $customer_name, string $customer_email,
*
* @param string $interval_type
* @param int $interval_count
* @param float|int $price
* @param float $price
* @param int $total_cycles
*
* @return \Srmklive\PayPal\Services\PayPal
Expand All @@ -138,7 +143,7 @@ public function addPlanTrialPricing(string $interval_type, int $interval_count,
*
* @param string $name
* @param string $description
* @param float|int $price
* @param float $price
* @param int $total_cycles
*
* @throws Throwable
Expand All @@ -164,7 +169,7 @@ public function addDailyPlan(string $name, string $description, float $price, in
*
* @param string $name
* @param string $description
* @param float|int $price
* @param float $price
* @param int $total_cycles
*
* @throws Throwable
Expand All @@ -190,7 +195,7 @@ public function addWeeklyPlan(string $name, string $description, float $price, i
*
* @param string $name
* @param string $description
* @param float|int $price
* @param float $price
* @param int $total_cycles
*
* @throws Throwable
Expand All @@ -216,7 +221,7 @@ public function addMonthlyPlan(string $name, string $description, float $price,
*
* @param string $name
* @param string $description
* @param float|int $price
* @param float $price
* @param int $total_cycles
*
* @throws Throwable
Expand All @@ -242,7 +247,7 @@ public function addAnnualPlan(string $name, string $description, float $price, i
*
* @param string $name
* @param string $description
* @param float|int $price
* @param float $price
* @param string $interval_unit
* @param int $interval_count
* @param int $total_cycles
Expand Down Expand Up @@ -327,14 +332,12 @@ public function addProduct(string $name, string $description, string $type, stri
return $this;
}

$request_id = Str::random();

$product = $this->createProduct([
'name' => $name,
'description' => $description,
'type' => $type,
'category' => $category,
], $request_id);
]);

if ($error = data_get($product, 'error', false)) {
throw new \RuntimeException(data_get($error, 'details.0.description', 'Failed to add product'));
Expand Down Expand Up @@ -389,8 +392,6 @@ public function addBillingPlanById(string $plan_id): \Srmklive\PayPal\Services\P
*/
protected function addBillingPlan(string $name, string $description, array $billing_cycles): void
{
$request_id = Str::random();

$plan_params = [
'product_id' => $this->product['id'],
'name' => $name,
Expand All @@ -404,7 +405,7 @@ protected function addBillingPlan(string $name, string $description, array $bill
],
];

$billingPlan = $this->createPlan($plan_params, $request_id);
$billingPlan = $this->createPlan($plan_params);
if ($error = data_get($billingPlan, 'error', false)) {
throw new \RuntimeException(data_get($error, 'details.0.description', 'Failed to add billing plan'));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/PayPalAPI/Trackers.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public function addTracking(array $data)
*
* @see https://developer.paypal.com/docs/api/tracking/v1/#trackers-batch_get
*/
public function listTrackingDetails(string $transaction_id, string $tracking_number = null)
public function listTrackingDetails(string $transaction_id, ?string $tracking_number = null)
{
$this->apiEndPoint = "v1/shipping/trackers?transaction_id={$transaction_id}".!empty($tracking_number) ? "&tracking_number={$tracking_number}" : '';
$this->apiEndPoint = "v1/shipping/trackers?transaction_id={$transaction_id}".(!empty($tracking_number) ? "&tracking_number={$tracking_number}" : '');

$this->verb = 'get';

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/PayPalExperienceContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ trait PayPalExperienceContext
/**
* @var array
*/
protected $experience_context = [];
protected ?array $experience_context = [];

/**
* Set Brand Name when setting experience context for payment.
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/PayPalHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected function defineCurlConstant(string $key, string $value)
*
* @return void
*/
public function setClient(HttpClient $client = null)
public function setClient(?HttpClient $client = null)
{
if ($client instanceof HttpClient) {
$this->client = $client;
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/PayPalRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait PayPalRequest
/**
* Set the current page for list resources API calls.
*
* @var bool
* @var int
*/
protected $current_page = 1;

Expand Down
9 changes: 8 additions & 1 deletion src/Traits/PayPalVerifyIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Srmklive\PayPal\Traits;

use Illuminate\Http\Request;

trait PayPalVerifyIPN
{
protected $webhook_id;
Expand All @@ -16,12 +18,16 @@ public function setWebHookID(string $webhook_id): \Srmklive\PayPal\Services\PayP
/**
* Verify incoming IPN through a web hook id.
*
* @param \Illuminate\Http\Request $request Laravel HTTP request object
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @phpstan-ignore-next-line
*/
public function verifyIPN(\Illuminate\Http\Request $request)
public function verifyIPN(Request $request)
{
/** @phpstan-ignore-next-line */
$headers = array_change_key_case($request->headers->all(), CASE_UPPER);

if (!isset($headers['PAYPAL-AUTH-ALGO'][0]) ||
Expand All @@ -36,6 +42,7 @@ public function verifyIPN(\Illuminate\Http\Request $request)
return ['error' => 'Invalid headers or webhook id provided'];
}

/** @phpstan-ignore-next-line */
$params = json_decode($request->getContent());

$payload = [
Expand Down
11 changes: 2 additions & 9 deletions tests/MockClientClasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,7 @@ private function getApiCredentials(): array

protected function setMethodsFunction(): bool
{
$useOnlyMethods = false;

foreach (['8.1', '8.2', '8.3'] as $php_version) {
if (strpos(phpversion(), $php_version) !== false) {
$useOnlyMethods = true;
}
}

return $useOnlyMethods;
// Always use onlyMethods as setMethods is deprecated in PHPUnit 8 and removed in PHPUnit 10
return true;
}
}