Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored IPN to use base IPN class from civicrm #225

Open
wants to merge 5 commits into
base: 4.7-dev
Choose a base branch
from

Conversation

jmcclelland
Copy link
Contributor

This allows use of webhook in format /civicrm/payment/ipn/N

#221

*/

static public function handlePaymentNotification() {
$data_raw = file_get_contents("php://input");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this line... Most of the payment processors seem to do something like $params = array_merge($_GET, $_REQUEST);

Can we do that here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That format also caught my eye because I'm not used to that format either.

However, I investigated and noticed that the Stripe payment processor recommends that syntax (https://stripe.com/docs/webhooks) and the PHP manual suggests that in some cases it is better then $_POST (https://secure.php.net/manual/en/wrappers.php.php).

But most importantly, it will fail if we switch to $_POST because stripe is not sending a normal key value pair - instead it is sending raw JSON.

Here's the difference - I wrote a test script:

<?php
print_r($_POST);
print_r(file_get_contents("php://input")); 
echo "\n";

And here's the difference:

0 jamie@turkey:cdtemp.Q7dESJ$ curl --data-raw '{"name":"bob"}' https://wfan.loc.cx/test.php
Array
(
    [{"name":"bob"}] => 
)
{"name":"bob"}
0 jamie@turkey:cdtemp.Q7dESJ$ 

If we use $_POST we have to extract the index which is cumbersome compared with simply getting the raw data, which is what we ultimately want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants