Skip to content

Commit c9d22e1

Browse files
committed
Add use case to mandate creation and retrieval
1 parent d1dda44 commit c9d22e1

10 files changed

Lines changed: 150 additions & 0 deletions

src/main/java/com/truelayer/java/mandates/entities/mandate/VRPCommercialMandate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.truelayer.java.mandates.entities.mandate.Mandate.Type.COMMERCIAL;
44

5+
import com.truelayer.java.entities.UseCase;
56
import com.truelayer.java.mandates.entities.beneficiary.Beneficiary;
67
import com.truelayer.java.payments.entities.providerselection.ProviderSelection;
78
import lombok.Builder;
@@ -20,4 +21,6 @@ public class VRPCommercialMandate extends Mandate {
2021
private Beneficiary beneficiary;
2122

2223
private String reference;
24+
25+
private UseCase useCase;
2326
}

src/main/java/com/truelayer/java/mandates/entities/mandatedetail/MandateDetail.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.truelayer.java.TrueLayerException;
66
import com.truelayer.java.commonapi.entities.UserDetail;
77
import com.truelayer.java.entities.CurrencyCode;
8+
import com.truelayer.java.entities.UseCase;
89
import com.truelayer.java.mandates.entities.Constraints;
910
import com.truelayer.java.mandates.entities.beneficiary.Beneficiary;
1011
import com.truelayer.java.payments.entities.providerselection.ProviderSelection;
@@ -40,6 +41,10 @@ public abstract class MandateDetail {
4041

4142
private ProviderSelection providerSelection;
4243

44+
private UseCase useCase;
45+
46+
private String type;
47+
4348
public abstract Status getStatus();
4449

4550
public AuthorizationRequiredMandateDetail asAuthorizationRequiredMandateDetail() {

src/test/java/com/truelayer/java/integration/MandatesIntegrationTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,33 @@ public void shouldGetAMandateById(Status expectedStatus) {
141141
assertEquals(expected, response.getData());
142142
}
143143

144+
@Test
145+
@SneakyThrows
146+
@DisplayName("It should get the commercial mandate details")
147+
public void shouldGetACommercialMandateById() {
148+
String jsonResponseFile = "mandates/200.get_commercial_mandate_by_id.json";
149+
RequestStub.New()
150+
.method("post")
151+
.path(urlPathEqualTo("/connect/token"))
152+
.status(200)
153+
.bodyFile("auth/200.access_token.json")
154+
.build();
155+
RequestStub.New()
156+
.method("get")
157+
.path(urlPathMatching("/mandates/" + A_MANDATE_ID))
158+
.withAuthorization()
159+
.status(200)
160+
.bodyFile(jsonResponseFile)
161+
.build();
162+
163+
ApiResponse<MandateDetail> response =
164+
tlClient.mandates().getMandate(A_MANDATE_ID).get();
165+
166+
verifyGeneratedToken(Collections.singletonList(RECURRING_PAYMENTS_SWEEPING));
167+
MandateDetail expected = deserializeJsonFileTo(jsonResponseFile, MandateDetail.class);
168+
assertEquals(expected, response.getData());
169+
}
170+
144171
@SneakyThrows
145172
@ParameterizedTest(name = "and get a response of type {0}")
146173
@ValueSource(strings = {"provider_selection", "redirect", "wait"})
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"status": "authorized",
3+
"id": "string",
4+
"type": "commercial",
5+
"use_case": "financial_services",
6+
"authorization_flow":{
7+
"actions":{
8+
"next":{
9+
"type":"provider_selection",
10+
"providers":[
11+
{
12+
"provider_id":"ob-bank-name",
13+
"display_name":"Bank Name",
14+
"icon_uri":"https://truelayer-provider-assets.s3.amazonaws.com/global/icon/generic.svg",
15+
"logo_uri":"https://truelayer-provider-assets.s3.amazonaws.com/global/logos/generic.svg",
16+
"bg_color":"#000000",
17+
"country_code":"GB"
18+
}
19+
]
20+
}
21+
}
22+
},
23+
"currency": "GBP",
24+
"beneficiary": {
25+
"type": "merchant_account",
26+
"id": "string",
27+
"account_holder_name": "string"
28+
},
29+
"reference": "a-mandate-ref",
30+
"provider_selection":{
31+
"type":"preselected",
32+
"provider_id": "a-provider-id",
33+
"remitter": {
34+
"account_holder_name": "Andrea Di Lisio",
35+
"account_identifier": {
36+
"type":"sort_code_account_number",
37+
"sort_code":"040662",
38+
"account_number":"00002723"
39+
}
40+
}
41+
},
42+
"user": {
43+
"id": "f9b48c9d-176b-46dd-b2da-fe1a2b77350c"
44+
},
45+
"created_at": "2022-01-17T17:13:18.214924Z",
46+
"authorized_at": "2022-01-17T17:13:18.214924Z",
47+
"constraints": {
48+
"valid_from": "2022-01-17T17:13:18.214924Z",
49+
"valid_to": "2023-01-17T17:13:18.214924Z",
50+
"maximum_individual_amount": 1,
51+
"periodic_limits": {
52+
"day": {
53+
"maximum_amount": 0,
54+
"period_alignment": "consent"
55+
},
56+
"week": {
57+
"maximum_amount": 0,
58+
"period_alignment": "consent"
59+
}
60+
}
61+
},
62+
"metadata": {
63+
"a_custom_key": "a-value"
64+
},
65+
"remitter": {
66+
"account_holder_name": "Andrea Di Lisio",
67+
"account_identifier": {
68+
"type":"iban",
69+
"iban":"GB53CLRB04066200002723"
70+
}
71+
}
72+
}

src/test/resources/__files/mandates/200.get_mandate_by_id.authorization_required.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"status": "authorization_required",
33
"id": "string",
4+
"type": "sweeping",
45
"currency": "GBP",
56
"beneficiary": {
67
"type": "merchant_account",

src/test/resources/__files/mandates/200.get_mandate_by_id.authorized.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"status": "authorized",
33
"id": "string",
4+
"type": "sweeping",
45
"authorization_flow":{
56
"actions":{
67
"next":{

src/test/resources/__files/mandates/200.get_mandate_by_id.authorizing.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"status": "authorizing",
33
"id": "string",
4+
"type": "sweeping",
45
"authorization_flow":{
56
"actions":{
67
"next":{

src/test/resources/__files/mandates/200.get_mandate_by_id.failed.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"status": "failed",
33
"id": "string",
4+
"type": "sweeping",
45
"failure_stage": "authorization_required",
56
"failure_reason": "a failure reason",
67
"currency": "GBP",

src/test/resources/__files/mandates/200.get_mandate_by_id.revoked.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"status": "revoked",
33
"id": "string",
4+
"type": "sweeping",
45
"revocation_source": "a revocation source",
56
"currency": "GBP",
67
"beneficiary": {

src/test/resources/__files/mandates/200.list_mandates.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{
44
"status": "authorization_required",
55
"id": "da91c0d2-4436-48f9-82f8-***",
6+
"type": "sweeping",
67
"currency": "GBP",
78
"beneficiary": {
89
"type": "external_account",
@@ -38,6 +39,7 @@
3839
{
3940
"status": "authorizing",
4041
"id": "4d528370-292a-4baf-a2fd-***",
42+
"type": "sweeping",
4143
"currency": "GBP",
4244
"beneficiary": {
4345
"type": "external_account",
@@ -70,6 +72,42 @@
7072
{
7173
"status": "authorization_required",
7274
"id": "6aeb626f-c80d-4538-9600-46352d8c7d84",
75+
"type": "sweeping",
76+
"currency": "GBP",
77+
"beneficiary": {
78+
"type": "external_account",
79+
"account_identifier": {
80+
"type": "sort_code_account_number",
81+
"sort_code": "140662",
82+
"account_number": "10003957"
83+
},
84+
"account_holder_name": "Andrea Java SDK"
85+
},
86+
"user": {
87+
"id": "8842dc0b-7ef1-478f-865a-fe48b6dbcf9b"
88+
},
89+
"created_at": "2022-04-13T16:17:29.332221Z",
90+
"constraints": {
91+
"valid_from": "2022-01-01T00:00:00Z",
92+
"valid_to": "2022-12-31T23:59:59Z",
93+
"maximum_individual_amount": 1000,
94+
"periodic_limits": {
95+
"day": {
96+
"maximum_amount": 0,
97+
"period_alignment": "consent"
98+
},
99+
"week": {
100+
"maximum_amount": 0,
101+
"period_alignment": "consent"
102+
}
103+
}
104+
}
105+
},
106+
{
107+
"status": "authorization_required",
108+
"id": "6aeb626f-c80d-4538-9600-46352d8c7d84",
109+
"type": "commercial",
110+
"use_case": "utilities",
73111
"currency": "GBP",
74112
"beneficiary": {
75113
"type": "external_account",

0 commit comments

Comments
 (0)