public void Execute() { _logger.Information("START TBC close Day task"); string url = _TbcPaymentSettings.ServiceURL; string certPath = $@"{HttpContext.Current.Request.PhysicalApplicationPath}Plugins\Payments.TBCBankCard\KeyStore\{_TbcPaymentSettings.CertificatePath}"; Code.Merchant merchant = new Code.Merchant(certPath, _TbcPaymentSettings.SecretPass, url, 30000); string closeResult = ""; try { closeResult = merchant.CloseDay(new Code.CommandParams()); Code.CloseDayResult clRes = new Code.CloseDayResult(closeResult); if (clRes.RESULT == "OK") { _logger.Information("START TBC close Day OK!"); } else { _logger.Information(closeResult); } } catch (Exception ex) { _logger.Error("TBC CLOSE Day error:" + ex.Message); } _logger.Information("END TBC close Day task"); }
public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest) { /// CHECKING ORDER if (!refundPaymentRequest.IsPartialRefund) { if (!string.IsNullOrEmpty(refundPaymentRequest.Order.AuthorizationTransactionId) && string.IsNullOrEmpty(refundPaymentRequest.Order.CaptureTransactionId)) { // Can check RefundPaymentResult res = new RefundPaymentResult(); // get Result Frm Bank var order = _orderService.GetOrderByAuthorizationTransactionIdAndPaymentMethod(refundPaymentRequest.Order.AuthorizationTransactionId, "Payments.TBCBankCard"); string lang = _workContext.WorkingLanguage.UniqueSeoCode; string url = _TbcPaymentSettings.ServiceURL; Debug($"Payment URL = {url}"); string certPath = $@"{HttpContext.Current.Request.PhysicalApplicationPath}Plugins\Payments.TBCBankCard\KeyStore\{_TbcPaymentSettings.CertificatePath}"; Code.Merchant merchant = new Code.Merchant(certPath, _TbcPaymentSettings.SecretPass, url, 30000); string bankPaymentResult = ""; Code.StatusResult CheckResult = null; try { bankPaymentResult = merchant.GetTransResult(new Code.CommandParams(lang) { trans_id = refundPaymentRequest.Order.AuthorizationTransactionId }); CheckResult = new Code.StatusResult(bankPaymentResult); if (CheckResult.RESULT == "OK") { order.PaymentStatus = Core.Domain.Payments.PaymentStatus.Authorized; order.AuthorizationTransactionCode = CheckResult.RESULT; _orderService.UpdateOrder(order); Debug($"Check result: {CheckResult.RESULT}. Code: {CheckResult.RESULT_CODE}"); res.Errors.Clear(); res.NewPaymentStatus = PaymentStatus.Authorized; return(res); } else { order.AuthorizationTransactionCode = bankPaymentResult; _orderService.UpdateOrder(order); res.AddError("bankPaymentResult"); Debug($"Check result: {CheckResult.RESULT}. Code: {CheckResult.RESULT_CODE}"); return(res); } } catch (Exception ex) { _logger.Error($"TBC Paysucces error check transaction :{ex.Message}"); res.AddError(ex.Message); return(res); } } } return(new RefundPaymentResult()); }
public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest) { var result = new ProcessPaymentResult(); string GetTransactionID(string responce) { if (responce.Substring(0, 14).ToUpper() == "TRANSACTION_ID") { return(responce.Substring(16, 28)); } else { return(""); } } string lang = _workContext.WorkingLanguage.UniqueSeoCode; Debug("process start"); // Registre transaction string url = _TbcPaymentSettings.ServiceURL; //Debug($"Payment URL = {url}"); string certPath = $@"{HttpContext.Current.Request.PhysicalApplicationPath}Plugins\Payments.TBCBankCard\KeyStore\{_TbcPaymentSettings.CertificatePath}"; Code.Merchant merchant = new Code.Merchant(certPath, _TbcPaymentSettings.SecretPass, url, 30000); string res = ""; try { Code.CommandParams param = new Code.CommandParams(lang) { amount = processPaymentRequest.OrderTotal }; //Debug(param.CommandString()); res = merchant.SendPreAuthorization(param); } catch (Exception ex) { result.AuthorizationTransactionResult = ex.Message; _logger.Debug("TBC payment error - PostProcess:" + ex.Message); result.AddError("TBC error: Register payment. " + ex.Message); return(result); } string transaction_id = GetTransactionID(res); result.AuthorizationTransactionId = transaction_id; result.AuthorizationTransactionCode = ""; result.AuthorizationTransactionResult = res; if (transaction_id == "") { _logger.Debug("TBC payment error - PostProcess: error registring payment"); result.AddError("TBC payment error: No Transaction ID"); return(result); } result.NewPaymentStatus = PaymentStatus.Pending; return(result); }
public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest) { CapturePaymentResult result = new CapturePaymentResult(); string lang = _workContext.WorkingLanguage.UniqueSeoCode; string trID = capturePaymentRequest.Order.AuthorizationTransactionId; Debug("start capture of:" + capturePaymentRequest.Order.OrderTotal.ToString()); // Registre transaction string url = _TbcPaymentSettings.ServiceURL; //Debug($"Payment URL = {url}"); string certPath = $@"{HttpContext.Current.Request.PhysicalApplicationPath}Plugins\Payments.TBCBankCard\KeyStore\{_TbcPaymentSettings.CertificatePath}"; Code.Merchant merchant = new Code.Merchant(certPath, _TbcPaymentSettings.SecretPass, url, 30000); string res = ""; Code.CommandParams param = new Code.CommandParams(lang) { trans_id = trID, amount = capturePaymentRequest.Order.OrderTotal }; //Debug(param.CommandString()); try { res = merchant.SendCapture(param); } catch (Exception ex) { _logger.Error("TBC payment error - Capture:" + ex.Message); result.AddError("TBC Capture error."); return(result); } Code.StatusResult CheckResult = null; CheckResult = new Code.StatusResult(res); if (CheckResult.RESULT_CODE == "000") { // success result.CaptureTransactionId = CheckResult.APPROVAL_CODE; result.CaptureTransactionResult = res; result.NewPaymentStatus = PaymentStatus.Paid; // _logger.Information("TBC OK: " + CheckResult.APPROVAL_CODE); } else { _logger.Error("TBC Capture failed: " + res); result.AddError("Capture failed: " + res); } return(result); }
public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { // Cancel Autorised Payment VoidPaymentResult Vres = new VoidPaymentResult(); string lang = _workContext.WorkingLanguage.UniqueSeoCode; string trID = voidPaymentRequest.Order.AuthorizationTransactionId; Debug("start Void of:" + voidPaymentRequest.Order.OrderTotal.ToString()); // Void transaction string url = _TbcPaymentSettings.ServiceURL; string certPath = $@"{HttpContext.Current.Request.PhysicalApplicationPath}Plugins\Payments.TBCBankCard\KeyStore\{_TbcPaymentSettings.CertificatePath}"; Code.Merchant merchant = new Code.Merchant(certPath, _TbcPaymentSettings.SecretPass, url, 30000); string res = ""; Code.CommandParams param = new Code.CommandParams(lang) { trans_id = trID, amount = voidPaymentRequest.Order.OrderTotal }; try { res = merchant.SendReversal(param); } catch (Exception ex) { _logger.Error("TBC payment error - Reversal:" + ex.Message); Vres.AddError("TBC Reversal error."); return(Vres); } Code.StatusResult CheckResult = null; CheckResult = new Code.StatusResult(res); if (CheckResult.RESULT_CODE == "400") { // success Vres.NewPaymentStatus = PaymentStatus.Voided; } else { _logger.Error("TBC Reversal failed: " + res); Vres.AddError("Reversal failed: " + res); } return(Vres); }