-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFailure.php
231 lines (199 loc) · 7.27 KB
/
Failure.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/*
* Copyright notice:
* (c) Copyright 2018 RocketGate
* All rights reserved.
*
* The copyright notice must not be removed without specific, prior
* written permission from RocketGate.
*
* This software is protected as an unpublished work under the U.S. copyright
* laws. The above copyright notice is not intended to effect a publication of
* this work.
* This software is the confidential and proprietary information of RocketGate.
* Neither the binaries nor the source code may be redistributed without prior
* written permission from RocketGate.
*
* The software is provided "as-is" and without warranty of any kind, express, implied
* or otherwise, including without limitation, any warranty of merchantability or fitness
* for a particular purpose. In no event shall RocketGate be liable for any direct,
* special, incidental, indirect, consequential or other damages of any kind, or any damages
* whatsoever arising out of or in connection with the use or performance of this software,
* including, without limitation, damages resulting from loss of use, data or profits, and
* whether or not advised of the possibility of damage, regardless of the theory of liability.
*
* File name: Failure.php
* Purpose: This page shows an example of how to handle a failure
* from the RocketGate Hosted Page system. All failures
* come to this page.
*
* Failures come in 5 catagories:
* errcat Description
* 1 Bank declined financial information
* 2 RocketGate scrubbing decline
* 3 System Error
* 4 Rejected: Missing fields / Field validation
* 5 Host Page Environment error
*
* Each error catagory has a series of error codes. Description
* of the codes can be found in the RocketGate documentation
*
*
*/
//
// Include the Database and Postback Configs
//
include("rg_config.php");
//
// Include the class that can build a link
//
include("LinkReader.php");
//
// It is important to confirm that the failure information is coming
// from RocketGate. This is done by checking the hash value in the
// incoming URL against our internally computed hash value.
//
// First, split the incoming URL to obtain everything after the "?".
//
list($uri_string, $values_string) = explode('?', $_SERVER['REQUEST_URI']);
//
// Create a LinkReader.php class instance to check the hash
// contained in the URL.
//
$link_reader = new LinkReader(RG_HASH_SECRET);
//
// Confirm that the incoming link is from RocketGate
//
if($link_reader->ParseLink($values_string) != 0){
//
// Either this link was not made by RocketGate, or there is a
// problem with the secret key
//
die("Link contains invalid hash value!!!<br/>\n");
}
//
// The error_msg variable will hold the message associated with the errcat
//
$error_msg = "";
$errcode = $link_reader->Get('errcode');
//
// Determine the type of error catagory
//
switch($link_reader->Get('errcat')){
case 1: // Bank declined financial information
$error_msg = "This transaction was declined by the financial institution.";
break;
case 2: // RocketGate scrubbing decline
if( ($errcode >= 208 && $errcode <= 210) || $errcode == 218) {
$error_msg = "You already appear to have an existing membership.";
} else {
$error_msg = "This transaction was declined due to fraud scrubbing.";
}
break;
case 3: // System Error
$error_msg = "This transaction has been declined and terminated due to an internal system error";
break;
case 4: // Rejected: Missing fields / Field validation
if($errcode == 439) {
$error_msg = "You have re-submitted a purchase.";
} elseif($errcode == 440) {
$error_msg = "You already appear to have an existing membership.";
} else {
$error_msg = "This transaction was declined due to invalid customer input";
}
break;
case 5: // Host Page Environment error
if($errcode == 506) {
$error_msg = "No Customer record found.";
} else {
$error_msg = "This transaction has been declined and terminated because the postback failed";
}
break;
default:
$error_msg = "This transaction has been declined for unknown reasons";
} // end switch
//
// If the error code is postback failure, remove the potential login so user can re-join.
//
if($link_reader->Get('errcode') >= 510 && $link_reader->Get('errcode') <= 516) {
$mysqli = new mysqli(RG_DB_SERVER, RG_DB_USERNAME, RG_DB_PASSWORD);
if($mysqli->connect_errno){
die("Problem connecting to the database: ");
} else {
//
// The db connection was successful - now select the database to use
//
if(! $mysqli->select_db(RG_DB_NAME) ){
//
// Indicate an error if it not possible to connect to the correct database
//
die("Problem selecting database: " . $mysqli->error );
}
}
if (!($stmt = $mysqli->prepare("delete from rg_user_info where user_id = ? AND invoice_id = ?"))) {
die("Prepare insert failed: ");
}
if (! $stmt->bind_param("ss", $_GET['id'], $_GET['invoiceID'] ) ) {
die("Update Binding failed.<br/>\n" . $mysqli->errno );
}
if (! $stmt->execute() ) {
die("Insert failed: ");
}
/* close connection */
$mysqli->close();
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="HandheldFriendly" content="True">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="cleartype" content="on">
<title>Purchase Failed</title>
<link rel="stylesheet" href="https://secure.rocketgate.com/hostedpage/parentFrame.css" type="text/css" media="screen" />
<link rel="stylesheet" href="https://secure.rocketgate.com/hp/css/release.1.0.css" type="text/css" media="screen" />
</head>
<body>
<div id="container">
<div id="masthead">
<h1 align=center><img src="/logo.jpg" width="252" height="33"></h1>
</div><!-- end masthead -->
<div id="contentWrapper">
<div id="sidebar">
<h2>General Links and Information</h2>
<ul>
<li><a href="http://www.example.com">Website Home</a></li>
</ul>
<h2>Customer Support</h2>
<p>Toll Free (US only): 855-553-1284</p>
<p>Outside US call: +1 702-749-4453</p>
<p><a href="support@example.com">support@example.com</a></p>
<h2>Warning:</h2>
<p>
For any questions or assistance, please contact support@example.com
or xxx-xxx-xxxx 24/7. We are always here to help!
</p>
</div><!-- end sidebar -->
<div id="frameWrapper">
<center>
<FORM METHOD="POST" ACTION="">
<div id="formWrapper">
<div class="header"> </div>
<h2>Transaction Failed!</h2>
<p class="errorMSG" style="text-align: center;">
<?=$error_msg?>
<br/><br/>
<a style="font-size: 130%" href="<?=RG_MERCHANT_URL?>">Return to site</a>
</p>
<br>
<div class="footer"> </div>
</div>
</form>
</div><!-- end frameWrapper -->
<div id="footer">
</div><!-- end footer -->
</div><!-- end contentWrapper -->
</div><!-- end container -->
</body>
</html>