Repository navigation
Expand file tree
/
Copy pathcreate-recuringprofile.php
More file actions
296 lines (237 loc) · 11.9 KB
/
Copy pathcreate-recuringprofile.php
File metadata and controls
296 lines (237 loc) · 11.9 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?
require '../vendor/autoload.php';
include("admin/config.php");
include('mailgun/RPAMailGun.php');
if(isset($_REQUEST['Plan']))
{
$_SESSION['plan']=$_REQUEST['Plan'];
}
$selec= mysql_fetch_assoc(mysql_query("select * from userthree where email = '".$_SESSION['user_email']."'"));
if(isset($selec['id']) and $selec['id']!='')
{
header("location:index.php");
}
if(isset($_REQUEST['cancel']) and $_REQUEST['cancel']==1)
{
$_SESSION['first_name']='';
$_SESSION['last_name']='';
$_SESSION['company']='';
$_SESSION['phone']='';
$_SESSION['user_email']='';
$_SESSION['nmls']='';
$_SESSION['dre']='';
//$_SESSION['user_login']='';
$_SESSION['pass1']='';
$_SESSION['plan']='';
$_SESSION['streetaddress']='';
$_SESSION['suite']='';
$_SESSION['city']='';
$_SESSION['state']='';
$_SESSION['zip']='';
$_SESSION['comment']='';
header('location:index.php');
}
$environment = 'sandbox'; // or 'beta-sandbox' or 'live'
$ROOT_URL = 'http://www.repreapproval.com/';
/**
* Send HTTP POST Request
*
* @param string The API method name
* @param string The POST Message fields in &name=value pair format
* @return array Parsed HTTP Response body
*/
function PPHttpPost($methodName_, $nvpStr_) {
global $environment;
$API_UserName = urlencode('tripathiveerendra87-facilitator_api1.gmail.com');
$API_Password = urlencode('1389298749');
$API_Signature = urlencode('AFcWxV21C7fd0v3bYYYRCpSSRl31AHkvFVWd5xc9qVPPk21Y917LbVyD');
$API_Endpoint = "https://api-3t.paypal.com/nvp";
if("sandbox" === $environment || "beta-sandbox" === $environment) {
$API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
}
$version = urlencode('51.0');
// setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// turning off the server and peer verification(TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// NVPRequest for submitting to server
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// setting the nvpreq as POST FIELD to curl
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// getting response from server
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
}
// Extract the RefundTransaction response details
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}
return $httpParsedResponseAr;
}
$amount=$_REQUEST['amount'];
$initialpayment = urlencode($amount);
$paymentAmount = urlencode($amount);
if(!isset($_REQUEST['token'])){
// Set request-specific fields.
$autobillamt=urlencode("AddToNextBilling");
$billingType = urlencode("RecurringPayments");;
$bilingdesc=urlencode("This is the membership charge you have to pay $".$initialpayment."instantly and every month");
$currencyID = urlencode('USD'); // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
// $paymentType = urlencode('Sale'); // or 'Sale' or 'Order'
$returnURL = urlencode($ROOT_URL.'create-recuringprofile.php?return=1&amount='.$amount);
$cancelURL = urlencode($ROOT_URL.'create-recuringprofile.php?cancel=1');
$ipnURL = urlencode($ROOT_URL.'ipn.php');
$contry=urlencode("IN");
// Add request-specific fields to the request string.
$nvpStr = "&IpnUrl=$ipnURL&Amt=$paymentAmount&ReturnUrl=$returnURL&CANCELURL=$cancelURL&PAYMENTACTION=$paymentType&CURRENCYCODE=$currencyID&BILLINGAGREEMENTDESCRIPTION=$bilingdesc&NOSHIPPING=1&BILLINGTYPE=$billingType&COUNTRY=$contry&AUTOBILLOUTAMT=$autobillamt";
// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('SetExpressCheckout', $nvpStr);
// print_r($httpParsedResponseAr);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
// Redirect to paypal.com.
$token = urldecode($httpParsedResponseAr["TOKEN"]);
$payPalURL = "https://www.paypal.com/webscr&cmd=_express-checkout&token=$token";
if("sandbox" === $environment || "beta-sandbox" === $environment) {
$payPalURL = "https://www.$environment.paypal.com/webscr&cmd=_express-checkout&token=$token";
}
header("Location:$payPalURL");
//echo '<a href="'.$payPalURL.'">PayPal</a>';
//exit;
} else {
exit('SetExpressCheckout failed: ' . print_r($httpParsedResponseAr, true));
}
}else{
$token =urlencode( $_REQUEST['token']);
$paymentAmount =urlencode ($initialpayment);
$paymentType = urlencode('Sale');
$currCodeType = urlencode('USD');
$payerID = urlencode($_REQUEST['PayerID']);
$ipnURL = urlencode($ROOT_URL.'ipn.php');
$nvpstr='&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION='.$paymentType.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currCodeType.'&IPNURL='.$ipnURL;
$resArray=PPHttpPost("DoExpressCheckoutPayment",$nvpstr);
if("SUCCESS" == strtoupper($resArray["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($resArray["ACK"]))
{
//Now create recurring profile
?>
<h1>Yes!</h1>
<?
$autobillamt=urlencode("AddToNextBilling");
$billingType = urlencode("RecurringPayments");;
$bilingdesc=urlencode("This is the membership charge you have to pay $".$initialpayment."instantly and every month");
$currencyID = urlencode("USD");
$date=strtotime(date('Y-m-d', strtotime("+30 days"))); // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
$startDate = urlencode(date('Y-m-d', strtotime("+30 days")).'T0:0:0');
$billingPeriod = urlencode("Month"); // or "Day", "Week", "SemiMonth", "Year"
$billingFreq = urlencode("1");
$ipnURL = urlencode($ROOT_URL.'ipn.php'); // combination of this and billingPeriod must be at most a year
$contry=urlencode("IN");
$nvpStr="&IpnUrl=$ipnURL&TOKEN=$token&AMT=$paymentAmount&CURRENCYCODE=$currencyID&PROFILESTARTDATE=$startDate&L_BILLINGAGREEMENTDESCRIPTION0=$bilingdesc&L_PAYMENTTYPE0=$billingType&AUTOBILLOUTAMT=$autobillamt&DESC=$bilingdesc&COUNTRY=$contry".'<br/>';
$nvpStr .="&BILLINGPERIOD=$billingPeriod&BILLINGFREQUENCY=$billingFreq";
$httpParsedResponseAr = PPHttpPost('CreateRecurringPaymentsProfile', $nvpStr);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
//print_r($httpParsedResponseAr);die;
$date=strtotime(date('Y-m-d', strtotime("+30 days")));
$pro=substr_replace($httpParsedResponseAr['PROFILEID'],'-',1,3);
$tty= time();
if($_SESSION['first_name']!='' and $_SESSION['phone']!='' and $_SESSION['user_email']!='' and $_SESSION['pass1']!='' and $_SESSION['zip']!='')
{
$inser= mysql_query("insert into userthree (`firstname`, `lastname`, `companyname`, `phone`, `email`,`password`, `accounttype`, `street`, `suite`, `city`, `state`, `zip`, `comment`, `createdby`, `created`,license,DRE,plan) values ('".$_SESSION['first_name']."', '".$_SESSION['last_name']."', '".$_SESSION['company']."', '".$_SESSION['phone']."', '".$_SESSION['user_email']."','".$_SESSION['pass1']."', 'LENDER', '".$_SESSION['streetaddress']."', '".$_SESSION['suite']."', '".$_SESSION['city']."', '".$_SESSION['state']."', '".$_SESSION['zip']."', '".$_SESSION['comment']."', '', '".$tty."','".$_SESSION['nmls']."','".$_SESSION['dre']."','".$_SESSION['plan']."')");
}
if($inser)// send welcome message
{
$LanderId=mysql_insert_id();
$selec= mysql_fetch_assoc(mysql_query("select * from userthree where id = '".$LanderId."'"));
$_SESSION['logge']=$selec;
$insert=mysql_query("insert into companyinvoices(profile_id,lender_id,date_billing,amount,exp_date,status)values('".$pro."','".$LanderId."','".$tty."','".$initialpayment."','".$date."','p')");
$subject= "Welcome to RePreApproval - You have successfully registered";
$to= $_SESSION['user_email'];
$from= "admin@repreapproval.com";
$mess= '<table width="550px">
<tr><td colspan="2" style="background-color:#93CE52"><img src="http://www.repreapproval.com/images/logo2.png" width="340px" style=""width:340px" /></td></tr>
<tr><td colspan="2" style="background-color:#045D92;height:10px"></td></tr>
<tr><td colspan="2" style="color:#000;">Congratulations! You have successfully registered with <strong>RePreApproval</strong>.</td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td><strong style="color:#000;">Username</strong></td><td><strong style="color:#045D92;">'.$_SESSION['user_email'].'</strong></td></tr>
<tr><td><strong style="color:#000;">Password</strong></td><td><strong style="color:#045D92;">'.$_SESSION['pass1'].'</strong></td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2">Please keep your login information in a secured location.</td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2">If you require additional assistance, do not hesitate to email us or visit our <a href="http://www.repreapproval.com/faq.php">Frequently Asked Questions</a> page.</td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2">Thank you for choosing <strong>RePreApproval</strong>.</td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2">We wish you great success.</td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2">The Team at <strong>RePreApproval</strong></td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2" style="background-color:#93CE52;height:20px;color:#fff;text-align:center;font-weight:bold;">To login, simply click on this <a href="http://www.repreapproval.com/login.php">link</a>.</td></tr>
<tr><td colspan="2" style="background-color:#045D92;height:2px"></td></tr>
<tr><td colspan="2"> </td></tr>
</table>';
// $headers = 'MIME-Version: 1.0' . "\r\n";
// $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// $headers .= 'From: '.$from. "\r\n";
// if(mail($to, $subject, $mess, $headers))
// {
// $_SESSION['first_name']='';
// $_SESSION['last_name']='';
// $_SESSION['company']='';
// $_SESSION['phone']='';
// $_SESSION['user_email']='';
// $_SESSION['plan']='';
// $_SESSION['nmls']='';
// $_SESSION['dre']='';
//
// // $_SESSION['user_login']='';
// $_SESSION['pass1']='';
//
// $_SESSION['streetaddress']='';
// $_SESSION['suite']='';
// $_SESSION['city']='';
// $_SESSION['state']='';
// $_SESSION['zip']='';
// $_SESSION['comment']='';
// }
$mailgun = new RPAMailGun();
if($mailgun->mail($to, $subject, $mess, array('register','recurring'))) {
$_SESSION['first_name']='';
$_SESSION['last_name']='';
$_SESSION['company']='';
$_SESSION['phone']='';
$_SESSION['user_email']='';
$_SESSION['plan']='';
$_SESSION['nmls']='';
$_SESSION['dre']='';
// $_SESSION['user_login']='';
$_SESSION['pass1']='';
$_SESSION['streetaddress']='';
$_SESSION['suite']='';
$_SESSION['city']='';
$_SESSION['state']='';
$_SESSION['zip']='';
$_SESSION['comment']='';
}
}
header('location:lenderdashboard.php?tab=profile');
//exit('CreateRecurringPaymentsProfile Completed Successfully: '.print_r($httpParsedResponseAr, true));
}
else
{
exit('CreateRecurringPaymentsProfile failed: ' . print_r($httpParsedResponseAr, true));
}
}}
?>