omise-php
is Omise API library written in PHP.
- PHP 5.3 and above.
- Built-in libcurl support.
You can install the library via Composer. If you don't already have Composer installed, first install it by following one of these instructions depends on your OS of choice:
- Composer installation instruction for Windows
- Composer installation instruction for Mac OS X and Linux
After composer is installed, you can declare Omise-PHP as project dependency by creating a composer.json
with the following content:
{
"require": {
"omise/omise-php": "dev-master"
}
}
Then run the following command to install the Omise-PHP library:
php composer.phar install
You can then add the following line to PHP script to load the library:
require_once dirname(__FILE__).'/vendor/autoload.php';
Please see usage section below for usage examples.
If you're not using Composer, you can also also clone the repository into the directory of your PHP script:
git clone https://github.com/omise/omise-php
However, using Composer is recommended as you can easily keep the library up-to-date. After cloning the repository, you can add the following line to PHP script to load the library:
require_once dirname(__FILE__).'/omise-php/lib/Omise.php';
Please see usage section below for usage examples.
The following flow is recommended in order to comply with the PCI Security Standards. You should never transmit card data through your servers unless you have a valid PCI certificate.
- User enters the credit card information on a form on your site, completely white-label (user never sees Omise).
- The card is sent directly from the browser to Omise server via HTTPS using our Javascript (Omise.js).
- Omise returns a Token that identifies the card and if the card passed the authorization
card.security_code_check
- Your page will send this token to your server to finally make the charge capture.
In step 3, if card.security_code_check
is false
, the card failed the authorization process, probably because of a wrong CVV, wrong expire date or wrong card number. In this case you should display an error message and ask user to enter card again.
In step 4, Omise will make the final capture of the amount. If this fails, but token was authorized, it can be due to card having no funds required for the charge.
Add the following to your PHP script and replace the keys by the one given in Omise dashboard:
define('OMISE_PUBLIC_KEY', 'pkey_XXXXXXXXXXXXXXXXX');
define('OMISE_SECRET_KEY', 'skey_XXXXXXXXXXXXXXXXX');
Once both keys are set, you can now use the API. For example, to create a customer with a card returned from the token API (e.g. via the card.js):
$customer = OmiseCustomer::create(array(
'email' => '[email protected]',
'description' => 'John Doe (id: 30)',
'card' => 'tokn_test_4xs9408a642a1htto8z'
));
To retrieve, update and destroy that customer:
$customer = OmiseCustomer::retrieve('cust_test_4xtrb759599jsxlhkrb');
$customer->update(array('description' => 'John W. Doe'));
$customer->destroy();
$customer->isDestroyed(); // => true
For full usage, please refer to API documentation. You may also refer to example in the tests/Omise
directory.
To run an automated test suite, make sure you already have a PHPUnit in your local machine. Then run the PHPUnit:
phpunit omise-php/tests
If you want to run with a specific test, let's try
phpunit omise-php/tests/omise/AccountTest
See LICENSE.txt