private string GetSecureHash(PayDollarPaymentOptions opt) { var hash = GetSHA1Hash(string.Format("{0}|{1}|{2}|{3}|{4}|{5}", opt.MerchantId, opt.MerchantRef, opt.Currency, opt.Amount, opt.PaymentType, opt.SecretKey)); return(hash); }
public override PaymentResult Authorize(Money money, CreditCard card, PaymentOptions options) { if (options.GetType() != typeof(PayDollarPaymentOptions)) { throw new ArgumentException("options parameter needs to be type of PayDollarPaymentOptions."); } PayDollarPaymentOptions opt = (PayDollarPaymentOptions)options; //"H" means hold which is AUTH return(MakePayment(money, card, "H", opt)); }
public override PaymentResult Purchase(Money money, CreditCard card, PaymentOptions options) { if (options.GetType() != typeof(PayDollarPaymentOptions)) { throw new ArgumentException("options parameter needs to be type of PayDollarPaymentOptions."); } PayDollarPaymentOptions opt = (PayDollarPaymentOptions)options; //"N" is normal sales return(MakePayment(money, card, "N", opt)); }
public override PaymentResult Refund(Money money, string transRef, PaymentOptions options) { if (options.GetType() != typeof(PayDollarPaymentOptions)) { throw new ArgumentException("options parameter needs to be type of PayDollarPaymentOptions."); } PayDollarPaymentOptions opt = (PayDollarPaymentOptions)options; string url = string.Format("{0}/merchant/api/onlineApi.jsp", Parameters.Options.BaseUrl); var sb = new StringBuilder(); sb.Append("merchantId="); sb.Append(opt.MerchantId); sb.Append("&loginId="); sb.Append(opt.LoginId); sb.Append("&password="******"&actionType=OnlineReversal"); sb.Append("&payRef="); sb.Append(transRef); sb.Append("&amount="); sb.Append(money.Amount); var result = HttpPost(url, sb.ToString(), "POST", "application/x-www-form-urlencoded"); var q = System.Web.HttpUtility.ParseQueryString(result); var r = new PayDollarPaymentResult(); r.SuccessCode = q["resultCode"]; r.Message = q["errMsg"]; r.GatewayRef = q["payRef"]; r.MerchantRef = q["ref"]; if (!string.IsNullOrWhiteSpace(q["amt"])) { r.Amount = decimal.Parse(q["amt"]); } r.OrderStatus = q["orderStatus"]; r.Currency = q["cur"]; return(r); }
/// <summary> /// make payment or hold payment (AUTH) /// </summary> /// <param name="money"></param> /// <param name="card"></param> /// <param name="paymentType">H: hold only; N: payment</param> /// <param name="opt"></param> /// <returns></returns> private PayDollarPaymentResult MakePayment(Money money, CreditCard card, string paymentType, PayDollarPaymentOptions opt) { opt.PaymentType = paymentType; string url = string.Format("{0}/directPay/payComp.jsp", Parameters.Options.BaseUrl); opt.Amount = money.Amount; opt.Currency = money.Currency; string hash = string.Empty; //apply to authorized merchant only if (!string.IsNullOrEmpty(opt.SecretKey)) { hash = GetSecureHash(opt); } var sb = new StringBuilder(); sb.Append("merchantId="); sb.Append(opt.MerchantId); sb.Append("&loginId="); sb.Append(opt.LoginId); sb.Append("&password="******"&orderRef="); sb.Append(opt.MerchantRef); sb.Append("&payType="); sb.Append(opt.PaymentType); sb.Append("&amount="); sb.Append(money.Amount); sb.Append("&currCode="); sb.Append(money.Currency); sb.Append("&pMethod="); sb.Append(opt.PaymentMethod); sb.Append("&epMonth="); sb.Append(card.ExpiryMonth); sb.Append("&epYear="); sb.Append(card.ExpiryYear); sb.Append("&cardNo="); sb.Append(card.CardNo); sb.Append("&cardHolder="); sb.Append(card.HolderName); sb.Append("&securityCode="); sb.Append(card.CVV); sb.Append("&remark="); sb.Append(opt.TransactionRemark); if (!string.IsNullOrEmpty(hash)) { sb.Append("&secureHash="); sb.Append(hash); } var result = HttpPost(url, sb.ToString(), "POST", "application/x-www-form-urlencoded"); var q = System.Web.HttpUtility.ParseQueryString(result); var r = new PayDollarPaymentResult(); r.SuccessCode = q["successcode"]; r.Message = q["errMsg"]; r.GatewayRef = q["PayRef"]; r.MerchantRef = q["Ref"]; r.Src = q["src"]; r.Prc = q["prc"]; if (!string.IsNullOrWhiteSpace(q["Amt"])) { r.Amount = decimal.Parse(q["Amt"]); } r.Holder = q["Holder"]; if (!string.IsNullOrWhiteSpace(q["TxTime"])) { r.TransactionTime = DateTime.Parse(q["TxTime"]); } r.BankRef = q["ord"]; r.ApprovalCode = q["AuthId"]; r.Currency = q["Cur"]; return(r); }