/
PayPal.cs
322 lines (265 loc) · 15.5 KB
/
PayPal.cs
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PayPal.Platform.SDK;
using PayPal.Services.Private.AP;
using System.Configuration;
using System.Net;
using Newtonsoft.Json.Linq;
using System.Data;
using System.Collections;
namespace BlueIkons
{
public class PayPal
{
public Boolean PreapprovalActive(string pakey, bool Live_Trial, int txkey)
{
Boolean isactive = false;
PreapprovalDetailsRequest preapprovalRequest = null;
BaseAPIProfile profile2 = new BaseAPIProfile();
profile2.APIProfileType = ProfileType.ThreeToken;
if (Live_Trial)//true = Live , false = trial
{
profile2.Environment = ConfigurationManager.AppSettings.Get("Live_Environment").ToString();
profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID_Live").ToString();
profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername_Live").ToString();
profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword_Live").ToString();
profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature_Live").ToString();
}
else
{
profile2.Environment = ConfigurationManager.AppSettings.Get("Trial_Environment").ToString();
profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID").ToString();
profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername").ToString();
profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword").ToString();
profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature").ToString();
}
profile2.RequestDataformat = "SOAP11";
profile2.ResponseDataformat = "SOAP11";
profile2.IsTrustAllCertificates = Convert.ToBoolean(ConfigurationManager.AppSettings["TrustAll"]);
try
{
preapprovalRequest = new PreapprovalDetailsRequest();
//preapprovalRequest.senderEmail = senderEmail.Value;
preapprovalRequest.requestEnvelope = new RequestEnvelope();
preapprovalRequest.requestEnvelope.errorLanguage = "en-US";
preapprovalRequest.preapprovalKey = pakey;
AdapativePayments ap = new AdapativePayments();
ap.APIProfile = profile2;
PreapprovalDetailsResponse PResponse = ap.preapprovalDetails(preapprovalRequest);
if (ap.isSuccess.ToUpper() == "FAILURE")
{
//HttpContext.Current.Session[Constants.SessionConstants.FAULT] = ap.LastError;
//HttpContext.Current.Response.Redirect("APIError.aspx", false);
}
else
{
if (PResponse.status == "ACTIVE")
{
isactive = true;
}
else if ((PResponse.status == "CANCELED") || (PResponse.status == "DEACTIVED"))
{
BlueIkons_DB.SPs.UpdateTransactionExpired(txkey).Execute();
}
}
}
catch (FATALException FATALEx)
{
// Session[Constants.SessionConstants.FATALEXCEPTION] = FATALEx;
// this.Response.Redirect(Constants.ASPXPages.APIERROR + "?" + Constants.QueryStringConstants.TYPE + "=FATAL", false);
}
catch (Exception ex)
{
//FATALException FATALEx = new FATALException("Error occurred in PreApproval Page.", ex);
//Session[Constants.SessionConstants.FATALEXCEPTION] = FATALEx;
//this.Response.Redirect("APIError.aspx?type=FATAL", false);
}
return isactive;
}
public string SetPreapproval(fbuser fbuser, bool Live_Trial, int Tx_Key, decimal amount)
{
string strReturn = "";
PreapprovalRequest preapprovalRequest = null;
BaseAPIProfile profile2 = new BaseAPIProfile();
profile2.APIProfileType = ProfileType.ThreeToken;
if (Live_Trial)//true = Live , false = trial
{
profile2.Environment = ConfigurationManager.AppSettings.Get("Live_Environment").ToString();
profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID_Live").ToString();
profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername_Live").ToString();
profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword_Live").ToString();
profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature_Live").ToString();
}
else
{
profile2.Environment = ConfigurationManager.AppSettings.Get("Trial_Environment").ToString();
profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID").ToString();
profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername").ToString();
profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword").ToString();
profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature").ToString();
}
profile2.RequestDataformat = "SOAP11";
profile2.ResponseDataformat = "SOAP11";
profile2.IsTrustAllCertificates = Convert.ToBoolean(ConfigurationManager.AppSettings["TrustAll"]);
try
{
decimal amountfee1 = (amount * Convert.ToDecimal(0.029)) + Convert.ToDecimal(0.3);
decimal amountblueikon = (amount * Convert.ToDecimal(0.1));
decimal amountfee2 = (amountblueikon * Convert.ToDecimal(0.029)) + Convert.ToDecimal(0.3);
amount = amount + amountblueikon + amountfee1 + amountfee2;
amount = decimal.Round(amount, 2);
string url = ConfigurationManager.AppSettings.Get("App_URL").ToString() ;
string returnURL = "http://www.blueikons.com/Order_Confirmation.aspx?Tx_key=" + Tx_Key.ToString();
string cancelURL = url;
preapprovalRequest = new PreapprovalRequest();
preapprovalRequest.cancelUrl = cancelURL;
preapprovalRequest.returnUrl = returnURL;
//preapprovalRequest.senderEmail = senderEmail.Value;
preapprovalRequest.requestEnvelope = new RequestEnvelope();
preapprovalRequest.requestEnvelope.errorLanguage = "en-US";
preapprovalRequest.maxNumberOfPayments = 2;
preapprovalRequest.maxTotalAmountOfAllPayments = amount;
preapprovalRequest.maxTotalAmountOfAllPaymentsSpecified = true;
preapprovalRequest.currencyCode = "USD";
preapprovalRequest.startingDate = DateTime.Today;
preapprovalRequest.endingDate = DateTime.Today.AddMonths(1);
preapprovalRequest.endingDateSpecified = true;
preapprovalRequest.clientDetails = new ClientDetailsType();
//preapprovalRequest.clientDetails = ClientInfoUtil.getMyAppDetails();
preapprovalRequest.memo = "BlueIkons";
preapprovalRequest.maxNumberOfPayments = 2;
preapprovalRequest.displayMaxTotalAmount = true;
preapprovalRequest.displayMaxTotalAmountSpecified = true;
preapprovalRequest.feesPayer = "SENDER";
AdapativePayments ap = new AdapativePayments();
ap.APIProfile = profile2;
PreapprovalResponse PResponse = ap.preapproval(preapprovalRequest);
if (ap.isSuccess.ToUpper() == "FAILURE")
{
//HttpContext.Current.Session[Constants.SessionConstants.FAULT] = ap.LastError;
//HttpContext.Current.Response.Redirect("APIError.aspx", false);
}
else
{
// Session[Constants.SessionConstants.PREAPPROVALKEY] = PResponse.preapprovalKey;
//this.Response.Redirect(ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"] + "_ap-preapproval&preapprovalkey=" + PResponse.preapprovalKey, false);
BlueIkons_DB.SPs.UpdateTransactionPakey(Tx_Key, PResponse.preapprovalKey).Execute();
if (Live_Trial)//true = Live , false = trial
{
//HttpContext.Current.Response.Redirect("https://paypal.com/webapps/adaptivepayment/flow/pay?paykey=" + PResponse.preapprovalKey, false);
}
else{
//HttpContext.Current.Response.Redirect("https://www.sandbox.paypal.com/webscr?cmd=" + "_ap-payment&paykey=" + PResponse.preapprovalKey, false);
}
strReturn = PResponse.preapprovalKey;
}
}
catch (FATALException FATALEx)
{
// Session[Constants.SessionConstants.FATALEXCEPTION] = FATALEx;
// this.Response.Redirect(Constants.ASPXPages.APIERROR + "?" + Constants.QueryStringConstants.TYPE + "=FATAL", false);
}
catch (Exception ex)
{
//FATALException FATALEx = new FATALException("Error occurred in PreApproval Page.", ex);
//Session[Constants.SessionConstants.FATALEXCEPTION] = FATALEx;
//this.Response.Redirect("APIError.aspx?type=FATAL", false);
}
return strReturn;
}
#region Parallel Payments
public Boolean ParallelPayment(bool Live_Trial, gift giftinfo, string receiveremail)
{
Boolean txcompleted = false;
BaseAPIProfile profile2 = new BaseAPIProfile();
int Tx_Key = giftinfo.txkey;
Site sitetemp = new Site();
Transactions txinfo = sitetemp.Gettx(giftinfo.txkey);
////Three token
profile2.APIProfileType = ProfileType.ThreeToken;
string blueikonemail = "";
if (Live_Trial)//true = Live , false = trial
{
profile2.Environment = ConfigurationManager.AppSettings.Get("Live_Environment").ToString();
profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID_Live").ToString();
profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername_Live").ToString();
profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword_Live").ToString();
profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature_Live").ToString();
blueikonemail = ConfigurationManager.AppSettings.Get("My_Email_Live").ToString();
}
else
{
profile2.Environment = ConfigurationManager.AppSettings.Get("Trial_Environment").ToString();
profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID").ToString();
profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername").ToString();
profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword").ToString();
profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature").ToString();
blueikonemail = ConfigurationManager.AppSettings.Get("My_Email_Trial").ToString();
}
/*profile2.RequestDataformat = "SOAP11";
profile2.ResponseDataformat = "SOAP11";
*/
profile2.IsTrustAllCertificates = Convert.ToBoolean(ConfigurationManager.AppSettings["TrustAll"]);
string url = ConfigurationManager.AppSettings.Get("Callback").ToString() + "/";
string returnURL = url + "Order_Confirmation.aspx?Tx_key=" + Tx_Key.ToString();
string cancelURL = url + "Order_Confirmation.aspx?Tx_key=0";
PayRequest payRequest = null;
payRequest = new PayRequest();
payRequest.cancelUrl = cancelURL;
payRequest.returnUrl = returnURL;
payRequest.reverseAllParallelPaymentsOnError = true;
//payRequest.senderEmail = email.Value;
//payRequest.clientDetails = new ClientDetailsType();
//payRequest.clientDetails = ClientInfoUtil.getMyAppDetails();
payRequest.feesPayer = "SENDER";//feesPayer.Value;
payRequest.memo = "BlueIkons";// memo.Value;
payRequest.actionType = "PAY";
payRequest.currencyCode = "USD"; //currencyCode.Items[currencyCode.SelectedIndex].Value;
payRequest.requestEnvelope = new RequestEnvelope();
payRequest.requestEnvelope.errorLanguage = "en_US";//ClientInfoUtil.getMyAppRequestEnvelope();
payRequest.preapprovalKey = txinfo.pakey;
payRequest.receiverList = new Receiver[2];
payRequest.receiverList[0] = new Receiver();
payRequest.receiverList[0].amount = decimal.Round(giftinfo.amount,2);//amount_0.Value);
payRequest.receiverList[0].email = receiveremail;//receiveremail_0.Value;
decimal blueikonamount = (giftinfo.amount * Convert.ToDecimal(.1));
if (receiveremail != blueikonemail)
{
payRequest.receiverList[1] = new Receiver();
payRequest.receiverList[1].amount = decimal.Round(blueikonamount, 2);
payRequest.receiverList[1].email = blueikonemail;
}
else
{
payRequest.receiverList[0].amount += decimal.Round(blueikonamount, 2);
}
//Eventomatic_DB.SPs.UpdateTransactionTicketAmountEmail(Tx_Key, strEmail1).Execute();
profile2.ResponseDataformat = "SOAP11";
profile2.RequestDataformat = "SOAP11";
AdapativePayments ap = new AdapativePayments();
ap.APIProfile = profile2;
PayResponse PResponse = ap.pay(payRequest);
if (ap.isSuccess.ToUpper() == "FAILURE")
{
//HttpContext.Current.Session[Constants.SessionConstants.FAULT] = ap.LastError;
for (int i = 0; i <= ap.LastError.ErrorDetails.Length - 1; i++)
{
FaultDetailFaultMessageError ETtemp = (FaultDetailFaultMessageError)ap.LastError.ErrorDetails.GetValue(i);
//decimal OverallTotal = decimal.Round(dcAmount1, 2) + decimal.Round(dcAmount2, 2);
//Eventomatic_DB.SPs.UpdateCCErrors(ETtemp.message.ToString(), Tx_Key, 2, OverallTotal.ToString()).Execute();
}
//HttpContext.Current.Response.Redirect("APIError.aspx", false);
}
else
{
//Payment went through
BlueIkons_DB.SPs.UpdateTransaction(Tx_Key, 0, 0, 0, 3, PResponse.responseEnvelope.correlationId, receiveremail).Execute();
txcompleted = true;
}
return txcompleted;
}
#endregion
}
}