/// <summary>
 /// Adds a new Product.
 /// </summary>
 /// <param name="newProduct">A ProductRequest object containing the data for the Product to be created.</param>
 /// <param name="format">The format used for the data transfer (XML or JSON). </param>
 /// <returns>>The ProductResponse object that corresponds to the newly-added Product record. </returns>
 public ProductResponse AddProduct(ProductRequest newProduct, string format = ContentFormat.XML)
 {
     return _service.Post<ProductRequest, ProductResponse>(string.Format("{0}/{1}", _gatewayURL, format), newProduct);
 }
 /// <summary>
 /// Updates a Product.
 /// </summary>
 /// <param name="updatedProduct">A ProductRequest object containing the Product record to be updated.</param>
 /// <param name="productId">The Id of the Product to be updated. </param>
 /// <param name="format">The format used for the data transfer (XML or JSON). </param>
 /// <returns>The ProductResponse object that corresponds to the updated Product</returns>
 public ProductResponse UpdateProduct(ProductRequest updatedProduct, string productId, string format = ContentFormat.XML)
 {
     return _service.Put<ProductRequest, ProductResponse>(string.Format("{0}/{1}.{2}", _gatewayURL, productId, format), updatedProduct);
 }
Example #3
0
        public ProductResponse AddProductToFamily(int familyId)
        {
            var productReq = new ProductRequest
            {
                FamilyId = familyId,
                AccountingCode = "AccountingCode",
                ApiRef1 = Guid.NewGuid().ToString("N"),
                Description = "Description",
                isBillingAddressAtSignupRequired = BoolOptional.Yes,
                isCreditCardAtSignupRequired = BoolOptional.Yes,
                Name = "Product - " + Guid.NewGuid().ToString("N"),
            };

            var pricingPlanReq = new PricingPlanRequest
            {
                CurrencyCode = CreateDefaultCurrency().Code,
                Name = "TestPricingPlan",
                TrialPeriodCharge = 100,
                TrialPeriodDurationDays = 3,
                UpfrontCharge = 200,
            };
            productReq.PricingPlans.Add(pricingPlanReq);

            var paymentSchedule = new ProductPricingPlanPaymentScheduleRequest
            {
                FrequencyInterval = 1,
                FrequencyRecurrenceFactor = 1,
                FrequencyRelativeInterval = FrequencyOccurrence.Fifth,
                FrequencyType = RecurringCyclePeriod.Daily,
                Name = string.Format("{0}_PaymentSchedule", pricingPlanReq.Name),
            };
            pricingPlanReq.PaymentScheduleList.Add(paymentSchedule);

            var meteredPriceList = new ProductMeteredPriceRequestList();
            meteredPriceList.Add(new ProductMeteredPriceRequest
            {
                StartQuantity = 1,
                EndQuantity = 10,
                UnitPrice = 5,
            });

            pricingPlanReq.ProductItemsList.Add(new ProductItemRequest
            {
                ChargeModel = ChargeModel.PerUnit,
                Name = "test product item 1",
                Description = "",
                ProductItemType = ProductItemType.Metered,
                IsVisibleOnHostedPage = true,
                MeteredPriceList = meteredPriceList,
            });

            meteredPriceList = new ProductMeteredPriceRequestList();
            meteredPriceList.Add(new ProductMeteredPriceRequest
            {
                StartQuantity = 1,
                UnitPrice = 10,
            });
            pricingPlanReq.ProductItemsList.Add(new ProductItemRequest
            {
                ChargeModel = ChargeModel.PerUnit,
                Name = "test product item 2",
                Description = "",
                ProductItemType = ProductItemType.OnOff,
                IsVisibleOnHostedPage = true,
                MeteredPriceList = meteredPriceList,
            });

            var product = _gateway.Products.AddProduct(productReq);
            Assert.IsNotNull(product);
            return product;
        }