Skip to content

Commit

Permalink
Merge pull request #1 from twitchalerts/chore/php-8-and-laravel-10.x
Browse files Browse the repository at this point in the history
PHP 8 & Laravel 10.x Compatible
  • Loading branch information
gideonappoh-sl authored Dec 12, 2023
2 parents cb00f24 + 565f1aa commit 329f1dc
Show file tree
Hide file tree
Showing 63 changed files with 250 additions and 237 deletions.
56 changes: 28 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"name": "twitchalerts/rest-api-sdk-php",
"description": "PayPal's PHP SDK for REST APIs",
"keywords": ["paypal", "payments", "rest", "sdk"],
"type": "library",
"license": "Apache-2.0",
"homepage": "http://paypal.github.io/PayPal-PHP-SDK/",
"authors": [
{
"name": "PayPal",
"homepage": "https://github.com/paypal/rest-api-sdk-php/contributors"
}
],
"require": {
"php": ">=5.3.0",
"ext-curl": "*",
"ext-json": "*",
"psr/log": "^1.0.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
},
"autoload": {
"psr-0": {
"PayPal": "lib/"
}
}
}
{
"name": "twitchalerts/rest-api-sdk-php",
"description": "PayPal's PHP SDK for REST APIs",
"keywords": ["paypal", "payments", "rest", "sdk"],
"type": "library",
"license": "Apache-2.0",
"homepage": "http://paypal.github.io/PayPal-PHP-SDK/",
"authors": [
{
"name": "PayPal",
"homepage": "https://github.com/paypal/rest-api-sdk-php/contributors"
}
],
"require": {
"php": ">=8.0.0",
"ext-curl": "*",
"ext-json": "*",
"psr/log": "^2.0.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-0": {
"PayPal": "lib/"
}
}
}
42 changes: 21 additions & 21 deletions lib/PayPal/Api/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Payment extends PayPalResourceModel
* Identifier of the payment resource created.
*
* @param string $id
*
*
* @return $this
*/
public function setId($id)
Expand All @@ -58,7 +58,7 @@ public function getId()
* Valid Values: ["sale", "authorize", "order"]
*
* @param string $intent
*
*
* @return $this
*/
public function setIntent($intent)
Expand All @@ -81,7 +81,7 @@ public function getIntent()
* Source of the funds for this payment represented by a PayPal account or a direct credit card.
*
* @param \PayPal\Api\Payer $payer
*
*
* @return $this
*/
public function setPayer($payer)
Expand All @@ -104,7 +104,7 @@ public function getPayer()
* Information that the merchant knows about the payer. This information is not definitive and only serves as a hint to the UI or any pre-processing logic.
* @deprecated Not publicly available
* @param \PayPal\Api\PotentialPayerInfo $potential_payer_info
*
*
* @return $this
*/
public function setPotentialPayerInfo($potential_payer_info)
Expand All @@ -126,7 +126,7 @@ public function getPotentialPayerInfo()
/**
* Receiver of funds for this payment.
* @param \PayPal\Api\Payee $payee
*
*
* @return $this
*/
public function setPayee($payee)
Expand All @@ -148,7 +148,7 @@ public function getPayee()
* ID of the cart to execute the payment.
* @deprecated Not publicly available
* @param string $cart
*
*
* @return $this
*/
public function setCart($cart)
Expand All @@ -171,7 +171,7 @@ public function getCart()
* Transactional details including the amount and item details.
*
* @param \PayPal\Api\Transaction[] $transactions
*
*
* @return $this
*/
public function setTransactions($transactions)
Expand Down Expand Up @@ -224,7 +224,7 @@ public function removeTransaction($transaction)
* Applicable for advanced payments like multi seller payment (MSP) to support partial failures
* @deprecated Not publicly available
* @param \PayPal\Api\Error[] $failed_transactions
*
*
* @return $this
*/
public function setFailedTransactions($failed_transactions)
Expand Down Expand Up @@ -277,7 +277,7 @@ public function removeFailedTransaction($error)
* Collection of PayPal generated billing agreement tokens.
* @deprecated Not publicly available
* @param string[] $billing_agreement_tokens
*
*
* @return $this
*/
public function setBillingAgreementTokens($billing_agreement_tokens)
Expand Down Expand Up @@ -330,7 +330,7 @@ public function removeBillingAgreementToken($billingAgreementToken)
* Credit financing offered to payer on PayPal side. Returned in payment after payer opts-in
* @deprecated Not publicly available
* @param \PayPal\Api\CreditFinancingOffered $credit_financing_offered
*
*
* @return $this
*/
public function setCreditFinancingOffered($credit_financing_offered)
Expand All @@ -353,7 +353,7 @@ public function getCreditFinancingOffered()
* Instructions for the payer to complete this payment.
* @deprecated Not publicly available
* @param \PayPal\Api\PaymentInstruction $payment_instruction
*
*
* @return $this
*/
public function setPaymentInstruction($payment_instruction)
Expand All @@ -377,7 +377,7 @@ public function getPaymentInstruction()
* Valid Values: ["created", "approved", "failed", "partially_completed", "in_progress"]
*
* @param string $state
*
*
* @return $this
*/
public function setState($state)
Expand All @@ -400,7 +400,7 @@ public function getState()
* PayPal generated identifier for the merchant's payment experience profile. Refer to [this](https://developer.paypal.com/docs/api/#payment-experience) link to create experience profile ID.
*
* @param string $experience_profile_id
*
*
* @return $this
*/
public function setExperienceProfileId($experience_profile_id)
Expand All @@ -423,7 +423,7 @@ public function getExperienceProfileId()
* free-form field for the use of clients to pass in a message to the payer
*
* @param string $note_to_payer
*
*
* @return $this
*/
public function setNoteToPayer($note_to_payer)
Expand All @@ -446,7 +446,7 @@ public function getNoteToPayer()
* Set of redirect URLs you provide only for PayPal-based payments.
*
* @param \PayPal\Api\RedirectUrls $redirect_urls
*
*
* @return $this
*/
public function setRedirectUrls($redirect_urls)
Expand All @@ -470,7 +470,7 @@ public function getRedirectUrls()
* Valid Values: ["UNABLE_TO_COMPLETE_TRANSACTION", "INVALID_PAYMENT_METHOD", "PAYER_CANNOT_PAY", "CANNOT_PAY_THIS_PAYEE", "REDIRECT_REQUIRED", "PAYEE_FILTER_RESTRICTIONS"]
*
* @param string $failure_reason
*
*
* @return $this
*/
public function setFailureReason($failure_reason)
Expand All @@ -493,7 +493,7 @@ public function getFailureReason()
* Payment creation time as defined in [RFC 3339 Section 5.6](http://tools.ietf.org/html/rfc3339#section-5.6).
*
* @param string $create_time
*
*
* @return $this
*/
public function setCreateTime($create_time)
Expand All @@ -516,7 +516,7 @@ public function getCreateTime()
* Payment update time as defined in [RFC 3339 Section 5.6](http://tools.ietf.org/html/rfc3339#section-5.6).
*
* @param string $update_time
*
*
* @return $this
*/
public function setUpdateTime($update_time)
Expand Down Expand Up @@ -544,7 +544,7 @@ public function getApprovalLink()
{
return $this->getLink(PayPalConstants::APPROVAL_URL);
}

/**
* Get token from Approval Link
*
Expand All @@ -553,10 +553,10 @@ public function getApprovalLink()
public function getToken()
{
$parameter_name = "token";
parse_str(parse_url($this->getApprovalLink(), PHP_URL_QUERY), $query);
parse_str((string) parse_url((string) $this->getApprovalLink(), PHP_URL_QUERY), $query);
return !isset($query[$parameter_name]) ? null : $query[$parameter_name];
}

/**
* Creates and processes a payment. In the JSON request body, include a `payment` object with the intent, payer, and transactions. For PayPal payments, include redirect URLs in the `payment` object.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/PayPal/Cache/AuthorizationCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public static function pull($config = null, $clientId = null)
/**
* Persists the data into a cache file provided in $CACHE_PATH
*
* @param array|null $config
* @param array $config
* @param $clientId
* @param $accessToken
* @param $tokenCreateTime
* @param $tokenExpiresIn
* @throws \Exception
*/
public static function push($config = null, $clientId, $accessToken, $tokenCreateTime, $tokenExpiresIn)
public static function push($config, $clientId, $accessToken, $tokenCreateTime, $tokenExpiresIn)
{
// Return if not enabled
if (!self::isEnabled($config)) {
Expand Down Expand Up @@ -94,7 +94,7 @@ public static function isEnabled($config)
$value = self::getConfigValue('cache.enabled', $config);
return empty($value) ? false : ((trim($value) == true || trim($value) == 'true'));
}

/**
* Returns the cache file path
*
Expand Down
2 changes: 1 addition & 1 deletion lib/PayPal/Common/ReflectionUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ public static function getter($class, $propertyName)
{
return method_exists($class, "get" . ucfirst($propertyName)) ?
"get" . ucfirst($propertyName) :
"get" . preg_replace_callback("/([_\-\s]?([a-z0-9]+))/", "self::replace_callback", $propertyName);
"get" . preg_replace_callback("/([_\-\s]?([a-z0-9]+))/", static::replace_callback(...), $propertyName);
}
}
5 changes: 2 additions & 3 deletions lib/PayPal/Converter/FormatConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ public static function formatToPrice($value, $currency = null)
{
$decimals = 2;
$currencyDecimals = array('JPY' => 0, 'TWD' => 0, 'HUF' => 0);

if ($currency && array_key_exists($currency, $currencyDecimals)) {
if (strpos($value, ".") !== false && (floor($value) != $value)) {
//throw exception if it has decimal values for JPY, TWD and HUF which does not ends with .00
throw new \InvalidArgumentException("value cannot have decimals for $currency currency");
}
$decimals = $currencyDecimals[$currency];
} elseif (strpos($value, ".") === false) {
// Check if value has decimal values. If not no need to assign 2 decimals with .00 at the end
$decimals = 0;
}

return self::formatToNumber($value, $decimals);
}
}
4 changes: 3 additions & 1 deletion lib/PayPal/Core/PayPalHttpConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,11 @@ public function setUserAgent($userAgentString)
* @param $prefix
* @return array
*/
public function getHttpConstantsFromConfigs($configs = array(), $prefix)
public function getHttpConstantsFromConfigs($configs, $prefix)
{
$configs = $configs ?: [];
$arr = array();

if ($prefix != null && is_array($configs)) {
foreach ($configs as $k => $v) {
// Check if it startsWith
Expand Down
4 changes: 2 additions & 2 deletions lib/PayPal/Handler/OauthHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function handle($httpConfig, $request, $options)

$headers = array(
"User-Agent" => PayPalUserAgent::getValue(PayPalConstants::SDK_NAME, PayPalConstants::SDK_VERSION),
"Authorization" => "Basic " . base64_encode($options['clientId'] . ":" . $options['clientSecret']),
"Authorization" => "Basic " . base64_encode(($options['clientId'] ?? '') . ":" . ($options['clientSecret'] ?? '')),
"Accept" => "*/*"
);
$httpConfig->setHeaders($headers);
Expand All @@ -71,7 +71,7 @@ public function handle($httpConfig, $request, $options)
*
* @param array $config
*
* @return PayPalHttpConfig
* @return string
* @throws \PayPal\Exception\PayPalConfigurationException
*/
private static function _getEndpoint($config)
Expand Down
13 changes: 12 additions & 1 deletion lib/PayPal/Log/PayPalLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@ public function initialize()
}
}

public function log($level, $message, array $context = array())
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, string|\Stringable $message, array $context = [])
{
if ($this->isLoggingEnabled) {
// Checks if the message is at level below configured logging level
Expand Down
3 changes: 2 additions & 1 deletion lib/PayPal/Transport/PayPalRestCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public function __construct(ApiContext $apiContext)
* @return mixed
* @throws \PayPal\Exception\PayPalConnectionException
*/
public function execute($handlers = array(), $path, $method, $data = '', $headers = array())
public function execute($handlers, $path, $method, $data = '', $headers = array())
{
$handlers = $handlers ?: [];
$config = $this->apiContext->getConfig();
$httpConfig = new PayPalHttpConfig(null, $method, $config);
$headers = $headers ? $headers : array();
Expand Down
21 changes: 17 additions & 4 deletions lib/PayPal/Validation/JsonValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PayPal\Validation;

use Throwable;

/**
* Class JsonValidator
*
Expand All @@ -19,17 +21,28 @@ class JsonValidator
*/
public static function validate($string, $silent = false)
{
@json_decode($string);
if (json_last_error() != JSON_ERROR_NONE) {
if ($string === '' || $string === null) {
return true;
try {
@json_decode($string);

if (json_last_error() != JSON_ERROR_NONE) {
if ($string === '' || $string === null) {
return true;
}
if ($silent == false) {
//Throw an Exception for string or array
throw new \InvalidArgumentException("Invalid JSON String");
}
return false;
}
} catch (Throwable $th) {
if ($silent == false) {
//Throw an Exception for string or array
throw new \InvalidArgumentException("Invalid JSON String");
}

return false;
}

return true;
}
}
Loading

0 comments on commit 329f1dc

Please sign in to comment.