Parsing/using WebhookEvent data sent to a PHP listener
I'm receiving the JSON data from PayPal's webhook to my end point.
I can of course parse it into a PHP object. Is this the best way to handle this data? I would have thought that the JSON data could be converted back into a new 'WebhookEvent' object and then handled that way?? But either that's not the case or I'm doing something wrong.
use PayPalApiWebhookEvent;
$webhook_json_data = '{"auth_algo": "SHA256withRSA","transmission_id": "d97395d0-de4a06f7","cert_url": "https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-aecacc47","webhook_id": "2V9E918418","transmission_sig": "Svsp/4l67b4sasdq/rjQojgKoOG95rltTuEtpip/UeNxTap7I/ao7Vg7VDJIYPaEzTz1UDNdsmI+/l1dhVfQsEAImg1bz0VpZ+0+JAwUuZpr0EtF7g==","transmission_time": "2018-11-16T03:01:01Z","webhook_event": {"id":"WH-6DT935852K089633W-9X42044474276933K","event_version":"1.0","create_time":"2018-11-16T03:01:01.000Z","resource_type":"payouts","event_type":"PAYMENT.PAYOUTSBATCH.SUCCESS","summary":"Payouts batch completed successfully.","resource":{"batch_header":{"payout_batch_id":"7PHK3S3LKM8D6","batch_status":"SUCCESS","time_created":"2018-11-16T03:00:42Z","time_completed":"2018-11-16T03:01:01Z","sender_batch_header":{"sender_batch_id":"5bee32daa6bd8"},"amount":{"currency":"USD","value":"235.0"},"fees":{"currency":"USD","value":"1.25"},"payments":5},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payouts/7PHM8D6","rel":"self","method":"GET"}]},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-6DT9276933K","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-6DT933K/resend","rel":"resend","method":"POST"}]}}';
$webhook_obj = json_decode ( $webhook_json_data );
$w_event = new PayPalApiWebhookEvent($webhook_json_data);
// this gives PAYMENT.PAYOUTSBATCH.SUCCESS
echo $webhook_obj->webhook_event->event_type ."<br>";
// this yields nothing !! (the $w_event data appears to
// be 'protected' and thus inaccessible)
echo $w_event->event_type ."<br>";
Is the correct way to use the data received on a Webhook notification to just walk through the JSON decoded structure? For example, I want to confirm the total amount of the Payouts payment, which in this case is $235.00
I can retrieve it using:
$webhook_obj->webhook_event->resource->batch_header->amount->value
But it seems like there should be a better way to process these Webhook notifications??
php paypal sdk paypal-webhooks
add a comment |
I'm receiving the JSON data from PayPal's webhook to my end point.
I can of course parse it into a PHP object. Is this the best way to handle this data? I would have thought that the JSON data could be converted back into a new 'WebhookEvent' object and then handled that way?? But either that's not the case or I'm doing something wrong.
use PayPalApiWebhookEvent;
$webhook_json_data = '{"auth_algo": "SHA256withRSA","transmission_id": "d97395d0-de4a06f7","cert_url": "https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-aecacc47","webhook_id": "2V9E918418","transmission_sig": "Svsp/4l67b4sasdq/rjQojgKoOG95rltTuEtpip/UeNxTap7I/ao7Vg7VDJIYPaEzTz1UDNdsmI+/l1dhVfQsEAImg1bz0VpZ+0+JAwUuZpr0EtF7g==","transmission_time": "2018-11-16T03:01:01Z","webhook_event": {"id":"WH-6DT935852K089633W-9X42044474276933K","event_version":"1.0","create_time":"2018-11-16T03:01:01.000Z","resource_type":"payouts","event_type":"PAYMENT.PAYOUTSBATCH.SUCCESS","summary":"Payouts batch completed successfully.","resource":{"batch_header":{"payout_batch_id":"7PHK3S3LKM8D6","batch_status":"SUCCESS","time_created":"2018-11-16T03:00:42Z","time_completed":"2018-11-16T03:01:01Z","sender_batch_header":{"sender_batch_id":"5bee32daa6bd8"},"amount":{"currency":"USD","value":"235.0"},"fees":{"currency":"USD","value":"1.25"},"payments":5},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payouts/7PHM8D6","rel":"self","method":"GET"}]},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-6DT9276933K","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-6DT933K/resend","rel":"resend","method":"POST"}]}}';
$webhook_obj = json_decode ( $webhook_json_data );
$w_event = new PayPalApiWebhookEvent($webhook_json_data);
// this gives PAYMENT.PAYOUTSBATCH.SUCCESS
echo $webhook_obj->webhook_event->event_type ."<br>";
// this yields nothing !! (the $w_event data appears to
// be 'protected' and thus inaccessible)
echo $w_event->event_type ."<br>";
Is the correct way to use the data received on a Webhook notification to just walk through the JSON decoded structure? For example, I want to confirm the total amount of the Payouts payment, which in this case is $235.00
I can retrieve it using:
$webhook_obj->webhook_event->resource->batch_header->amount->value
But it seems like there should be a better way to process these Webhook notifications??
php paypal sdk paypal-webhooks
add a comment |
I'm receiving the JSON data from PayPal's webhook to my end point.
I can of course parse it into a PHP object. Is this the best way to handle this data? I would have thought that the JSON data could be converted back into a new 'WebhookEvent' object and then handled that way?? But either that's not the case or I'm doing something wrong.
use PayPalApiWebhookEvent;
$webhook_json_data = '{"auth_algo": "SHA256withRSA","transmission_id": "d97395d0-de4a06f7","cert_url": "https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-aecacc47","webhook_id": "2V9E918418","transmission_sig": "Svsp/4l67b4sasdq/rjQojgKoOG95rltTuEtpip/UeNxTap7I/ao7Vg7VDJIYPaEzTz1UDNdsmI+/l1dhVfQsEAImg1bz0VpZ+0+JAwUuZpr0EtF7g==","transmission_time": "2018-11-16T03:01:01Z","webhook_event": {"id":"WH-6DT935852K089633W-9X42044474276933K","event_version":"1.0","create_time":"2018-11-16T03:01:01.000Z","resource_type":"payouts","event_type":"PAYMENT.PAYOUTSBATCH.SUCCESS","summary":"Payouts batch completed successfully.","resource":{"batch_header":{"payout_batch_id":"7PHK3S3LKM8D6","batch_status":"SUCCESS","time_created":"2018-11-16T03:00:42Z","time_completed":"2018-11-16T03:01:01Z","sender_batch_header":{"sender_batch_id":"5bee32daa6bd8"},"amount":{"currency":"USD","value":"235.0"},"fees":{"currency":"USD","value":"1.25"},"payments":5},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payouts/7PHM8D6","rel":"self","method":"GET"}]},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-6DT9276933K","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-6DT933K/resend","rel":"resend","method":"POST"}]}}';
$webhook_obj = json_decode ( $webhook_json_data );
$w_event = new PayPalApiWebhookEvent($webhook_json_data);
// this gives PAYMENT.PAYOUTSBATCH.SUCCESS
echo $webhook_obj->webhook_event->event_type ."<br>";
// this yields nothing !! (the $w_event data appears to
// be 'protected' and thus inaccessible)
echo $w_event->event_type ."<br>";
Is the correct way to use the data received on a Webhook notification to just walk through the JSON decoded structure? For example, I want to confirm the total amount of the Payouts payment, which in this case is $235.00
I can retrieve it using:
$webhook_obj->webhook_event->resource->batch_header->amount->value
But it seems like there should be a better way to process these Webhook notifications??
php paypal sdk paypal-webhooks
I'm receiving the JSON data from PayPal's webhook to my end point.
I can of course parse it into a PHP object. Is this the best way to handle this data? I would have thought that the JSON data could be converted back into a new 'WebhookEvent' object and then handled that way?? But either that's not the case or I'm doing something wrong.
use PayPalApiWebhookEvent;
$webhook_json_data = '{"auth_algo": "SHA256withRSA","transmission_id": "d97395d0-de4a06f7","cert_url": "https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-aecacc47","webhook_id": "2V9E918418","transmission_sig": "Svsp/4l67b4sasdq/rjQojgKoOG95rltTuEtpip/UeNxTap7I/ao7Vg7VDJIYPaEzTz1UDNdsmI+/l1dhVfQsEAImg1bz0VpZ+0+JAwUuZpr0EtF7g==","transmission_time": "2018-11-16T03:01:01Z","webhook_event": {"id":"WH-6DT935852K089633W-9X42044474276933K","event_version":"1.0","create_time":"2018-11-16T03:01:01.000Z","resource_type":"payouts","event_type":"PAYMENT.PAYOUTSBATCH.SUCCESS","summary":"Payouts batch completed successfully.","resource":{"batch_header":{"payout_batch_id":"7PHK3S3LKM8D6","batch_status":"SUCCESS","time_created":"2018-11-16T03:00:42Z","time_completed":"2018-11-16T03:01:01Z","sender_batch_header":{"sender_batch_id":"5bee32daa6bd8"},"amount":{"currency":"USD","value":"235.0"},"fees":{"currency":"USD","value":"1.25"},"payments":5},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payouts/7PHM8D6","rel":"self","method":"GET"}]},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-6DT9276933K","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-6DT933K/resend","rel":"resend","method":"POST"}]}}';
$webhook_obj = json_decode ( $webhook_json_data );
$w_event = new PayPalApiWebhookEvent($webhook_json_data);
// this gives PAYMENT.PAYOUTSBATCH.SUCCESS
echo $webhook_obj->webhook_event->event_type ."<br>";
// this yields nothing !! (the $w_event data appears to
// be 'protected' and thus inaccessible)
echo $w_event->event_type ."<br>";
Is the correct way to use the data received on a Webhook notification to just walk through the JSON decoded structure? For example, I want to confirm the total amount of the Payouts payment, which in this case is $235.00
I can retrieve it using:
$webhook_obj->webhook_event->resource->batch_header->amount->value
But it seems like there should be a better way to process these Webhook notifications??
php paypal sdk paypal-webhooks
php paypal sdk paypal-webhooks
asked Nov 16 '18 at 3:52
Phil GlauPhil Glau
344210
344210
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331182%2fparsing-using-webhookevent-data-sent-to-a-php-listener%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331182%2fparsing-using-webhookevent-data-sent-to-a-php-listener%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown