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 : (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.


public ResponseEntity payment(@RequestBody PaymentDTO payment) {
for (int i = 0; i < payment.getAccount().size(); i++) {
Money amountMoney = new Money.Builder()

  CreatePaymentRequest body = new CreatePaymentRequest.Builder(
    "XXXXXXXX", //Space for token
    .note("Brief description")

    .thenAccept(result -> {
    .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”: [
“amount”: [

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: