Skip to content

Commit

Permalink
Merge pull request #13 from omise/release/1.5.0.2
Browse files Browse the repository at this point in the history
Upgrade Omise-PHP version to 2.4.0 & Improve the checkout process.
  • Loading branch information
guzzilar committed Nov 16, 2015
2 parents 0b65bf9 + 3797b1a commit a6b09e4
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 641 deletions.
31 changes: 16 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
Change Log
==========

[1.5.0.1] - 2015-08-03
[1.5.0.2] 2015-11-16
----------------------
#### Updates
- *`Added`* Added `OMISE_USER_AGENT_SUFFIX` and `OMISE_API_VERSION` into the `user-agent` when request to the OMISE APIs
- *`Updated`* Updated checkout display, add `secured by Omise` logo into checkout form.
- *`Updated`* Upgrade `omise-php` library from 2.3.1 to 2.4.0.
- *`Fixed`* Improved the checkout process.

#### Versioning & Document
- *`Updated`* Updated the omise-opencart version number to `1.5.0.1`

#### Dependencies
- *`Updated`* Updated `omise-php` library from 2.1.2 to 2.3.1


[1.5.0.0] - 2015-07-06
[1.5.0.1] 2015-08-03
----------------------
#### Updates
- *`Updated`* Updated the omise-opencart version number to `1.5.0.1`.
- *`Updated`* Updated `omise-php` library from 2.1.2 to 2.3.1.

#### Versioning & Document
- *`Updated`* Updated the omise-opencart version number to `1.5.0.0`

[1.5.0.0] 2015-07-06
----------------------
#### Updates
- *`Updated`* Updated the omise-opencart version number to `1.5.0.0`.

[1.0] - 2015-05-18
[1.0] 2015-05-18
------------------

#### Featured
Implemented the Omise services into OpenCart 1.5.x, The features are as follows:
- *`Added`* Implemented **Omise Dashboard** into OpenCart's admin page.
Expand All @@ -31,7 +32,7 @@ Implemented the Omise services into OpenCart 1.5.x, The features are as follows:
- *`Added`* Implemented **Omise Keys Setting page** into OpenCart's admin page.
- *`Added`* Added **Omise menu** into top bar menu of OpenCart's admin page.
- *`Added`* Added **Omise Payment Gateway Module Configuration** into OpenCart's admin page in Extensions > Payments page.
- *`Added`* Implemented **Omise Charge API** (supported for `Authorize & Capture` method only)
- *`Added`* Implemented **Omise Charge API** (supported for `Authorize & Capture` method only).
- *`Added`* Added **Omise Checkout Form** into OpenCart's checkout page.
- *`Added`* Added [omise-php](https://github.com/omise/omise-php) library *(v2.1.2)* into this extension.
- *`Added`* Added **README.md** file.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- OpenCart 1.5.x

## Dependencies (Already included in Omise-OpenCart)
- [omise-php](https://github.com/omise/omise-php) (v2.3.1)
- [omise-php](https://github.com/omise/omise-php) (v2.4.0)
- [Jquery](https://github.com/jquery/jquery) (v1.7.1 from OpenCart (v1.5.6.4)'s dependency)
- [vQmod](https://github.com/vqmod/vqmod) (v2.5.1 with OpenCart integration edition)

Expand All @@ -14,8 +14,8 @@ Follow these steps to install **omise-opencart**:
1. Download this repository and unzip it into your `local machine` (or directly to your server)

Download links:
[omise-opencart-v1.5.0.1.zip](https://github.com/omise/omise-opencart/archive/v1.5.0.1.zip) or
[omise-opencart-v1.5.0.1.tar.gz](https://github.com/omise/omise-opencart/archive/v1.5.0.1.tar.gz)
[omise-opencart-v1.5.0.2.zip](https://github.com/omise/omise-opencart/archive/v1.5.0.2.zip) or
[omise-opencart-v1.5.0.2.tar.gz](https://github.com/omise/omise-opencart/archive/v1.5.0.2.tar.gz)

![omise-opencart Folder Structure](https://omise-cdn.s3.amazonaws.com/assets/omise-opencart/omise-opencart-install-01.png)

Expand Down
7 changes: 7 additions & 0 deletions src/admin/model/payment/omise.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
// Define 'OMISE_USER_AGENT_SUFFIX'
if(!defined('OMISE_USER_AGENT_SUFFIX') && defined('VERSION'))
define('OMISE_USER_AGENT_SUFFIX', 'OmiseOpenCart/1.5.0.2 OpenCart/'.VERSION);

// Define 'OMISE_API_VERSION'
if(!defined('OMISE_API_VERSION'))
define('OMISE_API_VERSION', '2014-07-27');

class ModelPaymentOmise extends Model
{
Expand Down
110 changes: 80 additions & 30 deletions src/catalog/controller/payment/omise.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ class ControllerPaymentOmise extends Controller
*/
public function checkout()
{
// Define 'OMISE_USER_AGENT_SUFFIX'
if(!defined('OMISE_USER_AGENT_SUFFIX') && defined('VERSION'))
define('OMISE_USER_AGENT_SUFFIX', 'OmiseOpenCart/1.5.0.2 OpenCart/'.VERSION);

// Define 'OMISE_API_VERSION'
if(!defined('OMISE_API_VERSION'))
define('OMISE_API_VERSION', '2014-07-27');

// If has a `post['omise_token']` request.
if (isset($this->request->post['omise_token'])) {
// Load `omise-php` library.
Expand All @@ -25,43 +33,85 @@ public function checkout()

// Create a order history with `Processing` status
$this->load->model('checkout/order');
$this->model_checkout_order->confirm($this->session->data['order_id'], 2);

try {
// Try to create a charge and capture it.
$omise_charge = OmiseCharge::create(
array(
"amount" => $this->request->post['amount'],
"currency" => "thb",
"description" => $this->request->post['description'],
"card" => $this->request->post['omise_token']
),
$omise['public_key'],
$omise['secret_key']
);

if (is_null($omise_charge['failure_code']) && is_null($omise_charge['failure_code']) && $omise_charge['captured'])
$this->model_checkout_order->update($this->session->data['order_id'], 15);
else
$this->model_checkout_order->update($this->session->data['order_id'], 10);
$order_id = $this->session->data['order_id'];
$order_info = $this->model_checkout_order->getOrder($order_id);
$order_total = number_format($order_info['total'], 2, '', '');

if ($order_info) {
try {
// Try to create a charge and capture it.
$omise_charge = OmiseCharge::create(
array(
"amount" => $order_total,
"currency" => 'thb',
"description" => $this->request->post['description'],
"card" => $this->request->post['omise_token']
),
$omise['public_key'],
$omise['secret_key']
);

if (is_null($omise_charge['failure_code']) && is_null($omise_charge['failure_code']) && $omise_charge['captured']) {
// Status: processed.
$this->model_checkout_order->confirm($order_id, 15);
} else {
// Status: failed.
$this->model_checkout_order->update($order_id, 10);
}

echo json_encode(
array(
'failure_code' => $omise_charge['failure_code'],
'failure_message' => $omise_charge['failure_message'],
'captured' => $omise_charge['captured'],
'omise' => $omise_charge
)
);
} catch (Exception $e) {
$this->model_checkout_order->update($this->session->data['order_id'], 10);
echo json_encode(array('error' => $e->getMessage()));
echo json_encode(
array(
'failure_code' => $omise_charge['failure_code'],
'failure_message' => $omise_charge['failure_message'],
'captured' => $omise_charge['captured'],
'omise' => $omise_charge
)
);
} catch (Exception $e) {
// Status: failed.
$this->model_checkout_order->update($this->session->data['order_id'], 10);
echo json_encode(array('error' => $e->getMessage()));
}
} else {
echo json_encode(array('error' => 'Cannot find your order, please try again.'));
}
} else {
return 'not authorized';
}
}

/**
* Retrieve list of months translation
*
* @return array
*/
public function getMonths()
{
$months = array();
for ($index=1; $index <= 12; $index++) {
$month = ($index < 10) ? '0'.$index : $index;
$months[$month] = $month;
}
return $months;
}

/**
* Retrieve array of available years
*
* @return array
*/
public function getYears()
{
$years = array();
$first = date("Y");

for ($index=0; $index <= 10; $index++) {
$year = $first + $index;
$years[$year] = $year;
}
return $years;
}

/**
* Omise card information form
* @return void
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions src/catalog/view/theme/default/template/payment/omise.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
// Token was created. Then, charge a card with token.
var posting = $.post("<?php echo $checkout_url; ?>", {
"omise_token": response.id,
"amount": "<?php echo str_replace('.', '', $orderamount); ?>",
"description": "Charge a card from OpenCart that order id is <?php echo $orderid; ?> from <?php echo $billemail; ?>"
});
Expand Down Expand Up @@ -88,7 +87,7 @@
<!-- Omise's checkout form -->
<form id="omise-form-checkout" method="post" action="<?php echo $success_url; ?>">
<img src="catalog/view/theme/default/image/secured_by_omise.png" width="200">
<!-- Collect a customer's card -->
<div class="omise-payment">
<h3>Card Information</h3>
Expand Down Expand Up @@ -120,8 +119,16 @@
<div class="input-group clearfix">
<div class="left"><label>Expire Date</label></div>
<div class="right">
<input type="text" data-omise="expiration_month" size="4" style="width: 10%;" placeholder="dd" value="" class="input-omise-collect-expiration-month"> /
<input type="text" data-omise="expiration_year" size="8" style="width: 10%;" placeholder="YYYY" value="" class="input-omise-collect-expiration-year">
<select data-omise="expiration_month" class="input-omise-collect-expiration-month"> >
<?php foreach ($this->getMonths() as $k=>$v): ?>
<option value="<?php echo $k?$k:'' ?>"><?php echo $v ?></option>
<?php endforeach ?>
</select>
<select data-omise="expiration_year" class="input-omise-collect-expiration-year">
<?php foreach ($this->getYears() as $k=>$v): ?>
<option value="<?php echo $k?$k:'' ?>"><?php echo $v ?></option>
<?php endforeach ?>
</select>
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions src/system/library/omise/omise-php/.gitignore

This file was deleted.

7 changes: 6 additions & 1 deletion src/system/library/omise/omise-php/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log

An [unreleased] version is not available on `master` branch. Elements of unreleased list may be edited or removed at any time.
## [2.4.0] 2015-11-13
- [Added] Add Omise-Version header to request.
- [Added] Add `OMISE_USER_AGENT_SUFFIX` constant that let's people add the suffix into the `user-agent` string.

## [2.3.2] 2015-09-30
- [Fixed] Pass key values into the OmiseRefundList object when call a refunds() method inside the OmiseCharge instance.

## [2.3.1] 2015-07-29
- [Added] New DigiCert CA certificates.
Expand Down
18 changes: 18 additions & 0 deletions src/system/library/omise/omise-php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ require_once dirname(__FILE__).'/omise-php/lib/Omise.php';

Please see usage section below for usage examples.

### API version

You can choose which API version to use with Omise. Each API version has new features and might not be compatible with previous versions. You can change the default version by visiting your Omise Dashboard.

To overwrite the API version to use, you can specify it by defining OMISE_API_VERSION.
The version configured here will have higher priority than the version set in your Omise account.
This is useful if you have multiple environments with different API versions for testing.
(e.g. Development on the latest version but production is on an older version).

```php
require_once dirname(__FILE__).'/omise-php/lib/Omise.php';

define('OMISE_API_VERSION', '2014-07-27');
```

It is highly recommended to set this version to the current version
you're using.

## Usage

### 1. Flow
Expand Down
9 changes: 0 additions & 9 deletions src/system/library/omise/omise-php/circle.yml

This file was deleted.

19 changes: 0 additions & 19 deletions src/system/library/omise/omise-php/composer.lock

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function capture() {
*/
public function refunds() {
$result = parent::execute(self::getUrl($this['id']).'/refunds', parent::REQUEST_GET, parent::getResourceKey());
return new OmiseRefundList($result, $this['id']);
return new OmiseRefundList($result, $this['id'], $this->_publickey, $this->_secretkey);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
require_once dirname(__FILE__).'/obj/OmiseObject.php';
require_once dirname(__FILE__).'/../exception/OmiseExceptions.php';

define('OMISE_PHP_LIB_VERSION', '2.3.1');
define('OMISE_API_VERSION', '2014-07-27');
define('OMISE_PHP_LIB_VERSION', '2.4.0');
define('OMISE_API_URL', 'https://api.omise.co/');
define('OMISE_VAULT_URL', 'https://vault.omise.co/');

Expand Down Expand Up @@ -208,13 +207,14 @@ private function _executeTest($url, $requestMethod, $key, $params = null) {
* @return array
*/
private function genOptions($requestMethod, $userpwd, $params) {
$user_agent = "OmisePHP/".OMISE_PHP_LIB_VERSION;
$omise_api_version = defined('OMISE_API_VERSION') ? OMISE_API_VERSION : null;

$options = array(
// Set the HTTP version to 1.1.
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
// Set the request method.
CURLOPT_CUSTOMREQUEST => $requestMethod,
// Set the user agent.
CURLOPT_USERAGENT => "OmiseOpenCart/1.5.0.1 OmisePHP/".OMISE_PHP_LIB_VERSION." OmiseAPI/".OMISE_API_VERSION,
// Make php-curl returns the data as string.
CURLOPT_RETURNTRANSFER => true,
// Do not include the header in the output.
Expand All @@ -234,6 +234,19 @@ private function genOptions($requestMethod, $userpwd, $params) {
CURLOPT_CAINFO => dirname(__FILE__).'/../../../data/ca_certificates.pem'
);

// Config Omise API Version
if ($omise_api_version) {
$options += array(CURLOPT_HTTPHEADER => array("Omise-Version: ".$omise_api_version));

$user_agent .= ' OmiseAPI/'.$omise_api_version;
}

// Config UserAgent
if (defined('OMISE_USER_AGENT_SUFFIX'))
$options += array(CURLOPT_USERAGENT => $user_agent." ".OMISE_USER_AGENT_SUFFIX);
else
$options += array(CURLOPT_USERAGENT => $user_agent);

// Also merge POST parameters with the option.
if(count($params) > 0) $options += array(CURLOPT_POSTFIELDS => http_build_query($params));

Expand Down
Loading

0 comments on commit a6b09e4

Please sign in to comment.