Payum / PayumBundle

Payum offers everything you need to work with payments. From simplest use cases to very advanced ones.
https://payum.gitbook.io/payum
MIT License
569 stars 142 forks source link

Paypal IPN: how to implement? #105

Closed wesleywillians closed 9 years ago

wesleywillians commented 10 years ago

Hi Folks,

I am using this bundle as recurring payment. I would like to know:

Can you guys provide me any docs/examples about this subject. I only saw this link referencing about IPN (https://github.com/Payum/Payum/blob/master/docs/paypal/ipn/get-it-started.md)

makasim commented 10 years ago

The controller is shipped with the bundle, though you have to do some work to make it finally work.

You have to create a payum's action that handle the notify request. Check the sandbox

code: https://github.com/Payum/PayumBundleSandbox/blob/master/app/config/payum.yml#L55 and online: http://sandbox.payum.forma-dev.com/

You may get some inspiration on how the action can look like in sylius too: https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/PayumBundle/Payum/Paypal/Action/NotifyOrderAction.php

wesleywillians commented 10 years ago

Hum. What about the action, which route does it respond to?

Example: actions:

makasim commented 10 years ago

Just set a target url of notify token: https://github.com/Payum/PayumBundleSandbox/blob/master/src/Acme/PaypalExpressCheckoutBundle/Controller/PurchaseExamplesController.php#L258

wesleywillians commented 10 years ago

Perfect.

But about the notify action, how can I register it? Just put?

And just need to create the file using this path? Is there any other setting?

@wesleywillians www.schoolofnet.com

On Mon, Mar 24, 2014 at 6:15 AM, Maksim Kotlyar notifications@github.comwrote:

Just set a target url of notify token: https://github.com/Payum/PayumBundleSandbox/blob/master/src/Acme/PaypalExpressCheckoutBundle/Controller/PurchaseExamplesController.php#L258

Reply to this email directly or view it on GitHubhttps://github.com/Payum/PayumBundle/issues/105#issuecomment-38423789 .

makasim commented 10 years ago

You have to create a service and register it in actions section.

Can we close it?

wesleywillians commented 10 years ago

Ok. Thanks a lot!

@wesleywillians www.schoolofnet.com

On Tue, Apr 8, 2014 at 4:30 AM, Maksim Kotlyar notifications@github.comwrote:

You have to create a service and register it in actions section.

Can we close it?

Reply to this email directly or view it on GitHubhttps://github.com/Payum/PayumBundle/issues/105#issuecomment-39819279 .

binarious commented 10 years ago

I still have a question about this.

According to the PayPal Docs (https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNIntro/#protocol_and_arch) you have to verify the IPN via a GET request to the PayPal server.

I assume this class does it: https://github.com/Payum/Payum/blob/master/src/Payum/Paypal/Ipn/Api.php

How do I call it in my StoreNotificationAction with all the options (sandbox, username, etc.) configured for the PayumBundle and maybe a Curl proxy? Or is it already done by the PayumBudle (I haven't found such a call. And if, I'd like to add a proxy to curl). The sandbox example (https://github.com/Payum/PayumBundleSandbox/blob/master/src/Acme/PaymentBundle/Payum/Action/StoreNotificationAction.php) just writes it to the database wihout a validation call as far as I can see.

makasim commented 10 years ago

I dont verify any data. For that I have several reasons:

Sometime ago I added generic NotifyAction. Be careful It is not integrated to PayumBundle yet. Also you can get some inspiration from sylius notify action.

binarious commented 10 years ago

Thanks for the fast reply!

Will the url token be deleted after it got a notification? So the basic idea is not to use the IPN verification process from PayPal but instead just do a SyncRequest? Is it possible to set a proxy for Payum's server to server requests?

makasim commented 10 years ago

Will the url token be deleted after it got a notification?

nope, as there can be any amount of notifications, not only one.

So the basic idea is not to use the IPN verification process from PayPal but instead just do a SyncRequest?

I think it is more secure to do so.

Is it possible to set a proxy for Payum's server to server requests?

sorry dont get this, could you explain better?

binarious commented 10 years ago

sorry dont get this, could you explain better?

Payum's SyncRequests are server to server requests (webserver to paypal) afaik. My webserver does not have direct access to the internet and therefore needs a proxy for webservice calls.

makasim commented 10 years ago

You can try to overwrite a buzz http client with one which support proxy. I hope it possible. To do so you have create your custom buzz client and set it in the config.

payum:
  contexts:
    paypal:
      paypal_express_checkout_nvp:
        api:
          client: your.buzz.client

The option is defined in the factory.

I've never tried to use it this way so there maybe some bugs or problems. Feel free to report or fix them

binarious commented 10 years ago

Okay, thanks a lot!

binarious commented 10 years ago

@makasim I think a SyncRequest won't work as an IPN receiver, because it uses the express checkout token to sync the data with PayPal. This token is only valid for 3 hours, after that time you receive an error from PayPal: "Token value no longer valid". An IPN could be triggered after the 3 hours (issue refund or something similar) and the SyncRequest can't handle that, because the token expired. Any ideas?

makasim commented 10 years ago

@binarious yes, you are right.

Then you have to get ipn details from NotifyRequest, validate it. Update the model. The last part could be tricky

I would try to fix the issue in next versions.

binarious commented 10 years ago

@makasim Why would updating the model be the tricky part? Could you tell me how to integrate https://github.com/Payum/PaypalIpn/blob/master/Api.php in an existing PayumBundle installation without changing too much?

makasim commented 10 years ago

@binarious

Why would updating the model be the tricky part?

Notification data is sent in a different format than the model have. So you have to convert it somehow. I dont know I have to take a look at it.

Could you tell me how to integrate https://github.com/Payum/PaypalIpn/blob/master/Api.php in an existing PayumBundle installation without changing too much?

There is how to use doc: http://payum.forma-dev.com/documentation/0.8/PaypalIpn/how-to-api. Should be simple to use. You can extend NotifyAction and add a check there at the beginning of execute method. Then add your notify action as a service to container. This service add to actions section of payum bundle config; Do similar things desctibed here but for the action: http://payum.forma-dev.com/documentation/0.8/PayumBundle/custom_api_usage

binarious commented 10 years ago

@makasim Thank you. Get IPN details, validate them and update the model (just the status for now) works for me.

makasim commented 10 years ago

@binarious could you share your work somewhere?

binarious commented 10 years ago

@makasim I tried to remove my project overhead: https://gist.github.com/binarious/08fda89ec326e37a9254 Hope that helps.

makasim commented 10 years ago

@binarious that's looks good. I will use it as base while fixing the bug.

binarious commented 10 years ago

@makasim Any news?

makasim commented 10 years ago

any progress so far, sorry.

makasim commented 10 years ago

There is a PR that fix this bug

makasim commented 9 years ago

@makasim I think a SyncRequest won't work as an IPN receiver, because it uses the express checkout token to sync the data with PayPal. This token is only valid for 3 hours,

this was fixed, preferred way is to use sync request

binarious commented 9 years ago

@makasim Could you provide an example or can I just use https://github.com/Payum/Payum/blob/master/docs/instant-payment-notification.md and handle that like in my gist in 1.0? I'm still on 0.8 and want to migrate to 1.0.