@@ -23,7 +23,7 @@ Add this dependency to your project's POM:
23
23
<dependency >
24
24
<groupId >com.postfinancecheckout</groupId >
25
25
<artifactId >postfinancecheckout-java-sdk</artifactId >
26
- <version >2.0.11 </version >
26
+ <version >2.1.0 </version >
27
27
<scope >compile</scope >
28
28
</dependency >
29
29
```
@@ -33,7 +33,7 @@ Add this dependency to your project's POM:
33
33
Add this dependency to your project's build file:
34
34
35
35
``` groovy
36
- compile "com.postfinancecheckout:postfinancecheckout-java-sdk:2.0.11 "
36
+ compile "com.postfinancecheckout:postfinancecheckout-java-sdk:2.1.0 "
37
37
```
38
38
39
39
### Others
@@ -46,7 +46,7 @@ mvn clean package
46
46
47
47
Then manually install the following JARs:
48
48
49
- * ` target/postfinancecheckout-java-sdk-2.0.11 .jar `
49
+ * ` target/postfinancecheckout-java-sdk-2.1.0 .jar `
50
50
* ` target/lib/*.jar `
51
51
52
52
## Usage
@@ -81,132 +81,104 @@ public class Example {
81
81
To get started with sending transactions, please review the example below:
82
82
83
83
``` java
84
- package com.postfinancecheckout.sdk.example ;
84
+ package com.postfinancecheckout.sdk.test ;
85
85
86
86
import com.postfinancecheckout.sdk.ApiClient ;
87
- import com.postfinancecheckout.sdk.ApiException ;
88
- import com.postfinancecheckout.sdk.ApiResponse ;
89
- import com.postfinancecheckout.sdk.service.TransactionPaymentPageService ;
90
- import com.postfinancecheckout.sdk.service.TransactionService ;
91
87
import com.postfinancecheckout.sdk.model.* ;
88
+ import com.postfinancecheckout.sdk.service.* ;
89
+
92
90
import org.junit.Assert ;
93
91
import org.junit.Before ;
94
92
import org.junit.Test ;
95
93
96
94
import java.math.BigDecimal ;
97
- import java.time.LocalDate ;
98
- import java.util.Arrays ;
99
- import java.util.UUID ;
100
95
96
+ /**
97
+ * API tests for TransactionPaymentPageService
98
+ */
101
99
public class TransactionPaymentPageServiceTest {
102
- private TransactionService transactionService;
103
- private TransactionCreate transactionCreate;
104
- private Long spaceId;
105
- private Long applicationUserId;
106
- private String authenticationKey;
100
+
101
+ // Credentials
102
+ private Long spaceId = (long ) 405 ;
103
+ private Long applicationUserId = (long ) 512 ;
104
+ private String authenticationKey = " FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=" ;
105
+
106
+ // Services
107
107
private ApiClient apiClient;
108
- private ApiResponse<Transaction > transaction;
108
+ private TransactionPaymentPageService transactionPaymentPageService;
109
+ private TransactionService transactionService;
110
+
111
+ // Models
112
+ private TransactionCreate transactionPayload;
109
113
110
114
@Before
111
115
public void setup () {
112
- this . applicationUserId = (long ) 512 ;
113
- this . spaceId = (long ) 405 ;
114
- this . authenticationKey = " FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=" ;
115
- this . apiClient = new ApiClient (applicationUserId, authenticationKey);
116
- this . transactionService = new TransactionService (this . apiClient);
117
- this . createTransaction();
116
+ if (this . apiClient == null ) {
117
+ this . apiClient = new ApiClient (applicationUserId, authenticationKey);
118
+ }
119
+ if (this . transactionPaymentPageService == null ) {
120
+ this . transactionPaymentPageService = new TransactionPaymentPageService (this . apiClient);
121
+ }
122
+ if (this . transactionService == null ) {
123
+ this . transactionService = new TransactionService (this . apiClient);
124
+ }
118
125
}
119
126
120
- private void createTransaction () {
121
-
122
- AddressCreate billingAddress = new AddressCreate ()
123
- .salutation(" Ms" )
124
- .givenName(" Good" )
125
- .familyName(" Customer" )
126
- .gender(Gender . FEMALE )
127
- .country(" CH" )
128
- .city(" Winterthur" )
129
- .postcode(" 8400" )
130
- .dateOfBirth(LocalDate . of(1991 , 1 , 11 ))
131
- .organizationName(" Test GmbH" )
132
- .mobilePhoneNumber(" +41791234567" )
133
- .emailAddress(
" [email protected] " );
134
-
135
- AddressCreate shippingAddress = new AddressCreate ()
136
- .salutation(" Ms" )
137
- .givenName(" Good" )
138
- .familyName(" Customer" )
139
- .gender(Gender . FEMALE )
140
- .country(" CH" )
141
- .city(" Winterthur" )
142
- .postcode(" 8400" )
143
- .dateOfBirth(LocalDate . of(1991 , 1 , 11 ))
144
- .organizationName(" Test GmbH" )
145
- .mobilePhoneNumber(" +41791234567" )
146
- .emailAddress(
" [email protected] " );
147
-
148
- LineItemCreate lineItem1 = new LineItemCreate ()
149
- .sku(" item-1" )
150
- .name(" Item 1" )
151
- .uniqueId(" unique-id-item-1" )
152
- .type(LineItemType . PRODUCT )
153
- .quantity(BigDecimal . ONE )
154
- .shippingRequired(true )
155
- .amountIncludingTax(new BigDecimal (" 67.47" ))
156
- .addTaxesItem(
157
- new TaxCreate (). title(" VAT" ). rate(new BigDecimal (8 ))
158
- );
159
-
160
- LineItemCreate lineItem2 = new LineItemCreate ()
161
- .sku(" test-shipping" )
162
- .name(" Shipping" )
163
- .uniqueId(" unique-id-test-shipping" )
164
- .type(LineItemType . SHIPPING )
165
- .quantity(BigDecimal . ONE )
166
- .amountIncludingTax(new BigDecimal (" 3.12" ))
167
- .addTaxesItem(
168
- new TaxCreate (). title(" VAT" ). rate(new BigDecimal (8 ))
169
- );
170
-
171
- this . transactionCreate = new TransactionCreate ();
172
- this . transactionCreate
. customerEmailAddress(
" [email protected] " );
173
- this . transactionCreate. customerId(" cutomer-x" );
174
- this . transactionCreate. merchantReference(UUID . randomUUID(). toString());
175
- this . transactionCreate. invoiceMerchantReference(" order-1" );
176
- this . transactionCreate. successUrl(" http://localhost/success?orderId=1" );
177
- this . transactionCreate. failedUrl(" http://localhost/failed?orderId=1" );
178
- this . transactionCreate. shippingMethod(" Test Shipping" );
179
- this . transactionCreate. chargeRetryEnabled(false );
180
- this . transactionCreate. allowedPaymentMethodConfigurations(Arrays . asList(8656l ));
181
- this . transactionCreate. language(" en-US" );
182
- this . transactionCreate. currency(" CHF" );
183
- this . transactionCreate. billingAddress(billingAddress);
184
- this . transactionCreate. shippingAddress(shippingAddress);
185
- this . transactionCreate. addLineItemsItem(lineItem1);
186
- this . transactionCreate. addLineItemsItem(lineItem2);
187
- try {
188
- this . transaction = this . transactionService. createWithHttpInfo(
189
- this . spaceId,
190
- this . transactionCreate
191
- );
192
- } catch (ApiException e) {
193
- Assert . fail(" Failed to create transaction. Reason: " + e. getMessage() + " Details: " + e. getResponseBody());
127
+ /**
128
+ * Get transaction payload
129
+ *
130
+ * @return TransactionCreate
131
+ */
132
+ private TransactionCreate getTransactionPayload () {
133
+ if (this . transactionPayload == null ) {
134
+ // Line item
135
+ LineItemCreate lineItem = new LineItemCreate ();
136
+ lineItem. name(" Red T-Shirt" )
137
+ .uniqueId(" 5412" )
138
+ .type(LineItemType . PRODUCT )
139
+ .quantity(BigDecimal . valueOf(1 ))
140
+ .amountIncludingTax(BigDecimal . valueOf(29.95 ))
141
+ .sku(" red-t-shirt-123" );
142
+
143
+ // Customer Billind Address
144
+ AddressCreate billingAddress = new AddressCreate ();
145
+ billingAddress. city(" Winterthur" )
146
+ .country(" CH" )
147
+ .emailAddress(
" [email protected] " )
148
+ .familyName(" Customer" )
149
+ .givenName(" Good" )
150
+ .postcode(" 8400" )
151
+ .postalState(" ZH" )
152
+ .organizationName(" Test GmbH" )
153
+ .mobilePhoneNumber(" +41791234567" )
154
+ .salutation(" Ms" );
155
+
156
+ this . transactionPayload = new TransactionCreate ();
157
+ this . transactionPayload. autoConfirmationEnabled(true ). currency(" CHF" ). language(" en-US" );
158
+ this . transactionPayload. setBillingAddress(billingAddress);
159
+ this . transactionPayload. setShippingAddress(billingAddress);
160
+ this . transactionPayload. addLineItemsItem(lineItem);
194
161
}
162
+ return this . transactionPayload;
195
163
}
196
164
165
+ /**
166
+ * Build Payment Page URL
167
+ *
168
+ * This operation creates the URL to which the user should be redirected to when the payment page should be used.
169
+ *
170
+ */
197
171
@Test
198
- public void testPaymentPageUrl () {
199
-
200
- TransactionPaymentPageService transactionPaymentPageService = new TransactionPaymentPageService (this . apiClient);
201
- String paymentPageUrl = null ;
172
+ public void paymentPageUrlTest () {
202
173
try {
203
- paymentPageUrl = transactionPaymentPageService. paymentPageUrl(this . spaceId, this . transaction. getData(). getId());
204
- } catch (ApiException e) {
174
+ Transaction transaction = this . transactionService. create(this . spaceId, this . getTransactionPayload());
175
+ String paymentPageUrl = this . transactionPaymentPageService. paymentPageUrl(spaceId, transaction. getId());
176
+ Assert . assertTrue(paymentPageUrl. contains(" https://" ));
177
+ } catch (Exception e) {
205
178
e. printStackTrace();
206
179
}
207
- System . out. println(paymentPageUrl);
208
- Assert . assertTrue(paymentPageUrl. contains(" http" ));
209
180
}
181
+
210
182
}
211
183
212
184
```
0 commit comments