-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcivicrm_esunbank.install
185 lines (169 loc) · 6.17 KB
/
civicrm_esunbank.install
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
// $Id: devel.install,v 1.24.2.7 2009/07/30 19:38:48 weitzman Exp $
/**
* @file
* Install file for civicrm_esunbank module.
*/
/**
* Implementation of hook_schema()
*/
function civicrm_esunbank_schema(){
$schema['civicrm_contribution_esunbank'] = array(
'fields' => array(
'cid' => array(
'description' => 'Contribution id for civicrm',
'type' => 'int',
'length' => '11',
'not null' => TRUE,
),
'created' => array(
'description' => 'Submit time for user confirmed transaction.',
'type' => 'int',
'length' => '11',
'not null' => FALSE,
),
'process_date' => array(
'description' => 'System process date',
'type' => 'datetime',
'not null' => FALSE,
),
'instrument' => array(
'description' => 'Payment instrument from esunbank',
'type' => 'varchar',
'length' => '64',
'not null' => FALSE,
),
'sequence' => array(
'description' => 'Sequence number',
'type' => 'int',
'length' => '11',
'not null' => FALSE,
),
'serial' => array(
'description' => 'Payment serial number.',
'type' => 'varchar',
'length' => '16',
'not null' => FALSE,
),
'amount' => array(
'description' => 'Payment amount.',
'type' => 'int',
'length' => '11',
'not null' => FALSE,
),
'payment_datetime' => array(
'description' => 'User real transaction date time',
'type' => 'datetime',
'not null' => FALSE,
),
'data' => array(
'description' => 'Original data from payment gateway. Only support bank, convinent store, postoffice.',
'type' => 'text',
'not null' => FALSE,
),
),
'primary key' => array('cid'),
'mysql_suffix' => 'ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci',
);
return $schema;
}
/**
* Implementation of hook_install()
*/
function civicrm_esunbank_install() {
drupal_install_schema('civicrm_esunbank');
civicrm_initialize( );
require_once "CRM/Core/DAO.php";
require_once('CRM/Core/OptionValue.php');
require_once('CRM/Core/Action.php');
// new payment processor
$sql = "INSERT INTO civicrm_payment_processor_type
(name, title, description, is_active, is_default, user_name_label, password_label, signature_label, subject_label, class_name, url_site_default, url_api_default, url_recur_default, url_button_default, url_site_test_default, url_api_test_default, url_recur_test_default, url_button_test_default, billing_mode, is_recur, payment_type)
VALUES
('ESUNBANK', '玉山銀行代收', NULL, 1, 0, '企業識別碼', '虛擬帳號長度', '檢核規則', '超商代碼', 'Payment_ESUNBANK', '', NULL, NULL, NULL, '', NULL, NULL, NULL, 4, 0, 1)";
CRM_Core_DAO::executeQuery($sql);
$ppt_id = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_payment_processor_type WHERE name LIKE 'ESUNBANK'");
// insert new msg template
$group_params = array(
'name' => 'msg_tpl_workflow_invoice',
'label' => '繳款單工作流程範本',
'description' => '捐款或活動繳費單的工作流程範本',
'is_active' => TRUE,
'is_reserved' => 0,
);
$option_params = array(
'label' => '繳款單-玉山銀行便利商店/ATM/銀行代收繳款單',
'name' => 'invoice_esunbank',
'is_active' => TRUE,
);
$action = CRM_Core_Action::ADD;
$option_id = 0;
$option = CRM_Core_OptionValue::addOptionValue($option_params, $group_params, $action, $option_id);
$params = array(
'msg_title' => '玉山銀行繳款單',
'msg_subject' => '便利商店/ATM/銀行代收 繳款單',
'msg_text' => "謝謝您的支持,請您至以下網址列印繳費單\n".'{$invoice_link}',
'msg_html' => '{$invoice_html}',
'is_active' => TRUE,
'workflow_id' => $option->id,
'is_default' => 1,
'is_reserved' => 0,
);
// add default template
CRM_Core_BAO_MessageTemplates::add($params);
$params['is_default'] = 0;
$params['is_reserved'] = 1;
// add reserved template
CRM_Core_BAO_MessageTemplates::add($params);
$gid = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_option_group WHERE name LIKE 'payment_instrument'");
$group_params = array('name' => 'payment_instrument');
$params = array(
'name' => 'Esunbank',
'label' => '玉山',
'is_active' => 1,
'is_reserved' => 1,
);
$dao = CRM_Core_DAO::executeQuery("SELECT id, value FROM civicrm_option_value WHERE option_group_id = {$gid} AND name = 'Esunbank'");
$dao->fetch();
if($dao->id){
$params['value'] = $dao->value;
$action = CRM_Core_Action::UPDATE;
$option_value_id = $dao->id;
}
else{
$action = CRM_Core_Action::ADD;
$option_value_id = 0;
}
CRM_Core_OptionValue::addOptionValue($params, $group_params, $action, $option_value_id);
}
/**
* Implementation of hook_uninstall().
*/
function civicrm_esunbank_uninstall() {
civicrm_initialize();
require_once "CRM/Core/DAO.php";
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_payment_processor_type WHERE name LIKE 'ESUNBANK'");
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_payment_processor WHERE payment_processor_type LIKE 'ESUNBANK'");
CRM_Core_DAO::executeQuery("OPTIMIZE TABLE civicrm_payment_processor_type");
// we won't delete instrument for preserve contribution record
// delete schema from drupal
drupal_uninstall_schema('civicrm_esunbank');
}
/**
* Implementation of hook_enable().
*/
function civicrm_esunbank_enable() {
civicrm_initialize();
require_once "CRM/Core/DAO.php";
CRM_Core_DAO::executeQuery("UPDATE civicrm_payment_processor_type SET is_active = 1 WHERE name LIKE 'ESUNBANK'");
CRM_Core_DAO::executeQuery("UPDATE civicrm_payment_processor SET is_active = 1 WHERE payment_processor_type LIKE 'ESUNBANK'");
}
/**
* Implementation of hook_disable().
*/
function civicrm_esunbank_disable() {
civicrm_initialize();
require_once "CRM/Core/DAO.php";
CRM_Core_DAO::executeQuery("UPDATE civicrm_payment_processor_type SET is_active = 0 WHERE name LIKE 'ESUNBANK'");
CRM_Core_DAO::executeQuery("UPDATE civicrm_payment_processor SET is_active = 0 WHERE payment_processor_type LIKE 'ESUNBANK'");
}