Exemplo n.º 1
0
        public string Run(CheckoutViewModel sa)
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX;

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = Configuration["AUTHNET_LOGIN_ID"],
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = Configuration["AUTH_TRANSACTION_KEY"]
            };

            creditCardType creditCard = new creditCardType
            {
                cardNumber     = Configuration["CreditCardNumber"],
                expirationDate = Configuration["ExpirationDate"]
            };

            customerAddressType billingAddress = GetAddress(sa);

            paymentType payment = new paymentType {
                Item = creditCard
            };

            transactionRequestType transRequestType = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount          = 123.45m,
                payment         = payment,
                billTo          = billingAddress
            };

            createTransactionRequest request = new createTransactionRequest
            {
                transactionRequest = transRequestType
            };

            var contoller = new createTransactionController(request);

            contoller.Execute();
            var response = contoller.GetApiResponse();

            if (response == null)
            {
                if (response.messages.resultCode == messageTypeEnum.Ok)
                {
                    return("Groomed to Perfection ;{");
                }
            }
            else
            {
                return("Not Groomed :[");
            }

            return("Not Groomed :[");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Refunds a payment
        /// </summary>
        /// <param name="refundPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
        {
            var result = new RefundPaymentResult();

            PrepareAuthorizeNet();

            var maskedCreditCardNumberDecrypted = _encryptionService.DecryptText(refundPaymentRequest.Order.MaskedCreditCardNumber);

            if (String.IsNullOrEmpty(maskedCreditCardNumberDecrypted) || maskedCreditCardNumberDecrypted.Length < 4)
            {
                result.AddError("Last four digits of Credit Card Not Available");
                return(result);
            }

            var lastFourDigitsCardNumber = maskedCreditCardNumberDecrypted.Substring(maskedCreditCardNumberDecrypted.Length - 4);
            var creditCard = new creditCardType
            {
                cardNumber     = lastFourDigitsCardNumber,
                expirationDate = "XXXX"
            };

            var codes = (string.IsNullOrEmpty(refundPaymentRequest.Order.CaptureTransactionId) ? refundPaymentRequest.Order.AuthorizationTransactionCode : refundPaymentRequest.Order.CaptureTransactionId).Split(',');
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.refundTransaction.ToString(),
                amount          = Math.Round(refundPaymentRequest.AmountToRefund, 2),
                refTransId      = codes[0],
                currencyCode    = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode,

                order = new orderType
                {
                    //x_invoice_num is 20 chars maximum. hece we also pass x_description
                    invoiceNumber = refundPaymentRequest.Order.OrderGuid.ToString().Substring(0, 20),
                    description   = string.Format("Full order #{0}", refundPaymentRequest.Order.OrderGuid)
                },

                payment = new paymentType {
                    Item = creditCard
                }
            };

            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };

            // instantiate the contoller that will call the service
            var controller = new createTransactionController(request);

            controller.Execute();

            GetApiResponse(controller, result.Errors);
            result.NewPaymentStatus = PaymentStatus.PartiallyRefunded;

            return(result);
        }
Exemplo n.º 3
0
        public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount)
        {
            Console.WriteLine("GetAnAcceptPaymentPage Sample");
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = AuthorizeNet.Environment.SANDBOX;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey,
            };

            settingType[] settings = new settingType[2];

            settings[0]              = new settingType();
            settings[0].settingName  = settingNameEnum.hostedPaymentButtonOptions.ToString();
            settings[0].settingValue = "{\"text\": \"Pay\"}";

            settings[1]              = new settingType();
            settings[1].settingName  = settingNameEnum.hostedPaymentOrderOptions.ToString();
            settings[1].settingValue = "{\"show\": false}";

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // authorize capture only
                amount          = amount
            };

            var request = new getHostedPaymentPageRequest();

            request.transactionRequest    = transactionRequest;
            request.hostedPaymentSettings = settings;

            // instantiate the controller that will call the service
            var controller = new getHostedPaymentPageController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            var response = controller.GetApiResponse();

            // validate response
            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
            {
                Console.WriteLine("Message code : " + response.messages.message[0].code);
                Console.WriteLine("Message text : " + response.messages.message[0].text);
                Console.WriteLine("Token : " + response.token);
            }
            else if (response != null)
            {
                Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
                Console.WriteLine("Failed to get hosted payment page");
            }

            return(response);
        }
        public string Run()
        {
            // decalred the type of environment
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX;

            // setup our merchant account credentials
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new AuthorizeNet.Api.Contracts.V1.merchantAuthenticationType()
            {
                name            = _config["AuthorizeLoginid"],
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = _config["AuthorizeTransactionKey"]
            };

            // create the card we want on file.
            // I want you to store these in your secrets file, adn choose a dropdown for the user in the checkout process

            var creditCard = new creditCardType
            {
                cardNumber     = "4111111111111111",
                expirationDate = "1020",
                cardCode       = "555"
            };

            customerAddressType billingAddress = GetsBillingAddress(3);

            //declare that thuse is going to use an existing Credit Cart to pay
            var paymentType = new paymentType {
                Item = creditCard
            };

            // // make the transactionRequest

            var transRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount          = 150.75m,
                payment         = paymentType,
                billTo          = billingAddress
            };

            // made teh transaction type, now we need to make the request
            var request = new createTransactionRequest {
                transactionRequest = transRequest
            };

            var controller = new createTransactionController(request);

            controller.Execute();

            var response = controller.GetApiResponse();


            return("");
        }
Exemplo n.º 5
0
        /// <summary>
        /// controllers.Base for authorize.net. Sets up the environment needed for authorize.net to run. We had also created/ set up a credit card, sets up our transactions
        /// </summary>
        /// <param name="checkoutInput">The users input from the checkout form</param>
        /// <returns></returns>
        public string Run(CheckoutInput checkoutInput)
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = AuthorizeNet.Environment.SANDBOX;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = _config["AN-ApiLoginID"],
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = _config["AN-TransactionKey"]
            };

            // creates the credits cards and passes in the type of card the user chooses to use. Either it be mastercard, visa, or american express
            var creditCard = new creditCardType
            {
                cardNumber     = checkoutInput.Payment,
                expirationDate = "1021",
                cardCode       = "102"
            };


            customerAddressType billingAddress = GetAddress(checkoutInput);

            var paymentType = new paymentType {
                Item = creditCard
            };

            var transaction = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount          = 200.0m,
                payment         = paymentType,
                billTo          = billingAddress
            };

            var request = new createTransactionRequest {
                transactionRequest = transaction
            };

            var controller = new createTransactionController(request);

            controller.Execute();

            var response = controller.GetApiResponse();

            // if the response fails, the user will see an error that the payment has failed to recieve a response
            if (response != null)
            {
                if (response.messages.resultCode == messageTypeEnum.Ok)
                {
                    return("Response recieved.");
                }
            }

            return("Failed to recieve response");
        }
        /// <summary>
        /// Capture a Transaction Previously Submitted Via CaptureOnly
        /// </summary>
        /// <param name="ApiLoginID">Your ApiLoginID</param>
        /// <param name="ApiTransactionKey">Your ApiTransactionKey</param>
        /// <param name="TransactionAmount">The amount submitted with CaptureOnly</param>
        /// <param name="TransactionID">The TransactionID of the previous CaptureOnly operation</param>
        public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal TransactionAmount, string TransactionID)
        {
            Console.WriteLine("Capture Previously Authorized Amount");

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX;

            // define the merchant information (authentication / transaction id)
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey
            };


            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(),    // capture prior only
                amount          = TransactionAmount,
                refTransId      = TransactionID
            };

            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };

            // instantiate the contoller that will call the service
            var controller = new createTransactionController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            var response = controller.GetApiResponse();

            //validate
            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
            {
                if (response.transactionResponse != null)
                {
                    Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
                }
            }
            else if (response != null)
            {
                Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
                if (response.transactionResponse != null)
                {
                    Console.WriteLine("Transaction Error : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText);
                }
            }

            return(response);
        }
Exemplo n.º 7
0
        public void SampleCodeCreateTransaction()
        {
            LogHelper.info(Logger, "Sample createTransaction");

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            //create a transaction
            var transactionRequestType = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount          = SetValidTransactionAmount(Counter),
                payment         = PaymentOne,
                order           = OrderType,
                customer        = CustomerDataOne,
                billTo          = CustomerAddressOne,
            };
            var createRequest = new createTransactionRequest
            {
                refId = RefId,
                transactionRequest = transactionRequestType,
            };

            //create controller, execute request and get response
            var createController = new createTransactionController(createRequest);

            createController.Execute();
            var createResponse = createController.GetApiResponse();

            //Test response
            Assert.IsNotNull(createResponse.transactionResponse);
            LogHelper.info(Logger, "Response: {0}", createResponse);
            DisplayResponse(createResponse, "Create Transaction Response");
            LogHelper.info(Logger, "Created Transaction: {0}", createResponse.transactionResponse);
            Assert.IsNotNull(createResponse.transactionResponse.transId);
            long transId;

            Assert.IsTrue(long.TryParse(createResponse.transactionResponse.transId, out transId));
            if (0 == transId)
            {
                ValidateFailure <createTransactionRequest, createTransactionResponse, createTransactionController>(createController, createResponse);
                Assert.IsNotNull(createResponse.transactionResponse.errors);
                foreach (var error in createResponse.transactionResponse.errors)
                {
                    LogHelper.info(Logger, "Error-> Code:{0}, Text:{1}", error.errorCode, error.errorText);
                }
            }
            else
            {
                Assert.AreNotEqual(0, transId);
                ValidateSuccess <createTransactionRequest, createTransactionResponse, createTransactionController>(createController, createResponse);
            }
        }
Exemplo n.º 8
0
        public createTransactionResponse RunCard(int orderAmount, string expDate, string number)
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX;



            // define the merchant information (authentication / transaction id)
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = _configuration.GetConnectionString("AuthorizeNet:ClientId"),
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = _configuration.GetConnectionString("Authorize:TransactionKey"),
            };

            var creditCard = new creditCardType
            {
                cardNumber     = number,
                expirationDate = expDate
            };

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = creditCard
            };

            // Set Max for Payment
            if (orderAmount > 4000)
            {
                orderAmount = 4000;
            }

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),   // charge the card
                amount          = orderAmount,
                payment         = paymentType
            };

            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };

            // instantiate the contoller that will call the service
            var controller = new createTransactionController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            var response = controller.GetApiResponse();

            return(response);
        }
Exemplo n.º 9
0
        public static createTransactionController DebitBankAccount(bankAccountType bankAccount, lineItemType[] lineItems, customerAddressType address, decimal billamount, int invoiceNumber)
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX;

            // define the merchant information (authentication / transaction id)
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey
            };

            //var bankAccount = new bankAccountType
            //{
            //    accountNumber = "4111111",
            //    routingNumber = "325070760",
            //    echeckType = echeckTypeEnum.WEB,   // change based on how you take the payment (web, telephone, etc)
            //    nameOnAccount = "Test Name"
            //};

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = bankAccount
            };

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // charge the card
                amount          = billamount,
                payment         = paymentType,
                lineItems       = lineItems,
                billTo          = address
            };
            var order = new AuthorizeNet.Api.Contracts.V1.orderType {
                invoiceNumber = "INV-" + invoiceNumber.ToString(), description = "Product Purchases"
            };

            transactionRequest.order = order;
            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };

            // instantiate the contoller that will call the service
            var controller = new createTransactionController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            return(controller);
        }
Exemplo n.º 10
0
        public static AuthorizeNetResponse CapturePreviouslyAuthorizeAmount(decimal amount, string transactionId, bool simulation = false)
        {
            AuthorizeNetResponse finalResponse = new AuthorizeNetResponse();

            try
            {
                InitEnvironmentAndAccount(simulation);
                //if (simulation)
                //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
                //else
                //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.PRODUCTION;


                //// define the merchant information (authentication / transaction id)
                //ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
                //{
                //    name = apiLoginId,
                //    ItemElementName = ItemChoiceType.transactionKey,
                //    Item = apiTransactionKey
                //};


                var transactionRequest = new transactionRequestType
                {
                    transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(),    // capture prior only
                    amount          = amount,
                    refTransId      = transactionId
                };

                System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // .net3.5沒有Tls12

                var request = new createTransactionRequest {
                    transactionRequest = transactionRequest
                };

                // instantiate the controller that will call the service
                var controller = new createTransactionController(request);
                controller.Execute();

                // get the response from the service (errors contained if any)
                var response = controller.GetApiResponse();

                finalResponse = ParseResponse(response);
            }
            catch (Exception ex)
            {
                finalResponse = GenerateExceptionResponse(ex.Message);
            }
            return(finalResponse);
        }
        public ANetApiResponse RefundTransaction(decimal TransactionAmount, string TransactionID, string cardNumber)
        {
            Console.WriteLine("Refund Transaction");

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX;

            // define the merchant information (authentication / transaction id)
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = "35WkY7AsU",
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = "85T8Hsv4JMu76P5b"
            };

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

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = creditCard
            };

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.refundTransaction.ToString(),    // refund type
                payment         = paymentType,
                amount          = TransactionAmount,
                refTransId      = TransactionID
            };

            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };

            // instantiate the controller that will call the service
            var controller = new createTransactionController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            var response = controller.GetApiResponse();

            // validate response


            return(response);
        }
Exemplo n.º 12
0
        public static createTransactionController ChargeCreditCard(creditCardType creditCard, lineItemType[] lineItems, customerAddressType address, decimal billamount, int invoiceNumber)
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX;

            // define the merchant information (authentication / transaction id)
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey,
            };

            //var creditCard = new creditCardType
            //{
            //    cardNumber = "4111111111111111",
            //    expirationDate = "0718",
            //    cardCode = "123"
            //};

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = creditCard
            };

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // charge the card
                amount          = billamount,
                payment         = paymentType,
                lineItems       = lineItems,
                billTo          = address
            };
            var order = new AuthorizeNet.Api.Contracts.V1.orderType {
                invoiceNumber = "INV-" + invoiceNumber.ToString(), description = "Product Purchases"
            };

            transactionRequest.order = order;
            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };

            // instantiate the contoller that will call the service
            var controller = new createTransactionController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            return(controller);
        }
        //private string authorizeNetUrl = "https://apitest.authorize.net/xml/v1/request.api";
        //private string authorizeNetUrl = "https://api.authorize.net/xml/v1/request.api";

        public createTransactionResponse RunCharge(String ApiLoginID, String ApiTransactionKey, creditCardType creditCard, customerAddressType billingAddress, lineItemType[] lineItems, decimal amount)
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX;

            // define the merchant information (authentication / transaction id)
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey,
            };

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = creditCard
            };

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),        // charge the card

                amount    = amount,
                payment   = paymentType,
                billTo    = billingAddress,
                lineItems = lineItems
            };

            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };

            // instantiate the controller that will call the service
            var controller = new createTransactionController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            var response = controller.GetApiResponse();

            // validate response
            if (response != null)
            {
                return(response);
            }
            else
            {
                return(null);
            }
        }
        private long GetTransactionId()
        {
            //Creates a credit card transaction and returns the transactions ID.

            //Common code to set for all requests
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            //set up data based on transaction
            var transactionAmount = SetValidTransactionAmount(Counter);
            var creditCard        = new creditCardType {
                cardNumber = "4111111111111111", expirationDate = "0622"
            };
            var aCustomer = new customerDataType {
                email = string.Format("{0}@b.bla", Counter)
            };

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = creditCard
            };
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),
                payment         = paymentType,
                amount          = transactionAmount,
                customer        = aCustomer,
            };
            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };
            var controller = new createTransactionController(request);

            controller.Execute();
            var response = controller.GetApiResponse();

            //validate
            Assert.NotNull(response);
            Assert.NotNull(response.messages);
            Assert.NotNull(response.transactionResponse);
            Assert.AreEqual(messageTypeEnum.Ok, response.messages.resultCode);
            Assert.False(string.IsNullOrEmpty(response.transactionResponse.transId));
            long transactionId;

            long.TryParse(response.transactionResponse.transId, out transactionId);
            Assert.AreNotEqual(0, transactionId);

            return(transactionId);
        }
Exemplo n.º 15
0
 public static void transactionRequestType(transactionRequestType request)
 {
     if (null != request)
     {
         if (0 <= request.amount)
         {
             request.amountSpecified = true;
         }
         if (request.taxExempt)
         {
             request.taxExemptSpecified = true;
         }
         lineItemType(request.lineItems);
     }
 }
Exemplo n.º 16
0
        //private string authorizeNetUrl = "https://apitest.authorize.net/xml/v1/request.api";
        //private string authorizeNetUrl = "https://api.authorize.net/xml/v1/request.api";
        //NOTE: cardCode not a required element of creditCardType for a refund, and only last four numbers of cardNumber needeed

        public createTransactionResponse RunRefund(String ApiLoginID, String ApiTransactionKey, creditCardType creditCard, decimal TransactionAmount, string TransactionID)
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX;

            // define the merchant information (authentication / transaction id)
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey
            };


            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = creditCard
            };

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.refundTransaction.ToString(),        // refund type
                payment         = paymentType,
                amount          = TransactionAmount,
                refTransId      = TransactionID
            };

            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };

            // instantiate the controller that will call the service
            var controller = new createTransactionController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            var response = controller.GetApiResponse();

            // validate response
            if (response != null)
            {
                return(response);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 17
0
        public void TransactionRequest_HandleError()
        {
            LogHelper.info(Logger, "CreateProfileWithCreateTransactionRequestTest");

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            //create a transaction
            var transactionRequestType = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount          = SetValidTransactionAmount(Counter),
                payment         = new paymentType {
                    Item = new creditCardType {
                        cardNumber = "0111111111111111", expirationDate = "122035"
                    }
                },
                order    = OrderType,
                customer = CustomerDataOne,
                billTo   = CustomerAddressOne,
                shipTo   = CustomerAddressOne,
            };
            var createRequest = new createTransactionRequest
            {
                refId = RefId,
                transactionRequest = transactionRequestType,
            };
            //create controller, execute and get response
            var createController = new createTransactionController(createRequest);

            createController.Execute();
            var createResponse = createController.GetApiResponse();

            //Validate error code where request is submitted properly, but request fails.
            Assert.AreEqual("6", createResponse.transactionResponse.errors[0].errorCode);

            //Validate error code where submission of request fails.
            ((creditCardType)transactionRequestType.payment.Item).cardNumber = "01";
            createController = new createTransactionController(createRequest);
            createController.Execute();

            if (createController.GetApiResponse() == null)
            {
                var errorResponse = createController.GetErrorResponse();
                Assert.AreEqual("E00003", errorResponse.messages.message[0].code);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Running authorization net
        /// </summary>
        /// <param name="addressType">Addresstype object that carries user's information</param>
        /// <param name="totalAmount">total amount that user owes</param>
        /// <returns>boolean if the payment went through</returns>
        public bool Run(customerAddressType addressType, decimal totalAmount)
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = AuthorizeNet.Environment.SANDBOX;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType
            {
                name            = _config["An-ApiId"],
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = _config["An-TransactionKey"]
            };

            var CreditCard = new creditCardType
            {
                cardNumber     = "4111111111111111",
                expirationDate = "0521",
                cardCode       = "102"
            };
            var paymentType = new paymentType
            {
                Item = CreditCard
            };
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount          = totalAmount,
                payment         = paymentType,
                billTo          = addressType
            };
            var request = new createTransactionRequest
            {
                transactionRequest = transactionRequest
            };
            var controller = new createTransactionController(request);

            controller.Execute();

            var response = controller.GetApiResponse();

            if (response != null)
            {
                if (response.messages.resultCode == messageTypeEnum.Ok)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 19
0
        private createTransactionRequest getRequest()
        {
            Debug.Write("Session Token" + this.sessionToken);
            Random random = new Random();

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                Item            = this.sessionToken,
                mobileDeviceId  = this.deviceID,
                ItemElementName = ItemChoiceType.sessionToken
            };

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = this.sdkEnvironment;

            transactionRequestType transaction = new transactionRequestType()
            {
                amount = Convert.ToDecimal(this.amount.Text, CultureInfo.InvariantCulture),
                transactionSettings = new settingType[] {
                },
                retail = new transRetailInfoType()
                {
                    deviceType = "7",
                    marketType = "2",
                },
                order = new orderType()
                {
                    description   = "Windows SDK Order",
                    invoiceNumber = Convert.ToString(random.Next(1999999, 999999999))
                }
            };

            transaction.terminalNumber = this.terminalID;
            createTransactionRequest request = new createTransactionRequest()
            {
                transactionRequest = transaction
            };

            Debug.Write("Session Token" + this.sessionToken);
            request.merchantAuthentication = new merchantAuthenticationType()
            {
                Item            = this.sessionToken,
                mobileDeviceId  = this.deviceID,
                ItemElementName = ItemChoiceType.sessionToken
            };
            return(request);
        }
Exemplo n.º 20
0
        public void SampleCodeCreateTransactionWithPayPal()
        {
            //Common code to set for all requests
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = AuthorizeNet.Environment.SANDBOX; //TestEnvironment;

            //set up data based on transaction
            var transactionAmount = new decimal(80.93);
            var payPalData        = new payPalType
            {
                paypalLc           = "IT",
                paypalPayflowcolor = "FFFF00",
                successUrl         = PayPalOne.successUrl,
                cancelUrl          = PayPalOne.cancelUrl,
            };

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = payPalData
            };
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),
                payment         = paymentType,
                amount          = transactionAmount,
            };
            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };
            var controller = new createTransactionController(request);

            controller.Execute();
            var response = controller.GetApiResponse();

            //validate
            Assert.NotNull(response);
            Assert.NotNull(response.messages);
            Assert.NotNull(response.transactionResponse);
            Assert.AreEqual(messageTypeEnum.Ok, response.messages.resultCode);
            Assert.False(string.IsNullOrEmpty(response.transactionResponse.transId));
            Assert.False(string.IsNullOrEmpty(response.transactionResponse.transHash));
            Assert.NotNull(response.transactionResponse.secureAcceptance);
            Assert.False(string.IsNullOrEmpty(response.transactionResponse.secureAcceptance.SecureAcceptanceUrl));
        }
Exemplo n.º 21
0
        public void SampleCodeCreateTransactionWithVisaCheckOut()
        {
            // The test setup.
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = "5KP3u95bQpv",
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = "346HZ32z3fP4hTG2",
            };

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = TestEnvironment;

            //set up data based on transaction
            var transactionAmount = SetValidTransactionAmount(Counter);
            var opaqueDataType    = new opaqueDataType
            {
                dataDescriptor = "COMMON.VCO.ONLINE.PAYMENT",
                dataKey        = "NQzcMISSxLX789w+CGX+tXi3lKntO1dpZbZaREOUprVRByJkg1xnpc2Wx9aT5/BLOxQmHqmIsjjy+tF6HqKKGwovvXjIS3fE3y3tBRNbz8D7y6vYMup+AWbEvZqDEBSi",
                dataValue      = "+6hn53rUcggeZZti2IdBp3qNLa9ohAH87cFSc1BggZFNEpsrfdJbRViWwv/JbCNkHkOD6CpFlRO3gCDH2VEQTd8laqWR1ccHiZpdYDnOxfhUQpU9E18ZByW7j17puVWogh7HaItbDUL0YvIxxfClX9bohurOo1JHyUgBO9YxTj3CLY2RdRkjmipAQqOyxiGX9enFQjAHdPgKj2RxnVMYe8on5ei94zbtYUbI3fXrp3I+DJcZCGZ4SzrlnPAPpcn20qaIoaOTX/xuD+voRAUKb/KE5oy+CuSNBtyMBgrvWU0Lf3SLjGfE/FJx3Bh9/LABCwWBYQvtpo3DQ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puEgXfWl09Sc3Dfg69UP8XBR80vWsP1YL8YtBxOmL2hinZc5SJZ4boulAOHiMQyKBwwkg2D1gJDEY9JzUJtbg3p06swB0UthNmVuo/1mV8047sB5QrjGCugEo87+vh9eV1EVvyLZLRFS+RIZoIpLR3UkO6Pe1s7MnO7ZvCsbz9sKNb0GtQPoFtU9b7KaCHgQ20vL7xjqTEmR2QwkHEriuGJ8a7oMdSd88w/e2InL1SfHCnS2JeWY9vY6RSTvmjkEf3BFGhHjFP5QRR3Bd8AVH/1YrFcxtSSJP5GeY3CVnJgjZToK+ngxsRzpDcEm6pz3RPUEIBNkk3c9plpdlMbyvuVVKXLSFdTdtAALRfiD9qhdpgGMqboZ0kXi+qn3irYXT19q8oQktoZ4ILkbzewloftLbfUTqQprA8cddy7/ikUKKhBoBVs/DAupRe9aRP3TLgIEz6eNNilZszXoFfUv9EgqOZ0EBb83KNV3HvbE2xGJcTArjRpmzszQQkNOpJnyRDtvPj7FU7K16UYQ9zQBrxnx5vnoWSaqNhzOxikd+hWZ6i5G7EPpCO+utdoMdyOTOoDAjBmiy5JsDHSVv4zvkT9ySYPH2PmS47mMEpZICKTAxuDrm3zTpT064P+7ivcGmaIyaBCkc4udIHaWSbi5XJ/ciXUxSqAtqaVcd5HD++6vjBzKhbAPU4shSBav6qCSp/XqFurEAJbkLB3VmXe7bghcM+VNPJHHiYlIdzndDaFENyaZCukypggK0Gf4cH+8CKI9YnQx9s4JMs4lX57i4IkkoJE7fjWaOHyxYM/AiKvWlMQtRO8Y5Yta454JfHVq7Mg11Wqu2Ex4q5QLNqKudVt3wveu3G1zoNFanW6i+d0Aa3hTdxerl9BacX/"
            };

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = opaqueDataType
            };
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                payment         = paymentType,
                amount          = transactionAmount,
                callId          = "1482912778237697701"
            };
            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };
            var controller = new createTransactionController(request);

            controller.Execute();
            var response = controller.GetApiResponse();

            //validate
            Assert.AreEqual("1", response.transactionResponse.messages[0].code);
        }
Exemplo n.º 22
0
        public void SampleCodeCreateTransactionWithApplePay()
        {
            // The test setup.
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType
            {
                name            = "????", // your ApplyPay ApiLoginIdKey
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = "????"  // your ApplyPay TransactionKey
            };
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = TestEnvironment;

            //set up data based on transaction
            var transactionAmount = SetValidTransactionAmount(Counter);
            var opaqueData        = new opaqueDataType
            {
                dataDescriptor = "COMMON.APPLE.INAPP.PAYMENT",
                dataValue      =
                    "eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLC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dRWDhLWFFZdVpMazJScjYzTjhBcFhzWHdCTDNjSjB4Z2VBd2dkMENBUUV3T3pBbk1TVXdJd1lEVlFRREhod0FZd0JvQUcwQVlRQnBBRUFBZGdCcEFITUFZUUF1QUdNQWJ3QnRBaEJjbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0="
            };

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = opaqueData
            };
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                payment         = paymentType,
                amount          = transactionAmount,
            };
            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };
            var controller = new createTransactionController(request);

            controller.Execute();
            var response = controller.GetApiResponse();

            //validate
            Assert.AreEqual("1", response.transactionResponse.messages[0].code);
        }
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            PrepareAuthorizeNet();

            var codes = capturePaymentRequest.Order.AuthorizationTransactionCode.Split(',');
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(),
                amount          = Math.Round(capturePaymentRequest.Order.OrderTotal, 2),
                refTransId      = codes[0],
                currencyCode    = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode,
            };

            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };

            // instantiate the contoller that will call the service
            var controller = new createTransactionController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            var response = GetApiResponse(controller, result.Errors);

            //validate
            if (response == null)
            {
                return(result);
            }

            result.CaptureTransactionId =
                $"{response.transactionResponse.transId},{response.transactionResponse.authCode}";
            result.CaptureTransactionResult =
                $"Approved ({response.transactionResponse.responseCode}: {response.transactionResponse.messages[0].description})";
            result.NewPaymentStatus = PaymentStatus.Paid;

            return(result);
        }
Exemplo n.º 24
0
        public void SampleCodeCreateTransactionWithPayPal()
        {
            /*
             * Please enable the PayPal feature of your ANet merchant account.
             */

            //Common code to set for all requests
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = AuthorizeNet.Environment.SANDBOX; //TestEnvironment;

            //set up data for transaction
            var transactionAmount = SetValidTransactionAmount(Counter) / 100;
            var payPalData        = new payPalType
            {
                paypalLc           = "IT",
                paypalPayflowcolor = "FFFF00",
                successUrl         = PayPalOne.successUrl,
                cancelUrl          = PayPalOne.cancelUrl,
            };

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = payPalData
            };
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),
                payment         = paymentType,
                amount          = transactionAmount,
            };
            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };
            var controller = new createTransactionController(request);

            controller.Execute();
            var response = controller.GetApiResponse();

            //validate. The code 2000 is: Need the payer's consent.
            Assert.AreEqual("2000", response.transactionResponse.messages[0].code);
        }
Exemplo n.º 25
0
        public void CreateTransactionInvalidRequestSchemaValidationTest()
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            //create a transaction
            var transactionRequestType = new transactionRequestType
            {
                //removing the transaction type here is important to expect the schema validation error
                //transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount   = SetValidTransactionAmount(Counter),
                payment  = PaymentOne,
                order    = OrderType,
                customer = CustomerDataOne,
                billTo   = CustomerAddressOne,
            };
            var createRequest = new createTransactionRequest
            {
                refId = RefId,
                transactionRequest = transactionRequestType,
            };

            //create controller, execute and get response
            var createController = new createTransactionController(createRequest);

            createController.Execute();
            var createResponse = createController.GetApiResponse();

            //validate response
            Assert.IsNull(createResponse);
            var errorResponse = createController.GetErrorResponse();

            Assert.IsNotNull(errorResponse);
            Assert.IsNotNull(errorResponse.messages);
            Assert.IsNotNull(errorResponse.messages.message);
            Assert.AreEqual(messageTypeEnum.Error, errorResponse.messages.resultCode);
            Assert.AreEqual(1, errorResponse.messages.message.Length);
            Assert.AreEqual("E00003", errorResponse.messages.message[0].code);
            ValidateErrorCode(errorResponse.messages, "E00003");
        }
Exemplo n.º 26
0
        public void CreateTransactionInvalidRequestSchemaValidationTest()
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            //create a transaction
            var transactionRequestType = new transactionRequestType
            {
                //removing the transaction type here is important to expect the schema validation error
                //transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount   = SetValidTransactionAmount(Counter),
                payment  = PaymentOne,
                order    = OrderType,
                customer = CustomerDataOne,
                billTo   = CustomerAddressOne,
            };
            var createRequest = new createTransactionRequest
            {
                refId = RefId,
                transactionRequest = transactionRequestType,
            };

            const string errorMessage = "The element 'transactionRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'amount' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'transactionType' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.";
            //create
            var createController = new createTransactionController(createRequest);

            createController.Execute();
            var createResponse = createController.GetApiResponse();

            Assert.IsNull(createResponse);
            var errorResponse = createController.GetErrorResponse();

            Assert.IsNotNull(errorResponse);
            Assert.IsNotNull(errorResponse.messages);
            Assert.IsNotNull(errorResponse.messages.message);
            Assert.AreEqual(messageTypeEnum.Error, errorResponse.messages.resultCode);
            Assert.AreEqual(1, errorResponse.messages.message.Length);
            Assert.AreEqual("E00003", errorResponse.messages.message[0].code);
            Assert.AreEqual(errorMessage, errorResponse.messages.message[0].text);
        }
Exemplo n.º 27
0
        public void ChargeSync()
        {
            var transaction = new transactionRequestType
            {
                amount          = 123.45m,
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                payment         = new paymentType
                {
                    Item = new creditCardType
                    {
                        cardNumber     = "4111111111111111",
                        expirationDate = "0349",
                        cardCode       = "123"
                    }
                },

                billTo = new customerAddressType
                {
                    firstName = "TestName",
                    lastName  = "McTesterson",
                    address   = "123 Here st.",
                    city      = "Springville",
                    state     = "WA",
                    zip       = "00000"
                }
            };

            var fullRequest = new createTransactionRequest
            {
                merchantAuthentication = MerchantAuthentication,
                transactionRequest     = transaction,
            };

            // Send the request.
            var controller = new createTransactionController(fullRequest);
            var response   = controller.ExecuteWithApiResponse(AuthorizeNet.Environment.SANDBOX);

            Assert.IsNotNull(response);
        }
Exemplo n.º 28
0
        /// <summary>
        /// @Zalak
        /// For issue #62 Github Dot.net SDK
        /// </summary>
        /// <param name="transactionRequestParameter"></param>
        /// <returns></returns>
        private createTransactionController CreateTransactionRequestTest(transactionRequestType transactionRequestParameter)
        {
            if (transactionRequestParameter == null)
            {
                throw new ArgumentNullException("transactionRequestParameter");
            }
            LogHelper.info(Logger, "CreateTransactionRequestTest");

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            //create a transaction
            var transactionRequestType = transactionRequestParameter;
            var createRequest          = new createTransactionRequest
            {
                refId = RefId,
                transactionRequest = transactionRequestType,
            };
            //create controller
            var createController = new createTransactionController(createRequest);

            return(createController);
        }
Exemplo n.º 29
0
        public void SampleCodeCreateTransactionWithCreditCard()
        {
            //Common code to set for all requests
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            //set up data based on transaction
            var transactionAmount = SetValidTransactionAmount(Counter);
            var creditCard        = new creditCardType {
                cardNumber = "4111111111111111", expirationDate = "0622"
            };

            //standard api call to retrieve response
            var paymentType = new paymentType {
                Item = creditCard
            };
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),
                payment         = paymentType,
                amount          = transactionAmount,
            };
            var request = new createTransactionRequest {
                transactionRequest = transactionRequest
            };
            var controller = new createTransactionController(request);

            controller.Execute();
            var response = controller.GetApiResponse();

            //validate
            Assert.NotNull(response);
            Assert.NotNull(response.messages);
            Assert.NotNull(response.transactionResponse);
            Assert.AreEqual(messageTypeEnum.Ok, response.messages.resultCode);
            Assert.False(string.IsNullOrEmpty(response.transactionResponse.transId));
        }
Exemplo n.º 30
0
        /// <summary>
        /// Method that takes in an address and UserViewModel to create our
        /// transaction request. Since we are only processing fake cards
        /// we are inputting a test card for the user in the method
        /// </summary>
        /// <param name="uvm">UserViewModel</param>
        /// <param name="address">Address</param>
        /// <returns>Transaction Request</returns>
        public transactionRequestType TransactionRequest(UserViewModel uvm, customerAddressType address)
        {
            var CreditCard = new creditCardType
            {
                cardNumber     = "4111111111111111",
                expirationDate = "0720"
            };

            var PaymentType = new paymentType
            {
                Item = CreditCard
            };

            var TransactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount          = uvm.Order.TotalPrice,
                payment         = PaymentType,
                billTo          = address,
                lineItems       = CreateLineItems(uvm),
            };

            return(TransactionRequest);
        }