How to send amount to different different location in Square?

I am connecting Square payment gateway with my springboot application. I am facing some challenges while doing payment.

Scenario: User can select multiple amount and when he proceeds further the amount should go to respective location. For ex: I have 2 unpaid amount $2 and $3 and are belongs to LAXXXXXXX and LBXXXXXXX locations respectively.

From frontend I have followed this documentation : https://developer.squareup.com/docs/web-payments/take-card-payment (I have removed that code from frontend in which it is hitting the server, I have created separate API in springboot to complete the payment)

From frontend I am taking the token to complete the payment but it is again and again going to exception block and I am not able to complete the payment.

BACKEND CODE-

@PostMapping(“/payment”)
public ResponseEntity payment(@RequestBody PaymentDTO payment) {
for (int i = 0; i < payment.getAccount().size(); i++) {
Money amountMoney = new Money.Builder()
.amount(payment.getAmount().get(i).longValue())
.currency(“USD”)
.build();

  CreatePaymentRequest body = new CreatePaymentRequest.Builder(
    "XXXXXXXX", //Space for token
    UUID.randomUUID().toString(),
    amountMoney)
    .autocomplete(true)
    .locationId(payment.getAccount().get(i))
    .note("Brief description")
    .build();

  square.getPaymentsApi().createPaymentAsync(body)
    .thenAccept(result -> {
      System.out.println("Success!");
    })
    .exceptionally(exception -> {
      System.out.println("Failed to make the request");
      System.out.println(String.format("Exception: %s", exception));
      return null;
    });
}
return new ResponseEntity<>(HttpStatus.OK);

}

Payment DTO:
{
“account”: [
“LAXXXXXXXXX”,
“LBXXXXXXXXX”
],
“amount”: [
200,
300
]
}

Currently, payments with our APIs can’t be split between multiple locations. You’ll need to create an individual payment for each location. You can either save the card on file an use the saved card to make a payment for each location or you’d have to have the customer enter their card information twice to generate two source_ids to complete the payments for each location. :slightly_smiling_face: