phpmob / omise
Just alternative Omise api client
Requires
- php: ^7.1
- doctrine/inflector: ^1.1
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.0
- php-http/httplug: ^1.0
- psr/http-message: ^1.0
- symfony/options-resolver: ^3.3
Requires (Dev)
- php-http/guzzle6-adapter: ^1.1
- phpspec/phpspec: ^4.0
- phpunit/phpunit: ^5.6
- sylius-labs/coding-standard: ^1.0
- symfony/property-access: ^3.3
- symfony/validator: ^3.3
Suggests
- php-http/guzzle6-adapter: To use built-in \PhpMob\Omise\Client\GuzzleHttpClient.
This package is auto-updated.
Last update: 2024-12-19 00:13:45 UTC
README
Just alternative Omise api client - in php.
Installation
Install via composer.
$ composer require phpmob/omise
To use guzzlehttp/guzzle you need to install it's adapter. Thanks httplug.
$ composer require php-http/guzzle6-adapter
Now you can use built-in \PhpMob\Omise\Client\GuzzleHttpClient
.
Usage
A phpmob/omise desinged for Solid
use and also add bonus for Static big fan use by implementing Facade
.
Solid Usage
<?php use PhpMob\Omise\Api\Charge as ChargeApi; use PhpMob\Omise\Api\Token as TokenApi; use PhpMob\Omise\Domain\Card; use PhpMob\Omise\Domain\Charge; use PhpMob\Omise\Domain\Token; use PhpMob\Omise\OmiseApi; use PhpMob\Omise\Client\GuzzleHttpClient; $client = new GuzzleHttpClient(); $options = [ 'secret_key' => 'secretKey', 'public_key' => 'publicKey', 'sandbox' => true, // livemode? ]; $api = new OmiseApi($client, $options); /** @var TokenApi $tokenApi */ $tokenApi = $api->create(TokenApi::class); // create token $token = new Token(); $token->card = new Card(); $token->card->name = 'Somchai Prasert'; $token->card->number = '4242424242424242'; $token->card->city = 'Bangkok'; $token->card->postalCode = '10320'; $token->card->expirationMonth = 10; $token->card->expirationYear = 2018; $token->card->securityCode = 123; $tokenApi->create($token); /** @var ChargeApi $chargeApi */ $chargeApi = $api->create(ChargeApi::class); // find single $charge = $chargeApi->find('charge_id'); echo $charge->id; // find all $charges = $chargeApi->all(); // Create charge $charge = new Charge(); $charge->amount = 10000; $charge->currency = 'thb'; $charge->cardToken = $token->id; $chargeApi->create($charge);
Static Usage
<?php use PhpMob\Omise\Facade\Card; use PhpMob\Omise\Facade\Charge; use PhpMob\Omise\Facade\Token; use PhpMob\Omise\OmiseApi; use PhpMob\Omise\Client\GuzzleHttpClient; $client = new GuzzleHttpClient(); $options = [ 'secret_key' => 'secretKey', 'public_key' => 'publicKey', 'sandbox' => true, // livemode? ]; OmiseApi::setupFacade($client, $options); // create token $token = Token::make(); $token->card = Card::make(); $token->card->name = 'Somchai Prasert'; $token->card->number = '4242424242424242'; $token->card->city = 'Bangkok'; $token->card->postalCode = '10320'; $token->card->expirationMonth = 10; $token->card->expirationYear = 2018; $token->card->securityCode = 123; $token->create(); // find single charge $charge = Charge::find('charge_id'); echo $charge->id; // find all $charges = Charge::all(); // Create charge $charge = Charge::make(); $charge->amount = 10000; $charge->currency = 'thb'; $charge->cardToken = $token->id; $charge->create();
Error handling.
A phpmob/omise provide two type of Error handling.
- InvalidRequestArgumentException When you need to capture error before sending request.
- InvalidResponseException When you need to capture error responded from api.
<?php use PhpMob\Omise\Exception\InvalidResponseException; use PhpMob\Omise\Facade\Charge; try { // Create charge $charge = Charge::make(); $charge->amount = 10000; $charge->currency = 'thb'; $charge->cardToken = 'token_id'; $charge->create(); } catch (InvalidResponseException $e) { echo $e->error->message; }
Contributing
Would like to help us and build the developer-friendly php code? Just follow our Coding Standards and test your code — see tests, spec.
Let Fork and PR now!
Coding Standards
When contributing code to PhpMob, you must follow its coding standards.
PhpMob follows the standards defined in the PSR-0, PSR-1 and PSR-2 documents.
TODOs Testing
- Writing spec tests.
- Writing unit tests.
- Add support PHP 5.6?
Tests
$ ./bin/phpspec run -fpretty $ ./bin/phpunit