public async Task SendPrecompiledLetterTest()
        {
            string reference = System.Guid.NewGuid().ToString();
            string postage   = "first";

            byte[] pdfContents;
            try
            {
                pdfContents = File.ReadAllBytes("../../../IntegrationTests/test_files/one_page_pdf.pdf");
            }
            catch (DirectoryNotFoundException)
            {
                pdfContents = File.ReadAllBytes("IntegrationTests/test_files/one_page_pdf.pdf");
            }

            LetterNotificationResponse response = await this.client.SendPrecompiledLetterAsync(reference, pdfContents, postage);

            Assert.IsNotNull(response.id);
            Assert.AreEqual(response.reference, reference);
            Assert.AreEqual(response.postage, postage);

            Notification notification = await this.client.GetNotificationByIdAsync(response.id);

            Assert.IsNotNull(notification);
            Assert.IsNotNull(notification.id);
            Assert.AreEqual(notification.id, response.id);

            Assert.AreEqual(notification.reference, response.reference);
            Assert.AreEqual(notification.postage, response.postage);

            NotifyAssertions.AssertNotification(notification);
        }
        public LetterNotificationResponse SendLetter(String templateId, Dictionary <String, dynamic> personalisation, String clientReference = null)
        {
            JObject o = CreateRequestParams(templateId, personalisation, clientReference);

            String response = this.POST(SEND_LETTER_NOTIFICATION_URL, o.ToString(Formatting.None));

            LetterNotificationResponse receipt = JsonConvert.DeserializeObject <LetterNotificationResponse>(response);

            return(receipt);
        }
        public void SendPrecompiledLetterNotificationGeneratesExpectedResponse()
        {
            LetterNotificationResponse expectedResponse = JsonConvert.DeserializeObject <LetterNotificationResponse>(Constants.fakePrecompiledLetterNotificationResponseJson);

            MockRequest(Constants.fakePrecompiledLetterNotificationResponseJson);

            LetterNotificationResponse actualResponse = client.SendPrecompiledLetter(Constants.fakeNotificationReference, Encoding.UTF8.GetBytes("%PDF-1.5 testpdf"));

            Assert.IsNotNull(expectedResponse.id);
            Assert.IsNotNull(expectedResponse.reference);
            Assert.IsNull(expectedResponse.content);
            Assert.IsTrue(expectedResponse.Equals(actualResponse));
        }
        public void SendLetterNotificationGeneratesExpectedResponse()
        {
            Dictionary <string, dynamic> personalisation = new Dictionary <string, dynamic>
            {
                { "address_line_1", "Foo" },
                { "address_line_2", "Bar" },
                { "postcode", "Baz" }
            };
            LetterNotificationResponse expectedResponse = JsonConvert.DeserializeObject <LetterNotificationResponse>(Constants.fakeLetterNotificationResponseJson);

            MockRequest(Constants.fakeLetterNotificationResponseJson);

            LetterNotificationResponse actualResponse = client.SendLetter(Constants.fakeTemplateId, personalisation, Constants.fakeNotificationReference);

            Assert.IsTrue(expectedResponse.Equals(actualResponse));
        }
Example #5
0
        public async Task SendLetterNotificationGeneratesExpectedResponse()
        {
            Dictionary <string, dynamic> personalisation = new Dictionary <string, dynamic>
            {
                { "address_line_1", "Foo" },
                { "address_line_2", "Bar" },
                { "postcode", "SW1 1AA" }
            };
            LetterNotificationResponse expectedResponse = JsonConvert.DeserializeObject <LetterNotificationResponse>(Constants.fakeLetterNotificationResponseJson);

            MockRequest(Constants.fakeLetterNotificationResponseJson);

            LetterNotificationResponse actualResponse = await client.SendLetterAsync(Constants.fakeTemplateId, personalisation, Constants.fakeNotificationReference);

            Assert.AreEqual(expectedResponse, actualResponse);
        }
        public async Task SendLetterTestWithPersonalisation()
        {
            Dictionary <String, dynamic> personalisation = new Dictionary <String, dynamic>
            {
                { "address_line_1", "Foo" },
                { "address_line_2", "Bar" },
                { "postcode", "SW1 1AA" }
            };

            LetterNotificationResponse response =
                await this.client.SendLetterAsync(LETTER_TEMPLATE_ID, personalisation);

            this.letterNotificationId = response.id;

            Assert.IsNotNull(response);

            Assert.AreEqual(response.content.body, TEST_LETTER_BODY);
            Assert.AreEqual(response.content.subject, TEST_LETTER_SUBJECT);
        }
        public void SendPrecompiledLetterNotificationGeneratesExpectedRequest()
        {
            JObject expected = new JObject
            {
                { "reference", Constants.fakeNotificationReference },
                { "content", "JVBERi0xLjUgdGVzdHBkZg==" }
            };

            MockRequest(Constants.fakeTemplatePreviewResponseJson,
                        client.SEND_LETTER_NOTIFICATION_URL,
                        AssertValidRequest,
                        HttpMethod.Post,
                        AssertGetExpectedContent, expected.ToString(Formatting.None));

            LetterNotificationResponse response = client.SendPrecompiledLetter(
                Constants.fakeNotificationReference,
                Encoding.UTF8.GetBytes("%PDF-1.5 testpdf")
                );
        }
Example #8
0
        public bool SendPinInThePost(IUrlHelper urlHelper, UserOrganisation userOrganisation, string pin, out string letterId)
        {
            string userFullNameAndJobTitle = $"{userOrganisation.User.Fullname} ({userOrganisation.User.JobTitle})";

            string companyName = userOrganisation.Organisation.OrganisationName;

            List <string> address = GetAddressInFourLineFormat(userOrganisation.Organisation);

            string postCode = userOrganisation.Organisation.GetLatestAddress().GetPostCodeInAllCaps();

            string   returnUrl     = urlHelper.Action("ManageOrganisationsGet", "ManageOrganisations", null, "https");
            DateTime pinExpiryDate = VirtualDateTime.Now.AddDays(Global.PinInPostExpiryDays);


            var personalisation = new Dictionary <string, dynamic> {
                { "address_line_1", userFullNameAndJobTitle },
                { "address_line_2", companyName },
                { "address_line_3", address.Count > 0 ? address[0] : "" },
                { "address_line_4", address.Count > 1 ? address[1] : "" },
                { "address_line_5", address.Count > 2 ? address[2] : "" },
                { "address_line_6", address.Count > 3 ? address[3] : "" },
                { "postcode", postCode },
                { "company", companyName },
                { "pin", pin },
                { "returnurl", returnUrl },
                { "expires", pinExpiryDate.ToString("d MMMM yyyy") }
            };

            LetterNotificationResponse response = govNotifyApi.SendLetter(GovUkNotifyPinInThePostLetterTemplateId, personalisation);

            if (response != null)
            {
                letterId = response.id;
                return(true);
            }

            letterId = null;
            return(false);
        }
        public void SendLetterNotificationGeneratesExpectedRequest()
        {
            Dictionary <string, dynamic> personalisation = new Dictionary <string, dynamic>
            {
                { "address_line_1", "Foo" },
                { "address_line_2", "Bar" },
                { "postcode", "Baz" }
            };
            JObject expected = new JObject
            {
                { "template_id", Constants.fakeTemplateId },
                { "personalisation", JObject.FromObject(personalisation) },
                { "reference", Constants.fakeNotificationReference }
            };

            MockRequest(Constants.fakeTemplatePreviewResponseJson,
                        client.SEND_LETTER_NOTIFICATION_URL,
                        AssertValidRequest,
                        HttpMethod.Post,
                        AssertGetExpectedContent, expected.ToString(Formatting.None));

            LetterNotificationResponse response = client.SendLetter(Constants.fakeTemplateId, personalisation, Constants.fakeNotificationReference);
        }
        public LetterNotificationResponse SendLetter(string templateId,
                                                     Dictionary <string, dynamic> personalisation,
                                                     string clientReference = null)
        {
            try
            {
                LetterNotificationResponse response = _client.SendLetter(templateId, personalisation, clientReference);

                return(response);
            }
            catch (NotifyClientException e)
            {
                CustomLogger.Error(
                    "Error whilst sending letter using Gov.UK Notify",
                    new {
                    NotifyTemplateId       = templateId,
                    Personalisation        = JsonConvert.SerializeObject(personalisation),
                    ErrorMessageFromNotify = e.Message
                });

                return(null);
            }
        }