zwaldeck / mollie

Java framework to consume the Mollie API
Other
39 stars 36 forks source link

Create payment fails with a 422 error when using the Amount class #78

Closed Tomasvdr198 closed 2 years ago

Tomasvdr198 commented 2 years ago

I'm trying to create a payment but it always fails. I'm doing the following to create a payment

Amount amount = new Amount();
amount.setCurrency("EUR");
amount.setValue(new BigDecimal(40.0));

PaymentRequest paymentRequest = new PaymentRequest();
paymentRequest.setAmount(amount);
PaymentResponse payment = client.payments().createPayment(paymentRequest);

I always get the same error no matter what I do. Error response from mollie with status code '422' and body: {"status":422,"title":"Unprocessable Entity","detail":"The amount contains an invalid value","field":"amount.value"

paulvaneijden commented 2 years ago

Correct, amount should contain 2 digits, so 40.00 in your example

Tomasvdr198 commented 2 years ago

this doesn't work, I still get the same error.

zwaldeck commented 2 years ago

@Tomasvdr198

You have 2 possibilities in your code example:

  1. Create your BigDecimal with a String "40.00"
  2. Use the .setScale() method of the BigDecimal class

I suggest you look up some resources how to work/calculate with BigDecimal and try to understand how to set the scale/precision