/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetPlanResponse response = new GetPlanResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("PythonScript", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.PythonScript = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ScalaCode", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ScalaCode = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Beispiel #2
0
        public static GetSubscriptionResponse InitializeSubscription(JObject data, string customerId, string cardId)
        {
            GetPlanResponse plan      = null;
            var             createSub = new CreateSubscriptionRequest();
            var             items     = new List <CreateIncrementRequest>();

            try
            {
                foreach (var product in data?["produtos"])
                {
                    string type = (string)product["tipo"];

                    switch (type)
                    {
                    case "plano":
                        string planId = (string)product["plano_id"];

                        plan = Client.Plans.GetPlan(planId);

                        break;

                    case "trimestral":
                        bool trial = (bool?)product?["periodo_teste"] ?? false;

                        plan = InitializePlan(type, 3, trial);

                        items.Add(new CreateIncrementRequest
                        {
                            IncrementType = "Flat",
                            Value         = 69,//Value = 69.9d,

                            Description = "Assinatura",
                        });

                        break;

                    case "mensal":
                        trial = (bool?)product?["periodo_teste"] ?? false;

                        plan = InitializePlan(type, 1, trial);

                        items.Add(new CreateIncrementRequest
                        {
                            IncrementType = "Flat",
                            Value         = 24,//Value = 24.5d,

                            Description = "Assinatura",
                        });

                        break;

                    case "yellowbook":

                        items.Add(new CreateIncrementRequest
                        {
                            IncrementType = "Flat",
                            Value         = 139, //Value = 139.9d,

                            Description = "YellowBook",
                            Cycles      = 1,
                        });
                        break;
                    }
                }

                createSub.PlanId     = plan?.Id;
                createSub.CustomerId = customerId;
                createSub.CardId     = cardId;
                createSub.Increments = items;

                var sub = Client.Subscriptions.CreateSubscription(createSub);

                if (string.IsNullOrEmpty(sub?.Id))
                {
                    throw new InvalidOperationException("Falha ao criar assinatura.");
                }

                return(sub);
            }
            catch (APIException ex)
            {
                throw new InvalidOperationException("Falha ao criar assinatura.", ex);
            }
        }
Beispiel #3
0
 /// <summary> Setter constructor. </summary>
 public GetPlan(GetPlanRequest request)
 {
     Request  = request;
     Response = new GetPlanResponse();
 }
Beispiel #4
0
 /// <summary> Empty constructor. </summary>
 public GetPlan()
 {
     Request  = new GetPlanRequest();
     Response = new GetPlanResponse();
 }