Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal Bulk Payout API

Tags:

php

paypal

I am trying to figure out the best workflow for Paypal bulk payout:

I have everything working i.e. I can send bulk payouts and read and store responses.

I have a PaypalService class that interacts with Paypals API.

// ...

use myApp\Contracts\Payment;

class PaypalService implements Payment
{
   public function sendBatchPayout(...)
   {
     ...
   }

  public function getPayoutDetails($payout_batch_id)
  {
   ...
  }
}

// .. etc

I want to know what the ideal process is to handle bulk payouts.

for eg:

  1. 3 recipients need to get X amount

  2. I do this with:

    create batch payout.

  3. This returns a response with the 'payout_batch_id' , and this is asynchronous.

  4. Do I make a call to get payout batch details immidiately after to get the status? or is there a waiting period?

  5. What part of the response am I to store in my Storage/DB, I create a record for each recipient of the bulk payout, should I assign 'payout_batch_id' to each of these records

  6. no.5 is important since the next time I wish to send a payout I want to deduct the amount of previous successful payouts from the current payout amount.

Please help. Thank you.

like image 942
Angad Dubey Avatar asked Jan 21 '26 08:01

Angad Dubey


1 Answers

Do I make a call to get payout batch details immidiately after to get the status? or is there a waiting period?

You can periodically check the status but ideally I would use Webhooks so you are notified when a batch / item is completed instead of polling. Then in case you miss the event notification (your server is down), either re-list the notification via /v1/notifications/webhooks-events or periodically poll if its been over a certain time limit since you last received an update (maybe 5/10/15/30/45 days).

What part of the response am I to store in my Storage/DB, I create a record for each recipient of the bulk payout, should I assign 'payout_batch_id' to each of these records

I recommend always using a sender_batch_id this way in case you do not get a response from PayPal you will resend the same sender_batch_id and if it did go through, you will get the same response back (Prevent duplicate payout). This should be stored as well as the resulting payout_batch_id. To distinguish each item in the batch store the payout_item_id. You can get the status based on either the payout_batch_id or the payout_item_id.

no.5 is important since the next time I wish to send a payout I want to deduct the amount of previous successful payouts from the current payout amount.

If you already sent the payout and it is pending (or any other indeterminate status) you should not issue another payout for the amount. Assume the money is sent successfully from the point right before you send the request to PayPal, then only assume it failed if you get a concrete failure scenario, otherwise you are likely still liable.

Hopefully this helps

like image 108
curlyhairedgenius Avatar answered Jan 23 '26 22:01

curlyhairedgenius