public PayoutBatch createBatchPayout(HttpServletRequest req, HttpServletResponse resp) { // ###Payout // A resource representing a payout // This is how our body should look like: /* * { "sender_batch_header": { "sender_batch_id": "random_uniq_id", * "email_subject": "You have a payment" }, "items": [ { * "recipient_type": "EMAIL", "amount": { "value": 0.99, "currency": * "USD" }, "receiver": "*****@*****.**", "note": * "Thank you.", "sender_item_id": "item_1" }, { "recipient_type": * "EMAIL", "amount": { "value": 0.90, "currency": "USD" }, "receiver": * "*****@*****.**", "note": "Thank you.", * "sender_item_id": "item_2" }, { "recipient_type": "EMAIL", "amount": * { "value": 2.00, "currency": "USD" }, "receiver": * "*****@*****.**", "note": "Thank you.", * "sender_item_id": "item_3" } ] } */ Payout payout = new Payout(); PayoutSenderBatchHeader senderBatchHeader = new PayoutSenderBatchHeader(); // ### NOTE: // You can prevent duplicate batches from being processed. If you // specify a `sender_batch_id` that was used in the last 30 days, the // batch will not be processed. For items, you can specify a // `sender_item_id`. If the value for the `sender_item_id` is a // duplicate of a payout item that was processed in the last 30 days, // the item will not be processed. // #### Batch Header Instance Random random = new Random(); senderBatchHeader .setSenderBatchId(new Double(random.nextDouble()).toString()) .setEmailSubject("You have a Payment!"); // ### Currency Currency amount1 = new Currency(); amount1.setValue("1.00").setCurrency("USD"); // ### Currency Currency amount2 = new Currency(); amount2.setValue("2.00").setCurrency("USD"); // ### Currency Currency amount3 = new Currency(); amount3.setValue("4.00").setCurrency("USD"); // #### Sender Item 1 // Please note that if you are using single payout with sync mode, you // can only pass one Item in the request PayoutItem senderItem1 = new PayoutItem(); senderItem1 .setRecipientType("Email") .setNote("Thanks for your patronage") .setReceiver("*****@*****.**") .setSenderItemId("201404324234") .setAmount(amount1); // #### Sender Item 1 // Please note that if you are using single payout with sync mode, you // can only pass one Item in the request PayoutItem senderItem2 = new PayoutItem(); senderItem2 .setRecipientType("Email") .setNote("Thanks for your patronage") .setReceiver("*****@*****.**") .setSenderItemId("201404324235") .setAmount(amount2); // #### Sender Item 1 // Please note that if you are using single payout with sync mode, you // can only pass one Item in the request PayoutItem senderItem3 = new PayoutItem(); senderItem3 .setRecipientType("Email") .setNote("Thanks for your patronage") .setReceiver("*****@*****.**") .setSenderItemId("201404324236") .setAmount(amount3); List<PayoutItem> items = new ArrayList<PayoutItem>(); items.add(senderItem1); items.add(senderItem2); items.add(senderItem3); payout.setSenderBatchHeader(senderBatchHeader).setItems(items); PayoutBatch batch = null; try { // ### Api Context // Pass in a `ApiContext` object to authenticate // the call and to send a unique request id // (that ensures idempotency). The SDK generates // a request id if you do not pass one explicitly. APIContext apiContext = new APIContext(clientID, clientSecret, mode); // ###Create Batch Payout batch = payout.create(apiContext, new HashMap<String, String>()); LOGGER.info("Payout Batch With ID: " + batch.getBatchHeader().getPayoutBatchId()); ResultPrinter.addResult( req, resp, "Payout Batch Create", Payout.getLastRequest(), Payout.getLastResponse(), null); } catch (PayPalRESTException e) { ResultPrinter.addResult( req, resp, "Payout Batch Create", Payout.getLastRequest(), null, e.getMessage()); } return batch; }