Skip to content

Commit

Permalink
feat: verifyV2 BYOP (#392)
Browse files Browse the repository at this point in the history
* Implement BYOP (custom code)

* Remove dead code
  • Loading branch information
Tr00d committed May 15, 2023
1 parent d4bb72f commit 692f0bc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"client_ref": "my-personal-reference",
"code_length": 4,
"brand": "ACME, Inc",
"code": "123456",
"workflow": [
{
"channel": "email",
Expand Down
11 changes: 11 additions & 0 deletions Vonage.Test.Unit/VerifyV2/StartVerification/RequestBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ public class RequestBuilderTest
.Should()
.BeSuccess("client ref");

[Fact]
public void Create_ShouldSetCode() =>
StartVerificationRequest.Build()
.WithBrand(this.fixture.Create<string>())
.WithWorkflow(EmailWorkflow.Parse(ValidEmail))
.WithCode("123456")
.Create()
.Map(request => request.Code)
.Should()
.BeSuccess("123456");

[Theory]
[InlineData(4)]
[InlineData(10)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SerializationTest
.WithChannelTimeout(300)
.WithClientReference("my-personal-reference")
.WithCodeLength(4)
.WithCode("123456")
.Create()
.GetStringContent()
.Should()
Expand Down
6 changes: 6 additions & 0 deletions Vonage/VerifyV2/StartVerification/StartVerificationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ namespace Vonage.VerifyV2.StartVerification;
/// </summary>
public Maybe<string> ClientReference { get; internal init; }

/// <summary>
/// An optional alphanumeric custom code to use, if you don't want Vonage to generate the code.
/// </summary>
public Maybe<string> Code { get; internal init; }

/// <summary>
/// Gets the length of the code to send to the user
/// </summary>
Expand Down Expand Up @@ -83,6 +88,7 @@ private StringContent GetRequestContent()
this.ClientReference.IfSome(some => values.Add("client_ref", some));
values.Add("code_length", this.CodeLength);
values.Add("brand", this.Brand);
this.Code.IfSome(some => values.Add("code", some));
values.Add("workflow", this.Workflows
.Select(workflow => workflow.Serialize(serializer))
.Select(serializedString => serializer.DeserializeObject<dynamic>(serializedString))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal class StartVerificationRequestBuilder :
private Locale locale = Locale.EnUs;
private Maybe<IResultFailure> failure = Maybe<IResultFailure>.None;
private Maybe<string> clientReference = Maybe<string>.None;
private Maybe<string> code;
private string brand;

/// <inheritdoc />
Expand All @@ -33,6 +34,7 @@ internal class StartVerificationRequestBuilder :
ClientReference = this.clientReference,
CodeLength = this.codeLength,
Workflows = this.workflows.ToArray(),
Code = this.code,
}))
.Bind(VerifyWorkflowsNotEmpty)
.Bind(VerifyBrandNotEmpty)
Expand Down Expand Up @@ -62,6 +64,13 @@ public IOptionalBuilder WithClientReference(string value)
return this;
}

/// <inheritdoc />
public IOptionalBuilder WithCode(string value)
{
this.code = value;
return this;
}

/// <inheritdoc />
public IOptionalBuilder WithCodeLength(int value)
{
Expand Down Expand Up @@ -189,6 +198,19 @@ public interface IOptionalBuilderForCodeLength
IOptionalBuilder WithCodeLength(int value);
}

/// <summary>
/// Represents a builder for Code.
/// </summary>
public interface IOptionalBuilderForCode
{
/// <summary>
/// Sets a custom code, if you don't want Vonage to generate the code.
/// </summary>
/// <param name="value">The custom code.</param>
/// <returns>The builder.</returns>
IOptionalBuilder WithCode(string value);
}

/// <summary>
/// Represents a builder for fallback workflow.
/// </summary>
Expand Down Expand Up @@ -237,6 +259,7 @@ public interface IOptionalBuilder :
IOptionalOptionalBuilderForChannelTimeout,
IOptionalOptionalBuilderForClientReference,
IOptionalBuilderForCodeLength,
IOptionalBuilderForFallbackWorkflow
IOptionalBuilderForFallbackWorkflow,
IOptionalBuilderForCode
{
}

0 comments on commit 692f0bc

Please sign in to comment.