Paypal REST API Webhooks integration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm interested in using webhooks to verify payments & save instances to my database. Currently I'm using the REST API to process credit cards and direct payments, and then using redirects & PHP sessions to verify user activity, but some payment instances are not being successfully saved. I've setup a webhook for my app inside developer.paypal.com, but only successful payments via the paypal login option are recieved in my webhook listener script and not direct credit card transactions or cancelled payments. Ideally I'd like to pass unique id's that refer to that database instance so erranious entries can be deleted. Basically I can't wrap my head around where in the full script the webhook instance goes so the webhook url can look like this:
https://www.mysite.com/webhooklistener.php?=uniqid....
But thats only possible through the php script.
Currently the php flow goes like this:
Javascript accepts / constructs the JSON objects & sends ajax request to payment_script.php;
payment_script.php constructs the paypal object using your PHP SDK and calls API;
If payment is made via credit card then your JSON object is returned & parsed, calls save_payment_to_database.php;
If payment is made via paypal direct then paypal_redirect.php & save_payment_to_database.php is called.
The webhook script looks like this currently:
<?php
// Paypal login
require __DIR__.'/bootstrap.php';
// Define return url
$webhook = new \Paypal\Api\Webhook();
$webhook->setUrl("https://dragaudsojourns.com/sql_webhook.php?=" . uniqid());
// Set webhooks to subscribe to
$webhookEventTypes = array();
$webhookEventTypes[] = new \PayPal\Api\WebhookEventType(
'{
"name":"PAYMENT.SALE.COMPLETED"
}'
);
$webhookEventTypes[] = new \PayPal\Api\WebhookEventType(
'{
"name":"PAYMENT.SALE.DENIED"
}'
);
$webhook->setEventTypes($webhookEventTypes);
// Create webhook
try {
$output = $webhook->create($apiContext);
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode();
echo $ex->getData();
die($ex);
} catch (Exception $ex) {
die($ex);
}
return $output;
?>
In which file / what point in the interaction is this script called? Do I need to pass the $transaction object along with the $apiContext?
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Paypal 4X credit : translated message & currency error in PayPal Payments Standard
- Need help to integrate PayPal Standard Checkout with Shopify in PayPal Payments Standard
- Error: "Unable to change shipping method. Please try again." in PayPal popup in REST APIs
- Question about the ButtonSource field when converting an integration from SOAP/NVP to REST API v1. in REST APIs
- Simple Paypal button integration results in 404 error in Sandbox Environment