Пример #1
0
        public override string VoidOrder(int orderNumber)
        {
            var useLiveTransactions = AppConfigProvider.GetAppConfigValue <bool>("UseLiveTransactions");

            var originalOrder = new AspDotNetStorefrontCore.Order(orderNumber);

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.voidTransaction.ToString(),
                payment         = GetPreviousOrderPaymentInfo(orderNumber),
                refTransId      = originalOrder.AuthorizationPNREF
            };

            if (useLiveTransactions)
            {
                transactionRequest.solution = new solutionType
                {
                    id = SolutionId
                }
            }
            ;

            var request = new createTransactionRequest
            {
                transactionRequest     = transactionRequest,
                merchantAuthentication = GetMerchantAuthentication(useLiveTransactions)
            };

            //Save the command we're sending
            DB.ExecuteSQL("UPDATE Orders SET VoidTXCommand = @command WHERE OrderNumber = @orderNumber",
                          new SqlParameter("@command", JsonConvert.SerializeObject(request)),
                          new SqlParameter("@orderNumber", orderNumber));

            var controller = new createTransactionController(request);

            controller.Execute(
                GetRunEnvironment(useLiveTransactions));

            var response = controller.GetApiResponse();

            if (response == null)
            {
                return("NO RESPONSE FROM GATEWAY!");
            }

            //Save the response
            DB.ExecuteSQL("UPDATE Orders SET VoidTXResult = @result WHERE OrderNumber = @orderNumber",
                          new SqlParameter("@result", JsonConvert.SerializeObject(response)),
                          new SqlParameter("@orderNumber", orderNumber));

            if (response.messages.resultCode != messageTypeEnum.Ok)
            {
                return(response.transactionResponse?.errors?[0].errorText
                       ?? response.messages.message[0].text);
            }

            if (response.transactionResponse.messages == null)
            {
                return(response.transactionResponse.errors?[0].errorText
                       ?? "Unspecified Error");
            }

            return(AppLogic.ro_OK);
        }
Пример #2
0
        public override string RefundOrder(
            int originalOrderNumber,
            int newOrderNumber,
            decimal refundAmount,
            string refundReason,
            AspDotNetStorefrontCore.Address billingAddress)
        {
            var useLiveTransactions = AppConfigProvider.GetAppConfigValue <bool>("UseLiveTransactions");

            var originalOrder = new AspDotNetStorefrontCore.Order(originalOrderNumber);

            refundAmount.ValidateNumberOfDigits(15);

            var transactionRequest = new transactionRequestType
            {
                payment         = GetPreviousOrderPaymentInfo(originalOrderNumber),
                transactionType = transactionTypeEnum.refundTransaction.ToString(),
                amount          = refundAmount,
                amountSpecified = true,
                refTransId      = originalOrder.AuthorizationPNREF
            };

            if (useLiveTransactions)
            {
                transactionRequest.solution = new solutionType
                {
                    id = SolutionId
                }
            }
            ;

            var request = new createTransactionRequest
            {
                transactionRequest     = transactionRequest,
                merchantAuthentication = GetMerchantAuthentication(useLiveTransactions)
            };

            //Save the command we're sending
            originalOrder.RefundTXCommand = JsonConvert.SerializeObject(request);

            var controller = new createTransactionController(request);

            controller.Execute(
                GetRunEnvironment(useLiveTransactions));

            var response = controller.GetApiResponse();

            if (response == null)
            {
                return("NO RESPONSE FROM GATEWAY!");
            }

            //Save the response
            originalOrder.RefundTXResult = JsonConvert.SerializeObject(response);

            if (response.messages.resultCode != messageTypeEnum.Ok)
            {
                return(response.transactionResponse?.errors?[0].errorText
                       ?? response.messages.message[0].text);
            }

            if (response.transactionResponse.messages == null)
            {
                return(response.transactionResponse.errors?[0].errorText
                       ?? "Unspecified Error");
            }

            return(AppLogic.ro_OK);
        }

        paymentType GetPreviousOrderPaymentInfo(int orderNumber)
        {
            var cardNumber = DB.GetSqlS("SELECT Last4 S FROM Orders WITH (NOLOCK) WHERE OrderNumber = @orderNumber",
                                        new SqlParameter("@orderNumber", orderNumber));

            var creditCard = new creditCardType
            {
                cardNumber     = cardNumber,
                expirationDate = "XXXX"
            };

            return(new paymentType
            {
                Item = creditCard
            });
        }

        AuthorizeNet.Environment GetRunEnvironment(bool liveMode)
        {
            return(liveMode
                                ? AuthorizeNet.Environment.PRODUCTION
                                : AuthorizeNet.Environment.SANDBOX);
        }

        merchantAuthenticationType GetMerchantAuthentication(bool liveMode)
        {
            return(new merchantAuthenticationType()
            {
                name = liveMode
                                        ? AppConfigProvider.GetAppConfigValue("AcceptJs.Live.ApiLoginId")
                                        : AppConfigProvider.GetAppConfigValue("AcceptJs.Test.ApiLoginId"),
                ItemElementName = ItemChoiceType.transactionKey,
                Item = liveMode
                                        ? AppConfigProvider.GetAppConfigValue("AcceptJs.Live.TransactionKey")
                                        : AppConfigProvider.GetAppConfigValue("AcceptJs.Test.TransactionKey"),
            });
        }
    }
Пример #3
0
        public override string CaptureOrder(AspDotNetStorefrontCore.Order order)
        {
            var useLiveTransactions = AppConfigProvider.GetAppConfigValue <bool>("UseLiveTransactions");

            var orderTotal = order.Total();

            orderTotal.ValidateNumberOfDigits(15);             // Accept.js limit

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(),
                amount          = orderTotal,
                amountSpecified = true,
                refTransId      = order.AuthorizationPNREF,
            };

            if (useLiveTransactions)
            {
                transactionRequest.solution = new solutionType
                {
                    id = SolutionId
                }
            }
            ;

            var request = new createTransactionRequest
            {
                transactionRequest     = transactionRequest,
                merchantAuthentication = GetMerchantAuthentication(useLiveTransactions)
            };

            //Save the command we're sending
            order.CaptureTXCommand = JsonConvert.SerializeObject(request);

            var controller = new createTransactionController(request);

            controller.Execute(
                GetRunEnvironment(useLiveTransactions));

            var response = controller.GetApiResponse();

            if (response == null)
            {
                return("NO RESPONSE FROM GATEWAY!");
            }

            //Save the response
            order.CaptureTXResult = JsonConvert.SerializeObject(response);

            if (response.messages.resultCode != messageTypeEnum.Ok)
            {
                return(response.transactionResponse?.errors?[0].errorText
                       ?? response.messages.message[0].text);
            }

            if (response.transactionResponse.messages == null)
            {
                return(response.transactionResponse.errors?[0].errorText
                       ?? "Unspecified Error");
            }

            return(AppLogic.ro_OK);
        }