Beispiel #1
0
        private void Validate()
        {
            ANetApiRequest request = GetApiRequest();

            //validate not nulls
            ValidateAndSetMerchantAuthentication();

            //set the client Id
            SetClientId();

            //validate nulls
            var merchantAuthenticationType = request.merchantAuthentication;

            //if ( null != ) throw new IllegalArgumentException(" needs to be null");

            //TODO

            /*
             *      if ( null != merchantAuthenticationType.Item.GetType().   sessionToken) throw new IllegalArgumentException("SessionToken needs to be null");
             *      if ( null != merchantAuthenticationType.getPass_word()) throw new IllegalArgumentException("Pass_word needs to be null");
             *      if ( null != merchantAuthenticationType.getMobileDeviceId()) throw new IllegalArgumentException("MobileDeviceId needs to be null");
             *
             *
             *  var impersonationAuthenticationType = merchantAuthenticationType.impersonationAuthentication;
             *      if ( null != impersonationAuthenticationType) throw new IllegalArgumentException("ImpersonationAuthenticationType needs to be null");
             */
            //	    impersonationAuthenticationType.setPartnerLoginId(CnpApiLoginIdKey);
            //	    impersonationAuthenticationType.setPartnerTransactionKey(CnpTransactionKey);
            //	    merchantAuthenticationType.setImpersonationAuthentication(impersonationAuthenticationType);

            ValidateRequest();
        }
Beispiel #2
0
 private void AuthenticateRequest(ANetApiRequest request)
 {
     request.merchantAuthentication                 = new merchantAuthenticationType();
     request.merchantAuthentication.name            = _apiLogin;
     request.merchantAuthentication.Item            = _transactionKey;
     request.merchantAuthentication.ItemElementName = ItemChoiceType.transactionKey;
 }
 /// <summary>
 /// Fill in the merchant authentication. This data is required for all API methods.
 /// </summary>
 /// <param name="request"></param>
 private void PopulateMerchantAuthentication(ANetApiRequest request)
 {
     request.merchantAuthentication                = new merchantAuthenticationType();
     request.merchantAuthentication.name           = _user;
     request.merchantAuthentication.transactionKey = _password;
     request.refId = Guid.NewGuid().ToString("N").Substring(0, 20);             // MaxLength for refId is 20
 }
Beispiel #4
0
        public void MockisAliveTest()
        {
            //define all mocked objects as final
            var mockController = GetMockController <ANetApiRequest, isAliveResponse>();
            var mockRequest    = new ANetApiRequest
            {
                merchantAuthentication = new merchantAuthenticationType()
                {
                    name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey
                },
            };
            var mockResponse = new isAliveResponse
            {
                refId        = "1234",
                sessionToken = "sessiontoken",
            };

            var errorResponse = new ANetApiResponse();
            var results       = new List <String>();
            const messageTypeEnum messageTypeOk = messageTypeEnum.Ok;

            SetMockControllerExpectations <ANetApiRequest, isAliveResponse, isAliveController>(
                mockController.MockObject, mockRequest, mockResponse, errorResponse, results, messageTypeOk);
            mockController.MockObject.Execute(AuthorizeNet.Environment.CUSTOM);
            //mockController.MockObject.Execute();
            // or var controllerResponse = mockController.MockObject.ExecuteWithApiResponse(AuthorizeNet.Environment.CUSTOM);
            var controllerResponse = mockController.MockObject.GetApiResponse();

            Assert.IsNotNull(controllerResponse);

            //Assert.IsNotNull(controllerResponse.Yyyyy);
            LogHelper.info(Logger, "isAlive: Details:{0}", controllerResponse);
        }
Beispiel #5
0
        private void ValidateAndSetMerchantAuthentication()
        {
            ANetApiRequest request = GetApiRequest();

            if (null == request.merchantAuthentication)
            {
                if (null != ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication)
                {
                    request.merchantAuthentication = ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication;
                }
                else
                {
                    throw new ArgumentException("MerchantAuthentication cannot be null");
                }
            }
        }
Beispiel #6
0
            public ANetApiResponse Send(ANetApiRequest apiRequest)
            {
                AuthenticateRequest(apiRequest);
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(_serviceUrl);

                httpWebRequest.Method      = "POST";
                httpWebRequest.ContentType = "text/xml";
                httpWebRequest.KeepAlive   = true;
                var       type          = apiRequest.GetType();
                var       xmlSerializer = new XmlSerializer(type);
                XmlWriter xmlWriter     = new XmlTextWriter(httpWebRequest.GetRequestStream(), Encoding.UTF8);

                xmlSerializer.Serialize(xmlWriter, apiRequest);
                xmlWriter.Close();
                var response = httpWebRequest.GetResponse();

                _xmlDoc = new XmlDocument();
                _xmlDoc.Load(XmlReader.Create(response.GetResponseStream()));
                var aNetApiResponse = DecideResponse(_xmlDoc);

                CheckForErrors(aNetApiResponse);
                return(aNetApiResponse);
            }
Beispiel #7
0
        private void SetClientId()
        {
            ANetApiRequest request = GetApiRequest();

            request.clientId = "sdk-dotnet-" + Constants.SDKVersion;
        }
Beispiel #8
0
 public static void ANetApiRequest(ANetApiRequest request)
 {
 }
 public static void isAliveType(ANetApiRequest request)
 {
 }
Beispiel #10
0
    public static string CreateSubscription(string firstName, string lastName, string email,
                                            string cardNumber, string expiration, decimal price, DateTime startDate)
    {
        ARBCreateSubscriptionRequest createSubscriptionRequest = new ARBCreateSubscriptionRequest();
        ARBSubscriptionType          subscription = new ARBSubscriptionType();
        creditCardType creditCard = new creditCardType();

        subscription.name = "Referral NetworX";

        creditCard.cardNumber     = cardNumber;
        creditCard.expirationDate = expiration;
        subscription.payment      = new paymentType();
        subscription.payment.Item = creditCard;

        subscription.billTo = new nameAndAddressType
        {
            firstName = firstName,
            lastName  = lastName
        };

        subscription.paymentSchedule = new paymentScheduleType
        {
            startDate                 = startDate,
            startDateSpecified        = true,
            totalOccurrences          = 9999,
            totalOccurrencesSpecified = true,
            trialOccurrencesSpecified = false,
            interval = new paymentScheduleTypeInterval
            {
                length = 1,
                unit   = ARBSubscriptionUnitEnum.months
            }
        };

        subscription.trialAmountSpecified = false;
        subscription.amount          = price;
        subscription.amountSpecified = true;

        subscription.customer = new customerType
        {
            email = email
        };

        ANetApiRequest aNetRequest = (ANetApiRequest)createSubscriptionRequest;

        aNetRequest.merchantAuthentication = new merchantAuthenticationType
        {
            name           = "8n3jE77yAPK",
            transactionKey = "7C5v485g9vKJZ9mH"
        };

        createSubscriptionRequest.subscription = subscription;

        //////////////////////

        XmlSerializer serializer;
        XmlDocument   xmldoc;

        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://api.authorize.net/xml/v1/request.api");

        webRequest.Method      = "POST";
        webRequest.ContentType = "text/xml";
        webRequest.KeepAlive   = true;

        serializer = new XmlSerializer(createSubscriptionRequest.GetType());
        XmlWriter xmlwriter = new XmlTextWriter(webRequest.GetRequestStream(), Encoding.UTF8);

        serializer.Serialize(xmlwriter, createSubscriptionRequest);
        xmlwriter.Close();

        WebResponse webResponse = webRequest.GetResponse();

        xmldoc = new XmlDocument();
        xmldoc.Load(XmlReader.Create(webResponse.GetResponseStream()));

        object apiResponse = null;

        switch (xmldoc.DocumentElement.Name)
        {
        case "ARBCreateSubscriptionResponse":
            serializer  = new XmlSerializer(typeof(ARBCreateSubscriptionResponse));
            apiResponse = (ARBCreateSubscriptionResponse)serializer.Deserialize(new StringReader(xmldoc.DocumentElement.OuterXml));
            break;

        case "ARBUpdateSubscriptionResponse":
            serializer  = new XmlSerializer(typeof(ARBUpdateSubscriptionResponse));
            apiResponse = (ARBUpdateSubscriptionResponse)serializer.Deserialize(new StringReader(xmldoc.DocumentElement.OuterXml));
            break;

        case "ARBCancelSubscriptionResponse":
            serializer  = new XmlSerializer(typeof(ARBCancelSubscriptionResponse));
            apiResponse = (ARBCancelSubscriptionResponse)serializer.Deserialize(new StringReader(xmldoc.DocumentElement.OuterXml));
            break;

        case "ARBGetSubscriptionStatusResponse":
            serializer  = new XmlSerializer(typeof(ARBGetSubscriptionStatusResponse));
            apiResponse = (ARBGetSubscriptionStatusResponse)serializer.Deserialize(new StringReader(xmldoc.DocumentElement.OuterXml));
            break;

        case "ErrorResponse":
            serializer  = new XmlSerializer(typeof(ANetApiResponse));
            apiResponse = (ANetApiResponse)serializer.Deserialize(new StringReader(xmldoc.DocumentElement.OuterXml));
            break;
        }

        ANetApiResponse baseResponse = (ANetApiResponse)apiResponse;
        //display.InnerHtml = baseResponse.messages.resultCode.ToString() + "<br />";
        string subscriptionId = null;

        if (baseResponse.messages.resultCode == messageTypeEnum.Ok)
        {
            if (apiResponse.GetType() == typeof(ARBCreateSubscriptionResponse))
            {
                ARBCreateSubscriptionResponse createSubscriptionResponse = (ARBCreateSubscriptionResponse)apiResponse;
                subscriptionId = createSubscriptionResponse.subscriptionId;
            }
        }
        else
        {
            foreach (messagesTypeMessage message in baseResponse.messages.message)
            {
                subscriptionId += message.code + ": " + message.text + "<br />";
            }
        }
        return(subscriptionId);
    }