Skip to content

Commit a6b09e4

Browse files
committed
Merge pull request #13 from omise/release/1.5.0.2
Upgrade Omise-PHP version to 2.4.0 & Improve the checkout process.
2 parents 0b65bf9 + 3797b1a commit a6b09e4

21 files changed

Lines changed: 159 additions & 641 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
Change Log
22
==========
33

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

7-
#### Versioning & Document
8-
- *`Updated`* Updated the omise-opencart version number to `1.5.0.1`
9-
10-
#### Dependencies
11-
- *`Updated`* Updated `omise-php` library from 2.1.2 to 2.3.1
12-
13-
14-
[1.5.0.0] - 2015-07-06
12+
[1.5.0.1] 2015-08-03
1513
----------------------
14+
#### Updates
15+
- *`Updated`* Updated the omise-opencart version number to `1.5.0.1`.
16+
- *`Updated`* Updated `omise-php` library from 2.1.2 to 2.3.1.
1617

17-
#### Versioning & Document
18-
- *`Updated`* Updated the omise-opencart version number to `1.5.0.0`
19-
18+
[1.5.0.0] 2015-07-06
19+
----------------------
20+
#### Updates
21+
- *`Updated`* Updated the omise-opencart version number to `1.5.0.0`.
2022

21-
[1.0] - 2015-05-18
23+
[1.0] 2015-05-18
2224
------------------
23-
2425
#### Featured
2526
Implemented the Omise services into OpenCart 1.5.x, The features are as follows:
2627
- *`Added`* Implemented **Omise Dashboard** into OpenCart's admin page.
@@ -31,7 +32,7 @@ Implemented the Omise services into OpenCart 1.5.x, The features are as follows:
3132
- *`Added`* Implemented **Omise Keys Setting page** into OpenCart's admin page.
3233
- *`Added`* Added **Omise menu** into top bar menu of OpenCart's admin page.
3334
- *`Added`* Added **Omise Payment Gateway Module Configuration** into OpenCart's admin page in Extensions > Payments page.
34-
- *`Added`* Implemented **Omise Charge API** (supported for `Authorize & Capture` method only)
35+
- *`Added`* Implemented **Omise Charge API** (supported for `Authorize & Capture` method only).
3536
- *`Added`* Added **Omise Checkout Form** into OpenCart's checkout page.
3637
- *`Added`* Added [omise-php](https://github.com/omise/omise-php) library *(v2.1.2)* into this extension.
3738
- *`Added`* Added **README.md** file.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- OpenCart 1.5.x
55

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

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

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

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

src/admin/model/payment/omise.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
// Define 'OMISE_USER_AGENT_SUFFIX'
3+
if(!defined('OMISE_USER_AGENT_SUFFIX') && defined('VERSION'))
4+
define('OMISE_USER_AGENT_SUFFIX', 'OmiseOpenCart/1.5.0.2 OpenCart/'.VERSION);
5+
6+
// Define 'OMISE_API_VERSION'
7+
if(!defined('OMISE_API_VERSION'))
8+
define('OMISE_API_VERSION', '2014-07-27');
29

310
class ModelPaymentOmise extends Model
411
{

src/catalog/controller/payment/omise.php

Lines changed: 80 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ class ControllerPaymentOmise extends Controller
88
*/
99
public function checkout()
1010
{
11+
// Define 'OMISE_USER_AGENT_SUFFIX'
12+
if(!defined('OMISE_USER_AGENT_SUFFIX') && defined('VERSION'))
13+
define('OMISE_USER_AGENT_SUFFIX', 'OmiseOpenCart/1.5.0.2 OpenCart/'.VERSION);
14+
15+
// Define 'OMISE_API_VERSION'
16+
if(!defined('OMISE_API_VERSION'))
17+
define('OMISE_API_VERSION', '2014-07-27');
18+
1119
// If has a `post['omise_token']` request.
1220
if (isset($this->request->post['omise_token'])) {
1321
// Load `omise-php` library.
@@ -25,43 +33,85 @@ public function checkout()
2533

2634
// Create a order history with `Processing` status
2735
$this->load->model('checkout/order');
28-
$this->model_checkout_order->confirm($this->session->data['order_id'], 2);
29-
30-
try {
31-
// Try to create a charge and capture it.
32-
$omise_charge = OmiseCharge::create(
33-
array(
34-
"amount" => $this->request->post['amount'],
35-
"currency" => "thb",
36-
"description" => $this->request->post['description'],
37-
"card" => $this->request->post['omise_token']
38-
),
39-
$omise['public_key'],
40-
$omise['secret_key']
41-
);
42-
43-
if (is_null($omise_charge['failure_code']) && is_null($omise_charge['failure_code']) && $omise_charge['captured'])
44-
$this->model_checkout_order->update($this->session->data['order_id'], 15);
45-
else
46-
$this->model_checkout_order->update($this->session->data['order_id'], 10);
36+
$order_id = $this->session->data['order_id'];
37+
$order_info = $this->model_checkout_order->getOrder($order_id);
38+
$order_total = number_format($order_info['total'], 2, '', '');
39+
40+
if ($order_info) {
41+
try {
42+
// Try to create a charge and capture it.
43+
$omise_charge = OmiseCharge::create(
44+
array(
45+
"amount" => $order_total,
46+
"currency" => 'thb',
47+
"description" => $this->request->post['description'],
48+
"card" => $this->request->post['omise_token']
49+
),
50+
$omise['public_key'],
51+
$omise['secret_key']
52+
);
53+
54+
if (is_null($omise_charge['failure_code']) && is_null($omise_charge['failure_code']) && $omise_charge['captured']) {
55+
// Status: processed.
56+
$this->model_checkout_order->confirm($order_id, 15);
57+
} else {
58+
// Status: failed.
59+
$this->model_checkout_order->update($order_id, 10);
60+
}
4761

48-
echo json_encode(
49-
array(
50-
'failure_code' => $omise_charge['failure_code'],
51-
'failure_message' => $omise_charge['failure_message'],
52-
'captured' => $omise_charge['captured'],
53-
'omise' => $omise_charge
54-
)
55-
);
56-
} catch (Exception $e) {
57-
$this->model_checkout_order->update($this->session->data['order_id'], 10);
58-
echo json_encode(array('error' => $e->getMessage()));
62+
echo json_encode(
63+
array(
64+
'failure_code' => $omise_charge['failure_code'],
65+
'failure_message' => $omise_charge['failure_message'],
66+
'captured' => $omise_charge['captured'],
67+
'omise' => $omise_charge
68+
)
69+
);
70+
} catch (Exception $e) {
71+
// Status: failed.
72+
$this->model_checkout_order->update($this->session->data['order_id'], 10);
73+
echo json_encode(array('error' => $e->getMessage()));
74+
}
75+
} else {
76+
echo json_encode(array('error' => 'Cannot find your order, please try again.'));
5977
}
6078
} else {
6179
return 'not authorized';
6280
}
6381
}
6482

83+
/**
84+
* Retrieve list of months translation
85+
*
86+
* @return array
87+
*/
88+
public function getMonths()
89+
{
90+
$months = array();
91+
for ($index=1; $index <= 12; $index++) {
92+
$month = ($index < 10) ? '0'.$index : $index;
93+
$months[$month] = $month;
94+
}
95+
return $months;
96+
}
97+
98+
/**
99+
* Retrieve array of available years
100+
*
101+
* @return array
102+
*/
103+
public function getYears()
104+
{
105+
$years = array();
106+
$first = date("Y");
107+
108+
for ($index=0; $index <= 10; $index++) {
109+
$year = $first + $index;
110+
$years[$year] = $year;
111+
}
112+
return $years;
113+
}
114+
65115
/**
66116
* Omise card information form
67117
* @return void
65.9 KB
Loading

src/catalog/view/theme/default/template/payment/omise.tpl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
// Token was created. Then, charge a card with token.
5454
var posting = $.post("<?php echo $checkout_url; ?>", {
5555
"omise_token": response.id,
56-
"amount": "<?php echo str_replace('.', '', $orderamount); ?>",
5756
"description": "Charge a card from OpenCart that order id is <?php echo $orderid; ?> from <?php echo $billemail; ?>"
5857
});
5958

@@ -88,7 +87,7 @@
8887

8988
<!-- Omise's checkout form -->
9089
<form id="omise-form-checkout" method="post" action="<?php echo $success_url; ?>">
91-
90+
<img src="catalog/view/theme/default/image/secured_by_omise.png" width="200">
9291
<!-- Collect a customer's card -->
9392
<div class="omise-payment">
9493
<h3>Card Information</h3>
@@ -120,8 +119,16 @@
120119
<div class="input-group clearfix">
121120
<div class="left"><label>Expire Date</label></div>
122121
<div class="right">
123-
<input type="text" data-omise="expiration_month" size="4" style="width: 10%;" placeholder="dd" value="" class="input-omise-collect-expiration-month"> /
124-
<input type="text" data-omise="expiration_year" size="8" style="width: 10%;" placeholder="YYYY" value="" class="input-omise-collect-expiration-year">
122+
<select data-omise="expiration_month" class="input-omise-collect-expiration-month"> >
123+
<?php foreach ($this->getMonths() as $k=>$v): ?>
124+
<option value="<?php echo $k?$k:'' ?>"><?php echo $v ?></option>
125+
<?php endforeach ?>
126+
</select>
127+
<select data-omise="expiration_year" class="input-omise-collect-expiration-year">
128+
<?php foreach ($this->getYears() as $k=>$v): ?>
129+
<option value="<?php echo $k?$k:'' ?>"><?php echo $v ?></option>
130+
<?php endforeach ?>
131+
</select>
125132
</div>
126133
</div>
127134

src/system/library/omise/omise-php/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/system/library/omise/omise-php/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log
22

3-
An [unreleased] version is not available on `master` branch. Elements of unreleased list may be edited or removed at any time.
3+
## [2.4.0] 2015-11-13
4+
- [Added] Add Omise-Version header to request.
5+
- [Added] Add `OMISE_USER_AGENT_SUFFIX` constant that let's people add the suffix into the `user-agent` string.
6+
7+
## [2.3.2] 2015-09-30
8+
- [Fixed] Pass key values into the OmiseRefundList object when call a refunds() method inside the OmiseCharge instance.
49

510
## [2.3.1] 2015-07-29
611
- [Added] New DigiCert CA certificates.

src/system/library/omise/omise-php/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ require_once dirname(__FILE__).'/omise-php/lib/Omise.php';
5656

5757
Please see usage section below for usage examples.
5858

59+
### API version
60+
61+
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.
62+
63+
To overwrite the API version to use, you can specify it by defining OMISE_API_VERSION.
64+
The version configured here will have higher priority than the version set in your Omise account.
65+
This is useful if you have multiple environments with different API versions for testing.
66+
(e.g. Development on the latest version but production is on an older version).
67+
68+
```php
69+
require_once dirname(__FILE__).'/omise-php/lib/Omise.php';
70+
71+
define('OMISE_API_VERSION', '2014-07-27');
72+
```
73+
74+
It is highly recommended to set this version to the current version
75+
you're using.
76+
5977
## Usage
6078

6179
### 1. Flow

src/system/library/omise/omise-php/circle.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)