@@ -50,7 +50,7 @@ private TransactionCreate getTransactionPayload() {
50
50
.amountIncludingTax (BigDecimal .valueOf (29.95 ))
51
51
.sku ("red-t-shirt-123" );
52
52
53
- // Customer Billind Address
53
+ // Customer Billing Address
54
54
AddressCreate billingAddress = new AddressCreate ();
55
55
billingAddress .city ("Winterthur" )
56
56
.country ("CH" )
@@ -150,64 +150,42 @@ public void readTest() {
150
150
* This operation creates and executes a refund of a particular transaction.
151
151
*/
152
152
@ Test
153
- public void refundTest () {
154
- try {
155
- Transaction transaction = this .apiClient .getTransactionService ().create (this .spaceId , this .getTransactionPayload ());
156
- // wait for transaction to be authorized
157
- for (int i = 1 ; i <= 5 ; i ++) {
158
- if (transaction .getState () == TransactionState .AUTHORIZED ) {
159
- break ;
160
- }
161
- System .out .println ("Waiting for transaction for be authorized --- transaction current state: " + transaction .getState ());
162
-
163
- try {
164
- Thread .sleep (i * 15000 );
165
- } catch (InterruptedException e ) {
166
- System .err .println (e .getMessage ());
167
- }
168
- transaction = this .apiClient .getTransactionService ().read (this .spaceId , transaction .getId ());
169
- }
170
- if (transaction .getState () == TransactionState .AUTHORIZED ) {
171
- transaction = this .apiClient .getTransactionService ().processWithoutUserInteraction (this .spaceId , transaction .getId ());
172
- for (int i = 1 ; i <= 5 ; i ++) {
173
- if (
174
- transaction .getState () == TransactionState .FULFILL ||
175
- transaction .getState () == TransactionState .FAILED
176
- ) {
177
- break ;
178
- }
179
-
180
- try {
181
- Thread .sleep (i * 15000 );
182
- } catch (InterruptedException e ) {
183
- System .err .println (e .getMessage ());
184
- }
185
- transaction = this .apiClient .getTransactionService ().read (this .spaceId , transaction .getId ());
186
- }
187
-
188
- if (transaction .getState () == TransactionState .FULFILL ) {
189
- TransactionCompletion transactionCompletion = this .apiClient .getTransactionCompletionService ().completeOffline (this .spaceId , transaction .getId ());
190
- Assert .assertEquals (
191
- "Transaction completion successful" ,
192
- transactionCompletion .getState (),
193
- TransactionCompletionState .SUCCESSFUL
194
- );
195
-
196
- transaction = this .apiClient .getTransactionService ().read (transaction .getLinkedSpaceId (), transactionCompletion .getLinkedTransaction ());
197
- Refund refund = this .apiClient .getRefundService ().refund (this .spaceId , getRefundPayload (transaction ));
198
-
199
- Assert .assertEquals (
200
- "Refund successful" ,
201
- refund .getState (),
202
- RefundState .SUCCESSFUL
203
- );
204
- }
205
- } else {
206
- Assert .assertTrue (transaction .getState () != TransactionState .AUTHORIZED );
153
+ public void refundTest () throws Exception {
154
+ Transaction transaction = this .apiClient .getTransactionService ().create (this .spaceId , this .getTransactionPayload ());
155
+ transaction = this .apiClient .getTransactionService ().processWithoutUserInteraction (spaceId , transaction .getId ());
156
+ // wait for transaction to be authorized
157
+ for (int i = 1 ; i <= 10 ; i ++) {
158
+ if (
159
+ transaction .getState () == TransactionState .FULFILL ||
160
+ transaction .getState () == TransactionState .FAILED
161
+ ) {
162
+ break ;
207
163
}
208
- } catch (Exception e ) {
209
- e .printStackTrace ();
210
- }
164
+
165
+ try {
166
+ Thread .sleep (i * 500 );
167
+ } catch (InterruptedException e ) {
168
+ System .err .println (e .getMessage ());
169
+ }
170
+ transaction = this .apiClient .getTransactionService ().read (this .spaceId , transaction .getId ());
171
+ }
172
+ Assert .assertEquals (TransactionState .FULFILL , transaction .getState ());
173
+
174
+ TransactionCompletion transactionCompletion = this .apiClient .getTransactionCompletionService ().completeOffline (this .spaceId , transaction .getId ());
175
+ Assert .assertEquals (
176
+ "Transaction completion successful" ,
177
+ transactionCompletion .getState (),
178
+ TransactionCompletionState .SUCCESSFUL
179
+ );
180
+
181
+ transaction = this .apiClient .getTransactionService ().read (transaction .getLinkedSpaceId (), transactionCompletion .getLinkedTransaction ());
182
+ Refund refund = this .apiClient .getRefundService ().refund (this .spaceId , getRefundPayload (transaction ));
183
+
184
+ Assert .assertEquals (
185
+ "Refund successful" ,
186
+ refund .getState (),
187
+ RefundState .SUCCESSFUL
188
+ );
211
189
}
212
190
213
191
/**
0 commit comments