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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Abstracts/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public function getPath()
{
return $this->base_path . $this->version . '/' . $this->endpoint;
}
}
}
2 changes: 1 addition & 1 deletion src/Facade/TapPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ protected static function getFacadeAccessor()
{
return 'tap-payment';
}
}
}
20 changes: 10 additions & 10 deletions src/Resources/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ class Invoice
protected $attributes;


public function __construct( $data )
public function __construct($data)
{
$this->attributes = (array)$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';
}


Expand All @@ -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,
Expand All @@ -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;
}
}
}
95 changes: 47 additions & 48 deletions src/Services/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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());
}
}

Expand All @@ -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();
}
}
}
11 changes: 6 additions & 5 deletions src/TapPaymentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
}
);
}
}
}
6 changes: 3 additions & 3 deletions src/TapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}