diff --git a/src/Commands/OmiseAccountCommand.php b/src/Commands/OmiseAccountCommand.php new file mode 100644 index 0000000..4bd09b6 --- /dev/null +++ b/src/Commands/OmiseAccountCommand.php @@ -0,0 +1,39 @@ +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; + } +} diff --git a/src/Facades/Omise.php b/src/Facades/Omise.php new file mode 100644 index 0000000..3d6833f --- /dev/null +++ b/src/Facades/Omise.php @@ -0,0 +1,16 @@ +hasConfigFile() ->hasCommand(OmiseVerifyCommand::class); } + + public function packageRegistered() + { + $this->app->singleton('omise', function ($app) { + return new Omise($app->make(OmiseConfig::class)); + }); + } } diff --git a/src/Omise.php b/src/Omise.php new file mode 100644 index 0000000..aec24e0 --- /dev/null +++ b/src/Omise.php @@ -0,0 +1,32 @@ +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); + } +} diff --git a/src/Omise/Account.php b/src/Omise/Account.php new file mode 100644 index 0000000..31a9cf8 --- /dev/null +++ b/src/Omise/Account.php @@ -0,0 +1,35 @@ +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; + } +} diff --git a/src/Omise/Charge.php b/src/Omise/Charge.php index fe91ab2..11d361f 100644 --- a/src/Omise/Charge.php +++ b/src/Omise/Charge.php @@ -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 @@ -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', @@ -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', diff --git a/src/Omise/Customer.php b/src/Omise/Customer.php index 58333a6..cd4f65a 100644 --- a/src/Omise/Customer.php +++ b/src/Omise/Customer.php @@ -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; } /** @@ -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', @@ -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', diff --git a/src/LaravelOmise.php b/src/OmiseConfig.php similarity index 98% rename from src/LaravelOmise.php rename to src/OmiseConfig.php index a881d74..dfb6541 100644 --- a/src/LaravelOmise.php +++ b/src/OmiseConfig.php @@ -2,7 +2,7 @@ namespace Soap\LaravelOmise; -class LaravelOmise +class OmiseConfig { protected static $url;