protected void btnSignalSend_Click(object sender, EventArgs e) { DateTime start = DateTime.Now; var client = new PostcodeNlApiRestClient(txtKey.Text, txtSecret.Text, txtApiUrl.Text); try { if (chkSignalShowRawRequestResponse.Checked) client.SetDebugEnabled(); DateTime birthDate; DateTime time; int houseNumber; double cost; int weight; var request = new PostcodeNlSignalRequest { Customer = new PostcodeNlSignalCustomer { FirstName = txtCustomerFirstName.Text.NullIfEmpty(), LastName = txtCustomerLastName.Text.NullIfEmpty(), BirthDate = DateTime.TryParse(txtCustomerBirthDate.Text, out birthDate) ? (DateTime?)birthDate : null, Email = txtCustomerEmail.Text.NullIfEmpty(), EmailDomain = txtCustomerEmailDomain.Text.NullIfEmpty(), PhoneNumber = txtCustomerPhoneNumber.Text.NullIfEmpty(), BankNumber = txtCustomerBankNumber.Text.NullIfEmpty(), Site = txtCustomerSite.Text.NullIfEmpty(), InternalId = txtCustomerInternalId.Text.NullIfEmpty(), Address = new PostcodeNlSignalAddress { Postcode = txtCustomerAddressPostcode.Text.NullIfEmpty(), HouseNumber = int.TryParse(txtCustomerAddressHouseNumber.Text, out houseNumber) ? (int?)houseNumber : null, HouseNumberAddition = txtCustomerAddressHouseNumberAddition.Text.NullIfEmpty(), Street = txtCustomerAddressStreet.Text.NullIfEmpty(), City = txtCustomerAddressCity.Text.NullIfEmpty(), Region = txtCustomerAddressRegion.Text.NullIfEmpty(), Country = ddlCustomerAddressCountry.SelectedValue.NullIfEmpty() } } }; request.Customer.Company = new PostcodeNlSignalCompany { Name = txtCustomerCompanyName.Text.NullIfEmpty(), GovernmentId = txtCustomerCompanyGovernmentId.Text.NullIfEmpty(), Country = ddlCustomerCompanyCountry.SelectedValue.NullIfEmpty() }; request.Access = new PostcodeNlSignalAccess { IpAddress = txtAccessIpAddress.Text.NullIfEmpty(), AdditionalIpAddresses = txtAccessAdditionalUpAddresses.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(), SessionId = txtAccessSessionId.Text.NullIfEmpty(), Time = DateTime.TryParse(txtAccessTime.Text, out time) ? (DateTime?)time : null, Browser = new PostcodeNlSignalBrowser { UserAgent = txtAccessBrowserUserAgent.Text.NullIfEmpty(), AcceptLanguage = txtAccessBrowserAcceptLanguage.Text.NullIfEmpty() } }; request.Transaction = new PostcodeNlSignalTransaction { InternalId = txtTransactionInternalId.Text.NullIfEmpty(), Status = ddlTransactionStatus.SelectedValue.NullIfEmpty(), Cost = double.TryParse(txtTransactionCost.Text, out cost) ? (double?)cost : null, CostCurrency = txtTransactionCostCurrency.Text.NullIfEmpty(), PaymentType = txtTransactionPaymentType.Text.NullIfEmpty(), Weight = int.TryParse(txtTransactionWeight.Text, out weight) ? (int?)weight : null, DeliveryAddress = new PostcodeNlSignalAddress { Postcode = txtTransactionDeliveryAddressPostcode.Text.NullIfEmpty(), HouseNumber = int.TryParse(txtTransactionDeliveryAddressHouseNumber.Text, out houseNumber) ? (int?)houseNumber : null, HouseNumberAddition = txtTransactionDeliveryAddressHouseNumberAddition.Text.NullIfEmpty(), Street = txtTransactionDeliveryAddressStreet.Text.NullIfEmpty(), City = txtTransactionDeliveryAddressCity.Text.NullIfEmpty(), Region = txtTransactionDeliveryAddressRegion.Text.NullIfEmpty(), Country = ddlTransactionDeliveryAddressCountry.SelectedValue.NullIfEmpty() } }; request.Config = new PostcodeNlSignalConfig { SelectServices = txtConfigSelectServices.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(), ExcludeServices = txtConfigExcludeServices.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(), SelectTypes = txtConfigSelectTypes.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .ToList(), ExcludeTypes = txtConfigExcludeTypes.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .ToList() }; var result = client.DoSignalCheck(request); lSignalCount.Text = string.Format("{0}", result.Signals.Count); hplReportPdfUrl.NavigateUrl = result.ReportPdfUrl; lResult.Text = result.ToString(); pnlResult.Visible = true; pnlSignalResponse.Visible = true; } catch (PostcodeNlApiRestClientClientException ex) { pnlError.Visible = true; lType.Text = "Client error"; lMessage.Text = ex.Message; lClass.Text = ex.GetType().ToString(); } catch (PostcodeNlApiRestClientServiceException ex) { pnlError.Visible = true; lType.Text = "Service error"; lMessage.Text = ex.Message; lClass.Text = ex.GetType().ToString(); } catch (PostcodeNlApiRestClientInputInvalidException ex) { pnlError.Visible = true; lType.Text = "Input error"; lMessage.Text = ex.Message; lClass.Text = ex.GetType().ToString(); } catch (PostcodeNlApiRestClientAuthenticationException ex) { pnlError.Visible = true; lType.Text = "Authentication error"; lMessage.Text = ex.Message; lClass.Text = ex.GetType().ToString(); } catch (PostcodeNlApiRestClientAddressNotFoundException ex) { pnlError.Visible = true; lType.Text = "Address not found"; lMessage.Text = ex.Message; lClass.Text = ex.GetType().ToString(); } catch (Exception ex) { pnlError.Visible = true; lType.Text = "Error"; lMessage.Text = ex.Message; lClass.Text = ex.GetType().ToString(); } if (chkSignalShowRawRequestResponse.Checked) { pnlRawRequestResponse.Visible = true; var debugData = client.GetDebugData(); if (debugData != null) { lRequest.Text = debugData["request"]; lResponse.Text = debugData["response"]; } } pnlTimeTaken.Visible = true; lTimeTaken.Text = DateTime.Now.Subtract(start).TotalSeconds.ToString(); }
/** Perform a Postcode.nl Signal check on the given transaction and/or customer information. Parameters: customer - (array) Data concerning a customer access - (array) Data concerning how a customer is accessing a service transaction - (array) Data concerning a transaction of a customer config - (array) Configuration for the signal check Returns: (array) signals checkId - (string) Identifier of the check (22 characters) signals - (array) All signals, each signal is an array, containing: concerning - (string) Field this signal is about type - (string) Name of signal type, including vendor, service name and response type warning - (boolean) If this signal is significant. message - (string) Human readable explanation for the signal data - (array|null) Optional data of the signal. See documentation on website for data definitions of the specific signal types. warningCount - (int) Number of warnings found in signals reportPdfUrl - (string) URL to a report of the signal check Reference: <https://api.postcode.nl/documentation> */ public PostcodeNlSignalResponse DoSignalCheck(PostcodeNlSignalRequest signalRequest) { string url = _restApiUrl + "/signal/check"; string data = JsonHelper.Serialize(signalRequest); string response = DoRestCall("POST", url, data); PostcodeNlSignalResponse signalResponse; try { signalResponse = JsonHelper.Deserialize<PostcodeNlSignalResponse>(response); } catch (Exception) { // We received a response, but we did not understand it... throw new PostcodeNlApiRestClientClientException("Did not understand Postcode.nl API response: '" + response + "'."); } return signalResponse; }