Home > Software design >  How to complete pending transactions in paypal payouts
How to complete pending transactions in paypal payouts

Time:11-07

I am trying to implement a single Payout functionality in Paypal. I have referred to the sample code given by Paypal's documentation here. Everything seems to be working in order but the response given by PayPal indicates this: "batch_status": "PENDING". Here is my payout function:

public function payoutWithPaypal()
{
    $request_amount = session()->get('request_amount');
    $transaction_id = session()->get('transaction_id');
    $receiver_email = session()->get('receiver_email');

    $payouts = new \PayPal\Api\Payout();
    $senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
    $senderBatchHeader->setSenderBatchId(uniqid())->setEmailSubject("You have a Payout!");
    $senderItem = new \PayPal\Api\PayoutItem();
    $senderItem->setRecipientType('Email')
                ->setNote('Thanks for your patronage!')
                ->setReceiver($receiver_email)
                ->setSenderItemId("001")
                ->setAmount(new \PayPal\Api\Currency('{
                            "value":"'.$request_amount.'",
                            "currency":"USD"
                        }'));

    $payouts->setSenderBatchHeader($senderBatchHeader)->addItem($senderItem);
    $request = clone $payouts;
    
    try {
        $output = $payouts->create(array('sync_mode' => 'false'), $this->_api_context);

    } catch (\Exception $ex) {
         dd($ex);
    }

    return $output;

}

The solutions provided here have not really solved my issue.

CodePudding user response:

Payouts run in a batch. For a batch status to begin as 'PENDING' is normal. The status of each payout within the batch is what matters. You can query them as needed, and if they are individually pending some reason may be given.

The most common reason for a PayPal payment to be pending in sandbox or live is if there is no PayPal account with a confirmed email (in sandbox or live, respectively) at the address to which the payment was sent. Receivers have 30 days to create an account and/or confirm the email on their account to accept the payment, otherwise it will be automatically refunded after 30 days. Reminders are sent to that email during this period.

  • Related