Skip to content

Commit

Permalink
Restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
kpscyber committed Dec 12, 2024
1 parent 6a4f83a commit 968ab1c
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 16 deletions.
39 changes: 39 additions & 0 deletions src/Commands/OmiseAccountCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Soap\LaravelOmise\Commands;

use Illuminate\Console\Command;

class OmiseAccountCommand extends Command
{
public $signature = 'omise:account';

public $description = 'Retrieve account information from Omise API';

public function handle(): int
{
$response = app('omise')->account()->retrieve();

if ($response instanceof \Soap\LaravelOmise\Omise\Error) {
$this->error($response->getMessage());

return self::FAILURE;
}
$this->line('Account information retrieved successfully!');
$this->table(['Key', 'Value'], [
['ID', $response->id],
['Email', $response->email],
['Type', $response->type],
['Name', $response->name],
['Bank', $response->bank],
['Description', $response->description],
['Public Key', $response->public_key],
['Secret Key', $response->secret_key],
['Currency', $response->currency],
['Location', $response->location],
['Created', $response->created],
]);

return self::SUCCESS;
}
}
16 changes: 16 additions & 0 deletions src/Facades/Omise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Soap\LaravelOmise\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @see \Soap\LaravelOmise\LaravelOmise
*/
class Treasurer extends Facade
{
protected static function getFacadeAccessor()
{
return 'omise';
}
}
7 changes: 7 additions & 0 deletions src/LaravelOmiseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ public function configurePackage(Package $package): void
->hasConfigFile()
->hasCommand(OmiseVerifyCommand::class);
}

public function packageRegistered()
{
$this->app->singleton('omise', function ($app) {
return new Omise($app->make(OmiseConfig::class));
});
}
}
32 changes: 32 additions & 0 deletions src/Omise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Soap\LaravelOmise;

use Soap\LaravelOmise\Omise\Account;
use Soap\LaravelOmise\Omise\Charge;
use Soap\LaravelOmise\Omise\Customer;

class Omise
{
protected $config;

public function __construct(OmiseConfig $omiseConfig)
{
$this->config = $omiseConfig;
}

public function account()
{
return new Account($this->config);
}

public function charge()
{
return new Charge($this->config);
}

public function customer()
{
return new Customer($this->config);
}
}
35 changes: 35 additions & 0 deletions src/Omise/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Soap\LaravelOmise\Omise;

use OmiseAccount;
use Soap\LaravelOmise\OmiseConfig;

class Account extends BaseObject
{
private $omiseConfig;

public function __construct(OmiseConfig $omiseConfig)
{
$this->omiseConfig = $omiseConfig;
}

/**
* Retrieve account information
*
* @return \Soap\LaravelOmise\Omise\Error|self
*/
public function retrieve()
{
try {
$this->refresh(OmiseAccount::retrieve($this->omiseConfig->getPublicKey(), $this->omiseConfig->getSecretKey()));
} catch (\Exception $e) {
return new Error([
'code' => 'not_found',
'message' => $e->getMessage(),
]);
}

return $this;
}
}
16 changes: 7 additions & 9 deletions src/Omise/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Exception;
use OmiseCharge;
use OmiseRefund;
use Soap\LaravelOmise\LaravelOmise;
use Soap\LaravelOmise\Omise\Helpers\OmiseMoney;
use Soap\LaravelOmise\OmiseConfig;

/**
* @property object $object
Expand Down Expand Up @@ -40,23 +40,21 @@
*/
class Charge extends BaseObject
{
private $laravelOmise;
private $omiseConfig;

public function __construct(LaravelOmise $laravelOmise)
public function __construct(OmiseConfig $omiseConfig)
{
$this->laravelOmise = $laravelOmise;
$this->omiseConfig = $omiseConfig;
}

/**
* @param string $id
* @param int|null $storeId
* @return \Soap\LaravelOmise\Omise\Error|self
*/
public function find($id, $storeId = null)
public function find($id)
{
try {
// $this->config->setStoreId($storeId);
$this->refresh(OmiseCharge::retrieve($id, $this->laravelOmise->getPublicKey(), $this->laravelOmise->getSecretKey()));
$this->refresh(OmiseCharge::retrieve($id, $this->omiseConfig->getPublicKey(), $this->omiseConfig->getSecretKey()));
} catch (Exception $e) {
return new Error([
'code' => 'not_found',
Expand All @@ -76,7 +74,7 @@ public function find($id, $storeId = null)
public function create($params)
{
try {
$this->refresh(OmiseCharge::create($params, $this->laravelOmise->getPublicKey(), $this->laravelOmise->getSecretKey()));
$this->refresh(OmiseCharge::create($params, $this->omiseConfig->getPublicKey(), $this->omiseConfig->getSecretKey()));
} catch (Exception $e) {
return new Error([
'code' => 'bad_request',
Expand Down
12 changes: 6 additions & 6 deletions src/Omise/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

use Exception;
use OmiseCustomer;
use Soap\LaravelOmise\LaravelOmise;
use Soap\LaravelOmise\OmiseConfig;

class Customer extends BaseObject
{
private $laravelOmise;
private $omiseConfig;

/**
* Injecting dependencies
*/
public function __construct(LaravelOmise $laravelOmise)
public function __construct(OmiseConfig $omiseConfig)
{
$this->laravelOmise = $laravelOmise;
$this->omiseConfig = $omiseConfig;
}

/**
Expand All @@ -25,7 +25,7 @@ public function __construct(LaravelOmise $laravelOmise)
public function find($id)
{
try {
$this->refresh(OmiseCustomer::retrieve($id, $this->laravelOmise->getPublicKey(), $this->laravelOmise->getSecretKey()));
$this->refresh(OmiseCustomer::retrieve($id, $this->omiseConfig->getPublicKey(), $this->omiseConfig->getSecretKey()));
} catch (Exception $e) {
return new Error([
'code' => 'not_found',
Expand All @@ -43,7 +43,7 @@ public function find($id)
public function create($params)
{
try {
$this->refresh(OmiseCustomer::create($params, $this->laravelOmise->getPublicKey(), $this->laravelOmise->getSecretKey()));
$this->refresh(OmiseCustomer::create($params, $this->omiseConfig->getPublicKey(), $this->omiseConfig->getSecretKey()));
} catch (Exception $e) {
return new Error([
'code' => 'bad_request',
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelOmise.php → src/OmiseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Soap\LaravelOmise;

class LaravelOmise
class OmiseConfig
{
protected static $url;

Expand Down

0 comments on commit 968ab1c

Please sign in to comment.