Skip to content

Commit f94d988

Browse files
congminh1254arjankowski
authored andcommitted
feat: Add redirect_url and declined_redirect_url to Sign Request (#870)
1 parent 1f8e3f9 commit f94d988

File tree

10 files changed

+88
-11
lines changed

10 files changed

+88
-11
lines changed

Sources/Requests/BodyData/SignRequestCreateParameters.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public struct SignRequestCreateSigner: Encodable {
105105
public let order: Int?
106106
/// User ID for the signer in an external application responsible for authentication when accessing the embed URL.
107107
public let embedUrlExternalUserId: String?
108+
/// The URL that the signer will be redirected to after signing.
109+
public let redirectUrl: String?
110+
/// The URL that a signer will be redirect to after declining to sign a document.
111+
public let declinedRedirectUrl: String?
108112

109113
/// Initializer.
110114
///
@@ -115,18 +119,24 @@ public struct SignRequestCreateSigner: Encodable {
115119
/// After the sender signs, they will be redirected to the next `inPerson` signer.
116120
/// - order: Order of the signer.
117121
/// - embedUrlExternalUserId: User ID for the signer in an external application responsible for authentication when accessing the embed URL.
122+
/// - redirectUrl: The URL that the signer will be redirected to after signing.
123+
/// - declinedRedirectUrl: The URL that a signer will be redirect to after declining to sign a document.
118124
public init(
119125
email: String,
120126
role: SignRequestSignerRole? = nil,
121127
isInPerson: Bool? = nil,
122128
order: Int? = nil,
123-
embedUrlExternalUserId: String? = nil
129+
embedUrlExternalUserId: String? = nil,
130+
redirectUrl: String? = nil,
131+
declinedRedirectUrl: String? = nil
124132
) {
125133
self.email = email
126134
self.role = role
127135
self.isInPerson = isInPerson
128136
self.order = order
129137
self.embedUrlExternalUserId = embedUrlExternalUserId
138+
self.redirectUrl = redirectUrl
139+
self.declinedRedirectUrl = declinedRedirectUrl
130140
}
131141
}
132142

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

160174
/// Initializer.
161175
///
@@ -168,6 +182,8 @@ public struct SignRequestCreateParameters: Encodable {
168182
/// - prefillTags: List of prefill tags.
169183
/// - daysValid: Number of days after which this request will automatically expire if not completed.
170184
/// - externalId: ID that serve as reference in an external system that the sign request is related to.
185+
/// - redirectUrl: The URL that a signer will be redirected to after signing a document.
186+
/// - declinedRedirectUrl: The URL that the signer will be redirected to after declining to sign a document.
171187
public init(
172188
isDocumentPreparationNeeded: Bool? = nil,
173189
areTextSignaturesEnabled: Bool? = nil,
@@ -176,7 +192,9 @@ public struct SignRequestCreateParameters: Encodable {
176192
areRemindersEnabled: Bool? = nil,
177193
prefillTags: [SignRequestPrefillTag]? = nil,
178194
daysValid: Int? = nil,
179-
externalId: String? = nil
195+
externalId: String? = nil,
196+
redirectUrl: String? = nil,
197+
declinedRedirectUrl: String? = nil
180198
) {
181199
self.isDocumentPreparationNeeded = isDocumentPreparationNeeded
182200
self.areTextSignaturesEnabled = areTextSignaturesEnabled
@@ -186,5 +204,7 @@ public struct SignRequestCreateParameters: Encodable {
186204
self.prefillTags = prefillTags
187205
self.daysValid = daysValid
188206
self.externalId = externalId
207+
self.redirectUrl = redirectUrl
208+
self.declinedRedirectUrl = declinedRedirectUrl
189209
}
190210
}

Sources/Responses/SignRequest.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public class SignRequest: BoxModel {
146146
public let daysValid: Int?
147147
/// A reference ID in an external system that the sign request is related to.
148148
public let externalId: String?
149+
/// The URL that a signer will be redirected to after signing a document.
150+
public let redirectUrl: String?
151+
/// The URL that a signer will be redirected to after declined signing a document.
152+
public let declinedRedirectUrl: String?
149153

150154
/// Initializer.
151155
///
@@ -180,5 +184,7 @@ public class SignRequest: BoxModel {
180184
prefillTags = try BoxJSONDecoder.optionalDecodeCollection(json: json, forKey: "prefill_tags")
181185
daysValid = try BoxJSONDecoder.optionalDecode(json: json, forKey: "days_valid")
182186
externalId = try BoxJSONDecoder.optionalDecode(json: json, forKey: "external_id")
187+
redirectUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "redirect_url")
188+
declinedRedirectUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "declined_redirect_url")
183189
}
184190
}

Sources/Responses/SignRequestSigner.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public class SignRequestSigner: BoxModel {
7373
public let inputs: [SignRequestSignerInput]?
7474
/// URL to direct a signer to for signing.
7575
public let embedUrl: String?
76+
/// The URL that a signer will be redirected to after signing a document.
77+
public let redirectUrl: String?
78+
/// The URL that a signer will be redirect to after declining to sign a document.
79+
public let declinedRedirectUrl: String?
7680

7781
/// Initializer.
7882
///
@@ -89,5 +93,7 @@ public class SignRequestSigner: BoxModel {
8993
signerDecision = try BoxJSONDecoder.optionalDecode(json: json, forKey: "signer_decision")
9094
inputs = try BoxJSONDecoder.optionalDecodeCollection(json: json, forKey: "inputs")
9195
embedUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "embed_url")
96+
redirectUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "redirect_url")
97+
declinedRedirectUrl = try BoxJSONDecoder.optionalDecode(json: json, forKey: "declined_redirect_url")
9298
}
9399
}

Tests/Modules/SignRequestsModuleSpecs.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ class SignRequestsModuleSpecs: QuickSpec {
3333
&& isPath("/2.0/sign_requests")
3434
&& isMethodPOST()
3535
&& hasJsonBody([
36-
"signers": [["email": "[email protected]", "role": "signer"]],
36+
"signers": [
37+
[
38+
"email": "[email protected]",
39+
"role": "signer",
40+
"redirect_url": "https://box.com/redirect_url_signer_1",
41+
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
42+
]
43+
],
3744
"source_files": [["id": "12345", "type": "file"]],
3845
"parent_folder": ["type": "folder", "id": "12345"],
3946
"is_document_preparation_needed": true,
@@ -46,7 +53,9 @@ class SignRequestsModuleSpecs: QuickSpec {
4653
"email_subject": "Sign Request from Acme",
4754
"email_message": "Hello! Please sign the document below",
4855
"external_id": "123",
49-
"days_valid": 2
56+
"days_valid": 2,
57+
"redirect_url": "https://box.com/redirect_url",
58+
"declined_redirect_url": "https://box.com/declined_redirect_url",
5059
])
5160
) { _ in
5261
OHHTTPStubsResponse(
@@ -56,7 +65,12 @@ class SignRequestsModuleSpecs: QuickSpec {
5665
}
5766

5867
waitUntil(timeout: .seconds(10)) { done in
59-
let signers = [SignRequestCreateSigner(email: "[email protected]", role: .signer)]
68+
let signers = [SignRequestCreateSigner(
69+
70+
role: .signer,
71+
redirectUrl: "https://box.com/redirect_url_signer_1",
72+
declinedRedirectUrl: "https://box.com/declined_redirect_url_signer_1"
73+
)]
6074
let sourceFiles = [SignRequestCreateSourceFile(id: "12345")]
6175
let parentFolder = SignRequestCreateParentFolder(id: "12345")
6276
let tags = [
@@ -71,7 +85,9 @@ class SignRequestsModuleSpecs: QuickSpec {
7185
areRemindersEnabled: true,
7286
prefillTags: tags,
7387
daysValid: 2,
74-
externalId: "123"
88+
externalId: "123",
89+
redirectUrl: "https://box.com/redirect_url",
90+
declinedRedirectUrl: "https://box.com/declined_redirect_url"
7591
)
7692

7793
self.sut.signRequests.create(
@@ -89,6 +105,8 @@ class SignRequestsModuleSpecs: QuickSpec {
89105
expect(signRequest.sourceFiles.first?.name).to(equal("Contract.pdf"))
90106
expect(signRequest.parentFolder.id).to(equal("12345"))
91107
expect(signRequest.parentFolder.name).to(equal("Contracts"))
108+
expect(signRequest.signers[0].redirectUrl).to(equal("https://box.com/redirect_url_signer_1"))
109+
expect(signRequest.signers[0].declinedRedirectUrl).to(equal("https://box.com/declined_redirect_url_signer_1"))
92110
expect(signRequest.signers[0].inputs?[0].documentTagId).to(equal("1234"))
93111
expect(signRequest.signers[0].inputs?[0].textValue).to(equal("text"))
94112
expect(signRequest.signers[0].inputs?[1].documentTagId).to(equal("4567"))
@@ -101,6 +119,8 @@ class SignRequestsModuleSpecs: QuickSpec {
101119
expect(signRequest.emailMessage).to(equal("Hello! Please sign the document below"))
102120
expect(signRequest.externalId).to(equal("123"))
103121
expect(signRequest.daysValid).to(equal(2))
122+
expect(signRequest.redirectUrl).to(equal("https://box.com/redirect_url"))
123+
expect(signRequest.declinedRedirectUrl).to(equal("https://box.com/declined_redirect_url"))
104124
case let .failure(error):
105125
fail("Expected call to create to succeed, but it failed: \(error)")
106126
}

Tests/Responses/SignRequestSpecs.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ class SignRequestSpecs: QuickSpec {
3838
expect(signRequest.externalId).to(equal("123"))
3939
expect(signRequest.daysValid).to(equal(2))
4040
expect(signRequest.autoExpireAt?.iso8601).to(equal("2021-04-26T08:12:13Z"))
41+
expect(signRequest.redirectUrl).to(equal("https://box.com/redirect_url"))
42+
expect(signRequest.declinedRedirectUrl).to(equal("https://box.com/declined_redirect_url"))
4143
expect(signRequest.signers[0].email).to(equal("[email protected]"))
4244
expect(signRequest.signers[0].role).to(equal(.signer))
4345
expect(signRequest.signers[0].isInPerson).to(equal(true))
4446
expect(signRequest.signers[0].order).to(equal(2))
4547
expect(signRequest.signers[0].embedUrlExternalUserId).to(equal("1234"))
4648
expect(signRequest.signers[0].hasViewedDocument).to(equal(true))
4749
expect(signRequest.signers[0].embedUrl).to(equal("https://example.com"))
50+
expect(signRequest.signers[0].redirectUrl).to(equal("https://box.com/redirect_url_signer_1"))
51+
expect(signRequest.signers[0].declinedRedirectUrl).to(equal("https://box.com/declined_redirect_url_signer_1"))
4852
expect(signRequest.signers[0].signerDecision?.type).to(equal(.signed))
4953
expect(signRequest.signers[0].signerDecision?.finalizedAt?.iso8601).to(equal("2021-04-26T08:12:13Z"))
5054
expect(signRequest.signers[0].inputs?[0].documentTagId).to(equal("1234"))

Tests/Stubs/Resources/SignRequests/CancelSignRequest.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
"page_index": 4
2525
}
2626
],
27-
"embed_url": "https://example.com"
27+
"embed_url": "https://example.com",
28+
"redirect_url": "https://box.com/redirect_url_signer_1",
29+
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
30+
2831
}
2932
],
3033
"source_files": [
@@ -60,6 +63,8 @@
6063
"type": "sign-request",
6164
"id": "12345",
6265
"prepare_url": "https://prepareurl.com",
66+
"redirect_url": "https://box.com/redirect_url",
67+
"declined_redirect_url": "https://box.com/declined_redirect_url",
6368
"signing_log": {
6469
"id": "12345",
6570
"etag": "1",

Tests/Stubs/Resources/SignRequests/CreateSignRequest.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
"page_index": 4
3535
}
3636
],
37-
"embed_url": "https://example.com"
37+
"embed_url": "https://example.com",
38+
"redirect_url": "https://box.com/redirect_url_signer_1",
39+
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
3840
}
3941
],
4042
"source_files": [
@@ -74,6 +76,8 @@
7476
"type": "sign-request",
7577
"id": "12345",
7678
"prepare_url": "https://prepareurl.com",
79+
"redirect_url": "https://box.com/redirect_url",
80+
"declined_redirect_url": "https://box.com/declined_redirect_url",
7781
"signing_log": {
7882
"id": "12345",
7983
"etag": "1",

Tests/Stubs/Resources/SignRequests/FullSignRequest.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"page_index": 4
2525
}
2626
],
27-
"embed_url": "https://example.com"
27+
"embed_url": "https://example.com",
28+
"redirect_url": "https://box.com/redirect_url_signer_1",
29+
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
2830
}
2931
],
3032
"source_files": [
@@ -60,6 +62,8 @@
6062
"type": "sign-request",
6163
"id": "12345",
6264
"prepare_url": "https://prepareurl.com",
65+
"redirect_url": "https://box.com/redirect_url",
66+
"declined_redirect_url": "https://box.com/declined_redirect_url",
6367
"signing_log": {
6468
"id": "12345",
6569
"etag": "1",

Tests/Stubs/Resources/SignRequests/GetSignRequest.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"page_index": 4
2525
}
2626
],
27-
"embed_url": "https://example.com"
27+
"embed_url": "https://example.com",
28+
"redirect_url": "https://box.com/redirect_url_signer_1",
29+
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
2830
}
2931
],
3032
"source_files": [
@@ -60,6 +62,8 @@
6062
"type": "sign-request",
6163
"id": "12345",
6264
"prepare_url": "https://prepareurl.com",
65+
"redirect_url": "https://box.com/redirect_url",
66+
"declined_redirect_url": "https://box.com/declined_redirect_url",
6367
"signing_log": {
6468
"id": "12345",
6569
"etag": "1",

Tests/Stubs/Resources/SignRequests/GetSignRequests.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"page_index": 0
3939
}
4040
],
41-
"embed_url": "https://example.com"
41+
"embed_url": "https://example.com",
42+
"redirect_url": "https://box.com/redirect_url_signer_1",
43+
"declined_redirect_url": "https://box.com/declined_redirect_url_signer_1"
4244
}
4345
],
4446
"source_files": [
@@ -74,6 +76,8 @@
7476
"type": "sign-request",
7577
"id": "12345",
7678
"prepare_url": "https://prepareurl.com",
79+
"redirect_url": "https://box.com/redirect_url",
80+
"declined_redirect_url": "https://box.com/declined_redirect_url",
7781
"signing_log": {
7882
"id": "12345",
7983
"etag": "1",

0 commit comments

Comments
 (0)