rendered paste bodyusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace Midgar
{
public enum MercanetErrorCodes
{
SUCCESS,
ERROR_INVALID_RESPONSE,
ERROR_API,
ERROR_CARD_NUMBER,
ERROR_CVV,
ERROR_INSUFFISANT_FUND,
ERROR_BANK,
ERROR_STOLEN_CARD
}
public class MercanetTransactionResponse
{
public MercanetErrorCodes Message;
public string MerchantID;
public string MerchantCountry;
public double Price;
public ulong TransactionID;
public string PaymentMethod;
public ulong TransmissionTimestamp;
public ulong PaymentTimestamp;
public string PaymentDate;
public byte ResponseCode;
public string PaymentCertificate;
public ulong AuthorisationID;
public short CurrencyCode;
public string CardLastNumbers;
public byte CvvFlag;
public string CvvResponseCode;
public byte BankResponseCode;
public byte ComplementaryCode;
public string ComplementaryInfo;
public byte ReturnContext;
public byte Caddie;
public byte ReceiptComplement;
public string MerchantLanguage;
public string Language;
public string CustomerID;
public string OrderID;
public string CustomerEmail;
public string CustomerIP;
public string CaptureDay;
public string CaptureMode;
public string Data;
}
public class MercanetClient
{
protected string SellerID;
protected ulong TransactionID;
protected ulong Amount;
protected string Country = "en";
protected short CurrencyCode = 840;
//protected short CurrencyCode = 978;
protected string WebUrl;
public MercanetClient(string sSellerID, ulong uTransactionID, double dAmount)
{
BuildPathfile();
SellerID = sSellerID;
TransactionID = uTransactionID;
Amount = (ulong)(dAmount * 100.0);
}
public ulong GetTransactionID()
{
return TransactionID;
}
public string GetSellerID()
{
return SellerID;
}
public double GetAmount()
{
return Amount / 100.0;
}
public void SetAmount(double dAmount)
{
Amount = (ulong)(dAmount * 100.0);
}
public void SetUrl(string Url)
{
WebUrl = Url;
}
public void SetCurrency(short uCurrencyCode)
{
CurrencyCode = uCurrencyCode;
}
public string DoRequest(string CustomData)
{
Process p = new Process();
string PluginPath = HttpContext.Current.Server.MapPath("~/Plugins/mercanet/");
ProcessStartInfo pi = new ProcessStartInfo(PluginPath + "request.exe", BuildRequestArgs(CustomData));
pi.UseShellExecute = false;
pi.RedirectStandardOutput = true;
pi.CreateNoWindow = true;
p.StartInfo = pi;
p.Start();
p.WaitForExit();
string data = p.StandardOutput.ReadToEnd();
string[] toks = data.Split(new string[] { "!" }, StringSplitOptions.None);
// Error
if (toks[1] != "0")
return toks[2];
return toks[3];
}
public MercanetTransactionResponse DecodeData(string decdata)
{
try
{
if (!Filter.IsAlphaNumeric(decdata))
{
MercanetTransactionResponse err = new MercanetTransactionResponse();
err.Message = MercanetErrorCodes.ERROR_INVALID_RESPONSE;
return err;
}
Process p = new Process();
string PluginPath = HttpContext.Current.Server.MapPath("~/Plugins/mercanet/");
ProcessStartInfo pi = new ProcessStartInfo(PluginPath + "response.exe", "message=" + decdata + BuildResponseArgs());
pi.UseShellExecute = false;
pi.RedirectStandardOutput = true;
pi.CreateNoWindow = true;
p.StartInfo = pi;
p.Start();
p.WaitForExit();
string data = p.StandardOutput.ReadToEnd();
string[] toks = data.Split(new string[] { "!" }, StringSplitOptions.None);
// Error
MercanetTransactionResponse resp = new MercanetTransactionResponse();
// Error
if (toks[1] != "0")
resp.Message = MercanetErrorCodes.ERROR_API;
resp.MerchantID = toks[3];
resp.MerchantCountry = toks[4];
resp.Price = double.Parse(toks[5]) / 100.0;
resp.TransactionID = ulong.Parse(toks[6]);
resp.PaymentMethod = toks[7];
resp.TransmissionTimestamp = ulong.Parse(toks[8]);
resp.PaymentTimestamp = ulong.Parse(toks[9]);
resp.PaymentDate = toks[10];
resp.ResponseCode = byte.Parse(toks[11]);
resp.BankResponseCode = byte.Parse(toks[18]);
resp.CvvResponseCode = toks[17];
resp.Data = toks[32];
switch (resp.BankResponseCode)
{
case 0:
resp.Message = MercanetErrorCodes.SUCCESS;
break;
case 1:
resp.Message = MercanetErrorCodes.ERROR_INSUFFISANT_FUND;
break;
case 5:
resp.Message = MercanetErrorCodes.ERROR_INSUFFISANT_FUND;
break;
case 12:
resp.Message = MercanetErrorCodes.ERROR_CARD_NUMBER;
break;
case 13:
resp.Message = MercanetErrorCodes.ERROR_INSUFFISANT_FUND;
break;
case 30:
resp.Message = MercanetErrorCodes.ERROR_API;
break;
case 33:
resp.Message = MercanetErrorCodes.ERROR_BANK;
break;
case 43:
resp.Message = MercanetErrorCodes.ERROR_STOLEN_CARD;
break;
case 51:
resp.Message = MercanetErrorCodes.ERROR_INSUFFISANT_FUND;
break;
case 54:
resp.Message = MercanetErrorCodes.ERROR_BANK;
break;
case 61:
resp.Message = MercanetErrorCodes.ERROR_INSUFFISANT_FUND;
break;
case 63:
resp.Message = MercanetErrorCodes.ERROR_BANK;
break;
case 90:
resp.Message = MercanetErrorCodes.ERROR_API;
break;
default:
resp.Message = MercanetErrorCodes.ERROR_INVALID_RESPONSE;
break;
}
return resp;
}
catch (Exception)
{
MercanetTransactionResponse resp = new MercanetTransactionResponse();
resp.Message = MercanetErrorCodes.ERROR_BANK;
return resp;
}
}
protected string BuildResponseArgs()
{
string ParamPath = HttpContext.Current.Server.MapPath("~/Plugins/mercanet/param/");
string args = @" pathfile=" + ParamPath + "pathfile";
return args;
}
protected string BuildRequestArgs(string CustomData)
{
string ParamPath = HttpContext.Current.Server.MapPath("~/Plugins/mercanet/param/");
string args = "merchant_id=" + SellerID;
args += " merchant_country=fr";
args += " transaction_id=" + TransactionID;
args += " currency_code=" + CurrencyCode;
args += " amount=" + Amount;
args += " language=en";
args += " normal_return_url=" + WebUrl;
args += " automatic_response_url=" + WebUrl;
args += " cancel_return_url=" + WebUrl;
args += " data=" + CustomData;
args += " payment_means=AMEX,2,CB,2,VISA,2,MASTERCARD,2"; //,AURORE,2";
args += @" pathfile=" + ParamPath + "pathfile";
return args;
}
protected void BuildPathfile()
{
string ParamPath = HttpContext.Current.Server.MapPath("~/Plugins/mercanet/param/");
FileStream fs = new FileStream(ParamPath + "pathfile", FileMode.Create);
string pf = @"DEBUG!NO!";
pf += "\n";
pf += @"D_LOGO!/WebPage/imgs/mercanet/!";
pf += "\n";
pf += @"F_DEFAULT!" + ParamPath + "parmcom.mercanet!";
pf += "\n";
pf += @"F_PARAM!" + ParamPath + "parmcom!";
pf += "\n";
pf += @"F_CERTIFICATE!" + ParamPath + "certif!";
pf += "\n";
pf += @"F_CTYPE!php!";
fs.Write(Encoding.UTF8.GetBytes(pf), 0, (int)Encoding.UTF8.GetByteCount(pf));
fs.Close();
}
}
}