Beispiel #1
0
        public BindableLinkDescription(LinkDescription original)
        {
            if (original is null)
            {
                throw new ArgumentNullException(nameof(original));
            }

            this.LinkText = original.LinkText;
            this.OriginalLink = original.OriginalLink;
            this.Result = original.Result;
            this.LinkAfterRedirect = original.LinkAfterRedirect;
        }
        public async Task <string> GetPaymentUrlAsync(CoursePayInputModel inputModel)
        {
            OrderRequest order = new()
            {
                CheckoutPaymentIntent = "CAPTURE",
                ApplicationContext    = new ApplicationContext()
                {
                    ReturnUrl          = inputModel.ReturnUrl,
                    CancelUrl          = inputModel.CancelUrl,
                    BrandName          = options.CurrentValue.BrandName,
                    ShippingPreference = "NO_SHIPPING"
                },
                PurchaseUnits = new List <PurchaseUnitRequest>()
                {
                    new PurchaseUnitRequest()
                    {
                        CustomId            = $"{inputModel.CourseId}/{inputModel.UserId}",
                        Description         = inputModel.Description,
                        AmountWithBreakdown = new AmountWithBreakdown()
                        {
                            CurrencyCode = inputModel.Price.Currency.ToString(),
                            Value        = inputModel.Price.Amount.ToString(CultureInfo.InvariantCulture) // 14.50
                        }
                    }
                }
            };

            PayPalEnvironment env    = GetPayPalEnvironment(options.CurrentValue);
            PayPalHttpClient  client = new PayPalHttpClient(env);

            OrdersCreateRequest request = new();

            request.RequestBody(order);
            request.Prefer("return=representation");

            HttpResponse response = await client.Execute(request);

            Order result = response.Result <Order>();

            LinkDescription link = result.Links.Single(link => link.Rel == "approve");

            return(link.Href);
        }
        /// <summary>
        /// Finds the links in the supplied HTML source.
        /// </summary>
        /// <param name="html">The HTML.</param>
        /// <returns></returns>
        public static List <LinkDescription> FindLinks(string html)
        {
            var doc = TextCleaner.CreateHtmlDocument(html);

            var links = doc.DocumentNode.SelectNodes("//a[@href]") ?? Enumerable.Empty <HtmlNode>();

            var result = new List <LinkDescription>();

            foreach (var link in links)
            {
                var lnk = new LinkDescription();
                lnk.LinkText     = HttpUtility.HtmlDecode(link.InnerText);
                lnk.OriginalLink = link.GetAttributeValue("href", string.Empty);
                if (!lnk.OriginalLink.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    // neither "http" nor "https"
                    lnk.Result = LinkCheckSummary.Ignored;
                }

                result.Add(lnk);
            }

            return(result);
        }
Beispiel #4
0
 public DescriptionEvent(LinkDescription description)
 {
     Description = description;
 }