-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubscriptions-twoCheckOut.php
138 lines (112 loc) · 3.07 KB
/
Subscriptions-twoCheckOut.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
<?php
/**
* Pluggable payment gateway for subscriptions paid through 2CheckOut.
*
* @package Wedge
* @copyright 2010 René-Gilles Deberdt, wedge.org
* @license http://wedge.org/license/
* @author see contributors.txt
*/
// This won't be dedicated without this - this must exist in each gateway!
// Wedge Payment Gateway: twocheckout
if (!defined('WEDGE'))
die('Hacking attempt...');
class twocheckout_display
{
public $title = 'twoCheckOut | 2co';
public function getGatewaySettings()
{
global $txt;
$setting_data = array(
array('text', '2co_id', 'subtext' => $txt['2co_id_desc']),
array('text', '2co_password', 'subtext' => $txt['2co_password_desc']),
);
return $setting_data;
}
// Can we accept payments with 2co?
public function gatewayEnabled()
{
global $settings;
return !empty($settings['2co_id']) && !empty($settings['2co_password']);
}
public function fetchGatewayFields($unique_id, $sub_data, $value, $period, $return_url)
{
global $settings, $txt, $boardurl;
$return_data = array(
'form' => 'https://www.2checkout.com/2co/buyer/purchase',
'id' => 'twocheckout',
'hidden' => array(),
'title' => $txt['2co'],
'desc' => $txt['paid_confirm_2co'],
'submit' => $txt['paid_2co_order'],
'javascript' => '',
);
// Now some hidden fields.
$return_data['hidden']['x_login'] = $settings['2co_id'];
$return_data['hidden']['x_invoice_num'] = $unique_id;
$return_data['hidden']['x_amount'] = $value;
$return_data['hidden']['x_Email'] = we::$user['email'];
$return_data['hidden']['fixed'] = 'Y';
$return_data['hidden']['demo'] = empty($settings['paidsubs_test']) ? 'N' : 'Y';
$return_data['hidden']['return_url'] = $return_url;
return $return_data;
}
}
class twocheckout_payment
{
private $return_data;
public function isValid()
{
global $settings;
// Is it even on?
if (empty($settings['2co_id']) || empty($settings['2co_password']))
return false;
// Is it a 2co hash?
if (empty($_POST['x_MD5_Hash']))
return false;
// Do we have an invoice number?
if (empty($_POST['x_invoice_num']))
return false;
return true;
}
public function precheck()
{
global $settings, $txt;
// Is this the right hash?
if (empty($settings['2co_password']) || $_POST['x_MD5_Hash'] != strtoupper(md5($settings['2co_password'] . $settings['2co_id'] . $_POST['x_trans_id'] . $_POST['x_amount'])))
generateSubscriptionError($txt['2co_password_wrong']);
// Verify the currency
list (, $currency) = explode(':', $_POST['x_invoice_num']);
// Verify the currency!
if (strtolower($currency) != $settings['currency_code'])
exit;
// Return the ID_SUB/ID_MEMBER
return explode('+', $_POST['x_invoice_num']);
}
// Is this a refund?
public function isRefund()
{
return false;
}
// Is this a subscription?
public function isSubscription()
{
return false;
}
// Is this a normal payment?
function isPayment()
{
// We have to assume so?
return true;
}
// How much was paid?
public function getCost()
{
return $_POST['x_amount'];
}
// Redirect the user away.
public function close()
{
exit;
}
}