Skip to content

Commit ccd7829

Browse files
Types fix
1 parent 9a64bda commit ccd7829

6 files changed

Lines changed: 57 additions & 17 deletions

File tree

‎src/main/java/com/checkout/payments/ProcessingSettings.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public final class ProcessingSettings {
3737
* The total amount of sales tax on the total purchase amount.
3838
* [Optional]
3939
*/
40-
private Long taxAmount;
40+
private Double taxAmount;
4141

4242
/**
4343
* The surcharge amount applied to the transaction in minor currency units by the merchant.
@@ -49,25 +49,25 @@ public final class ProcessingSettings {
4949
* The discount amount applied to the transaction by the merchant.
5050
* [Optional]
5151
*/
52-
private Long discountAmount;
52+
private Double discountAmount;
5353

5454
/**
5555
* The total charges for any import or export duty included in the transaction.
5656
* [Optional]
5757
*/
58-
private Long dutyAmount;
58+
private Double dutyAmount;
5959

6060
/**
6161
* The total freight or shipping and handling charges for the transaction.
6262
* [Optional]
6363
*/
64-
private Long shippingAmount;
64+
private Double shippingAmount;
6565

6666
/**
6767
* The tax amount on the freight or shipping and handling charges for the transaction.
6868
* [Optional]
6969
*/
70-
private Long shippingTaxAmount;
70+
private Double shippingTaxAmount;
7171

7272
/**
7373
* Indicates if the payment is an Account Funding Transaction (AFT).
@@ -111,7 +111,7 @@ public final class ProcessingSettings {
111111
* The original order amount when a payment is split. Indicates the full order price.
112112
* [Optional]
113113
*/
114-
private Long originalOrderAmount;
114+
private Double originalOrderAmount;
115115

116116
/**
117117
* Merchant receipt ID.

‎src/main/java/com/checkout/payments/contexts/PaymentContextsProcessing.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ public final class PaymentContextsProcessing {
3131
* The discount amount the merchant applied to the transaction.
3232
* [Optional]
3333
*/
34-
private Integer discountAmount;
34+
private Double discountAmount;
3535

3636
/**
3737
* The total freight or shipping and handling charges for the transaction.
3838
* [Optional]
3939
*/
40-
private Integer shippingAmount;
40+
private Double shippingAmount;
4141

4242
/**
4343
* The total tax amount for the transaction, in the minor currency unit.
4444
* [Optional]
4545
*/
46-
private Integer taxAmount;
46+
private Double taxAmount;
4747

4848
/**
4949
* Invoice ID number.

‎src/main/java/com/checkout/payments/response/ProcessingData.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public final class ProcessingData {
4848
* Total tax amount of the order.
4949
* [Optional]
5050
*/
51-
private Long taxAmount;
51+
private Double taxAmount;
5252

5353
/**
5454
* The country where the purchase was made. ISO 3166-1 alpha-2 country code.

‎src/test/java/com/checkout/payments/CaptureTestIT.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,17 @@ private ProductRequest createProductRequest() {
168168
private ProcessingSettings createProcessingSettings() {
169169
return ProcessingSettings.builder()
170170
.orderId("123456789")
171-
.taxAmount(3000L)
172-
.discountAmount(0L)
173-
.dutyAmount(0L)
174-
.shippingAmount(300L)
175-
.shippingTaxAmount(100L)
171+
.taxAmount(3000d)
172+
.discountAmount(0d)
173+
.dutyAmount(0d)
174+
.shippingAmount(300d)
175+
.shippingTaxAmount(100d)
176176
.aft(true)
177177
.preferredScheme(PreferredSchema.MASTERCARD)
178178
.merchantInitiatedReason(MerchantInitiatedReason.DELAYED_CHARGE)
179179
.productType(ProductType.QR_CODE)
180180
.openId("oUpF8uMuAJO_M2pxb1Q9zNjWeS6o")
181-
.originalOrderAmount(10L)
181+
.originalOrderAmount(10d)
182182
.receiptId("10")
183183
.terminalType(TerminalType.WAP)
184184
.osType(OsType.ANDROID)

‎src/test/java/com/checkout/payments/RequestApmPaymentsIT.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ private PaymentRequest createTamaraPaymentRequest() {
658658
.successUrl("https://testing.checkout.com/success")
659659
.failureUrl("https://testing.checkout.com/failure")
660660
.reference("ORD-5023-4E89")
661-
.processing(ProcessingSettings.builder().taxAmount(500L).shippingAmount(1000L).build())
661+
.processing(ProcessingSettings.builder().taxAmount(500d).shippingAmount(1000d).build())
662662
.processingChannelId("pc_zs5fqhybzc2e3jmq3efvybybpq")
663663
.customer(createTamaraCustomer())
664664
.items(Collections.singletonList(createTamaraProduct()))

‎src/test/java/com/checkout/serialization/CustomDeserializerPolicyTest.java‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import com.checkout.payments.PaymentAction;
99
import com.checkout.payments.Passenger;
1010
import com.checkout.payments.AirlineData;
11+
import com.checkout.payments.ProcessingSettings;
1112
import com.checkout.payments.ProductResponse;
13+
import com.checkout.payments.response.ProcessingData;
1214
import com.google.gson.reflect.TypeToken;
1315
import org.junit.jupiter.api.Test;
1416

@@ -34,6 +36,44 @@ class CustomDeserializerPolicyTest {
3436
* getProductDeserializer matches JSON keys against @SerializedName, the exact field name, OR the
3537
* naming-policy translation. This verifies snake_case keys map to annotation-less camelCase fields.
3638
*/
39+
// The swagger types tax_amount, discount_amount, shipping_amount, shipping_tax_amount,
40+
// duty_amount and original_order_amount as `number`, not `integer`, and the live API honours
41+
// that: POST /payments with "tax_amount": 10.5 returns 201 and GET /payments/{id} echoes 10.5
42+
// back. While these fields were Long, Gson threw
43+
// JsonSyntaxException: NumberFormatException: Expected a long but was 10.5 on that response,
44+
// so the whole payment failed to deserialize. Keep them Double.
45+
@Test
46+
void processingAcceptsFractionalAmounts() {
47+
final String json = "{\"tax_amount\":10.5,\"discount_amount\":0.25,"
48+
+ "\"shipping_amount\":3.75,\"shipping_tax_amount\":1.5,"
49+
+ "\"duty_amount\":2.05,\"original_order_amount\":99.99}";
50+
51+
final ProcessingSettings settings = serializer.fromJson(json, ProcessingSettings.class);
52+
53+
assertEquals(10.5d, settings.getTaxAmount());
54+
assertEquals(0.25d, settings.getDiscountAmount());
55+
assertEquals(3.75d, settings.getShippingAmount());
56+
assertEquals(1.5d, settings.getShippingTaxAmount());
57+
assertEquals(2.05d, settings.getDutyAmount());
58+
assertEquals(99.99d, settings.getOriginalOrderAmount());
59+
}
60+
61+
@Test
62+
void processingDataAcceptsFractionalTaxAmount() {
63+
final ProcessingData data =
64+
serializer.fromJson("{\"tax_amount\":10.5}", ProcessingData.class);
65+
66+
assertEquals(10.5d, data.getTaxAmount());
67+
}
68+
69+
@Test
70+
void processingStillAcceptsWholeAmounts() {
71+
final ProcessingSettings settings =
72+
serializer.fromJson("{\"tax_amount\":3000}", ProcessingSettings.class);
73+
74+
assertEquals(3000d, settings.getTaxAmount());
75+
}
76+
3777
@Test
3878
void productDeserializer_honorsNamingPolicyWithoutSerializedName() {
3979
final String json = "{"

0 commit comments

Comments
 (0)