Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PayPalTest {
- private static final Logger LOG = LoggerFactory.getLogger(PayPalTest.class);
- private static final String CLIENT_ID = "";
- private static final String SECRET = "";
- private static final String MODE = "sandbox";
- @Test
- public void createPayoutBatchTest() throws PayPalRESTException {
- createPayoutBatch(createPayout());
- }
- @Test
- public void getPayoutItemStatusTest() throws PayPalRESTException {
- final PayoutBatch batch = createPayoutBatch(createPayout());
- String payoutBatchId = batch.getBatchHeader().getPayoutBatchId();
- // ### 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(CLIENT_ID, SECRET, MODE);
- // ###Get Payout Batch Status
- PayoutBatch response = Payout.get(apiContext, payoutBatchId);
- LOG.info("Payout Batch With ID: " + response.getBatchHeader().getPayoutBatchId());
- assertEquals(response.getItems().size(), 3);
- }
- private Payout createPayout() {
- // ###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": "shirt-supplier-one@mail.com", "note":
- * "Thank you.", "sender_item_id": "item_1" }, { "recipient_type":
- * "EMAIL", "amount": { "value": 0.90, "currency": "USD" }, "receiver":
- * "shirt-supplier-two@mail.com", "note": "Thank you.",
- * "sender_item_id": "item_2" }, { "recipient_type": "EMAIL", "amount":
- * { "value": 2.00, "currency": "USD" }, "receiver":
- * "shirt-supplier-three@mail.com", "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(
- Double.toString(random.nextDouble())).setEmailSubject(
- "You have a Payment!");
- Currency amount1 = new Currency();
- amount1.setValue("1.00").setCurrency("USD");
- Currency amount2 = new Currency();
- amount2.setValue("2.00").setCurrency("USD");
- Currency amount3 = new Currency();
- amount3.setValue("4.00").setCurrency("USD");
- PayoutItem senderItem1 = new PayoutItem();
- senderItem1.setRecipientType("Email")
- .setNote("Thanks for your patronage")
- .setReceiver("shirt-supplier-one@gmail.com")
- .setSenderItemId("201404324234").setAmount(amount1);
- PayoutItem senderItem2 = new PayoutItem();
- senderItem2.setRecipientType("Email")
- .setNote("Thanks for your patronage")
- .setReceiver("shirt-supplier-two@gmail.com")
- .setSenderItemId("201404324235").setAmount(amount2);
- PayoutItem senderItem3 = new PayoutItem();
- senderItem3.setRecipientType("Email")
- .setNote("Thanks for your patronage")
- .setReceiver("shirt-supplier-three@gmail.com")
- .setSenderItemId("201404324236").setAmount(amount3);
- List<PayoutItem> items = new ArrayList<>();
- items.add(senderItem1);
- items.add(senderItem2);
- items.add(senderItem3);
- payout.setSenderBatchHeader(senderBatchHeader).setItems(items);
- return payout;
- }
- private PayoutBatch createPayoutBatch(final Payout payout) throws PayPalRESTException {
- // ### 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.
- final APIContext apiContext = new APIContext(CLIENT_ID, SECRET, MODE);
- final PayoutBatch batch = payout.create(apiContext, new HashMap<>());
- LOG.info("Payout Batch ID: " + batch.getBatchHeader().getPayoutBatchId());
- return batch;
- }
- }
Add Comment
Please, Sign In to add comment