diff --git a/composer.json b/composer.json index 27de1b0..a6fb41e 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,11 @@ ], "minimum-stability": "dev", "require": { - "php": "^7.1", + "php": "^8.2", "ext-curl": "*", "ext-json": "*", - "illuminate/support": "5.6.*|5.7.*|5.8.*", - "guzzlehttp/guzzle": ">=6.0" + "illuminate/support": "^11.0", + "guzzlehttp/guzzle": "^7.0" }, "autoload": { "psr-4": { diff --git a/src/Abstracts/AbstractService.php b/src/Abstracts/AbstractService.php index fee58bb..a6e0f0b 100644 --- a/src/Abstracts/AbstractService.php +++ b/src/Abstracts/AbstractService.php @@ -22,4 +22,4 @@ public function getPath() { return $this->base_path . $this->version . '/' . $this->endpoint; } -} \ No newline at end of file +} diff --git a/src/Facade/TapPayment.php b/src/Facade/TapPayment.php index 54849e3..55c8166 100644 --- a/src/Facade/TapPayment.php +++ b/src/Facade/TapPayment.php @@ -18,4 +18,4 @@ protected static function getFacadeAccessor() { return 'tap-payment'; } -} \ No newline at end of file +} diff --git a/src/Resources/Invoice.php b/src/Resources/Invoice.php index c2b5488..f715f54 100644 --- a/src/Resources/Invoice.php +++ b/src/Resources/Invoice.php @@ -7,7 +7,7 @@ class Invoice protected $attributes; - public function __construct( $data ) + public function __construct($data) { $this->attributes = (array)$data; } @@ -15,13 +15,13 @@ public function __construct( $data ) public function isSuccess() { - return isset( $this->attributes['status'] ) && strtolower( $this->attributes['status'] ) == 'captured'; + return isset($this->attributes['status']) && strtolower($this->attributes['status']) == 'captured'; } public function isInitiated() { - return isset( $this->attributes['status'] ) && strtolower( $this->attributes['status'] ) == 'initiated'; + return isset($this->attributes['status']) && strtolower($this->attributes['status']) == 'initiated'; } @@ -42,7 +42,7 @@ public function getMetaData() return $this->attributes['metadata'] ?? null; } - public function checkHash( $hash ) + public function checkHash($hash) { $data = [ 'x_id' => $this->attributes['id'] ?? null, @@ -56,23 +56,23 @@ public function checkHash( $hash ) $decimals = $data['x_currency'] == 'KWD' ? 3 : 2; - $data['x_amount'] = number_format( $data['x_amount'], $decimals, '.', '' ); + $data['x_amount'] = number_format($data['x_amount'], $decimals, '.', ''); $stringToHash = implode( '', array_map( - function( $value, $key ) { + function ($value, $key) { return $key . $value; }, $data, - array_keys( $data ) + array_keys($data) ) ); - $key = config( 'tap-payment.auth.api_key' ); + $key = config('tap-payment.auth.api_key'); - $hashedString = hash_hmac( 'sha256', $stringToHash, $key ); + $hashedString = hash_hmac('sha256', $stringToHash, $key); return $hashedString == $hash; } -} \ No newline at end of file +} diff --git a/src/Services/Charge.php b/src/Services/Charge.php index afa3c80..f18b37a 100644 --- a/src/Services/Charge.php +++ b/src/Services/Charge.php @@ -13,67 +13,67 @@ class Charge extends AbstractService protected $attributes = []; - public function __construct( $id = null ) + public function __construct($id = null) { - if ( $id ) { + if ($id) { $this->attributes['id'] = $id; - $this->setEndpoint( $id ); + $this->setEndpoint($id); } parent::__construct(); } - protected function setEndpoint( $endpoint ) + protected function setEndpoint($endpoint) { $this->endpoint .= $endpoint; } - public function setAmount( $amount ) + public function setAmount($amount) { $this->attributes['amount'] = $amount; } - public function setCurrency( $currency ) + public function setCurrency($currency) { $this->attributes['currency'] = $currency; } - public function setThreeDSecure( $threeDSecure ) + public function setThreeDSecure($threeDSecure) { $this->attributes['threeDSecure'] = $threeDSecure; } - public function setSave_card( $save_card ) + public function setSave_card($save_card) { $this->attributes['save_card'] = $save_card; } - public function setDescription( $description ) + public function setDescription($description) { $this->attributes['description'] = $description; } - public function setCustomerName( $name ) + public function setCustomerName($name) { - $name = explode( ' ', $name ); - $this->attributes['customer']['first_name'] = array_shift( $name ); - $this->attributes['customer']['last_name'] = implode( ' ', $name ); + $name = explode(' ', $name); + $this->attributes['customer']['first_name'] = array_shift($name); + $this->attributes['customer']['last_name'] = implode(' ', $name); } - public function setCustomerEmail( $email ) + public function setCustomerEmail($email) { $this->attributes['customer']['email'] = $email; } - public function setCustomerPhone( $country_code, $phone ) + public function setCustomerPhone($country_code, $phone) { $this->attributes['customer']['phone'] = [ 'country_code' => $country_code, @@ -82,31 +82,31 @@ public function setCustomerPhone( $country_code, $phone ) } - public function setRedirectUrl( $url ) + public function setRedirectUrl($url) { $this->attributes['redirect']['url'] = $url; } - public function setPostUrl( $url ) + public function setPostUrl($url) { $this->attributes['post']['url'] = $url; } - public function setSource( $source ) + public function setSource($source) { $this->attributes['source']['id'] = $source; } - public function setMetaData( array $meta ) + public function setMetaData(array $meta) { $this->attributes['metadata'] = $meta; } - public function setRawAttributes( array $attributes ) + public function setRawAttributes(array $attributes) { $this->attributes = $attributes; } @@ -118,19 +118,19 @@ public function setRawAttributes( array $attributes ) */ public function find() { - $this->setMethod( 'get' ); + $this->setMethod('get'); if ( - $this->validateAttributes( - [ - 'id' => 'required' - ] - ) + $this->validateAttributes( + [ + 'id' => 'required' + ] + ) ) return $this->send(); } - protected function setMethod( $method ) + protected function setMethod($method) { $this->method = $method; } @@ -142,12 +142,12 @@ protected function setMethod( $method ) * @return bool * @throws \Exception */ - public function validateAttributes( array $rules, $messages = [] ) + public function validateAttributes(array $rules, $messages = []) { - $validator = Validator::make( $this->attributes, $rules, $messages ); + $validator = Validator::make($this->attributes, $rules, $messages); - if ( $validator->fails() ) - throw new \Exception( $validator->errors()->first() ); + if ($validator->fails()) + throw new \Exception($validator->errors()->first()); return true; } @@ -166,16 +166,15 @@ protected function send() [ 'form_params' => $this->attributes, 'headers' => [ - 'Authorization' => 'Bearer ' . config( 'tap-payment.auth.api_key' ), + 'Authorization' => 'Bearer ' . config('tap-payment.auth.api_key'), 'Accept' => 'application/json', ] ] ); - return new Invoice( json_decode( $response->getBody()->getContents(), true ) ); - } - catch ( \Throwable $exception ) { - throw new \Exception( $exception->getMessage() ); + return new Invoice(json_decode($response->getBody()->getContents(), true)); + } catch (\Throwable $exception) { + throw new \Exception($exception->getMessage()); } } @@ -193,24 +192,24 @@ public function pay() 'source.id' => 'required', 'redirect.url' => 'required', ]; - foreach ( config( 'tap-payment.customer.requirements' ) as $item ) { - if ( $item == 'mobile' ) { + foreach (config('tap-payment.customer.requirements') as $item) { + if ($item == 'mobile') { $rules['customer.phone'] = 'required'; - $rules['customer.phone.country_code'] = [ 'required', 'numeric' ]; - $rules['customer.phone.number'] = [ 'required', 'numeric' ]; + $rules['customer.phone.country_code'] = ['required', 'numeric']; + $rules['customer.phone.number'] = ['required', 'numeric']; } else { - $rules[ 'customer.' . $item ] = 'required'; + $rules['customer.' . $item] = 'required'; } } if ( - $this->validateAttributes( - $rules, - [ - 'id.regex' => "ID should be empty when you create a new Charge." - ] - ) + $this->validateAttributes( + $rules, + [ + 'id.regex' => "ID should be empty when you create a new Charge." + ] + ) ) return $this->send(); } -} \ No newline at end of file +} diff --git a/src/TapPaymentServiceProvider.php b/src/TapPaymentServiceProvider.php index 64ee3fd..9c28be2 100644 --- a/src/TapPaymentServiceProvider.php +++ b/src/TapPaymentServiceProvider.php @@ -15,7 +15,7 @@ public function boot() { $this->publishes( [ - __DIR__ . '/Publishing/config.php' => config_path( 'tap-payment.php' ), + __DIR__ . '/Publishing/config.php' => config_path('tap-payment.php'), ] ); $this->mergeConfigFrom( @@ -33,9 +33,10 @@ public function boot() public function register() { $this->app->singleton( - 'tap-payment', function() { - return new TapService(); - } + 'tap-payment', + function () { + return new TapService(); + } ); } -} \ No newline at end of file +} diff --git a/src/TapService.php b/src/TapService.php index 7d8b9cf..9ffcaee 100644 --- a/src/TapService.php +++ b/src/TapService.php @@ -21,10 +21,10 @@ public function createCharge() * @return mixed * @throws \GuzzleHttp\Exception\GuzzleException */ - public function findCharge( $id ) + public function findCharge($id) { - $charge = new Charge( $id ); + $charge = new Charge($id); return $charge->find(); } -} \ No newline at end of file +}