Salve a tutti,
negli ultimi periodi mi son trovato a dover fare i conti con questo sistema di pagamento tramite carta di credito online.
Banca sella mette a dispozione una classe (e una dll) scritte in Java per effettuare la transazione, il problema nasce per gli utenti che hanno scelto la tecnologia .net costretti ad usare l'interop (e una JVM installata sul server) per poterle utilizzare.
Spulciando in giro ho trovato sul forum di banca sella una classe scritta in c# che può venirci in contro.
La versione però non è aggiornata (anche con qualche imperfezione nel codice, es. la verifica di uguaglianza tra oggetti di tipo stringa con == invece di utilizzare il metodo Equals) e non funziona correttamente.
Per questo motivo l'ho aggiornata e ve la propongo di seguito.
GestPayCrypt.cs
using System;
using System.Net;
using System.IO;
using System.Web;
namespace COMCaller
{
public class GestPayCrypt
{
private String ShopLogin;
private String Currency;
private String Amount;
private String ShopTransactionID;
private String BuyerName;
private String BuyerEmail;
private String Language;
private String CustomInfo;
private String AuthorizationCode;
private String ErrorCode;
private String ErrorDescription;
private String BankTransactionID;
private String AlertCode;
private String AlertDescription;
private String EncryptedString;
private String ToBeEncript;
private String Decripted;
private String TransactionResult;
private String ProtocolAuthServer;
private String DomainName;
private String separator;
private String errDescription;
private String errNumber;
private String Version;
private String Min;
private String CVV;
private String country;
private String vbvrisp;
private String vbv;
private String trans;
public GestPayCrypt()
{
/*init value*/
ShopLogin = String.Empty;
Currency = String.Empty;
Amount = String.Empty;
ShopTransactionID = String.Empty;
BuyerName = String.Empty;
BuyerEmail = String.Empty;
Language = String.Empty;
CustomInfo = String.Empty;
AuthorizationCode = String.Empty;
ErrorCode = String.Empty;
ErrorDescription = String.Empty;
BankTransactionID = String.Empty;
AlertCode = String.Empty;
AlertDescription = String.Empty;
EncryptedString = String.Empty;
ToBeEncript = String.Empty;
Decripted = String.Empty;
ProtocolAuthServer = "http://";
DomainName = String.Empty;
//DomainName = "ecomm.sella.it/CryptHTTP";
separator = "*P1*";
errDescription = String.Empty;
errNumber = "0";
Min = String.Empty;
CVV = String.Empty;
country = String.Empty;
vbvrisp = String.Empty;
vbv = String.Empty;
trans = String.Empty;
Version = "3.0";
}
/**************** SET *****************/
public void SetShopLogin(String xstr)
{
ShopLogin = xstr;
}
public void SetCurrency(String xstr)
{
Currency = xstr;
}
public void SetAmount(String xstr)
{
Amount = xstr;
}
public void SetShopTransactionID(String xstr)
{
ShopTransactionID = URLDecode(xstr.Trim());
}
public void SetMIN(String xstr)
{
Min = xstr;
}
public void SetCVV(String xstr)
{
CVV = xstr;
}
public void SetBuyerName(String xstr)
{
BuyerName = URLDecode(xstr.Trim());
}
public void SetBuyerEmail(String xstr)
{
BuyerEmail = xstr.Trim();
}
public void SetLanguage(String xstr)
{
Language = xstr.Trim();
}
public void SetCustomInfo(String xstr)
{
CustomInfo = URLDecode(xstr.Trim());
}
public void SetEncryptedString(String xstr)
{
EncryptedString = xstr;
}
// giugno '07
public void setProtocolServer(String xstr)
{
ProtocolAuthServer = xstr;
}
// giugno '07
public void setDomainName(String xstr)
{
DomainName = xstr;
}
/************* GET *************/
public String GetShopLogin()
{
return ShopLogin;
}
public String GetCurrency()
{
return Currency;
}
public String GetAmount()
{
return Amount;
}
public String GetCountry()
{
return country;
}
public String GetVBV()
{
return vbv;
}
public String GetVBVrisp()
{
return vbvrisp;
}
public String GetShopTransactionID()
{
String app = String.Empty;
try
{
app = URLDecode(ShopTransactionID);
}
catch (Exception ex) { }
return app;
}
public String GetBuyerName()
{
String appBuyername = String.Empty;
try
{
appBuyername = URLDecode(BuyerName);
}
catch (Exception ex) { appBuyername = "errore"; }
return appBuyername;
}
public String GetBuyerEmail()
{
return BuyerEmail;
}
public String GetCustomInfo()
{
String appCustom = String.Empty;
try
{
appCustom = URLDecode(CustomInfo);
}
catch (Exception ex) { }
return appCustom;
}
public String GetAuthorizationCode()
{
return AuthorizationCode;
}
public String GetErrorCode()
{
return ErrorCode;
}
public String GetErrorDescription()
{
return ErrorDescription;
}
public String GetBankTransactionID()
{
return BankTransactionID;
}
public String GetTransactionResult()
{
return TransactionResult;
}
public String GetAlertCode()
{
return AlertCode;
}
public String GetAlertDescription()
{
return AlertDescription;
}
public String GetEncryptedString()
{
return EncryptedString;
}
// giungo '07
public String getProtocolServer()
{
return ProtocolAuthServer;
}
// giungo '07
public String getDomainName()
{
return DomainName;
}
/**
*
*** metodo Enrypt()
*
*/
public bool Encrypt()
{
String sErr = String.Empty;
ErrorCode = "0";
ErrorDescription = String.Empty;
try
{/*contact Encryption Server*/
// Giugno 2007
// se il protocollo e il dominio non sono stati modificati dall'esercente questi puntano di default a
// https://testecomm.sella.it--> per i codici di test oppure a
// https://ecomms2s.sella.it --> per i codici di produzione
if (String.IsNullOrEmpty(ProtocolAuthServer))
{
ProtocolAuthServer = "http://";
}
trans = ShopLogin.Substring(0, 6);
trans = trans.ToLower();
if (String.IsNullOrEmpty(DomainName))
{
if (trans.Equals("gespay"))
{
DomainName = "testecomm.sella.it/CryptHTTP"; // codici di test
}
else
{
DomainName = "ecomms2s.sella.it/CryptHTTP"; // codici di produzione
}
}
// ************
if (ShopLogin.Length <= 0)
{
ErrorCode = "546";
ErrorDescription = "IDshop not valid";
return false;
}
if (Currency.Length <= 0)
{
ErrorCode = "552";
ErrorDescription = "Currency not valid";
return false;
}
if (Amount.Length <= 0)
{
ErrorCode = "553";
ErrorDescription = "Amount not valid";
return false;
}
if (ShopTransactionID.Length <= 0)
{
ErrorCode = "551";
ErrorDescription = "Shop Transaction ID not valid";
return false;
}
ToBeEncript = String.Empty;
if (CVV.Length > 0)
{
ToBeEncript = ToBeEncript + separator + "PAY1_CVV=" + CVV;
}
if (Min.Length > 0)
{
ToBeEncript = ToBeEncript + separator + "PAY1_MIN=" + Min;
}
if (Currency.Length > 0)
{
ToBeEncript = ToBeEncript + separator + "PAY1_UICCODE=" + Currency;
}
if (Amount.Length > 0)
{
ToBeEncript = ToBeEncript + separator + "PAY1_AMOUNT=" + Amount;
}
if (ShopTransactionID.Length > 0)
{
ToBeEncript = ToBeEncript + separator + "PAY1_SHOPTRANSACTIONID=" + ShopTransactionID;
}
if (BuyerName.Length > 0)
{
ToBeEncript = ToBeEncript + separator + "PAY1_CHNAME=" + BuyerName;
}
if (BuyerEmail.Length > 0)
{
ToBeEncript = ToBeEncript + separator + "PAY1_CHEMAIL=" + BuyerEmail;
}
if (Language.Length > 0)
{
ToBeEncript = ToBeEncript + separator + "PAY1_IDLANGUAGE=" + Language;
}
if (CustomInfo.Length > 0)
{
ToBeEncript = ToBeEncript + separator + CustomInfo;
}
String urlString =
ProtocolAuthServer + DomainName + "/Encrypt.asp?a=" +
ShopLogin + "&b=" + ToBeEncript.Substring(4, ToBeEncript.Length-4) + "&c=" + Version;
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(urlString);
Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
int nStart = 0;
int nEnd = 0;
String line = String.Empty;
while (line != null)
{
line = objReader.ReadLine();
//HttpContext.Current.Response.Write("1");
if (line != null)
{
//HttpContext.Current.Response.Write("2");
nStart = line.IndexOf("#cryptstring#");
nEnd = line.LastIndexOf("#/cryptstring#");
if (nStart != -1 & nEnd > nStart + 14)
{
//HttpContext.Current.Response.Write("3");
EncryptedString = line.Substring(nStart + 13, nEnd - (nStart + 13));
}
nStart = line.IndexOf("#error#");
nEnd = line.LastIndexOf("#/error#");
if (nStart != -1 & nEnd > nStart + 8)
{
//HttpContext.Current.Response.Write("4");
sErr = line.Substring(nStart + 7, nEnd - (nStart + 7));
int intsep = sErr.IndexOf("-");
ErrorCode = sErr.Substring(0, intsep);
ErrorDescription = sErr.Substring(intsep + 1, sErr.Length - (intsep + 1));
return false;
}
}
}
objReader.Close();
return true;
}
catch (UriFormatException ex) { ErrorCode = "9999"; ErrorDescription = "Bad URL"; return false; }
catch (IOException ex) { ErrorCode = "9999"; ErrorDescription = "Bad URL Request"; return false; }
catch (Exception ex) { ErrorCode = "9999"; ErrorDescription = "ServiceException occurred."; return false; }
}
/**
**
*** metodo Decrypt()
**
*/
public bool Decrypt()
{
String sErr;
ErrorCode = "0";
ErrorDescription = String.Empty;
String strdaelim = String.Empty;
if (ShopLogin.Length <= 0)
{
ErrorCode = "546";
ErrorDescription = "IDshop not valid";
return false;
}
if (EncryptedString.Length <= 0)
{
ErrorCode = "1009";
ErrorDescription = "String to Decrypt not valid";
return false;
}
// Giugno 2007
// se il protocollo e il dominio non sono stati modificati dall'esercente questi puntano di default a
// https://testecomm.sella.it--> per i codici di test oppure a
// https://ecomms2s.sella.it --> per i codici di produzione
if (String.IsNullOrEmpty(ProtocolAuthServer))
{
ProtocolAuthServer = "http://";
}
trans = ShopLogin.Substring(0, 6);
trans = trans.ToLower();
if (String.IsNullOrEmpty(DomainName))
{
if (trans.Equals("gespay"))
{
DomainName = "testecomm.sella.it/CryptHTTP"; // codici di test
}
else
{
DomainName = "ecomms2s.sella.it/CryptHTTP"; // codici di produzione
}
}
// ************
try
{
/*contact Decryption Server*/
String urlString =
ProtocolAuthServer + DomainName + "/Decrypt.asp?a=" +
ShopLogin + "&b=" + EncryptedString + "&c=" + Version;
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(urlString);
Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
int nStart = 0;
int nEnd = 0;
String line = String.Empty;
while (line != null)
{
line = objReader.ReadLine();
if (line != null)
{
nStart = line.IndexOf("#decryptstring#");
nEnd = line.LastIndexOf("#/decryptstring#");
if (nStart != -1 & nEnd > nStart + 16)
{
Decripted = line.Substring(nStart + 15, nEnd - (nStart + 15));
}
nStart = line.IndexOf("#error#");
nEnd = line.LastIndexOf("#/error#");
if (nStart != -1 & nEnd > nStart + 8)
{
sErr = line.Substring(nStart + 7, nEnd - (nStart + 7));
int intsep = sErr.IndexOf("-");
ErrorCode = sErr.Substring(0, intsep);
ErrorDescription = sErr.Substring(intsep + 1, sErr.Length - (intsep + 1));
return false;
}
}
}
objReader.Close();
if (Decripted.Trim().Equals(String.Empty))
{
ErrorCode = "9999";
ErrorDescription = "Void String";
return false;
}
if (!Parsing(Decripted)) { return false; }
return true;
}
catch (UriFormatException ex) { ErrorCode = "9999"; ErrorDescription = "Bad URL"; return false; }
catch (IOException ex) { ErrorCode = "9999"; ErrorDescription = "Bad URL Request"; return false; }
catch (Exception ex){ErrorCode="9999";ErrorDescription="Service Exception occurred."; return false;}
}
/**
**
*** Parsing()
**
*/
private bool Parsing(String StringToBeParsed)
{
int nStart = 0;
int nEnd = 0;
ErrorCode = String.Empty;
ErrorDescription = String.Empty;
try
{
/* set attribute from crypt string*/
nStart = StringToBeParsed.IndexOf("PAY1_UICCODE");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
Currency = StringToBeParsed.Substring(nStart + 13, nEnd - (nStart + 13));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
Currency = StringToBeParsed.Substring(nStart + 13, nEnd - (nStart + 13));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_AMOUNT");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
Amount = StringToBeParsed.Substring(nStart + 12, nEnd - (nStart + 12));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
Amount = StringToBeParsed.Substring(nStart + 12, nEnd - (nStart + 12));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_SHOPTRANSACTIONID");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
ShopTransactionID = StringToBeParsed.Substring(nStart + 23, nEnd - (nStart + 23));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
ShopTransactionID = StringToBeParsed.Substring(nStart + 23, nEnd - (nStart + 23));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_CHNAME");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
BuyerName = StringToBeParsed.Substring(nStart + 12, nEnd - (nStart + 12));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
BuyerName = StringToBeParsed.Substring(nStart + 12, nEnd - (nStart + 12));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_CHEMAIL");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
BuyerEmail = StringToBeParsed.Substring(nStart + 13, nEnd - (nStart + 13));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
BuyerEmail = StringToBeParsed.Substring(nStart + 13, nEnd - (nStart + 13));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_AUTHORIZATIONCODE");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
AuthorizationCode = StringToBeParsed.Substring(nStart + 23, nEnd - (nStart + 23));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
AuthorizationCode = StringToBeParsed.Substring(nStart + 23, nEnd - (nStart + 23));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_ERRORCODE");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
ErrorCode = StringToBeParsed.Substring(nStart + 15, nEnd - (nStart + 15));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
ErrorCode = StringToBeParsed.Substring(nStart + 15, nEnd - (nStart + 15));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_ERRORDESCRIPTION");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
ErrorDescription = StringToBeParsed.Substring(nStart + 22, nEnd - (nStart + 22));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
ErrorDescription = StringToBeParsed.Substring(nStart + 22, nEnd - (nStart + 22));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_BANKTRANSACTIONID");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
BankTransactionID = StringToBeParsed.Substring(nStart + 23, nEnd - (nStart + 23));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
BankTransactionID = StringToBeParsed.Substring(nStart + 23, nEnd - (nStart + 23));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_ALERTCODE");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
AlertCode = StringToBeParsed.Substring(nStart + 15, nEnd - (nStart + 15));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
AlertCode = StringToBeParsed.Substring(nStart + 15, nEnd - (nStart + 15));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_ALERTDESCRIPTION");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
AlertDescription = StringToBeParsed.Substring(nStart + 22, nEnd - (nStart + 22));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
AlertDescription = StringToBeParsed.Substring(nStart + 22, nEnd - (nStart + 22));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_COUNTRY");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
country = StringToBeParsed.Substring(nStart + 13, nEnd - (nStart + 13));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
country = StringToBeParsed.Substring(nStart + 13, nEnd - (nStart + 13));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_VBVRISP");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
vbvrisp = StringToBeParsed.Substring(nStart + 13, nEnd - (nStart + 13));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
vbvrisp = StringToBeParsed.Substring(nStart + 13, nEnd - (nStart + 13));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_VBV");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
vbv = StringToBeParsed.Substring(nStart + 9, nEnd - (nStart + 9));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
vbv = StringToBeParsed.Substring(nStart + 9, nEnd - (nStart + 9));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_IDLANGUAGE");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
Language = StringToBeParsed.Substring(nStart + 16, nEnd - (nStart + 16));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
Language = StringToBeParsed.Substring(nStart + 16, nEnd - (nStart + 16));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
nStart = StringToBeParsed.IndexOf("PAY1_TRANSACTIONRESULT");
if (nStart != -1)
{
nEnd = StringToBeParsed.IndexOf(separator, nStart);
if (nEnd == -1)
{
nEnd = StringToBeParsed.Length;
TransactionResult = StringToBeParsed.Substring(nStart + 23, nEnd - (nStart + 23));
if (nStart >= 4) { StringToBeParsed = StringToBeParsed.Substring(0, nStart - 4); }
else { StringToBeParsed = StringToBeParsed.Substring(0, nStart); }
}
else
{
TransactionResult = StringToBeParsed.Substring(nStart + 23, nEnd - (nStart + 23));
StringToBeParsed = StringToBeParsed.Substring(0, nStart) + StringToBeParsed.Substring(nEnd + 4, StringToBeParsed.Length - (nEnd + 4));
}
}
CustomInfo = StringToBeParsed.Trim();
}
catch (Exception e) { ErrorCode = "9999"; ErrorDescription = "Error parsing String"; return false; }
return true;
}
public String URLDecode(String str)
{
if (String.IsNullOrEmpty(str))
{
return null;
}
else
{
return HttpUtility.UrlDecode(str);
}
}
}
}
Per effettuare delle prove si può accedere al sito dedicato da banca sella
https://www.easynolo.it/easynolo/index.jsp (cliccare su e-commerce poi su "Scarica i codici di Test") iscriversi (Codice e Chiave, che tradotti sono username e password di accesso) e richiedere un codice di test (seguendo la procedura guidata per la richiesta, il codice sarà inviato alla email da voi scelta in fase di registrazione).
Ps. Nella fase di richiesta ricordatevi di specificare un codice di test per la versione advanced di GestPay, poichè la versione di base sembra avere qualche problema nel test.
Ricevuto il codice si può utilizzare una semplice pagina di prova come la seguente per effettuare le prove di comunicazione
Pagina aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form action="https://testecomm.sella.it/gestpay/pagam.asp" method="get" >
<input id="a" type="hidden" value="" name="a" runat="server"/>
<input id="b" type="hidden" value="" name="b" runat="server"/>
<input type="submit" value=" OK " name="Input" />
</form>
<asp:Label ID="lblError" runat="server" Text=""></asp:Label>
</body>
</html>
Code behind
using System;
using COMCaller;
public partial class _Default : System.Web.UI.Page
{
private string myshoplogin = "GESPAY43990"; //Codice di test
private string mycurrency = "242"; //Es. 242 per euro o 18 lira
private string myamount = "100.45"; //Es. un valore che indica il prezzo della transazione
private string myshoptransactionID = "t1"; //L'identificativo scelto per la transazione
protected void Page_Load(object sender, EventArgs e)
{
GestPayCrypt objCrypt;
objCrypt = new COMCaller.GestPayCrypt();
objCrypt.SetShopLogin(myshoplogin);
objCrypt.SetCurrency(mycurrency);
objCrypt.SetAmount(myamount);
objCrypt.SetShopTransactionID(myshoptransactionID);
objCrypt.Encrypt();
if (objCrypt.GetErrorCode().Equals("0"))
{
b.Value = objCrypt.GetEncryptedString();
a.Value = objCrypt.GetShopLogin();
}
else
{
lblError.Text = objCrypt.GetErrorCode() + "<br> "+objCrypt.GetErrorDescription();
}
}
}
Nell'interfaccia di gestione di GestPay all'inizio si dovranno configurare alcuni parametri tra cui gli indirizzi IP da cui provengono le nostre richieste verso banca sella (L'IP pubblico del ns. server dove stiamo effettuando le prove), altrimenti non riusciremo ad effettuare l'autenticazione verso banca sella.
Spero di esservi stato di aiuto.