コード例 #1
0
        /// <summary>
        /// Uploads the card.
        /// </summary>
        /// <param name="frontBase64Encoded">The front base64 encoded.</param>
        /// <param name="backBase64Encoded">The back base64 encoded.</param>
        /// <param name="webhookUrl">The webhook URL.</param>
        /// <param name="casing">The casing.</param>
        /// <param name="sandbox">The sandbox.</param>
        /// <param name="verified">The verified.</param>
        /// <param name="verifiedOnly">The verified only.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">frontBase64Encoded;A front image is required to process a card.</exception>
        public CardReaderResponse UploadCard(
            string frontBase64Encoded,
            string backBase64Encoded,
            string webhookUrl,
            Casing? casing = null,
            SandboxMode? sandbox = null,
            Verified? verified = null,
            bool? verifiedOnly = null)
        {
            if (string.IsNullOrWhiteSpace(frontBase64Encoded)) throw new ArgumentNullException("frontBase64Encoded", "A front image is required to process a card.");

            var request = GetCardReaderRequest(webhookUrl, casing, sandbox, verified, verifiedOnly);
            request.RequestFormat = DataFormat.Json;
            request.AddBody(new { front = frontBase64Encoded, back = backBase64Encoded });
            return Execute<CardReaderResponse>(request);
        }
コード例 #2
0
        /// <summary>
        /// Uploads the card.
        /// </summary>
        /// <param name="front">The front.</param>
        /// <param name="back">The back.</param>
        /// <param name="webhookUrl">The webhook URL.</param>
        /// <param name="casing">The casing.</param>
        /// <param name="sandbox">The sandbox.</param>
        /// <param name="verified">The verified.</param>
        /// <param name="verifiedOnly">The verified only.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">A webhook is required to process a card.</exception>
        public CardReaderResponse UploadCard(
            byte[] front,
            byte[] back,
            string webhookUrl,
            Casing? casing = null,
            SandboxMode? sandbox = null,
            Verified? verified = null,
            bool? verifiedOnly = null)
        {
            if (front == null || front.Length == 0) throw new ArgumentNullException("front", "A front image is required to process a card.");

            var request = GetCardReaderRequest(webhookUrl, casing, sandbox, verified, verifiedOnly);
            request.AddFile("front", front, "front.png|jpg|gif", "image/png|jpg|gif");

            if (back != null && back.Length > 0)
            {
                request.AddFile("back", back, "back.png|jpg|gif", "image/png|jpg|gif");
            }

            return Execute<CardReaderResponse>(request);
        }
コード例 #3
0
        private static void KitchenSink()
        {
            String  apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
            dynamic sg     = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");

            Mail mail = new Mail();

            Email email = new Email();

            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            mail.From     = email;

            mail.Subject = "Hello World from the SendGrid CSharp Library";

            Personalization personalization = new Personalization();

            email         = new Email();
            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            personalization.AddTo(email);
            email         = new Email();
            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            personalization.AddCc(email);
            email         = new Email();
            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            personalization.AddCc(email);
            email         = new Email();
            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            personalization.AddBcc(email);
            email         = new Email();
            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            personalization.AddBcc(email);
            personalization.Subject = "Thank you for signing up, %name%";
            personalization.AddHeader("X-Test", "True");
            personalization.AddHeader("X-Mock", "True");
            personalization.AddSubstitution("%name%", "Example User");
            personalization.AddSubstitution("%city%", "Denver");
            personalization.AddCustomArgs("marketing", "false");
            personalization.AddCustomArgs("transactional", "true");
            personalization.SendAt = 1461775051;
            mail.AddPersonalization(personalization);

            personalization = new Personalization();
            email           = new Email();
            email.Name      = "Example User";
            email.Address   = "*****@*****.**";
            personalization.AddTo(email);
            email         = new Email();
            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            personalization.AddCc(email);
            email         = new Email();
            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            personalization.AddCc(email);
            email         = new Email();
            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            personalization.AddBcc(email);
            email         = new Email();
            email.Name    = "Example User";
            email.Address = "*****@*****.**";
            personalization.AddBcc(email);
            personalization.Subject = "Thank you for signing up, %name%";
            personalization.AddHeader("X-Test", "True");
            personalization.AddHeader("X-Mock", "True");
            personalization.AddSubstitution("%name%", "Example User");
            personalization.AddSubstitution("%city%", "Denver");
            personalization.AddCustomArgs("marketing", "false");
            personalization.AddCustomArgs("transactional", "true");
            personalization.SendAt = 1461775051;
            mail.AddPersonalization(personalization);

            Content content = new Content();

            content.Type  = "text/plain";
            content.Value = "Textual content";
            mail.AddContent(content);
            content       = new Content();
            content.Type  = "text/html";
            content.Value = "<html><body>HTML content</body></html>";
            mail.AddContent(content);
            content       = new Content();
            content.Type  = "text/calendar";
            content.Value = "Party Time!!";
            mail.AddContent(content);

            Attachment attachment = new Attachment();

            attachment.Content     = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12";
            attachment.Type        = "application/pdf";
            attachment.Filename    = "balance_001.pdf";
            attachment.Disposition = "attachment";
            attachment.ContentId   = "Balance Sheet";
            mail.AddAttachment(attachment);

            attachment             = new Attachment();
            attachment.Content     = "BwdW";
            attachment.Type        = "image/png";
            attachment.Filename    = "banner.png";
            attachment.Disposition = "inline";
            attachment.ContentId   = "Banner";
            mail.AddAttachment(attachment);

            mail.TemplateId = "13b8f94f-bcae-4ec6-b752-70d6cb59f932";

            mail.AddHeader("X-Day", "Monday");
            mail.AddHeader("X-Month", "January");

            mail.AddSection("%section1", "Substitution for Section 1 Tag");
            mail.AddSection("%section2", "Substitution for Section 2 Tag");

            mail.AddCategory("customer");
            mail.AddCategory("vip");

            mail.AddCustomArgs("campaign", "welcome");
            mail.AddCustomArgs("sequence", "2");

            ASM asm = new ASM();

            asm.GroupId = 3;
            List <int> groups_to_display = new List <int>()
            {
                1, 4, 5
            };

            asm.GroupsToDisplay = groups_to_display;
            mail.Asm            = asm;

            mail.SendAt = 1461775051;

            mail.SetIpPoolId = "23";

            // This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
            // mail.BatchId = "some_batch_id";

            MailSettings mailSettings = new MailSettings();
            BCCSettings  bccSettings  = new BCCSettings();

            bccSettings.Enable       = true;
            bccSettings.Email        = "*****@*****.**";
            mailSettings.BccSettings = bccSettings;
            BypassListManagement bypassListManagement = new BypassListManagement();

            bypassListManagement.Enable       = true;
            mailSettings.BypassListManagement = bypassListManagement;
            FooterSettings footerSettings = new FooterSettings();

            footerSettings.Enable       = true;
            footerSettings.Text         = "Some Footer Text";
            footerSettings.Html         = "<bold>Some HTML Here</bold>";
            mailSettings.FooterSettings = footerSettings;
            SandboxMode sandboxMode = new SandboxMode();

            sandboxMode.Enable       = true;
            mailSettings.SandboxMode = sandboxMode;
            SpamCheck spamCheck = new SpamCheck();

            spamCheck.Enable       = true;
            spamCheck.Threshold    = 1;
            spamCheck.PostToUrl    = "https://gotchya.example.com";
            mailSettings.SpamCheck = spamCheck;
            mail.MailSettings      = mailSettings;

            TrackingSettings trackingSettings = new TrackingSettings();
            ClickTracking    clickTracking    = new ClickTracking();

            clickTracking.Enable           = true;
            clickTracking.EnableText       = false;
            trackingSettings.ClickTracking = clickTracking;
            OpenTracking openTracking = new OpenTracking();

            openTracking.Enable           = true;
            openTracking.SubstitutionTag  = "Optional tag to replace with the open image in the body of the message";
            trackingSettings.OpenTracking = openTracking;
            SubscriptionTracking subscriptionTracking = new SubscriptionTracking();

            subscriptionTracking.Enable           = true;
            subscriptionTracking.Text             = "text to insert into the text/plain portion of the message";
            subscriptionTracking.Html             = "<bold>HTML to insert into the text/html portion of the message</bold>";
            subscriptionTracking.SubstitutionTag  = "text to insert into the text/plain portion of the message";
            trackingSettings.SubscriptionTracking = subscriptionTracking;
            Ganalytics ganalytics = new Ganalytics();

            ganalytics.Enable           = true;
            ganalytics.UtmCampaign      = "some campaign";
            ganalytics.UtmContent       = "some content";
            ganalytics.UtmMedium        = "some medium";
            ganalytics.UtmSource        = "some source";
            ganalytics.UtmTerm          = "some term";
            trackingSettings.Ganalytics = ganalytics;
            mail.TrackingSettings       = trackingSettings;

            email         = new Email();
            email.Address = "*****@*****.**";
            mail.ReplyTo  = email;

            String ret = mail.Get();

            string  requestBody = ret;
            dynamic response    = sg.client.mail.send.post(requestBody: requestBody);

            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.Body.ReadAsStringAsync().Result);
            Console.WriteLine(response.Headers.ToString());

            Console.WriteLine(ret);
            Console.ReadLine();
        }
コード例 #4
0
        /// <summary>
        /// Gets the card reader request.
        /// </summary>
        /// <param name="webhookUrl">The webhook URL.</param>
        /// <param name="casing">The casing.</param>
        /// <param name="sandbox">The sandbox.</param>
        /// <param name="verified">The verified.</param>
        /// <param name="verifiedOnly">The verified only.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">A webhook is required to process a card.</exception>
        private RestRequest GetCardReaderRequest(
            string webhookUrl,
            Casing? casing = null,
            SandboxMode? sandbox = null,
            Verified? verified = null,
            bool? verifiedOnly = null)
        {
            if (string.IsNullOrWhiteSpace(webhookUrl)) throw new ArgumentNullException("webhookUrl", "A webhook is required to process a card.");

            var request = new RestRequest("/cardReader.json", Method.POST);
            request.AddQueryParameter("webhookUrl", webhookUrl);

            if (casing.HasValue)
            {
                request.AddQueryParameter("casing", casing.Value.ToString());
            }

            if (sandbox.HasValue)
            {
                request.AddQueryParameter("sandbox", sandbox.Value.ToString());
            }

            if (verified.HasValue)
            {
                request.AddQueryParameter("verified", verified.Value.ToString());
            }

            if (verifiedOnly.HasValue && verifiedOnly.Value)
            {
                request.AddQueryParameter("returnedData", "verifiedOnly");
            }

            return request;
        }