Search code examples
phplaravelpaypalpaypal-rest-sdk

Laravel Paypal Payout. How to make it complete ? It returns json response


I have created single batch payout using their documentation. so that I can send money to seller.

But I don't know what I should do after it. How can I show a payment form, where user can login in PayPal and pay the amount?

This is my code in controller function

 public function payViaPaypal(){
   
        $payouts = new \PayPal\Api\Payout();
        $senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
        $senderBatchHeader->setSenderBatchId(uniqid('invoice-1qaqw23wdwdwew').microtime('true'))
            ->setEmailSubject("You have a Payout!");

        $senderItem = new \PayPal\Api\PayoutItem();
        $senderItem->setRecipientType('Email')
            ->setNote('Thanks for your patronage!')
            ->setReceiver('sb-cwdzv2614448@business.example.com')
            ->setSenderItemId(uniqid().microtime('true'))
            ->setAmount(new \PayPal\Api\Currency('{
                        "value":"1.0",
                        "currency":"USD"
                    }'));

        $payouts->setSenderBatchHeader($senderBatchHeader)
            ->addItem($senderItem);



        $request = clone $payouts;
        $redirect_url = null;
        try {
            $output = $payouts->create(null, $this->api_context);

        } catch (\Exception $e) {
            dd('here',$this->errorDetails($e));
        }
//        dd("Created Single Synchronous Payout", "Payout", $output->getBatchHeader()->getPayoutBatchId(), $request, $output);
        $redirect_url = null;
        foreach($output->getLinks() as $link) {
            if($link->getRel() == 'self') {
                $redirect_url = $link->getHref();
                break;
            }
        }
        return $output;
}

when I hit route to access this code and I receive this json response.

{ "batch_header": { "payout_batch_id": "79CTFV2X5TS58", "batch_status": "PENDING", "sender_batch_header": { "sender_batch_id": "invoice-1qaqw23wdwdwew5f0f5003612091594839043.3978", "email_subject": "You have a Payout!" } }, "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payouts/79CTFV2X5TS58", "rel": "self", "method": "GET", "enctype": "application/json" } ] }

I am expecting that user will be taken to PayPal payment page where user will login and pay amount after that PayPal will inform me about the payment.

But I have tried to find the solution over internet but no example/solution I can find.


Solution

  • Payouts is for sending money from your account to another account. There is no form to show or log into. You are the API caller, and payments are automatically approved as coming from your account.

    If you want a form for a user to approve paying from their account to some other account, use invoicing: https://developer.paypal.com/docs/invoicing/

    Alternatively, maybe you don't need an invoice form but just a regular PayPal Checkout with a 'payee' recipient set: https://developer.paypal.com/docs/checkout/integration-features/custom-payee/