Skip to content

Commit

Permalink
add options for embedded invite request
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNDRmac committed Oct 16, 2024
1 parent a690219 commit 058eb79
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 2 deletions.
17 changes: 17 additions & 0 deletions SignNow.Net.Test/TestData/FakeModels/EmbeddedInviteFaker.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Bogus;
using SignNow.Net.Model;
using SignNow.Net.Model.Requests;
Expand All @@ -17,7 +18,15 @@ public class EmbeddedInviteFaker : Faker<EmbeddedInvite>
/// <code>
/// {
/// "email": "[email protected]",
/// "language": "en",
/// "auth_method": "none",
/// "first_name": "Jesus",
/// "last_name": "Monahan",
/// "prefill_signature_name": "Jesus Monahan prefill signature",
/// "force_new_signature": "1",
/// "redirect_uri": "https://signnow.com",
/// "decline_redirect_uri": "https://signnow.com",
/// "redirect_target": "self",
/// "role_id": "c376990ca7e1e84ea7f6e252144e435f314bb63b",
/// "order": 1
/// }
Expand All @@ -28,7 +37,15 @@ public EmbeddedInviteFaker()
Rules((f, o) =>
{
o.Email = f.Internet.Email();
o.Language = f.PickRandom<Lang>();
o.AuthMethod = f.PickRandom<EmbeddedAuthType>();
o.Firstname = f.Person.FirstName;
o.Lastname = f.Person.LastName;
o.PrefillSignatureName = $"{f.Person.FirstName} {f.Person.LastName} prefill signature";
o.ForceNewSignature = f.Random.Bool();
o.RedirectUrl = new Uri(f.Internet.Url());
o.DeclineRedirectUrl = new Uri(f.Internet.Url());
o.RedirectTarget = f.PickRandom<RedirectTarget>();
o.RoleId = f.Random.Hash(40);
o.SigningOrder = (uint)f.Random.Number(1, 10);
});
Expand Down
136 changes: 134 additions & 2 deletions SignNow.Net/Model/EmbeddedInvite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SignNow.Net.Internal.Extensions;
using SignNow.Net.Internal.Helpers.Converters;
using SignNow.Net.Model.Requests;

namespace SignNow.Net.Model
Expand All @@ -14,6 +15,20 @@ public class EmbeddedInvite
private string email { get; set; }
private uint signingOrder { get; set; }

private string prefillSignatureName { get; set; }
private bool forceNewSignature { get; set; }

private string requiredPresetSignatureName { get; set; }

/// <summary>
/// Prefilled text in the Signature field, disabled for editing by signer.
/// Cannot be used together with prefill_signature_name and/or force_new_signature.
/// </summary>
private bool isPrefilledSignatureName { get; set; }

private bool isRequiredPresetEnabled { get; set; }


/// <summary>
/// Signer's email address.
/// </summary>
Expand All @@ -25,13 +40,13 @@ public string Email
}

/// <summary>
/// Signer's role ID.
/// Signer's role id in the document.
/// </summary>
[JsonProperty("role_id")]
public string RoleId { get; set; }

/// <summary>
/// Order of signing. Cannot be 0.
/// The order of signing. Cannot be 0.
/// </summary>
[JsonProperty("order")]
public uint SigningOrder
Expand All @@ -48,11 +63,128 @@ public uint SigningOrder
}
}

/// <summary>
/// Sets the language of the signing session for the signer.
/// </summary>
[JsonProperty("language")]
[JsonConverter(typeof(StringEnumConverter))]
public Lang Language { get; set; }

/// <summary>
/// Signer authentication method.
/// </summary>
[JsonProperty("auth_method")]
[JsonConverter(typeof(StringEnumConverter))]
public EmbeddedAuthType AuthMethod { get; set; } = EmbeddedAuthType.None;

/// <summary>
/// Signer's first name.
/// </summary>
[JsonProperty("first_name", NullValueHandling = NullValueHandling.Ignore)]
public string Firstname { get; set; }

/// <summary>
/// Signer's last name.
/// </summary>
[JsonProperty("last_name", NullValueHandling = NullValueHandling.Ignore)]
public string Lastname { get; set; }

/// <summary>
/// Prefilled text in the Signature field.
/// </summary>
/// <exception cref="ArgumentException">String lenght cannot be greater than 255 characters</exception>
/// <exception cref="ArgumentException">Cannot be used together with Required preset for Signature name</exception>
[JsonProperty("prefill_signature_name", NullValueHandling = NullValueHandling.Ignore)]
public string PrefillSignatureName
{
get { return prefillSignatureName; }
set
{
if (value.Length > 255)
{
throw new ArgumentException(
"Prefilled text in the Signature field can be maximum 255 characters.",
nameof(PrefillSignatureName));
}

if (isRequiredPresetEnabled)
{
throw new ArgumentException(
"Required preset for Signature name is set. Cannot be used together with",
nameof(PrefillSignatureName));
}

prefillSignatureName = value;
isPrefilledSignatureName = true;
}
}

/// <exception cref="ArgumentException">Cannot be used together with Required preset for Signature name</exception>
[JsonProperty("force_new_signature", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(BoolToIntJsonConverter))]
public bool ForceNewSignature
{
get { return forceNewSignature; }
set
{
if (isRequiredPresetEnabled)
{
throw new ArgumentException(
"Required preset for Signature name is set. Cannot be used together with",
nameof(ForceNewSignature));
}

forceNewSignature = value;

if (value)
{
isPrefilledSignatureName = true;
}
}
}

/// <summary>
/// Prefilled text in the Signature field, disabled for editing by signer.
/// </summary>
/// <exception cref="ArgumentException">Cannot be used together with prefill for Signature name</exception>
[JsonProperty("required_preset_signature_name", NullValueHandling = NullValueHandling.Ignore)]
public string RequiredPresetSignatureName
{
get { return requiredPresetSignatureName; }
set
{
if (isPrefilledSignatureName)
{
throw new ArgumentException(
"Prefill for Signature name or Force new signature is set. Cannot be used together with",
nameof(RequiredPresetSignatureName));
}

requiredPresetSignatureName = value;
isRequiredPresetEnabled = true;
}
}

/// <summary>
/// The link that opens after the signing session has been completed.
/// </summary>
[JsonProperty("redirect_uri", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringToUriJsonConverter))]
public Uri RedirectUrl { get; set; }

/// <summary>
/// The link that opens after the signing session has been declined by the signer.
/// </summary>
[JsonProperty("decline_redirect_uri", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringToUriJsonConverter))]
public Uri DeclineRedirectUrl { get; set; }

/// <summary>
/// Determines whether to open the redirect link in the new tab in the browser, or in the same tab after the signing session.
/// Possible values: blank - opens the link in the new tab, self - opens the link in the same tab, default value.
/// </summary>
[JsonProperty("redirect_target", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
public RedirectTarget RedirectTarget { get; set; }
}
}
16 changes: 16 additions & 0 deletions SignNow.Net/Model/Lang.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Runtime.Serialization;

namespace SignNow.Net.Model
{
public enum Lang
{
[EnumMember(Value = "en")]
English,

[EnumMember(Value = "es")]
Spanish,

[EnumMember(Value = "fr")]
French
}
}
19 changes: 19 additions & 0 deletions SignNow.Net/Model/RedirectTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Runtime.Serialization;

namespace SignNow.Net.Model
{
public enum RedirectTarget
{
/// <summary>
/// opens the link in the new tab
/// </summary>
[EnumMember(Value = "blank")]
Blank,

/// <summary>
/// opens the link in the same tab.
/// </summary>
[EnumMember(Value = "self")]
Self
}
}

0 comments on commit 058eb79

Please sign in to comment.