/
OmiseExt.php
155 lines (141 loc) · 4.86 KB
/
OmiseExt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* This file is part of EC-CUBE Plugin OmiseExt
*
* @copyright 2016 Omise All Rights Reserved.
* @author Akira Narita
*
*/
require_once PLUGIN_UPLOAD_REALDIR . "OmiseExt/inc/include.php";
require_once OMISE_CLASS_REALDIR . "OmiseWrapper.php";
require_once OMISE_MODELS_REALDIR . "Omise_Models_Charge.php";
require_once OMISE_MODELS_REALDIR . "Omise_Models_Customer.php";
class OmiseExt extends SC_Plugin_Base
{
/**
* install will execute on plugin installation.
*
* @param array $arrPlugin plugin_infoを元にDBに登録されたプラグイン情報(dtb_plugin)
* @return void
*/
public function install($arrPlugin)
{
OmiseConfig::getInstance()->install($arrPlugin);
}
/**
* uninstall will ececute on uninstalltion
*
* @param array $arrPlugin プラグイン情報の連想配列(dtb_plugin)
* @return void
*/
public function uninstall($arrPlugin)
{
OmiseConfig::getInstance()->uninstall($arrPlugin);
}
/**
* 稼働
* enableはプラグインを有効にした際に実行されます.
* 引数にはdtb_pluginのプラグイン情報が渡されます.
*
* @param array $arrPlugin プラグイン情報の連想配列(dtb_plugin)
* @return void
*/
public function enable($arrPlugin)
{
OmiseConfig::getInstance()->enableOmisePayment($arrPlugin);
}
/**
* 停止
* disableはプラグインを無効にした際に実行されます.
* 引数にはdtb_pluginのプラグイン情報が渡されます.
*
* @param array $arrPlugin プラグイン情報の連想配列(dtb_plugin)
* @return void
*/
public function disable($arrPlugin)
{
OmiseConfig::getInstance()->disableOmisePayment($arrPlugin);
}
/* -------------------- Hook Points -------------------- */
/**
* prefilterコールバック関数
* テンプレートの変更処理を行います.
*
* @param string &$source テンプレートのHTMLソース
* @param LC_Page_Ex $objPage ページオブジェクト
* @param string $filename テンプレートのファイル名
* @return void
*/
public function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename)
{
$objTransform = new SC_Helper_Transform($source);
switch ($objPage->arrPageLayout['device_type_id']) {
case DEVICE_TYPE_MOBILE:
case DEVICE_TYPE_SMARTPHONE:
case DEVICE_TYPE_PC:
break;
case DEVICE_TYPE_ADMIN:
case null: // 未設定は admin
if (strpos($filename, 'order/edit.tpl') !== false) {
// 個別受注画面に OmiseのChargeを連携させる
$template = OMISE_TEMPLATES_REALDIR . 'admin/omiseext_admin_order_charge_add.tpl';
$objTransform->select('div#order')->appendFirst(file_get_contents($template));
}
break;
default:
break;
}
// 変更を実行します
$source = $objTransform->getHTML();
}
/**
* hook function called before LC_Page_Admin_Order_Edit
* Send requests to Omise if mode is of plg_omiseext
*/
public function beforeAdminOrderEdit(LC_Page_Ex $objPage)
{
// Capture the Omise Charge
// 実売上化
if ($objPage->getMode() === 'plg_omiseext_capture') {
$_GET['mode'] = 'recalculate';
$order_id = $_POST['order_id'];
if (empty($order_id)) {
return;
}
$objCharge = new Omise_Models_Charge($order_id);
$message = $objCharge->capture();
if ($message !== null) {
$objPage->plg_omiseext_capture_error = $message;
}
}
// Refund the Omise Charge
// 全額返金
if ($objPage->getMode() === 'plg_omiseext_refund') {
$_GET['mode'] = 'recalculate';
$order_id = $_POST['order_id'];
if (empty($order_id)) {
return;
}
$objCharge = new Omise_Models_Charge($order_id);
$message = $objCharge->refund();
if ($message !== null) {
$objPage->plg_omiseext_refund_error = $message;
}
}
}
/**
* hook function called after LC_Page_Admin_Order_Edit
* Set template variables to show Omise charge statuses
*/
public function afterAdminOrderEdit(LC_Page_Ex $objPage)
{
$order_id = $objPage->arrForm['order_id']['value'];
if (empty($order_id)) {
return;
}
$objCharge = new Omise_Models_Charge($order_id);
// Sync Omise Charge data with ECCUBE db
$objCharge->syncOmise();
$objPage->plg_omiseext_objCharge = $objCharge;
}
}