About Paypal integration with M2

hello!

so i'm busy setting up m2 on some of my sites, and i need to set up the ipn listener to get the paid subscriptions running through paypal.
1 - do i need to have a merchant / business account with them to do that, or can it be a personal account?
2 - can i set up multiple ipn listeners for multiple sites on 1 paypal account?

thanks!

  • Sajid

    Hi @Symi! Hope you are doing good today :slight_smile:

    1 - do i need to have a merchant / business account with them to do that, or can it be a personal account?

    No! you can use your persoanl account to setup IPN. But its better to use merchant / business PayPal account for transactions.

    2 - can i set up multiple ipn listeners for multiple sites on 1 paypal account?

    No! you can not use multiple IPN listeners for multiple sites on one PayPal account. Here is a workaround provided by the author of this tutorial.
    http://codeseekah.com/2012/02/11/how-to-setup-multiple-ipn-receivers-in-paypal/

    Hope it helps :slight_smile:

    Cheers, Sajid

  • Symi

    Oooh Ooh - please tell me,
    in this specific script,
    how would I set up the fingerprint?

    From the example it says that there are specific items in the shopping cart, etc.
    is it possible to create a fingerprint based on the application on a site that pushes the transaction through? :slight_smile:

    (I'm going back to go read it again, so if it's really obvious, I should get it on the 4th or so re-read...)

    Thanks again for your help.

  • Sajid

    Hi @Symi

    Hope you are doing good today :slight_smile:

    I did not tried the code myself yet. But the approach seems to be pretty easy and straight forward.

    You just need to host this script on your server and use it as IPN listener for PayPal.

    The fingerprint is hash or any unique identifier that you wish to use for security purposes to identify from where the request is coming and to what site you want it to redirect. You can pass this using custom variable of PayPal. That is the only variable it accepts other than its default HTML variables. This is how it should work, but again it needs more testing and experiments to fully understand its purpose.

    In your case, if you are using it with membership 2, then I think its not for you. Because you have to change the checkout form in order to add your custom variable and its value. Also if there is already a variable being used by plugin then there will be conflicts.

    As stated by author of this script:

    you can remove the fingerprints part in most cases

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Symi

    Hi Sajid,

    Uhm, OK - now i'm really worried.
    I will need to use this script with a variety of apps on different websites in the array, quite a couple of them will be appts+, membership pro 2. They all need to talk back to the same paypal merchant account.

    The point of the membership pro is to take subscriptions for a drip membership.

    To automate the subscription, as I read it, I have to use IPN on the Standard Paypal Payment function?

    I'm quite happy to take out the fingerprint. But as I understood, the appts+ and the membership 2 plugins on each site have their own ipn link, and that's how they do their magic? They send through the amounts due and they figure out if the subscription is active?

    I look forward to hearing back from you!

  • Sajid

    Hi @Symi

    Hope you are doing good today :slight_smile:

    I am sorry for delay here.

    Yes that's why this script been developed to handle multiple IPN handlers. But to uniquely identify the correct IPN response to forward on correct IPN hanlder on a site we have to use app prefix.

    Here is updated and simpler code provide by our lead developer on this thread. There you can have complete setup guide too and can get answer of your questions. Yes I know its late and I am really sorry to not find and post it for you earlier.
    https://premium.wpmudev.org/forums/topic/multiples-ipn-dynamically-setting-the-notification-url#post-608459

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Symi

    Hi Sajid,

    from reading the thread, it looks like it was created for pro sites, will this script require further modification to work for membership 2 and appointments +? Or can I simply follow directions and use the script and plugins as is?

    The path for membership doesn't end on .php like A+ does, is that a problem? On the contrary: it looks like this: http://mydomain.com/ms-payment-return/paypalstandard

    So inside the script, my array would look like this?

    /* Membership Site */
    array('prefix' => 'membership',
    'domain' => 'mydomain.com',
    'path' => '/ms-payment-return/paypalstandard',
    'live' => true),

    /* Appointments + */
    array('prefix' => 'appts2',
    'domain' => 'stillmysamedomain.com,
    'path' => '/wp-admin/admin-ajax.php?action=app_paypal_ipn',
    'live' => false)
    );

    do i have this right?

    and only 1 pwd to be set up, because there's one config file?

    Like - really, can't this be developed as a plugin? there were various people asking for the same thing on the original thread...

  • Symi

    Hi, this is a bump in the post -
    i've done a bit of reading up, and the .htaccess file allows you to password protect a folder, so - is that what we're trying to do to keep the logs safe? does the password only keep outside traffic out, but the php file will be able to scribble all it likes?

    Also - i think i've figured out the editing on the php file, the setting up of the array is quite similar to the original script we looked at, but i just want to confirm that the two ipn listeners use the same pwd in any event, because they're on the same domain in this instance. there's only one wpconfig file to edit.. yes?

    I'm curious to hear your answer, as i'm really geared to start testing the script and launching this site.

  • Sajid

    Hi @Symi

    Hope you are doing good today :slight_smile:

    from reading the thread, it looks like it was created for pro sites, will this script require further modification to work for membership 2 and appointments +? Or can I simply follow directions and use the script and plugins as is?

    No! You can not use it as it is. You have to modified the membership and appointments+ checkout page. I have asked the developer whether we have similar constant that can be difined in wp-config.php file for these two plugins as well. I am waiting for their response and update you here once got more info.

    So inside the script, my array would look like this? /* Membership Site */
    array('prefix' => 'membership',
    'domain' => 'mydomain.com',
    'path' => '/ms-payment-return/paypalstandard',
    'live' => true),

    Yes! Do not worry about the .php at the end. You are doing it correctly.

    and only 1 pwd to be set up, because there's one config file?

    The password is to confirm that the response is coming from our forwarder script. I think that was for Pro Sites because the script that is reviving the response have that password match. You can simply ignore it or use it too. But if you use it then you have to customize that is receiving the response.

    The only important part is we should have prefix defined and pushed them correctly. To verify what IPN response from PayPal will go to what URL.

    For .htaccess protection, you can protect the directory from outside traffic, PHP can still write log files and update it. I suggest you to move this step at very end of development so we have the core functionality working first.

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Sajid

    Hi @Symi

    I have got response from appointments+ developer. I am afraid we can not use custom variable for prefix (that is required for IPN forwarder), its already being used for service ID, that is required for IPN process. But we do not need IPN forwarder for appointments+ IPN processing. It automatically used its own dynamic IPN URL to communicate with PayPal.

    I am still waiting for Membership 2 Pro developer though. Will post a reply here when got response :slight_smile:

    Cheers, Sajid

  • Symi

    hi sajid,
    sorry -
    i'm confused.
    teh ipn listener enables 2-way comms between the plugin and the payment portal, yes?
    so for appts+, you want refunds to happen when an appointment is cancelled,
    and for membership, you want it to know when a membership has terminated, or you want access to cease if a repeat payment bounced.

    as paypal only listens to one ipn, the way i have it, i can't have appts+ AND membership chatting to paypal at one time. so we have to use a magic doodaah like the ipn listener script. yes?

    to get both of them to talk to paypal.

    i'm not getting any closer to a resolution. infact, we're just faffing around forwards and backwards here... :slight_frown:

  • Sajid

    Hi @Symi

    Hope you are doing good today :slight_smile:

    The ipn listener enables 2-way comms between the plugin and the payment portal, yes?
    so for appts+, you want refunds to happen when an appointment is cancelled,
    and for membership, you want it to know when a membership has terminated, or you want access to cease if a repeat payment bounced.

    I am sorry for confusion, but multiple IPN is not currently being supported widely so we have to find a workaround for it. So there can be confusions. The custom field that is required by ipn-forwarder is already being used in appointments+ so we can not use it.
    I talked with developer for appointments+, IPN and he said we already have dynamic IPN in our checkout form to communicate with PayPal. So appointments+ will handle subscription, refunds and cacelation with the help of that dynamic IPN. So we should not worry about this one.

    A good news, for Membership 2 Pro:
    I got response from Membership 2 Pro developer and he said we can add our custom variable to send prefix without modifying the core files. To do that add below code in functions.php file of your child theme.

    add_filter( 'ms_gateway_paypalstandard_view_prepare_fields', 'wpmu_add_chekcout_custom_field' );
    function add_custom_field( $fields ) {
        $fields['custom'] = '<input type="hidden" name="custom" value="membership">';
        return $fields;
    }

    Apply these changes and start testing the script.

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Symi

    hi Sajid,

    i couldn't figure out why nobody else has this problem, and why it's such a custom solution. don't other people use A+ and M2? and don't other people use multiple websites with M2? how is that even possible?

    Here is the only mention of how A+ Paypal IPN works inside the plugin, so it's not like the details are documented for users --> "Just for your information, your IPN link is: http://domain.com/wp-admin/admin-ajax.php?action=app_paypal_ipn . You may need this information in some cases."

    then i got this documentation after you explained that A+ uses dynamic IPN.
    -->You can specify an IPN listener for a specific payment; this is the only way to receive IPNs associated with Adaptive Payments. In this case, PayPal sends the IPN message to the listener specified in the notification URL for a specific button or API operation instead of the listener specified in your Profile.<--
    https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNSetup/

    so that means that A+ sorts itself out regardless of the IPN listener defined in other plugins / sites.
    we only have to worry about M2 integration.

    OK - so when we only have to worry about M2 integration, and M2 supplies the IPN in the setup pages, it should be down hill from here?

    But we still have to do the workaround because A+ uses the site's variable already, it kind of means that you can't run A+ and M2 out of the box, on the same website, both using paypal as payment option? so i still have to paste in the custom code from your last post into the theme's functions.php file??

    is that right?

    because that would mean that you can't integrate M2 and A+ with Paypal out of the box at all?

    or do i have it wrong, and i could have simply chucked the M2 IPN into the default IPN setting for Paypal, and I just wasted 2,5 weeks waiting for magic code from developers that should not be necessary?

    I figure that for site number 2 and 3 and 4, I will simply have to define the M2 IPN's in a default Listener that disperses the notifications to the array, and the array will only include the M2 install IPN's. That Appts+ will sort itself out regardless.

    <<<<My only question left now, is do i need the custom code for M2 at all?>>>>.

  • Sajid

    Hi @Symi

    Hope you are doing good today :slight_smile:

    First of all I am sorry for delay and massive confusion. This was workaround and not a solution. I was not sure that you want to use A+ and M2 together on one website (if its that stop reading below and start setting up both plugins). First I thought you might need A+ static IPN URL to make it work for instant notifications, but after having discussion with developer of A+ he said its not necessary for A+ to setup IPN in PayPal settings to make it work. Then I updated you accordingly in my previous thread regarding appointments+.

    Here is the only mention of how A+ Paypal IPN works inside the plugin, so it's not like the details are documented for users --> "Just for your information, your IPN link is: http://domain.com/wp-admin/admin-ajax.php?action=app_paypal_ipn . You may need this information in some cases."

    Yes! You can use this IPN link in some cases to recive IPN notifications but its not necessary all the time. Its kind of an alternate method if, for some reason, dynamic IPN does not work.

    But we still have to do the workaround because A+ uses the site's variable already, it kind of means that you can't run A+ and M2 out of the box, on the same website, both using paypal as payment option? so i still have to paste in the custom code from your last post into the theme's functions.php file??

    If you are using both plugin then you do not need that code to be added in functions.php or to the ipn-forwarder.php. But if you want to use one PayPal account and want to link with two or more systems then you do need that code to use. Again it will not work out of the box and we have make sure its compatible or make it compatible for that system. I know its confusing but as stated by the author of the code its only method to make one PayPal account work for multiple IPNs.

    <<<<My only question left now, is do i need the custom code for M2 at all?>>>>.

    If you want to use it on one website along with appointments+ then you do not need this code. If you want to use your one PayPal email for multiple website then even if its only M2 then you still NEED this code for IPN forwarding.

    Sorry for confusion again. Feel free to post a reply and I will try my best to provide you a workaround.

    Best Regards
    Sajid J

  • Symi

    Hi Sajid, thanks for engaging.

    Yes - i am setting up domain 1 now, and as soon as that is up and running, domain 2 will rise up, with exactly the same functionality (M2 and A+) with new content, but using the same Paypal account.
    so what your'e saying is don't worry about the workaround yet for domain 1 if that's all i'm building.
    awesome.
    however - by the time i get to domain 2, i will need to have the script in functions.php on each domain, and i will need to start using the script to make M2 on domain 1 and M2 on domain 2 use the same paypal account.
    if the dynamic ipn works as we are hoping for A+, i won't need to add them to the script?

    do i have it right?

    also - i need a couple more pointers on how to set the permissions on the log folder security. the only .htaccess pointers i got talk about setting a password and i am afraid i may start summoning a demon if i try that. can i lock down with linux permissions? what permissions should i use on the folder to not allow browser access, but still allow the script to write to the server?

    thanks.

  • Sajid

    Hi @Symi

    Hope you are doing good today :slight_smile:

    so what your'e saying is don't worry about the workaround yet for domain 1 if that's all i'm

    Yes! You can add the M2 IPN URL in PayPal for one website/domain.

    however - by the time i get to domain 2, i will need to have the script in functions.php on each domain, and i will need to start using the script to make M2 on domain 1 and M2 on domain 2 use the same paypal account.

    Yes! Now you need to use the ipn-forwarder.php script to manage multiple IPN URLs under one PayPal account for Membership 2 Pro (even if A+ dynamic IPN is working).

    To uniquely identify the request you have to add the snippet I posted in above post in functions.php file for each website and change the prefix.

    Later on we will be using that prefix in ipn-forwarder.php script to identify from where that request is coming and submit the response to that particular website/domain.

    also - i need a couple more pointers on how to set the permissions on the log folder security. the only .htaccess pointers i got talk about setting a password and i am afraid i may start summoning a demon if i try that. can i lock down with linux permissions? what permissions should i use on the folder to not allow browser access, but still allow the script to write to the server?

    Please create separate thread for separate issues to get fastest response from other staff members and also its very easy for us to keep things organized. Thanks for understanding :slight_smile:

    Hope it helps :slight_smile: Feel free to post a reply if need to.

    Cheers, Sajid