/// <summary>
        /// Gets the subscription details.
        /// </summary>
        /// <param name="subscriptionID">The subscription ID.</param>
        /// <returns></returns>
        public ARBGetSubscriptionResponse GetSubscription(string subscriptionID)
        {
            var req = new ARBGetSubscriptionRequest();

            req.subscriptionId = subscriptionID;
            var response = (ARBGetSubscriptionResponse)_gateway.Send(req);

            return(response);
        }
        public void ARBGetSubscriptionSampleTest()
        {
            LogHelper.info(Logger, "Sample GetSubscriptionList");

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

            //create a subscription
            var createRequest = new ARBCreateSubscriptionRequest
            {
                refId        = RefId,
                subscription = ArbSubscriptionOne,
            };

            var createController = new ARBCreateSubscriptionController(createRequest);

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

            Assert.IsNotNull(createResponse.subscriptionId);
            LogHelper.info(Logger, "Created Subscription: {0}", createResponse.subscriptionId);
            var subscriptionId = createResponse.subscriptionId;

            //get subscription details
            var getRequest = new ARBGetSubscriptionRequest
            {
                refId          = RefId,
                subscriptionId = subscriptionId
            };
            var getController = new ARBGetSubscriptionController(getRequest);
            var getResponse   = getController.ExecuteWithApiResponse();

            Assert.IsNotNull(getResponse.subscription);
            Logger.info(String.Format("Subscription Name : {0}", getResponse.subscription.name));
            Assert.AreEqual(ArbSubscriptionOne.name, getResponse.subscription.name);
            Assert.AreEqual(ArbSubscriptionOne.amountSpecified, getResponse.subscription.amountSpecified);

            //cancel subscription
            var cancelRequest = new ARBCancelSubscriptionRequest
            {
                merchantAuthentication = CustomMerchantAuthenticationType,
                refId          = RefId,
                subscriptionId = subscriptionId
            };
            var cancelController = new ARBCancelSubscriptionController(cancelRequest);
            var cancelResponse   = cancelController.ExecuteWithApiResponse(TestEnvironment);

            Assert.IsNotNull(cancelResponse.messages);
            Logger.info(String.Format("Subscription Cancelled: {0}", subscriptionId));
        }
        public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string subscriptionId)
        {
            Console.WriteLine("Get Subscription Sample");

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

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey
            };

            var request = new ARBGetSubscriptionRequest {
                subscriptionId = subscriptionId
            };

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

            controller.Execute();

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

            //validate
            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
            {
                if (response.subscription != null)
                {
                    Console.WriteLine("Subscription returned : " + response.subscription.name);
                }
            }
            else if (response != null)
            {
                if (response.messages.message.Length > 0)
                {
                    Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
                                      response.messages.message[0].text);
                }
            }
            else
            {
                if (controller.GetErrorResponse().messages.message.Length > 0)
                {
                    Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
                }
            }

            return(response);
        }
Esempio n. 4
0
        public void MockARBGetSubscriptionTest()
        {
            //define all mocked objects as final
            var mockController = GetMockController <ARBGetSubscriptionRequest, ARBGetSubscriptionResponse>();
            var mockRequest    = new ARBGetSubscriptionRequest
            {
                merchantAuthentication = new merchantAuthenticationType()
                {
                    name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey
                },
                subscriptionId = "1234"
            };

            var customerPaymentProfileMaskedType = new customerPaymentProfileMaskedType
            {
                customerPaymentProfileId = "1234",
            };

            Random rnd = new Random(DateTime.Now.Millisecond);
            var    SubscriptionMaskedType = new ARBSubscriptionMaskedType()
            {
                name            = "Test",
                paymentSchedule = new paymentScheduleType
                {
                    interval = new paymentScheduleTypeInterval
                    {
                        length = 1,
                        unit   = ARBSubscriptionUnitEnum.months,
                    },
                    startDate        = DateTime.UtcNow,
                    totalOccurrences = 12
                },
                amount               = 9.99M,
                amountSpecified      = true,
                trialAmount          = 100,
                trialAmountSpecified = true,
                status               = ARBSubscriptionStatusEnum.active,
                statusSpecified      = true,
                profile              = new subscriptionCustomerProfileType()
                {
                    paymentProfile = customerPaymentProfileMaskedType,
                },
                order = new orderType {
                    description = string.Format("member monthly {0}", rnd.Next(99999))
                }
            };

            var mockResponse = new ARBGetSubscriptionResponse
            {
                refId        = "1234",
                sessionToken = "sessiontoken",
                subscription = SubscriptionMaskedType
            };

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

            SetMockControllerExpectations <ARBGetSubscriptionRequest, ARBGetSubscriptionResponse, ARBGetSubscriptionController>(
                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.subscription);
            LogHelper.info(Logger, "ARBGetSubscription: Details:{0}", controllerResponse.subscription);
        }
Esempio n. 5
0
        public async Task <ITransactionResponse> UpdateSubscription(ICustomerPayment customerPayment)
        {
            var transactionResponse = new TransactionResponse();

            var task = Task.Run(() =>
            {
                if (Convert.ToBoolean(string.IsNullOrEmpty(ConfigurationManager.AppSettings["AuthNetIsProduction"]) ? "false" : ConfigurationManager.AppSettings["AuthNetIsProduction"]))
                {
                    ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION;
                }
                else
                {
                    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,
                };

                // get subscription
                var subscriptionRequest = new ARBGetSubscriptionRequest {
                    subscriptionId = customerPayment.SubscriptionId
                };

                var controllerSubscription = new ARBGetSubscriptionController(subscriptionRequest);          // instantiate the contoller that will call the service
                controllerSubscription.Execute();

                ARBGetSubscriptionResponse subscriptionResponse = controllerSubscription.GetApiResponse();   // get the response from the service (errors contained if any)

                //validate
                if (subscriptionResponse != null && subscriptionResponse.messages.resultCode == messageTypeEnum.Ok)
                {
                    if (subscriptionResponse.subscription != null)
                    {
                        //Do nothing
                    }
                }
                else if (subscriptionResponse != null)
                {
                    if (subscriptionResponse.messages.message.Length > 0)
                    {
                        transactionResponse.IsSuccess = false;

                        System.Diagnostics.Debug.WriteLine("Error: " + subscriptionResponse.messages.message[0].code + "  " + subscriptionResponse.messages.message[0].text);

                        transactionResponse.Messages = new TransactionResponseMessage[] { new TransactionResponseMessage()
                                                                                          {
                                                                                              Code = subscriptionResponse.messages.message[0].code, Description = subscriptionResponse.messages.message[0].text
                                                                                          } };
                    }
                }
                else
                {
                    if (controllerSubscription.GetErrorResponse().messages.message.Length > 0)
                    {
                        transactionResponse.IsSuccess = false;

                        System.Diagnostics.Debug.WriteLine("Error: " + subscriptionResponse.messages.message[0].code + "  " + subscriptionResponse.messages.message[0].text);

                        transactionResponse.Messages = new TransactionResponseMessage[] { new TransactionResponseMessage()
                                                                                          {
                                                                                              Code = subscriptionResponse.messages.message[0].code, Description = subscriptionResponse.messages.message[0].text
                                                                                          } };
                    }
                }

                var currentSubscription = subscriptionResponse.subscription;

                var creditCard = new creditCardType
                {
                    cardNumber     = customerPayment.CardNumber,
                    expirationDate = customerPayment.ExpirationDate,
                    cardCode       = customerPayment.CardCode
                };

                var billingAddress = new nameAndAddressType
                {
                    company   = customerPayment.Company,
                    firstName = customerPayment.FirstName,
                    lastName  = customerPayment.LastName,
                    address   = customerPayment.Address,
                    city      = customerPayment.City,
                    zip       = customerPayment.Zip
                };

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

                ARBSubscriptionType subscriptionType = new ARBSubscriptionType()
                {
                    billTo  = billingAddress,
                    payment = paymentType
                };

                var request = new ARBUpdateSubscriptionRequest {
                    subscription = subscriptionType, subscriptionId = customerPayment.SubscriptionId
                };

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

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

                if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
                {
                    if (response != null && response.messages.message != null)
                    {
                        System.Diagnostics.Debug.WriteLine("Success");

                        transactionResponse.Errors    = null;
                        transactionResponse.IsSuccess = true;
                        transactionResponse.Messages  = null;
                    }
                    else
                    {
                        transactionResponse.IsSuccess = false;
                    }
                }
                else if (response != null && response.messages.message != null)
                {
                    transactionResponse.IsSuccess = false;

                    System.Diagnostics.Debug.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);

                    transactionResponse.Messages = new TransactionResponseMessage[] { new TransactionResponseMessage()
                                                                                      {
                                                                                          Code = response.messages.message[0].code, Description = response.messages.message[0].text
                                                                                      } };
                }

                return(response);
            });

            await task;

            return(transactionResponse);
        }
Esempio n. 6
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string subscriptionId)
        //{
        //    Console.WriteLine("Get Subscription Sample");

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

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item = ApiTransactionKey
        //    };

        //    var request = new ARBGetSubscriptionRequest { subscriptionId = subscriptionId };

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

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

        //    //validate
        //    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        //    {
        //        if (response.subscription != null)
        //        {
        //            Console.WriteLine("Subscription returned : " + response.subscription.name);
        //        }
        //    }
        //    else if (response != null)
        //    {
        //        if (response.messages.message.Length > 0)
        //        {
        //            Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                              response.messages.message[0].text);
        //        }
        //    }
        //    else
        //    {
        //        if (controller.GetErrorResponse().messages.message.Length > 0)
        //        {
        //            Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
        //        }
        //    }

        //    return response;
        //}
        public static void GetSubscriptionExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetASubscription.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get Subscription Sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append Data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        // Create Instance of Customer Api
                        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,
                        };
                        string subscriptionId = null;
                        string TestCase_Id    = null;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "subscriptionId":
                                subscriptionId = csv[i];
                                break;

                            case "TestCase_Id":
                                TestCase_Id = csv[i];
                                break;

                            default:
                                break;
                            }
                        }
                        //Write to output file
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Data
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            //response = instance.GetCustomer(customerId, authorization);

                            var request = new ARBGetSubscriptionRequest {
                                subscriptionId = subscriptionId
                            };

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

                            ARBGetSubscriptionResponse response = controller.GetApiResponse();
                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok &&
                                response.subscription != null)
                            {
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GAS_00" + flag.ToString());
                                    row1.Add("GetASubscription");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;
                                    Console.WriteLine("Subscription returned : " + response.subscription.name);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GAS_00" + flag.ToString());
                                    row1.Add("GetASubscription");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                    flag = flag + 1;
                                }
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("GAS_00" + flag.ToString());
                                row1.Add("GetASubscription");
                                row1.Add("Fail");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                //Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                flag = flag + 1;
                            }
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("GAS_00" + flag.ToString());
                            row2.Add("GetASubscription");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TestCase_Id + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }