-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPaymentSubMerchantsIntegrationTest.java
More file actions
104 lines (85 loc) · 4.13 KB
/
Copy pathPaymentSubMerchantsIntegrationTest.java
File metadata and controls
104 lines (85 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.truelayer.java.integration;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.truelayer.java.Constants.Scopes.PAYMENTS;
import static com.truelayer.java.TestUtils.assertNotError;
import static org.junit.jupiter.api.Assertions.*;
import com.truelayer.java.TestUtils.RequestStub;
import com.truelayer.java.http.entities.ApiResponse;
import com.truelayer.java.payments.entities.paymentdetail.ExecutedPaymentDetail;
import com.truelayer.java.payments.entities.paymentdetail.PaymentDetail;
import com.truelayer.java.payments.entities.submerchants.BusinessClient;
import com.truelayer.java.payments.entities.submerchants.UltimateCounterparty;
import java.util.Collections;
import lombok.SneakyThrows;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
class PaymentSubMerchantsIntegrationTest extends IntegrationTests {
@Test
@DisplayName("It should deserialize payment response with sub_merchants")
@SneakyThrows
void shouldDeserializePaymentWithSubMerchants() {
String paymentId = "payment-id";
RequestStub.New()
.method("post")
.path(urlPathEqualTo("/connect/token"))
.status(200)
.bodyFile("auth/200.access_token.json")
.build();
RequestStub.New()
.method("get")
.path(urlPathEqualTo(String.format("/payments/%s", paymentId)))
.status(200)
.bodyFile("payments/200.get_payment_by_id.with_submerchants.json")
.build();
ApiResponse<PaymentDetail> response =
tlClient.payments().getPayment(paymentId).get();
verifyGeneratedToken(Collections.singletonList(PAYMENTS));
assertNotError(response);
PaymentDetail result = response.getData();
assertNotNull(result);
assertTrue(result.isExecuted());
ExecutedPaymentDetail executedPayment = result.asExecuted();
assertNotNull(executedPayment.getSubMerchants());
assertNotNull(executedPayment.getSubMerchants().getUltimateCounterparty());
UltimateCounterparty ultimateCounterparty =
executedPayment.getSubMerchants().getUltimateCounterparty();
assertTrue(ultimateCounterparty.isBusinessClient());
BusinessClient businessClient = ultimateCounterparty.asBusinessClient();
assertEquals("client-123", businessClient.getId());
assertEquals("Example Trading Ltd", businessClient.getTradingName());
assertEquals("Example Commercial Name", businessClient.getCommercialName());
assertEquals("https://example.com", businessClient.getUrl());
assertEquals("1234", businessClient.getMcc());
assertEquals("12345678", businessClient.getRegistrationNumber());
assertNotNull(businessClient.getAddress());
assertEquals("London", businessClient.getAddress().getCity());
}
@Test
@DisplayName("It should handle payment response without sub_merchants (backward compatibility)")
@SneakyThrows
void shouldHandlePaymentWithoutSubMerchants() {
String paymentId = "payment-id";
RequestStub.New()
.method("post")
.path(urlPathEqualTo("/connect/token"))
.status(200)
.bodyFile("auth/200.access_token.json")
.build();
RequestStub.New()
.method("get")
.path(urlPathEqualTo(String.format("/payments/%s", paymentId)))
.status(200)
.bodyFile("payments/200.get_payment_by_id.bank_transfer.executed.json")
.build();
ApiResponse<PaymentDetail> response =
tlClient.payments().getPayment(paymentId).get();
verifyGeneratedToken(Collections.singletonList(PAYMENTS));
assertNotError(response);
PaymentDetail result = response.getData();
assertNotNull(result);
assertTrue(result.isExecuted());
ExecutedPaymentDetail executedPayment = result.asExecuted();
// subMerchants should be null for backward compatibility
assertNull(executedPayment.getSubMerchants());
}
}