forked from craftgate/craftgate-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MerchantSample.java
188 lines (159 loc) · 7.41 KB
/
MerchantSample.java
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package io.craftgate.sample;
import io.craftgate.Craftgate;
import io.craftgate.model.*;
import io.craftgate.request.CreateMerchantPosRequest;
import io.craftgate.request.SearchMerchantPosRequest;
import io.craftgate.request.UpdateMerchantPosCommissionsRequest;
import io.craftgate.request.UpdateMerchantPosRequest;
import io.craftgate.request.dto.CreateMerchantPosUser;
import io.craftgate.request.dto.UpdateMerchantPosCommission;
import io.craftgate.request.dto.UpdateMerchantPosUser;
import io.craftgate.response.MerchantPosCommissionListResponse;
import io.craftgate.response.MerchantPosListResponse;
import io.craftgate.response.MerchantPosResponse;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.*;
public class MerchantSample {
private final Craftgate craftgate = new Craftgate("api-key", "secret-key", "https://sandbox-api.craftgate.io");
@Test
void create_merchant_pos() {
CreateMerchantPosUser createMerchantPosUser = CreateMerchantPosUser.builder()
.posOperationType(PosOperationType.STANDARD)
.posUserType(PosUserType.API)
.posUsername("username")
.posPassword("password")
.build();
CreateMerchantPosRequest request = CreateMerchantPosRequest.builder()
.name("my test pos")
.clientId("client id")
.terminalId("terminal id")
.threedsKey("3d secure key")
.status(PosStatus.AUTOPILOT)
.currency(Currency.TRY)
.orderNumber(1)
.enableInstallment(true)
.enableForeignCard(true)
.enablePaymentWithoutCvc(true)
.posIntegrator(PosIntegrator.AKBANK)
.enabledPaymentAuthenticationTypes(Arrays.asList(PaymentAuthenticationType.THREE_DS, PaymentAuthenticationType.NON_THREE_DS))
.merchantPosUsers(Collections.singletonList(createMerchantPosUser))
.build();
MerchantPosResponse response = craftgate.merchant().createMerchantPos(request);
assertNotNull(response.getId());
assertNotNull(response.getHostname());
assertNotNull(response.getAlias());
assertNotNull(response.getPath());
assertNotNull(response.getThreedsPath());
assertEquals(response.getBankName(), "AKBANK T.A.Ş.");
assertEquals(response.getPosIntegrator(), PosIntegrator.AKBANK);
}
@Test
void update_merchant_pos() {
Long merchantPosId = 10L;
UpdateMerchantPosUser merchantPosUser = UpdateMerchantPosUser.builder()
.id(100L)
.posOperationType(PosOperationType.STANDARD)
.posUserType(PosUserType.API)
.posUsername("username")
.posPassword("password")
.build();
UpdateMerchantPosRequest request = UpdateMerchantPosRequest.builder()
.name("my updated test pos")
.hostname("https://www.sanalakpos.com")
.clientId("updated client id")
.mode("P")
.path("/fim/api")
.port(443)
.threedsKey("3d secure key")
.threedsPath("https://www.sanalakpos.com/fim/est3dgate")
.enableForeignCard(true)
.enableInstallment(true)
.enablePaymentWithoutCvc(true)
.newIntegration(false)
.orderNumber(1)
.enabledPaymentAuthenticationTypes(Arrays.asList(PaymentAuthenticationType.THREE_DS, PaymentAuthenticationType.NON_THREE_DS))
.supportedCardAssociations(Arrays.asList(CardAssociation.MASTER_CARD, CardAssociation.VISA))
.merchantPosUsers(Collections.singletonList(merchantPosUser))
.build();
MerchantPosResponse response = craftgate.merchant().updateMerchantPos(merchantPosId, request);
assertNotNull(response.getId());
assertNotNull(response.getHostname());
assertNotNull(response.getAlias());
assertNotNull(response.getPath());
assertNotNull(response.getThreedsPath());
assertEquals(response.getBankName(), "AKBANK T.A.Ş.");
assertEquals(response.getPosIntegrator(), PosIntegrator.AKBANK);
}
@Test
void update_merchant_pos_status() {
Long merchantPosId = 1L;
PosStatus posStatus = PosStatus.PASSIVE;
craftgate.merchant().updateMerchantPosStatus(merchantPosId, posStatus);
}
@Test
void retrieve_merchant_pos() {
Long merchantPosId = 1L;
MerchantPosResponse response = craftgate.merchant().retrieve(merchantPosId);
assertEquals(response.getId(), merchantPosId);
}
@Test
void delete_merchant_pos() {
Long merchantPosId = 1L;
craftgate.merchant().deleteMerchantPos(merchantPosId);
}
@Test
void search_merchant_poses() {
SearchMerchantPosRequest request = SearchMerchantPosRequest.builder()
.currency(Currency.TRY)
.page(0)
.size(10)
.build();
MerchantPosListResponse response = craftgate.merchant().searchMerchantPos(request);
assertEquals(0, response.getPage());
assertEquals(10, response.getSize());
assertFalse(response.getItems().isEmpty());
}
@Test
void retrieve_merchant_pos_commissions() {
Long merchantPosId = 1L;
MerchantPosCommissionListResponse response = craftgate.merchant().retrieveMerchantPosCommissions(merchantPosId);
assertFalse(response.getItems().isEmpty());
}
@Test
void update_merchant_pos_commissions() {
Long merchantPosId = 1L;
UpdateMerchantPosCommission installment1 = UpdateMerchantPosCommission.builder()
.installment(1)
.blockageDay(7)
.status(Status.ACTIVE)
.cardBrandName(CardBrand.AXESS.toName())
.installmentLabel("Single installment")
.bankOnUsDebitCardCommissionRate(BigDecimal.valueOf(1.0))
.bankOnUsCreditCardCommissionRate(BigDecimal.valueOf(1.1))
.bankNotOnUsDebitCardCommissionRate(BigDecimal.valueOf(1.2))
.bankNotOnUsCreditCardCommissionRate(BigDecimal.valueOf(1.3))
.bankForeignCardCommissionRate(BigDecimal.valueOf(1.5))
.build();
UpdateMerchantPosCommission installment2 = UpdateMerchantPosCommission.builder()
.installment(2)
.blockageDay(7)
.status(Status.ACTIVE)
.cardBrandName(CardBrand.AXESS.toName())
.installmentLabel("installment 2")
.bankOnUsCreditCardCommissionRate(BigDecimal.valueOf(2.1))
.merchantCommissionRate(BigDecimal.valueOf(2.3))
.build();
ArrayList<UpdateMerchantPosCommission> commissions = new ArrayList<>();
commissions.add(installment1);
commissions.add(installment2);
UpdateMerchantPosCommissionsRequest request = UpdateMerchantPosCommissionsRequest.builder()
.commissions(commissions)
.build();
MerchantPosCommissionListResponse response = craftgate.merchant().updateMerchantPosCommissions(merchantPosId, request);
assertFalse(response.getItems().isEmpty());
}
}