Ejemplo n.º 1
0
        public void raise_conventionCreated_when_create_convention()
        {
            var contactId  = Guid.NewGuid();
            var convention = Agreement.Create(contactId, 6000, AgreementType.Free);

            convention.UncommitedEvents.GetStream().Should().Contain(new AgreementCreated(Guid.Empty, 0, contactId, 6000, AgreementType.Free));
        }
Ejemplo n.º 2
0
        public static Agreement CreateBillingAgreement(string planId, ShippingAddress shippingAddress,
                                                       string name, string description, DateTime startDate)
        {
            // PayPal Authentication tokens
            var apiContext = PayPalConfig.GetAPIContext();

            var agreement = new Agreement()
            {
                name        = name,
                description = description,
                start_date  = startDate.ToString("yyyy-MM-ddTHH:mm:ss") + "Z",
                payer       = new Payer()
                {
                    payment_method = "paypal",
                },
                plan = new Plan()
                {
                    id = planId
                },
                shipping_address = shippingAddress
            };

            var createdAgreement = agreement.Create(apiContext);

            return(createdAgreement);
        }
Ejemplo n.º 3
0
        public ActionResult Purchase(PurchaseVm model)
        {
            var plan = Plan.Plans.FirstOrDefault(x => x.PayPalPlanId == model.Plan.PayPalPlanId);

            if (ModelState.IsValid)
            {
                // Since we take an Initial Payment (instant payment), the start date of the recurring payments will be next month.
                var startDate = DateTime.UtcNow.AddMonths(1);

                var apiContext = PayPalApiHelperService.GetApiContext();

                var subscription = new Subscription()
                {
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    Email        = model.Email,
                    StartDate    = startDate,
                    PayPalPlanId = plan.PayPalPlanId
                };
                _dbContext.Subscriptions.Add(subscription);
                _dbContext.SaveChanges();

                var agreement = new Agreement()
                {
                    name        = plan.Name,
                    description = $"{plan.NumberOfBeers} beer(s) delivered for ${(plan.Price/100M).ToString("0.00")} each month.",
                    start_date  = startDate.ToString("yyyy-MM-ddTHH:mm:ssZ"),
                    plan        = new PayPal.Api.Plan()
                    {
                        id = plan.PayPalPlanId
                    },
                    payer = new Payer()
                    {
                        payment_method = "paypal"
                    }
                };

                // Send the agreement to PayPal
                var createdAgreement = agreement.Create(apiContext);

                // Save the token so we can match the returned request to our subscription.
                subscription.PayPalAgreementToken = createdAgreement.token;
                _dbContext.SaveChanges();

                // Find the Approval URL to send our user to
                var approvalUrl =
                    createdAgreement.links.FirstOrDefault(
                        x => x.rel.Equals("approval_url", StringComparison.OrdinalIgnoreCase));

                // Send the user to PayPal to approve the payment
                return(Redirect(approvalUrl.href));
            }

            model.Plan = plan;
            return(View(model));
        }
Ejemplo n.º 4
0
        private void NewAgreementBttn_Click(object sender, EventArgs e)
        {
            string description = agreementDescriprionTbx.Text;
            string title       = agreementTitleTbx.Text;

            if (string.IsNullOrEmpty(title))
            {
                throw new ApplicationException("Please, specify a title.");
            }

            Agreement agreement = Agreement.Create(title,
                                                   string.IsNullOrWhiteSpace(description) ? null : description);

            AddAgreementToUI(agreement);
        }
Ejemplo n.º 5
0
        public Agreement Execute(Guid contactId, IEnumerable <Guid> seatsIds, AgreementType agreementType)
        {
            CheckThereAreNoDuplicate(seatsIds);
            var  aggregatesToCommit = new List <AggregateRoot>();
            Guid?companyId          = null;

            var agreementNumber = _agreementQueries.GetNextAgreementNumber();

            if (agreementNumber <= 0)
            {
                throw new Exception("Impossible d'obtenir le numéro de convention.");
            }

            var agreement = Agreement.Create(contactId, agreementNumber, agreementType);

            aggregatesToCommit.Add(agreement);

            NotificationManager manager = null;

            foreach (var seatId in seatsIds)
            {
                var seat = GetAggregate <Seat>(seatId);
                if (manager == null)
                {
                    var managerId = _notificationQueries.GetNotificationManagerId(seat.SessionId);
                    manager = GetAggregate <NotificationManager>(managerId);
                    aggregatesToCommit.Add(manager);
                }

                if (companyId.HasValue && companyId.Value != seat.CompanyId)
                {
                    throw new AgreementCompanyException();
                }
                companyId = seat.CompanyId;

                seat.AssociateAgreement(agreement.AggregateId);
                manager.SignalAgreementAssociated(agreement.AggregateId, seat.AggregateId, seat.CompanyId);

                aggregatesToCommit.Add(seat);
            }

            PublishUncommitedEvents(aggregatesToCommit.ToArray());
            return(agreement);
        }
Ejemplo n.º 6
0
        private Agreement EjecutarPlanRecurrente(Plan plan, int diasCobro)
        {
            try
            {
                DateTime startDate = DateTime.Now.AddDays(diasCobro);
                DateTime endDate   = startDate.AddMonths(1);

                APIContext apiContext = GetAPIContext();

                var shippingAddress = new ShippingAddress()
                {
                    line1        = "AVENIDA JUAREZ 1123, COL. UNIVERSIDAD",
                    city         = "TOLUCA",
                    state        = "ESTADO DE MEXICO",
                    postal_code  = "95070",
                    country_code = "MX"
                };

                var agreement = new Agreement()
                {
                    name        = plan.name,
                    description = plan.description,
                    start_date  = startDate.ToString("yyyy-MM-ddTHH:mm:ss") + "Z",
                    //update_time = endDate.ToString("yyyy-MM-ddTHH:mm:ss") + "Z",
                    payer = new Payer()
                    {
                        payment_method = "paypal"
                    },
                    plan = new Plan()
                    {
                        id = plan.id
                    },
                    shipping_address = shippingAddress
                };

                var createdAgreement = agreement.Create(apiContext);

                return(createdAgreement);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 7
0
        private void NewAgreementBttn_Click(object sender, EventArgs e)
        {
            string description = agreementDescriprionTbx.Text;
            string title       = agreementTitleTbx.Text;

            if (String.IsNullOrEmpty(description))
            {
                MessageBox.Show("Add description");
                return;
            }

            if (String.IsNullOrEmpty(title))
            {
                MessageBox.Show("Add title");
                return;
            }

            Agreement.Create(title, description, Server.CurrentSession);
            ReloadAgreements();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 本示例只介绍如何请求支付凭据(charge 对象),以及如何查询指定 charge 对象和 charge 列表,
        /// 至于如何将 charge 对象传递给客户端需要接入者自行处理
        /// </summary>
        public static void Example(string appId)
        {
            Console.WriteLine("**** 创建签约示例 ****");
            var param = new Dictionary <string, object> {
                { "app", appId },
                { "contract_no", randomStr(10) },
                { "channel", "qpay" },
                { "extra", new Dictionary <string, object> {
                      { "display_account", "签约测试" }
                  } },
                { "metadata", new Dictionary <string, object> {
                  } }
            };

            var agreement = Agreement.Create(param);

            Console.WriteLine(agreement);
            Console.WriteLine();

            Console.WriteLine("****查询 agreement 对象****");
            Console.WriteLine(Agreement.Retrieve(agreement.Id));
            Console.WriteLine();

            Console.WriteLine("****解除签约 agreement 对象****");
            Console.WriteLine(Agreement.Cancel(agreement.Id));
            Console.WriteLine();


            Console.WriteLine("****查询 agreement 列表****");
            Dictionary <string, object> listParams = new Dictionary <string, object> {
                { "app", appId },   // 必填 签约使用的 app id
                { "per_page", 10 }, //限制有多少对象可以被返回,限制范围是从 1-100 项,默认是 10 项。
            };

            Console.WriteLine(Agreement.List(listParams));
        }
        /// <summary>
        ///
        /// </summary>
        private void CreateBillingAgreement()
        {
            var apiContext = Configuration.GetAPIContext();

            // Before we can setup the billing agreement, we must first create a
            // billing plan that includes a redirect URL back to this test server.
            var plan = BillingPlanCreate.CreatePlanObject(HttpContext.Current);
            var guid = Convert.ToString((new Random()).Next(100000));

            plan.merchant_preferences.return_url = Request.Url.ToString() + "?guid=" + guid;
            var createdPlan = plan.Create(apiContext);

            // Activate the plan
            var patch = new Patch()
            {
                op    = "replace",
                path  = "/",
                value = new Plan()
                {
                    state = "ACTIVE"
                }
            };
            var patchRequest = new PatchRequest();

            patchRequest.Add(patch);
            createdPlan.Update(apiContext, patchRequest);

            // With the plan created and activated, we can now create the
            // billing agreement.
            var payer = new Payer()
            {
                payment_method = "paypal"
            };
            var shippingAddress = new ShippingAddress()
            {
                line1        = "111 First Street",
                city         = "Saratoga",
                state        = "CA",
                postal_code  = "95070",
                country_code = "US"
            };

            var agreement = new Agreement()
            {
                name        = "T-Shirt of the Month Club",
                description = "Agreement for T-Shirt of the Month Club",
                start_date  = "2015-02-19T00:37:04Z",
                payer       = payer,
                plan        = new Plan()
                {
                    id = createdPlan.id
                },
                shipping_address = shippingAddress
            };

            HttpContext.Current.Items.Add("RequestJson", Common.FormatJsonString(agreement.ConvertToJson()));

            // Create the billing agreement.
            var createdAgreement = agreement.Create(apiContext);

            HttpContext.Current.Items.Add("ResponseJson", Common.FormatJsonString(createdAgreement.ConvertToJson()));

            // Get the redirect URL to allow the user to be redirected to PayPal to accept the agreement.
            var links = createdAgreement.links.GetEnumerator();

            while (links.MoveNext())
            {
                Links lnk = links.Current;
                if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                {
                    HttpContext.Current.Items.Add("RedirectURLText", "Redirect to PayPal to approve billing agreement...");
                    HttpContext.Current.Items.Add("RedirectURL", lnk.href);
                }
            }
            Session.Add(guid, createdAgreement.token);
        }
Ejemplo n.º 10
0
        public ActionResult CreatePurchase(PurchaseInfo purchaseInfo)
        {
            try
            {
                string action = "Index";

                var payer = new Payer
                {
                    payment_method      = "credit_card",
                    funding_instruments = new List <FundingInstrument>(),
                    payer_info          = new PayerInfo
                    {
                        email = "*****@*****.**"
                    }
                };

                var creditCard = new CreditCard();

                if (!string.IsNullOrEmpty(purchaseInfo.CreditCardId))
                {
                    payer.funding_instruments.Add(new FundingInstrument()
                    {
                        credit_card_token = new CreditCardToken()
                        {
                            credit_card_id = purchaseInfo.CreditCardId
                        }
                    });
                }
                else
                {
                    creditCard = new CreditCard()
                    {
                        billing_address = new Address()
                        {
                            city         = "Orlando",
                            country_code = "US",
                            line1        = "123 Test Way",
                            postal_code  = "32803",
                            state        = "FL"
                        },
                        cvv2         = purchaseInfo.CVV2,
                        expire_month = purchaseInfo.ExpMonth,
                        expire_year  = purchaseInfo.ExpYear,
                        first_name   = purchaseInfo.FirstName,
                        last_name    = purchaseInfo.LastName,
                        number       = purchaseInfo.CreditCardNumber,
                        type         = Common.GetCardType(purchaseInfo.CreditCardNumber)
                    };

                    payer.funding_instruments.Add(new FundingInstrument()
                    {
                        credit_card = creditCard
                    });
                }

                if (!purchaseInfo.IsRecurring)
                {
                    var transaction = new Transaction
                    {
                        amount = new Amount
                        {
                            currency = "USD",
                            total    = purchaseInfo.Amount.ToString()
                        },
                        description    = "Featured Profile on ProductionHUB",
                        invoice_number = Common.GetRandomInvoiceNumber()
                    };

                    var payment = new Payment()
                    {
                        intent       = "sale",
                        payer        = payer,
                        transactions = new List <Transaction>()
                        {
                            transaction
                        }
                    };

                    var createdPayment = payment.Create(apiContext);
                    TempData["info"] = createdPayment.id;

                    if (createdPayment.state == "approved")
                    {
                        action = "Completed";
                    }
                    else
                    {
                        action = "Rejected";
                    }
                }
                else
                {
                    var agreement = new Agreement()
                    {
                        name        = "Basic profile",
                        description = "Monthly basic profile in perpetuity",
                        payer       = payer,
                        plan        = new Plan {
                            id = purchaseInfo.BillingPlanId
                        },
                        start_date = DateTime.UtcNow.AddDays(1).ToString("u").Replace(" ", "T"),
                    };

                    var createdAgreement = agreement.Create(apiContext);

                    TempData["info"] = createdAgreement.create_time;

                    TempData["success"] = "Recurring agreement created";
                }

                if (purchaseInfo.SavePaymentInfo)
                {
                    creditCard.external_customer_id = customerId;
                    creditCard.Create(apiContext);
                }

                return(RedirectToAction(action));
            }
            catch (Exception exc)
            {
                TempData["error"] = exc.Message;
            }

            ViewBag.Cards = CreditCard.List(apiContext, externalCustomerId: customerId);
            ViewBag.Plans = plans;
            AddPaymentDropdowns();
            return(View());
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        private void CreateBillingAgreement(APIContext apiContext)
        {
            // Before we can setup the billing agreement, we must first create a
            // billing plan that includes a redirect URL back to this test server.
            var plan = BillingPlanCreate.CreatePlanObject(HttpContext.Current);
            var guid = Convert.ToString((new Random()).Next(100000));

            plan.merchant_preferences.return_url = Request.Url.ToString() + "?guid=" + guid;

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Create new billing plan", plan);
            #endregion

            var createdPlan = plan.Create(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(createdPlan);
            #endregion

            // Activate the plan
            var patchRequest = new PatchRequest()
            {
                new Patch()
                {
                    op    = "replace",
                    path  = "/",
                    value = new Plan()
                    {
                        state = "ACTIVE"
                    }
                }
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Update the plan", patchRequest);
            #endregion

            createdPlan.Update(apiContext, patchRequest);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordActionSuccess("Plan updated successfully");
            #endregion

            // With the plan created and activated, we can now create the billing agreement.
            var payer = new Payer()
            {
                payment_method = "paypal"
            };
            var shippingAddress = new ShippingAddress()
            {
                line1        = "111 First Street",
                city         = "Saratoga",
                state        = "CA",
                postal_code  = "95070",
                country_code = "US"
            };

            var agreement = new Agreement()
            {
                name        = "T-Shirt of the Month Club",
                description = "Agreement for T-Shirt of the Month Club",
                start_date  = "2016-02-19T00:37:04Z",
                payer       = payer,
                plan        = new Plan()
                {
                    id = createdPlan.id
                },
                shipping_address = shippingAddress
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Create billing agreement", agreement);
            #endregion

            // Create the billing agreement.
            var createdAgreement = agreement.Create(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(createdAgreement);
            #endregion

            // Get the redirect URL to allow the user to be redirected to PayPal to accept the agreement.
            var links = createdAgreement.links.GetEnumerator();

            while (links.MoveNext())
            {
                var link = links.Current;
                if (link.rel.ToLower().Trim().Equals("approval_url"))
                {
                    this.flow.RecordRedirectUrl("Redirect to PayPal to approve billing agreement...", link.href);
                }
            }
            Session.Add("flow-" + guid, this.flow);
            Session.Add(guid, createdAgreement.token);
        }
        //protected RequestFlow flow;
        /// <summary>
        ///
        /// </summary>
        private string CreateBillingAgreement(APIContext apiContext)
        {
            var returnUrl = string.Empty;

            try
            {
                // Before we can setup the billing agreement, we must first create a
                // billing plan that includes a redirect URL back to this test server.
                var plan = CreatePlanObject(System.Web.HttpContext.Current);
                var guid = Convert.ToString((new Random()).Next(100000));
                plan.merchant_preferences.return_url = Request.Url.ToString() + "?guid=" + guid;


                var createdPlan = plan.Create(apiContext);

                // Activate the plan
                var patchRequest = new PatchRequest()
                {
                    new Patch()
                    {
                        op    = "replace",
                        path  = "/",
                        value = new Plan()
                        {
                            state = "ACTIVE"
                        }
                    }
                };


                createdPlan.Update(apiContext, patchRequest);

                // With the plan created and activated, we can now create the billing agreement.
                var payer = new Payer()
                {
                    payment_method = "paypal"
                };
                var shippingAddress = new ShippingAddress()
                {
                    line1        = "111 First Street",
                    city         = "Saratoga",
                    state        = "CA",
                    postal_code  = "95070",
                    country_code = "US"
                };

                var agreement = new Agreement()
                {
                    name        = "T-Shirt of the Month Club",
                    description = "Agreement for T-Shirt of the Month Club",
                    start_date  = "2019-02-19T00:37:04Z",//DateTimeOffset.Now.AddDays(2).ToString(),
                    payer       = payer,

                    plan = new Plan()
                    {
                        id = createdPlan.id,
                    },                                         // We can use the existing plan id
                    shipping_address = shippingAddress
                };


                // Create the billing agreement.
                var createdAgreement = agreement.Create(apiContext);


                // Get the redirect URL to allow the user to be redirected to PayPal to accept the agreement.
                var links = createdAgreement.links.GetEnumerator();

                while (links.MoveNext())
                {
                    var link = links.Current;
                    if (link.rel.ToLower().Trim().Equals("approval_url"))
                    {
                        this.flow.RecordRedirectUrl("Redirect to PayPal to approve billing agreement...", link.href);
                        returnUrl = link.href;
                    }
                }

                Session.Add(guid, createdAgreement.token);
                //Redirect()
                return(returnUrl);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 13
0
        public bool createBillingAgreement(Models.CreditCardModel model, Models.MyIdentityUser user)
        {
            var apiContext = Models.Configuration.GetAPIContext();

            var billingPlan = new Models.BillingPlanCreate();

            var plan = billingPlan.CreatePlanObject(System.Web.HttpContext.Current);
            var guid = Convert.ToString((new Random()).Next(100000));

            plan.merchant_preferences.return_url = Request.Url.ToString() + "?guid=" + guid;
            plan.merchant_preferences.cancel_url = Request.Url.ToString();

            var createdPlan = plan.Create(apiContext);

            var patchRequest = new PatchRequest()
            {
                new Patch()
                {
                    op    = "replace",
                    path  = "/",
                    value = new Plan()
                    {
                        state = "ACTIVE"
                    }
                }
            };

            createdPlan.Update(apiContext, patchRequest);

            var payer = new Payer
            {
                payment_method      = "credit_card",
                funding_instruments = new List <FundingInstrument>
                {
                    new FundingInstrument
                    {
                        credit_card = new CreditCard
                        {
                            billing_address = new Address
                            {
                                city         = model.City,
                                country_code = model.Country,
                                line1        = model.Address,
                                postal_code  = model.ZipCode,
                                state        = model.State
                            },
                            cvv2         = model.cvv2,
                            expire_month = Int32.Parse(model.ExpireMonth),
                            expire_year  = Int32.Parse(model.ExpireYear),
                            first_name   = model.FirstName,
                            last_name    = model.LastName,
                            number       = model.CardNumber,
                            type         = model.CardType
                        }
                    }
                }
            };

            var shippingAddress = new ShippingAddress()
            {
                line1        = "111 First Street",
                city         = "Saratoga",
                state        = "CA",
                postal_code  = "95070",
                country_code = "US"
            };

            var agreement = new Agreement()
            {
                name        = "Webvnue",
                description = "Monthly Subscription",
                //start_date = "2015-02-19T00:37:04Z",
                start_date = DateTime.Now.AddDays(1).ToString("yyyy-MM-ddTHH:mm:ssZ"),
                payer      = payer,
                plan       = new Plan()
                {
                    id = createdPlan.id
                },
                shipping_address = shippingAddress
            };

            var createdAgreement = agreement.Create(apiContext);

            return(true);
        }
Ejemplo n.º 14
0
        public ActionResult TestRecurring()
        {
            string sPricePlan = Helpers.Tools.PriceFormat(priceItem);
            string sTaxAmt    = Helpers.Tools.PriceFormat(priceItem * tax);
            //string sSubtotal = Helpers.Tools.PriceFormat(decimal.Parse(sPriceItem) - decimal.Parse(sTaxAmt));

            APIContext apiContext = clsPayPal.PayPalConfig.GetAPIContext();

            Session["accesstoken"] = apiContext.AccessToken;

            ChargeModel cModel = new ChargeModel()
            {
                amount = new Currency()
                {
                    currency = currency,
                    value    = sTaxAmt
                },
                type = "TAX"
            };

            //cModel = new ChargeModel()
            //{
            //    amount = new Currency()
            //    {
            //        currency = currency,
            //        value = sTaxAmt
            //    },
            //    type = "SHIPPING"
            //};

            List <ChargeModel> lstModels = new List <ChargeModel>();

            lstModels.Add(cModel);

            PaymentDefinition pDef = new PaymentDefinition()
            {
                amount = new Currency()
                {
                    currency = currency,
                    value    = sPricePlan
                },
                cycles             = "11",
                charge_models      = lstModels,
                frequency          = "MONTH",
                frequency_interval = "1",
                type = "REGULAR",
                name = "pmt recurring",
            };
            List <PaymentDefinition> lstPayDef = new List <PaymentDefinition>();

            lstPayDef.Add(pDef);

            MerchantPreferences merPref = new MerchantPreferences()
            {
                setup_fee = new Currency()
                {
                    currency = currency,
                    value    = "1"
                },
                auto_bill_amount           = "YES",
                max_fail_attempts          = "0",
                initial_fail_amount_action = "CONTINUE",
                return_url = returnURL,
                cancel_url = cancelURL
            };

            Plan createdPlan = Plan.Get(apiContext, "P-4NL72850M8850524J7ZREBTY");

            if (createdPlan == null)
            {
                Plan myPlan = new Plan();
                myPlan.name                 = "Plan One";
                myPlan.description          = "Plan One Description";
                myPlan.type                 = "fixed";
                myPlan.payment_definitions  = lstPayDef;
                myPlan.merchant_preferences = merPref;
                var guid = Convert.ToString((new Random()).Next(100000));
                myPlan.merchant_preferences.return_url = Request.Url.ToString() + "?guid=" + guid;
                createdPlan = myPlan.Create(apiContext);
            }

            // Activate the plan
            var patchRequest = new PatchRequest()
            {
                new Patch()
                {
                    op    = "replace",
                    path  = "/",
                    value = new Plan()
                    {
                        state = "ACTIVE"
                    }
                }
            };

            createdPlan.Update(apiContext, patchRequest);

            ShippingAddress shippAddr = new ShippingAddress()
            {
                line1        = "111 First Street",
                city         = "Toronto",
                state        = "ON",
                postal_code  = "95070",
                country_code = "CA"
            };

            //Agreement newSub =clsPayPal.CreateBillingAgreement(hPlan.id, shippAddr, "some name", "some description", DateTime.Now);

            var agreement = new Agreement()
            {
                name        = "some name",
                description = "some description",
                start_date  = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + "Z",
                payer       = new Payer()
                {
                    payment_method = "paypal",
                },
                plan = new Plan()
                {
                    id = createdPlan.id
                },
                shipping_address = shippAddr,
            };


            var createdAgreement = agreement.Create(apiContext);

            //return createdAgreement;



            /////

            //Details dtl = new Details()
            //{
            //    tax = sTaxAmt,
            //    subtotal = sSubtotal,
            //    shipping = "0",
            //};

            ////contact infor
            //Address addr = new Address()
            //{
            //    city = sCity,
            //    country_code = sCountryCode,
            //    line1 = sAddressLine1,
            //    line2 = sAddressLine2,
            //    phone = sPhone,
            //    postal_code = sPostalCode,
            //    state = sProvince,
            //};

            //PayerInfo payInfo = new PayerInfo()
            //{
            //    //billing_address = addr,
            //    //country_code= sCountryCode,
            //    first_name = sFirstName,
            //    last_name = sLastName,
            //    //middle_name ="",
            //    email = sEmail,
            //    //phone =sPhone,
            //};

            //Amount amnt = new Amount()
            //{
            //    currency = currency,
            //    total = sPricePlan,
            //    details = dtl,
            //};

            //List<Transaction> transactionList = new List<Transaction>();
            //Transaction tran = new Transaction()
            //{
            //    description = sItemName,
            //    custom = sItemName + " some additional information",
            //    amount = amnt
            //};
            //transactionList.Add(tran);

            //Payer payr = new Payer();
            //payr.payment_method = "paypal";
            //payr.payer_info = payInfo;

            //RedirectUrls redirUrls = new RedirectUrls();
            //redirUrls.cancel_url = "https://devtools-paypal.com/guide/pay_paypal/dotnet?cancel=true";
            ////redirUrls.return_url = "https://devtools-paypal.com/guide/pay_paypal/dotnet?success=true";
            //redirUrls.return_url = "https://localhost:44320/PayPal/ReturnTestRecurring";

            //Payment pymnt = new Payment();
            //pymnt.intent = "sale";
            //pymnt.payer = payr;
            //pymnt.transactions = transactionList;
            //pymnt.redirect_urls = redirUrls;

            //Payment createdPayment = pymnt.Create(apiContext);
            //string ApprovalURL = createdPayment.GetApprovalUrl();

            //Response.Redirect(ApprovalURL);

            return(View());
        }
        protected override void RunSample()
        {
            // ### Api Context
            // Pass in a `APIContext` object to authenticate
            // the call and to send a unique request id
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly.
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = Configuration.GetAPIContext();

            // For demonstration purposes, we'll first setup a billing plan in
            // an active state to be used to make an agreement with.
            var plan = BillingPlanCreate.CreatePlanObject(HttpContext.Current);
            var guid = Convert.ToString((new Random()).Next(100000));

            plan.merchant_preferences.return_url = Request.Url.ToString() + "?guid=" + guid;
            plan.merchant_preferences.cancel_url = Request.Url.ToString();

            // > Note: Both `return_url` and `cancel_url` are being set in
            // `plan.merchant_preferences` since many plans may be setup well
            // in advance of anyone setting up an agreement for it.  These URLs
            // are only used for agreements setup with `payer.payment_method`
            // set to `paypal` to establish where the customer should be redirected
            // once they approve or cancel the agreement using their PayPal account.

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Create new billing plan", plan);
            #endregion

            var createdPlan = plan.Create(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(createdPlan);
            #endregion

            // Activate the plan
            var patchRequest = new PatchRequest()
            {
                new Patch()
                {
                    op    = "replace",
                    path  = "/",
                    value = new Plan()
                    {
                        state = "ACTIVE"
                    }
                }
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Update the plan", patchRequest);
            #endregion

            createdPlan.Update(apiContext, patchRequest);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordActionSuccess("Plan updated successfully");
            #endregion

            // With the plan created and activated, we can now create the billing agreement.
            // A resource representing a Payer that funds a payment.
            var payer = new Payer
            {
                payment_method      = "credit_card",
                funding_instruments = new List <FundingInstrument>
                {
                    new FundingInstrument
                    {
                        credit_card = new CreditCard
                        {
                            billing_address = new Address
                            {
                                city         = "Johnstown",
                                country_code = "US",
                                line1        = "52 N Main ST",
                                postal_code  = "43210",
                                state        = "OH"
                            },
                            cvv2         = "874",
                            expire_month = 11,
                            expire_year  = 2018,
                            first_name   = "Joe",
                            last_name    = "Shopper",
                            number       = "4877274905927862",
                            type         = "visa"
                        }
                    }
                }
            };

            var shippingAddress = new ShippingAddress()
            {
                line1        = "111 First Street",
                city         = "Saratoga",
                state        = "CA",
                postal_code  = "95070",
                country_code = "US"
            };

            var agreement = new Agreement()
            {
                name        = "T-Shirt of the Month Club",
                description = "Agreement for T-Shirt of the Month Club",
                start_date  = "2015-02-19T00:37:04Z",
                payer       = payer,
                plan        = new Plan()
                {
                    id = createdPlan.id
                },
                shipping_address = shippingAddress
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Create billing agreement", agreement);
            #endregion

            // Create the billing agreement.
            var createdAgreement = agreement.Create(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(createdAgreement);
            #endregion

            // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/).
        }