Ejemplo n.º 1
0
 public static string CreateVerifyData(SamanCallbackResult callbackResult, SamanGatewayAccount account)
 {
     return
         ("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:Foo\">" +
          "<soapenv:Header/>" +
          "<soapenv:Body>" +
          "<urn:verifyTransaction soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
          $"<String_1 xsi:type=\"xsd:string\">{callbackResult.TransactionId}</String_1>" +
          $"<String_2 xsi:type=\"xsd:string\">{account.MerchantId}</String_2>" +
          "</urn:verifyTransaction>" +
          "</soapenv:Body>" +
          "</soapenv:Envelope>");
 }
Ejemplo n.º 2
0
        public static PaymentVerifyResult CreateVerifyResult(string webServiceResponse, InvoiceContext context, SamanCallbackResult callbackResult, MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(webServiceResponse, "result");

            //  This result is actually: TotalAmount
            //  it must be equals to TotalAmount in database.
            var numericResult = Convert.ToInt64(result);

            var isSuccess = numericResult > 0 && numericResult == (long)context.Payment.Amount;

            var message = isSuccess
                ? messagesOptions.PaymentSucceed
                : SamanResultTranslator.Translate(numericResult, messagesOptions);

            return(new PaymentVerifyResult
            {
                IsSucceed = isSuccess,
                TransactionCode = callbackResult.TransactionId,
                Message = message
            });
        }
Ejemplo n.º 3
0
        public static PaymentVerifyResult CreateVerifyResult(string webServiceResponse, InvoiceContext context, SamanCallbackResult callbackResult, MessagesOptions messagesOptions)
        {
            var stringResult = XmlHelper.GetNodeValueFromXml(webServiceResponse, "result");

            //  This result is actually: TotalAmount
            //  it must be equals to TotalAmount in database.
            var numericResult = Convert.ToInt64(stringResult);

            var isSuccess = numericResult > 0 && numericResult == (long)context.Payment.Amount;

            var message = isSuccess
                ? messagesOptions.PaymentSucceed
                : SamanResultTranslator.Translate(numericResult, messagesOptions);

            var result = new PaymentVerifyResult
            {
                Status          = isSuccess ? PaymentVerifyResultStatus.Succeed : PaymentVerifyResultStatus.Failed,
                TransactionCode = callbackResult.TransactionId,
                Message         = message
            };

            result.AdditionalData.Add(AdditionalVerificationDataKey, new SamanAdditionalVerificationData
            {
                Cid       = callbackResult.Cid,
                TraceNo   = callbackResult.TraceNo,
                SecurePan = callbackResult.SecurePan,
                Rrn       = callbackResult.Rrn
            });

            return(result);
        }
Ejemplo n.º 4
0
        public ActionResult SamanCallback(string refNum, string resNum, string state, string traceNo)
        {
            var callbackResult = new SamanCallbackResult
            {
                ReferenceNumber   = refNum,
                ReservationNumber = resNum,
                State             = state,
                TraceNumber       = traceNo
            };

            // load settings for a chosen store scope
            var  storeScope           = GetActiveStoreScopeConfiguration(_storeService, _workContext);
            var  samanPaymentSettings = _settingService.LoadSetting <SamanPaymentSettings>(storeScope);
            Guid orderGuid;

            try
            {
                orderGuid = Guid.Parse(resNum);
            }
            catch (Exception ex)
            {
                _logger.Error("Callback failed.", ex);
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            var order = _orderService.GetOrderByGuid(orderGuid);

            if (order == null)
            {
                _logger.Error("Callback failed.", new NopException("Order is null."));
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            order.AuthorizationTransactionResult = callbackResult.ToString();

            _orderService.UpdateOrder(order);

            ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };

            var service = new Sep.ReferencePayment.PaymentIFBinding();
            var result  = service.verifyTransaction(refNum, samanPaymentSettings.MerchantId);

            order.AuthorizationTransactionCode = result.ToString();

            _orderService.UpdateOrder(order);

            if (result > 0)
            {
                _orderProcessingService.MarkAsAuthorized(order);

                if (result == (double)order.OrderTotal)
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                    return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
                }
                else
                {
                    var reverseId = service.reverseTransaction(refNum, samanPaymentSettings.MerchantId, samanPaymentSettings.MerchantId, samanPaymentSettings.Passcode);
                    order.CaptureTransactionId = reverseId.ToString();
                    _orderService.UpdateOrder(order);

                    if (reverseId == 1)
                    {
                        _orderProcessingService.Refund(order);
                        _logger.Error("Transaction reverse process was successful.", new NopException(reverseId.ToString()));
                    }
                    else
                    {
                        _logger.Error("Transaction reverse process was not successful.", new NopException(reverseId.ToString()));
                    }

                    return(RedirectToAction("Index", "Home", new { area = "" }));
                }
            }
            else
            {
                _logger.Error("Transaction verification failed.", new NopException(result.ToString()));
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }
        }