示例#1
0
        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());
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }