Skip to content

Commit

Permalink
Socioboard 3.0.52
Browse files Browse the repository at this point in the history
Socioboard 3.0.52
  • Loading branch information
RajGlobussoft committed Aug 13, 2018
1 parent 67a3a4b commit 9e28abc
Show file tree
Hide file tree
Showing 12 changed files with 711 additions and 9 deletions.
218 changes: 217 additions & 1 deletion src/Api.Socioboard/Controllers/PaymentTransactionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
using Microsoft.AspNetCore.Hosting;
using Domain.Socioboard.Models;
using Domain.Socioboard.Interfaces.Services;
using System.Net;
using System.Text;
using System.IO;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Api.Socioboard.Model;


// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
Expand Down Expand Up @@ -232,7 +239,216 @@ public IActionResult UpdateRecurringUser(string subscr_id, string txn_id, DateTi
}
return Ok();
}



[HttpPost("PostBlueSnapSubscription")]
public IActionResult PostBlueSnapSubscription(string XMLData, string emailId)
{
string responseFromServer = string.Empty;
try
{
// Create a request using a URL that can receive a post.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://sandbox.bluesnap.com/services/2/recurring/subscriptions");
// Set the Method property of the request to POST.
request.Method = "POST";
request.Headers["Authorization"] = "Basic " + _appSettings.bluesnapBase64;
request.UserAgent = ".NET Framework Test Client";
string postData = XMLData;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/xml";
request.ContentLength = byteArray.Length;

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

// Get the response.

HttpWebResponse myHttpWebResponse = (HttpWebResponse)request.GetResponse();
Console.WriteLine((myHttpWebResponse.StatusDescription));
dataStream = myHttpWebResponse.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
myHttpWebResponse.Close();
}
catch (WebException wex)
{
var pageContent = new StreamReader(wex.Response.GetResponseStream())
.ReadToEnd();

Console.WriteLine(wex.Message);
return BadRequest();
}



DatabaseRepository dbr = new Model.DatabaseRepository(_logger, _appEnv);
try
{

//JSON
XmlDocument doc = new XmlDocument();
doc.LoadXml(responseFromServer);
JObject jsonTextResponse = JObject.Parse(JsonConvert.SerializeXmlNode(doc));


User userObj = dbr.FindSingle<User>(t => t.EmailId == emailId);

PaymentTransaction objPaymentTransaction = new PaymentTransaction();
objPaymentTransaction.amount = jsonTextResponse["recurring-subscription"]["recurring-charge-amount"].ToString();
objPaymentTransaction.userid = userObj.Id;
objPaymentTransaction.email = userObj.EmailId;
objPaymentTransaction.paymentdate = DateTime.UtcNow;
objPaymentTransaction.trasactionId = jsonTextResponse["recurring-subscription"]["subscription-id"].ToString();
try
{
objPaymentTransaction.paymentId = jsonTextResponse["recurring-subscription"]["charge"]["charge-id"].ToString();
}
catch
{
objPaymentTransaction.paymentId = "NA";
}
objPaymentTransaction.PaymentType = Domain.Socioboard.Enum.PaymentType.bluesnap;
try
{
objPaymentTransaction.paymentstatus = jsonTextResponse["recurring-subscription"]["status"].ToString();
}
catch
{
objPaymentTransaction.paymentstatus = "NA";
}
objPaymentTransaction.itemname = "Socioboard" + userObj.AccountType.ToString();
objPaymentTransaction.Payername = userObj.FirstName + " " + userObj.LastName;
objPaymentTransaction.email = userObj.EmailId;
dbr.Add<PaymentTransaction>(objPaymentTransaction);

userObj.ExpiryDate = DateTime.Now.AddYears(1);
userObj.PaymentStatus = Domain.Socioboard.Enum.SBPaymentStatus.Paid;
userObj.TrailStatus = Domain.Socioboard.Enum.UserTrailStatus.active;
userObj.PayPalAccountStatus = Domain.Socioboard.Enum.PayPalAccountStatus.added;
userObj.PaymentType = Domain.Socioboard.Enum.PaymentType.bluesnap;

dbr.Update<User>(userObj);

return Ok();
}
catch
{
return BadRequest();
}


}

[HttpPost("PostBlueSnapPlan")]
public IActionResult PostBlueSnapPlan(string XMLData)
{
string responseFromServer = string.Empty;
try
{
// Create a request using a URL that can receive a post.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://sandbox.bluesnap.com/services/2/recurring/plans");
// Set the Method property of the request to POST.
request.Method = "POST";
request.Headers["Authorization"] = "Basic " + _appSettings.bluesnapBase64;
request.UserAgent = ".NET Framework Test Client";
string postData = XMLData;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/xml";
request.ContentLength = byteArray.Length;

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

// Get the response.

HttpWebResponse myHttpWebResponse = (HttpWebResponse)request.GetResponse();
Console.WriteLine((myHttpWebResponse.StatusDescription));
dataStream = myHttpWebResponse.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
myHttpWebResponse.Close();
}
catch (WebException wex)
{
var pageContent = new StreamReader(wex.Response.GetResponseStream())
.ReadToEnd();

Console.WriteLine(wex.Message);
}


return Ok(responseFromServer);
}


[HttpPost("GetBlueSnapPlan")]
public IActionResult GetBlueSnapPlan(string planId)
{
string responseFromServer = string.Empty;
try
{
// Create a request using a URL that can receive a post.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://sandbox.bluesnap.com/services/2/recurring/plans/" + planId);
// Set the Method property of the request to POST.
request.Method = "GET";
request.Headers["Authorization"] = "Basic " + _appSettings.bluesnapBase64;
request.UserAgent = ".NET Framework Test Client";
request.ContentType = "application/json";
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

// Get the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)request.GetResponse();
Console.WriteLine((myHttpWebResponse.StatusDescription));
Stream dataStream = myHttpWebResponse.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
myHttpWebResponse.Close();
}
catch (WebException wex)
{
var pageContent = new StreamReader(wex.Response.GetResponseStream())
.ReadToEnd();

Console.WriteLine(wex.Message);
}


Dictionary<string, string> planValues = new Dictionary<string, string>();
//XML
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(responseFromServer);
foreach (XmlNode childrenNode in xmlDoc)
{
if (childrenNode.Name == "plan")
{
foreach (XmlNode items in childrenNode.ChildNodes)
{
planValues.Add(items.Name, items.InnerText);
}
}
}

return Ok(responseFromServer);
}


}
}
7 changes: 7 additions & 0 deletions src/Api.Socioboard/Helper/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,12 @@ public class AppSettings
public string paypalapiPassword { get; set; }
public string paypalapiSignature { get; set; }

//Bluesnap

public string bluesnapApiKey { get; set; }
public string bluesnapPassword { get; set; }
public string bluesnapBase64 { get; set; }


}
}
7 changes: 5 additions & 2 deletions src/Api.Socioboard/Helper/LinkedInHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,17 @@ public static string GetAccessToken(string Code, Helper.AppSettings _appSettings
oAuthLinkedIn _oauth = new oAuthLinkedIn();
_oauth.ConsumerKey = _appSettings.LinkedinApiKey;
_oauth.ConsumerSecret = _appSettings.LinkedinSecretKey;
string access_token_Url = "https://www.linkedin.com/uas/oauth2/accessToken";
//string access_token_Url = "https://www.linkedin.com/uas/oauth2/accessToken";
string access_token_Url = "https://www.linkedin.com/oauth/v2/accessToken";
string access_token_postData = "grant_type=authorization_code&code=" + Code + "&redirect_uri=" + _appSettings.LinkedinCallBackURL + "&client_id=" + _appSettings.LinkedinApiKey + "&client_secret=" + _appSettings.LinkedinSecretKey;
//ServicePointManager.Expect100Continue = true;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string token = _oauth.APIWebRequestAccessToken("POST", access_token_Url, access_token_postData);
var oathtoken = JObject.Parse(token);
_oauth.Token = oathtoken["access_token"].ToString().TrimStart('"').TrimEnd('"');
return _oauth.Token.ToString();
}
catch
catch(Exception ex)
{
return null;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Api.Socioboard/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@

"paypalapiUsername": "",
"paypalapiPassword": "",
"paypalapiSignature": ""
"paypalapiSignature": "",

"bluesnapApiKey": "",
"bluesnapPassword": "",
"bluesnapBase64": "" //base 64 for "bluesnapApiKey:bluesnapPassword"
}
}
3 changes: 2 additions & 1 deletion src/Domain.Socioboard/Enum/PaymentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Domain.Socioboard.Enum
public enum PaymentType
{
paypal = 0,
payumoney = 1
payumoney = 1,
bluesnap=2
}
}
13 changes: 13 additions & 0 deletions src/Domain.Socioboard/Enum/SBAccountType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ public enum SBAccountType
Platinum = 7

}

public enum SBAccountTypeBlueSnap
{
Free = 0,
Standard = 2414221,
Premium = 2414223,
Deluxe = 2414225,
Topaz = 2414227,
Ruby = 2414229,
Gold = 2414231,
Platinum = 2414233

}
}
5 changes: 3 additions & 2 deletions src/Socioboard.LinkedIn/Authentication/oAuthLinkedIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public string APIWebRequest(string method, string url, string postData)

webRequest.PreAuthenticate = true;
webRequest.ServicePoint.Expect100Continue = false;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
if (postData != null)
{
byte[] fileToSend = Encoding.UTF8.GetBytes(postData);
Expand Down Expand Up @@ -322,7 +322,7 @@ public string APIWebRequestAccessToken(string method, string url, string postDat

webRequest.PreAuthenticate = true;
webRequest.ServicePoint.Expect100Continue = false;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
if (postData != null)
{
byte[] fileToSend = Encoding.UTF8.GetBytes(postData);
Expand Down Expand Up @@ -465,6 +465,7 @@ public string LinkedProfilePostWebRequest(string method, string url, string Comm
stream.Flush();
stream.Close();
}
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
try
{
WebResponse webResponse = webRequest.GetResponse();
Expand Down
Loading

0 comments on commit 9e28abc

Please sign in to comment.