i2-Services, Inc. Forums

Full Version: Steps to integrate with PayPal Instant Payment Notification
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Below are the steps to take to integrate new registrations and account upgrades with PayPal.

(1) Login to your PayPal.Com account.

(1a) Click on the [Profile] Link
(1b) Click on link [Instant Payment Notification Preferences] (To the right)
(1c) Check the box to turn IPN On
(1d) Enter the full http:// URL to the paypal_ipn.php file within your installation folder.

(2) Within your PayPal.Com account create your buy now or subscription button. Note the "item name" or "item number" field during this process. For example we'll name it "purchase".

Once you have complete the buy now / subscription option PayPal will provide you with the code to use. Copy this code.

(3) Within PHP Membership Manager administration (admin.php) go to the Setup options --> Membership Types.

Create a new membership type with PayPal.Com as the gateway. Once you have saved the membership type. Click on [Edit] for the membership type you have just created.

At the bottom of the membership type details page an area is provided to paste the code PayPal gave you in step #2.

(3a) Within the <form> to </form> code you pasted into this section add the following hidden form tag above the closing </form> tag.

<input type="hidden" name="custom" value="%email%">

Click the [Save] button to save your membership type changes.

(4) Now we need to add the "item number" or "item name" you have given this paypal button / purchase option to the /configs/paypal_config.php file.

Open/Edit the file within your PHP Membership Manager Installation:

/configs/paypal_config.php

For PayPal buy now buttons add a new {if} {/if} section (remember our example purchase option was given the name "purchase". Replace this with the name you have given the button / subscription option.

Code:
if($paypal[item_name] == "purchase") {
   $create_account = "1";    // Leave this as is "1"
}


For PayPal Subscriptions add this line:

Code:
if($paypal[item_number] == "purchase") {
   $create_account = "1";    // Leave this as is "1"
}





The /configs/paypal_config.php code above is for new registrations, NOT membership types for existing accounts. The paypal configuration code changes slightly as you will need to assign expiration time and any sub/user group access within the configuration file.

Below is an example:

Code:
if($paypal[item_number] == "purchase_upgrade") {

   $account_length_days  = "365";    // Set # Of Days or "0" for no expiration
   $sub_groups = ",1,";              // Set Sub-Group access. Start and end with commas
   $create_account  = "1";           // Leave this as is "1"
}





NOTES:

- You should receive an e-mail to the administration e-mail address set in the Admin --> Setup options after any paypal transaction. This contains all name=value data that PayPal sent to PHP Membership Manager. It also states the account action taken if any.

This e-mail is a great way to see exactly what paypal sent back to PHP Member Manager and if you need to alter any of your steps above. Such as item_name verses item_number and its value.

- During the paypal button / subscription create you have the ability to set a return URL where the customer is sent to after the payment is made.

You can enter the following code within the <form> </form> paypal code to set this manually:

Code:
<input type="hidden" name="return" value="http://www.your-domain.com/payment_received.html">


Change the above URL to a page on your site, URL to the control panel or URL to your protected folder which would first redirect them to the control panel to login. On successful login they would be taken to your protected / members area.

Also if you do not want IPN turned on in your paypal account because you have other payments coming in you can always add this in the <form> </form> tags of the button in step (3):

IE: <input type="hidden" name="notify_url" value="http://www.your-url.com/mm2/paypal_ipn.php">
(make sure to change the value above to your URL to paypal_ipn.php)

This eliminates steps (1a)-(1d)!!

Jason had to help me with this one... Thanks for all the help Jason.
Reference URL's