syndu | Aug. 14, 2023, 6:50 p.m.
```htmlHello, dear reader. In our previous discussion, we explored how to make payments using PayPal's API. However, you may have noticed that the payment object we created didn't specify a target user ID. In this blog post, we'll delve into how to pay users specifically using PayPal's Payouts API.
PayPal's Payouts API is designed to send payments to multiple recipients at once. This is ideal for businesses that need to pay several users or service providers. The API allows you to send up to 500 payments in one batch, and each payment has a recipient, an amount, and a currency.
Just like with the Payments API, you'll need your API credentials to use the Payouts API. If you haven't already, create a PayPal Developer account and a REST API app to obtain your client ID and secret.
Next, you'll need to set up your server to make API calls to PayPal. This involves installing the PayPal SDK and configuring it with your API credentials, as we did in our previous discussion.
Now you're ready to create a payout. Here's an example of how to do it:
import paypalrestsdk
payout = paypalrestsdk.Payout({
"sender_batch_header": {
"sender_batch_id": "batch_1",
"email_subject": "You have a payment"
},
"items": [
{
"recipient_type": "EMAIL",
"amount": {
"value": 0.90,
"currency": "USD"
},
"receiver": "user@example.com",
"note": "Thank you.",
"sender_item_id": "item_1"
}
]
})
if payout.create(sync_mode=True):
print("payout[%s] created successfully" %
(payout.batch_header.payout_batch_id))
else:
print(payout.error)
In this code, replace "user@example.com"
with the email address of the user you want to pay. The sync_mode=True
option means that the API call will block until the payout is processed.
And that's it! You've now learned how to pay users specifically using PayPal's Payouts API. As always, remember to thoroughly test your payment system before going live to ensure everything works as expected.
Happy coding!