Skip to content

Commit

Permalink
feat: Add redirect_url and declined_redirect_url to Sign Request (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
congminh1254 authored and arjankowski committed Aug 29, 2022
1 parent 1f8e3f9 commit f94d988
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 11 deletions.
24 changes: 22 additions & 2 deletions Sources/Requests/BodyData/SignRequestCreateParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public struct SignRequestCreateSigner: Encodable {
public let order: Int?
/// User ID for the signer in an external application responsible for authentication when accessing the embed URL.
public let embedUrlExternalUserId: String?
/// The URL that the signer will be redirected to after signing.
public let redirectUrl: String?
/// The URL that a signer will be redirect to after declining to sign a document.
public let declinedRedirectUrl: String?

/// Initializer.
///
Expand All @@ -115,18 +119,24 @@ public struct SignRequestCreateSigner: Encodable {
/// After the sender signs, they will be redirected to the next `inPerson` signer.
/// - order: Order of the signer.
/// - embedUrlExternalUserId: User ID for the signer in an external application responsible for authentication when accessing the embed URL.
/// - redirectUrl: The URL that the signer will be redirected to after signing.
/// - declinedRedirectUrl: The URL that a signer will be redirect to after declining to sign a document.
public init(
email: String,
role: SignRequestSignerRole? = nil,
isInPerson: Bool? = nil,
order: Int? = nil,
embedUrlExternalUserId: String? = nil
embedUrlExternalUserId: String? = nil,
redirectUrl: String? = nil,
declinedRedirectUrl: String? = nil
) {
self.email = email
self.role = role
self.isInPerson = isInPerson
self.order = order
self.embedUrlExternalUserId = embedUrlExternalUserId
self.redirectUrl = redirectUrl
self.declinedRedirectUrl = declinedRedirectUrl
}
}

Expand Down Expand Up @@ -156,6 +166,10 @@ public struct SignRequestCreateParameters: Encodable {
public let daysValid: Int?
/// This can be used to reference an ID in an external system that the sign request is related to.
public let externalId: String?
/// The URL that a signer will be redirected to after signing a document.
public let redirectUrl: String?
/// The URL that the signer will be redirected to after declining to sign a document.
public let declinedRedirectUrl: String?

/// Initializer.
///
Expand All @@ -168,6 +182,8 @@ public struct SignRequestCreateParameters: Encodable {
/// - prefillTags: List of prefill tags.
/// - daysValid: Number of days after which this request will automatically expire if not completed.
/// - externalId: ID that serve as reference in an external system that the sign request is related to.
/// - redirectUrl: The URL that a signer will be redirected to after signing a document.
/// - declinedRedirectUrl: The URL that the signer will be redirected to after declining to sign a document.
public init(
isDocumentPreparationNeeded: Bool? = nil,
areTextSignaturesEnabled: Bool? = nil,
Expand All @@ -176,7 +192,9 @@ public struct SignRequestCreateParameters: Encodable {
areRemindersEnabled: Bool? = nil,
prefillTags: [SignRequestPrefillTag]? = nil,
daysValid: Int? = nil,
externalId: String? = nil
externalId: String? = nil,
redirectUrl: String? = nil,
declinedRedirectUrl: String? = nil
) {
self.isDocumentPreparationNeeded = isDocumentPreparationNeeded
self.areTextSignaturesEnabled = areTextSignaturesEnabled
Expand All @@ -186,5 +204,7 @@ public struct SignRequestCreateParameters: Encodable {
self.prefillTags = prefillTags
self.daysValid = daysValid
self.externalId = externalId
self.redirectUrl = redirectUrl
self.declinedRedirectUrl = declinedRedirectUrl
}
}
6 changes: 6 additions & 0 deletions Sources/Responses/SignRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public class SignRequest: BoxModel {
public let daysValid: Int?
/// A reference ID in an external system that the sign request is related to.
public let externalId: String?
/// The URL that a signer will be redirected to after signing a document.
public let redirectUrl: String?
/// The URL that a signer will be redirected to after declined signing a document.
public let declinedRedirectUrl: String?

/// Initializer.
///
Expand Down Expand Up @@ -180,5 +184,7 @@ public class SignRequest: BoxModel {
prefillTags = try BoxJSONDecoder.optionalDecodeCollection(json: json, forKey: "prefill_tags")
daysValid = try BoxJSONDecoder.optionalDecode(json: json, forKey: "days_valid")
externalId = try BoxJSONDecoder.optionalDecode(json: json, forKey: "external_id")
redirectUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "redirect_url")
declinedRedirectUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "declined_redirect_url")
}
}
6 changes: 6 additions & 0 deletions Sources/Responses/SignRequestSigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public class SignRequestSigner: BoxModel {
public let inputs: [SignRequestSignerInput]?
/// URL to direct a signer to for signing.
public let embedUrl: String?
/// The URL that a signer will be redirected to after signing a document.
public let redirectUrl: String?
/// The URL that a signer will be redirect to after declining to sign a document.
public let declinedRedirectUrl: String?

/// Initializer.
///
Expand All @@ -89,5 +93,7 @@ public class SignRequestSigner: BoxModel {
signerDecision = try BoxJSONDecoder.optionalDecode(json: json, forKey: "signer_decision")
inputs = try BoxJSONDecoder.optionalDecodeCollection(json: json, forKey: "inputs")
embedUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "embed_url")
redirectUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "redirect_url")
declinedRedirectUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "declined_redirect_url")
}
}
28 changes: 24 additions & 4 deletions Tests/Modules/SignRequestsModuleSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ class SignRequestsModuleSpecs: QuickSpec {
&& isPath("/2.0/sign_requests")
&& isMethodPOST()
&& hasJsonBody([
"signers": [["email": "example@gmail.com", "role": "signer"]],
"signers": [
[
"email": "example@gmail.com",
"role": "signer",
"redirect_url": "https://box.com/redirect_url_signer_1",
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
]
],
"source_files": [["id": "12345", "type": "file"]],
"parent_folder": ["type": "folder", "id": "12345"],
"is_document_preparation_needed": true,
Expand All @@ -46,7 +53,9 @@ class SignRequestsModuleSpecs: QuickSpec {
"email_subject": "Sign Request from Acme",
"email_message": "Hello! Please sign the document below",
"external_id": "123",
"days_valid": 2
"days_valid": 2,
"redirect_url": "https://box.com/redirect_url",
"declined_redirect_url": "https://box.com/declined_redirect_url",
])
) { _ in
OHHTTPStubsResponse(
Expand All @@ -56,7 +65,12 @@ class SignRequestsModuleSpecs: QuickSpec {
}

waitUntil(timeout: .seconds(10)) { done in
let signers = [SignRequestCreateSigner(email: "example@gmail.com", role: .signer)]
let signers = [SignRequestCreateSigner(
email: "example@gmail.com",
role: .signer,
redirectUrl: "https://box.com/redirect_url_signer_1",
declinedRedirectUrl: "https://box.com/declined_redirect_url_signer_1"
)]
let sourceFiles = [SignRequestCreateSourceFile(id: "12345")]
let parentFolder = SignRequestCreateParentFolder(id: "12345")
let tags = [
Expand All @@ -71,7 +85,9 @@ class SignRequestsModuleSpecs: QuickSpec {
areRemindersEnabled: true,
prefillTags: tags,
daysValid: 2,
externalId: "123"
externalId: "123",
redirectUrl: "https://box.com/redirect_url",
declinedRedirectUrl: "https://box.com/declined_redirect_url"
)

self.sut.signRequests.create(
Expand All @@ -89,6 +105,8 @@ class SignRequestsModuleSpecs: QuickSpec {
expect(signRequest.sourceFiles.first?.name).to(equal("Contract.pdf"))
expect(signRequest.parentFolder.id).to(equal("12345"))
expect(signRequest.parentFolder.name).to(equal("Contracts"))
expect(signRequest.signers[0].redirectUrl).to(equal("https://box.com/redirect_url_signer_1"))
expect(signRequest.signers[0].declinedRedirectUrl).to(equal("https://box.com/declined_redirect_url_signer_1"))
expect(signRequest.signers[0].inputs?[0].documentTagId).to(equal("1234"))
expect(signRequest.signers[0].inputs?[0].textValue).to(equal("text"))
expect(signRequest.signers[0].inputs?[1].documentTagId).to(equal("4567"))
Expand All @@ -101,6 +119,8 @@ class SignRequestsModuleSpecs: QuickSpec {
expect(signRequest.emailMessage).to(equal("Hello! Please sign the document below"))
expect(signRequest.externalId).to(equal("123"))
expect(signRequest.daysValid).to(equal(2))
expect(signRequest.redirectUrl).to(equal("https://box.com/redirect_url"))
expect(signRequest.declinedRedirectUrl).to(equal("https://box.com/declined_redirect_url"))
case let .failure(error):
fail("Expected call to create to succeed, but it failed: \(error)")
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/Responses/SignRequestSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ class SignRequestSpecs: QuickSpec {
expect(signRequest.externalId).to(equal("123"))
expect(signRequest.daysValid).to(equal(2))
expect(signRequest.autoExpireAt?.iso8601).to(equal("2021-04-26T08:12:13Z"))
expect(signRequest.redirectUrl).to(equal("https://box.com/redirect_url"))
expect(signRequest.declinedRedirectUrl).to(equal("https://box.com/declined_redirect_url"))
expect(signRequest.signers[0].email).to(equal("example@gmail.com"))
expect(signRequest.signers[0].role).to(equal(.signer))
expect(signRequest.signers[0].isInPerson).to(equal(true))
expect(signRequest.signers[0].order).to(equal(2))
expect(signRequest.signers[0].embedUrlExternalUserId).to(equal("1234"))
expect(signRequest.signers[0].hasViewedDocument).to(equal(true))
expect(signRequest.signers[0].embedUrl).to(equal("https://example.com"))
expect(signRequest.signers[0].redirectUrl).to(equal("https://box.com/redirect_url_signer_1"))
expect(signRequest.signers[0].declinedRedirectUrl).to(equal("https://box.com/declined_redirect_url_signer_1"))
expect(signRequest.signers[0].signerDecision?.type).to(equal(.signed))
expect(signRequest.signers[0].signerDecision?.finalizedAt?.iso8601).to(equal("2021-04-26T08:12:13Z"))
expect(signRequest.signers[0].inputs?[0].documentTagId).to(equal("1234"))
Expand Down
7 changes: 6 additions & 1 deletion Tests/Stubs/Resources/SignRequests/CancelSignRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"page_index": 4
}
],
"embed_url": "https://example.com"
"embed_url": "https://example.com",
"redirect_url": "https://box.com/redirect_url_signer_1",
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"

}
],
"source_files": [
Expand Down Expand Up @@ -60,6 +63,8 @@
"type": "sign-request",
"id": "12345",
"prepare_url": "https://prepareurl.com",
"redirect_url": "https://box.com/redirect_url",
"declined_redirect_url": "https://box.com/declined_redirect_url",
"signing_log": {
"id": "12345",
"etag": "1",
Expand Down
6 changes: 5 additions & 1 deletion Tests/Stubs/Resources/SignRequests/CreateSignRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"page_index": 4
}
],
"embed_url": "https://example.com"
"embed_url": "https://example.com",
"redirect_url": "https://box.com/redirect_url_signer_1",
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
}
],
"source_files": [
Expand Down Expand Up @@ -74,6 +76,8 @@
"type": "sign-request",
"id": "12345",
"prepare_url": "https://prepareurl.com",
"redirect_url": "https://box.com/redirect_url",
"declined_redirect_url": "https://box.com/declined_redirect_url",
"signing_log": {
"id": "12345",
"etag": "1",
Expand Down
6 changes: 5 additions & 1 deletion Tests/Stubs/Resources/SignRequests/FullSignRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"page_index": 4
}
],
"embed_url": "https://example.com"
"embed_url": "https://example.com",
"redirect_url": "https://box.com/redirect_url_signer_1",
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
}
],
"source_files": [
Expand Down Expand Up @@ -60,6 +62,8 @@
"type": "sign-request",
"id": "12345",
"prepare_url": "https://prepareurl.com",
"redirect_url": "https://box.com/redirect_url",
"declined_redirect_url": "https://box.com/declined_redirect_url",
"signing_log": {
"id": "12345",
"etag": "1",
Expand Down
6 changes: 5 additions & 1 deletion Tests/Stubs/Resources/SignRequests/GetSignRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"page_index": 4
}
],
"embed_url": "https://example.com"
"embed_url": "https://example.com",
"redirect_url": "https://box.com/redirect_url_signer_1",
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
}
],
"source_files": [
Expand Down Expand Up @@ -60,6 +62,8 @@
"type": "sign-request",
"id": "12345",
"prepare_url": "https://prepareurl.com",
"redirect_url": "https://box.com/redirect_url",
"declined_redirect_url": "https://box.com/declined_redirect_url",
"signing_log": {
"id": "12345",
"etag": "1",
Expand Down
6 changes: 5 additions & 1 deletion Tests/Stubs/Resources/SignRequests/GetSignRequests.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"page_index": 0
}
],
"embed_url": "https://example.com"
"embed_url": "https://example.com",
"redirect_url": "https://box.com/redirect_url_signer_1",
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
}
],
"source_files": [
Expand Down Expand Up @@ -74,6 +76,8 @@
"type": "sign-request",
"id": "12345",
"prepare_url": "https://prepareurl.com",
"redirect_url": "https://box.com/redirect_url",
"declined_redirect_url": "https://box.com/declined_redirect_url",
"signing_log": {
"id": "12345",
"etag": "1",
Expand Down

0 comments on commit f94d988

Please sign in to comment.