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 PayPalApiPayout();
$senderBatchHeader = new PayPalApiPayoutSenderBatchHeader();
$senderBatchHeader->setSenderBatchId(uniqid('invoice-1qaqw23wdwdwew').microtime('true'))
->setEmailSubject("You have a Payout!");
$senderItem = new PayPalApiPayoutItem();
$senderItem->setRecipientType('Email')
->setNote('Thanks for your patronage!')
->setReceiver('[email protected]')
->setSenderItemId(uniqid().microtime('true'))
->setAmount(new PayPalApiCurrency('{
"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.
2
Answers
I was using wrong approach.
Solution is to create a payment object and add payee (who will receive payment as seller) email address in it.
There are two functions required.
1 to create payment object 2 to get payment details from paypal using API and then execute this payment so that amount can be transferred to receipeint account.
3 Routes are required for following
Here is full code example
Routes
Controller
You can read this official example as well
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/