Support Multiple TaxPayer
TaxPro GST User Control Library provides support for single TaxPayer ApiSetting and ApiLoginDetails store in default Json files, out-of-box. GstSession object would be internally created by reading these settings and there is no need to set GstSession property of API Enabled control.
If host application needs to support multiple TaxPayer, it needs to store ApiLoginDetails for multiple TaxPayer and needs to implement TPSession (creating different session object for each TaxPayer). Same logic may be implemented for all GSTR controls. Using TPSession name is not compulsary. Developer may use any convenient name and assign this object to GstSession property of all API Enabled controls (in host form/page constructor.)
Sample C# Code:
using System;
using RestSharp;
using TaxProGST.API;
using TaxProGST.Controls;
using System.Reflection;
namespace TaxProGST
{
public class TPSession : GSTSession
{
public int TaxPayerId { get; set; }
public string TaxPayerName { get; set; } //If required
/// <summary>
/// Constructor for use in case of Non TaxPayer Specific API
/// </summary>
public TPSession() : base(true, false)
{
if (ApiSetting.ASPName?.ToUpper() == "GSTN_SANDBOX")
UserIP = "123.123.123.123";
else
UserIP = "DeskTopApp";
}
/// <summary>
/// Constructor for TaxPayerID dependencyt injection in GSTSession
/// </summary>
/// <param name="TPID"></param>
public TPSession(int TPID) : base(true, false)
{
LoadLoginSettings(TPID);
if (ApiSetting.ASPName?.ToUpper() == "GSTN_SANDBOX")
UserIP = "123.123.123.123";
else
UserIP = "DeskTopApp";
StartingApiTxn += CheckForLic;
//RefreshSessionCompleted += StoreRefreshedSession; //Use for TaxPro GST GetKey Completion if you want to store ASP-GSP Session details
RefreshAuthTokenCompleted += StoreRefreshedAuth;
}
private void LoadLoginSettings(int tpID)
{
//Query various properties (as below) for ApiLoginDetails from database for Company tpID
ApiLoginDetails = new APILoginDetails();
ApiLoginDetails.AppKey = "AppKey for tpID";
ApiLoginDetails.AuthToken = "AuthToken for tpID";
ApiLoginDetails.GstPortalUserID = "GSTPortalUserName for tpID";
ApiLoginDetails.SessionEK = "SessionEK for tpID";
ApiLoginDetails.GSTIN = "GSTIN for tpID";
//ApiLoginDetails.TokenExp = TokenExp.HasValue ? (DateTime)TokenExp : DateTime.Now;
//TaxPayerName = CoName;
}
private void CheckForLic(object sender, EventArgs e)
{
//if(!LicenseVersion)
//{
// CancelApiMsg = "API Transactions not activated in Preview / Demo Version.";
// CancleApiTxn = true;
//}
}
public override void AddApiHeaders(RestRequest request)
{
request.AddHeader("appver", "TPDEMO" + Assembly.GetExecutingAssembly().GetName().Version.ToString());
base.AddApiHeaders(request);
}
public override void AddGspApiHeaders(RestRequest request)
{
request.AddHeader("appver", "TPDEMO" + Assembly.GetExecutingAssembly().GetName().Version.ToString());
base.AddGspApiHeaders(request);
}
private async void StoreRefreshedAuth(object sender, EventArgs e)
{
//Update Refresh AuthToken, SEK, TokenExp, AppKey to APILoginDetails for TaxPayer TPID
//AuthToken = ApiLoginDetails.AuthToken;
//SEK = ApiLoginDetails.SessionEK;
//TokenExp = ApiLoginDetails.TokenExp;
//AppKey = ApiLoginDetails.AppKey;
//SaveChanges();
}
public async override void LogAPITxn(APITxnLogArgs e)
{
try
{
//using(MyDbContext db = new MyDbContext())
//{
// APITxnItem al = db.dbApiTxnLog.Create();
// al.TPClientId = TaxPayerId;
// al.TPClientName = TaxPayerName;
// al.TxnID = TxnID;
// al.IsSuccess = e.IsSuccess;
// al.FilingPeriod = e.FilingPeriod;
// al.FormNo = e.FormNo;
// al.ApiAction = e.ApiAction;
// al.ApiTitle = e.ApiTitle;
// al.OutcomeMsg = e.OutcomeMsg;
// if(e.IsSuccess)
// al.Info1 = e.Info1;
// else
// al.ErrCode = e.ErrCode;
// al.Info2 = e.Info2;
// al.TxnDateTime = e.TxnDateTime;
// al.ASPName = ApiSetting.ASPName;
// al.AppUserName = strOperatorID;
// db.dbApiTxnLog.Add(al);
// await db.SaveChangesAsync();
// if(e.IsSuccess && e.ApiAction == "RETSUBMIT")
// {
// //StoreRetAckNo
// }
//}
}
catch(Exception)
{
}
}
}
}