/
inspirepay.inc.php
210 lines (191 loc) · 7.66 KB
/
inspirepay.inc.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
if (!defined('INCLUDED_AMEMBER_CONFIG'))
die("Direct access to this location is not allowed");
/*
*
*
* Author: Alex Scott
* Email: alex@cgi-central.net
* Web: http://www.cgi-central.net
* Details: inspirepay payment plugin
* FileName $RCSfile: inspirepay.inc.php,v $
* Release: @VERSION@ ($Revision: 1.1.2.17 $)
*
* Please direct bug reports,suggestions or feedback to the cgi-central forums.
* http://www.cgi-central.net/forum/
*
* aMember PRO is a commercial software. Any distribution is strictly prohibited.
*
*/
global $config;
require_once($config['root_dir']."/plugins/payment/cc_core/cc_core.inc.php");
class payment_inspirepay extends amember_payment {
function do_payment($payment_id, $member_id, $product_id,
$price, $begin_date, $expire_date, &$vars){
return cc_core_do_payment('inspirepay', $payment_id, $member_id, $product_id,
$price, $begin_date, $expire_date, $vars);
}
function get_cancel_link($payment_id){
global $db;
return cc_core_get_cancel_link('inspirepay', $payment_id);
}
function get_plugin_features(){
return array(
'title' => 'Inspire Pay',
'description' => 'Credit card payment',
'phone' => 2,
'code' => 1,
'name_f' => 2
);
}
function void_transaction($payment_id, &$log){
$vars = array(
"type" => 'void',
"username" => $this->config['login'],
"password" => $this->config['pass'],
"transactionid" => $payment_id,
);
$log[] = $vars;
$res = $this->run_transaction($vars);
return $res;
}
function run_transaction($vars){
foreach ($vars as $kk=>$vv){
$v = urlencode($vv);
$k = urlencode($kk);
$vars1[] = "$k=$v";
}
$vars1 = join('&', $vars1);
$ret = cc_core_get_url("https://secure.inspiregateway.net/api/transact.php", $vars1);
parse_str($ret, $res);
return $res;
}
/*************************************************************
cc_bill - do real cc bill
***************************************************************/
function cc_bill($cc_info, $member, $amount,
$currency, $product_description,
$charge_type, $invoice, $payment){
global $config;
$log = array();
//////////////////////// cc_bill /////////////////////////
srand(time());
if ($charge_type == CC_CHARGE_TYPE_TEST)
$amount = "1.00";
$vars = array(
"type" => 'sale',
"username" => $this->config['login'],
"password" => $this->config['pass'],
"orderid" => $payment['payment_id'],
"amount" => $amount,
"orderdescription" => $product_description
);
if($charge_type == CC_CHARGE_TYPE_RECURRING){
$vars['customer_vault_id'] = $member['data']['inspirepay_customer_vault_id'];
}else{
$vars +=array(
"ccnumber" => $cc_info['cc_number'],
"ccexp" => $cc_info['cc-expire'],
"email" => $member['email'],
"firstname" => $cc_info['cc_name_f'],
"lastname" => $cc_info['cc_name_l'],
"address1" => $cc_info['cc_street'],
"city" => $cc_info['cc_city'],
"state" => $cc_info['cc_state'],
"zip" => $cc_info['cc_zip'],
"country" => $cc_info['cc_country'],
"ipaddress" => $member['remote_addr'] ? $member['remote_addr'] : $_SERVER['REMOTE_ADDR'],
"phone" => $cc_info['cc_phone']
);
if ($cc_info['cc_code'])
$vars['cvv'] = $cc_info['cc_code'];
}
// prepare log record
$vars_l = $vars;
if($vars['ccnumber'])
$vars_l['ccnumber'] = $cc_info['cc'];
if ($vars['cvv'])
$vars_l['cvv'] = preg_replace('/./', '*', $vars['cvv']);
$log[] = $vars_l;
/////
$res = $this->run_transaction($vars);
$log[] = $res;
if ($res['response'] == '1'){
if ($charge_type == CC_CHARGE_TYPE_TEST)
$this->void_transaction($res['transactionid'], $log);
return array(CC_RESULT_SUCCESS, "", $res['transactionid'], $log);
} elseif ($res['response'] == '2') {
return array(CC_RESULT_DECLINE_PERM, $res['responsetext'], "", $log);
} else {
return array(CC_RESULT_INTERNAL_ERROR, $res['responsetext'], "", $log);
}
}
function save_cc_info($cc_info, $member){
if(!$member['data']['inspirepay_customer_vault_id']){
$this->add_customer($member, $cc_info);
}else{
$this->update_customer($member, $cc_info);
}
}
function add_customer($member, $cc_info){
global $db;
$vars = array(
'customer_vault' => 'add_customer',
'username' => $this->config['login'],
'password' => $this->config['pass'],
'ccnumber' => $cc_info['cc_number'],
'ccexp' => $cc_info['cc-expire'],
'email' => $member['email'],
'firstname' => $cc_info['cc_name_f'],
'lastname' => $cc_info['cc_name_l'],
'address1' => $cc_info['cc_street'],
'city' => $cc_info['cc_city'],
'state' => $cc_info['cc_state'],
'zip' => $cc_info['cc_zip'],
'country' => $cc_info['cc_country'],
'ipaddress' => $member['remote_addr'] ? $member['remote_addr'] : $_SERVER['REMOTE_ADDR'],
'phone' => $cc_info['cc_phone']
);
if ($cc_info['cc_code'])
$vars['cvv'] = $cc_info['cc_code'];
$resp = $this->run_transaction($vars);
if($resp['response'] == 1 && $resp['customer_vault_id']){
$member['data']['inspirepay_customer_vault_id'] = $resp['customer_vault_id'];
$db->update_user($member['member_id'], $member);
}
return $resp;
}
function update_customer($member, $cc_info){
global $db;
$vars = array(
'customer_vault' => 'update_customer',
'customer_vault_id' => $member['data']['inspirepay_customer_vault_id'],
'username' => $this->config['login'],
'password' => $this->config['pass'],
'ccnumber' => $cc_info['cc_number'],
'ccexp' => $cc_info['cc-expire'],
'email' => $member['email'],
'firstname' => $cc_info['cc_name_f'],
'lastname' => $cc_info['cc_name_l'],
'address1' => $cc_info['cc_street'],
'city' => $cc_info['cc_city'],
'state' => $cc_info['cc_state'],
'zip' => $cc_info['cc_zip'],
'country' => $cc_info['cc_country'],
'ipaddress' => $member['remote_addr'] ? $member['remote_addr'] : $_SERVER['REMOTE_ADDR'],
'phone' => $cc_info['cc_phone']
);
if ($cc_info['cc_code'])
$vars['cvv'] = $cc_info['cc_code'];
$resp = $this->run_transaction($vars);
return $resp;
}
}
function inspirepay_get_member_links($user){
return cc_core_get_member_links('inspirepay', $user);
}
function inspirepay_rebill(){
return cc_core_rebill('inspirepay');
}
cc_core_init('inspirepay');
add_member_field("inspirepay_customer_vault_id", "Inspire Pay Customer Vault ID", "text");