Paypal на яндекс :: Про гроші

 

Главная » Paypal » Paypal на яндекс

Paypal на яндекс

How to Set Up PayPal Integration with PHP & MySQL

Paypal на яндекс

Updates: 10th August 2011

  • The payments. php code (Line 60-64) has been slightly amended to fix the IPN Invalid Response.
  • If you are not receiving the correct response from Paypal ensure that you are using the main test account (Verified Business Account) from your Paypal Sandbox account.
  • Also ensure that you are testing the Paypal IPN Script on an online webserver (Not MAMP, Xampp etc..) as Paypal requires a reachable 'return url', 'cancel url' and 'notify url'.
  • The downloadable source code has been updated with the above changes.

PayPal is the most popular payment service on the web so being able to integrate your website with PayPal's Instant Payment Notification Service (IPN) is essential if you need to process payments through your website.

There are 3 main parts to the PayPal IPN system.

  • A webpage that initiates a request to PayPal to make a payment.
  • A PHP page on your webserver that PayPal calls to notify you that payment has been made.
  • A webpage that confirms the above payment and continues on to the next phase of your web application, such as a 'Thank You' page.
  • Parts 1 and 3 are accessible by customers on your website. Part 2 is only visible to PayPal. The diagram below illustrates the interaction between your customer, PayPal and your website.

    The following steps break down each part of the process into easy to follow chunks, it is assumed that you have knowledge of PHP and MySQL.

    Step 1 - Setup PayPal Account

    Sign up for a PayPal account if you do not already have one. Select an appropriate account type, either Personal or Business.

    Once you have a registered PayPal account your account must be setup correctly to use IPN.

    Select 'edit profile' from your PayPal account and check the following settings.

    www. example. com / payment. php)
  • Under 'Selling Preferences' >> 'payment receiving preferences'
    • Block payments from users who pay with echeck. (This is because these will not be instant payments)
  • Under 'account information' >> 'email'
    • Note down your primary email address. This email will be visible to users so make it a professional one. User's may feel apprehensive about sending money to an e-mail address with the domain 'hotmail. com 'or' Yahoo. com 'etc...
  • Step 2 - Simple HTML Form

    Your website must now send all the required values ​​to PayPal so that the payment can be processed.

    The following code example demonstrates a basic form that we will use to send the values:

    The

    Business name, price, submit type, notify URL and other sensitive values ​​will be sent during the next step.

    A full list of the values to send can be found at the PayPal website under the title "A Sample IPN Message and Response" .

    Step 3 - Payments. php (The Request)

    The payment. php page will be used to handle the outgoing request to PayPal and also to handle the incoming response after the payment has been processed.

    The following sample code shows the querystring being constructed before it is posted to PayPal. Here you can specify the following values:

    • Business ($ paypal_email) - Enter the email address of your PayPal account.
    • Item name ($ item_name) - The name of the item being purchased.
    • Amount ($ item_amount) - The price of the item.
    • Return ($ return_url) - The address to return to after a successful payment.
    • Cancel Return ($ cancel_url) - the address to return to after a cancelled payment.
    • Notify URL ($ notify_url) - The address of the payments. php page on your website.
    • Custom - Any other data to be sent and returned with the PayPal request.

    Step 4 - Payments. php (The Response)

    The next part of the payments. php page handles the response from PayPal. The response is re-assigned to variables and then posted back to PayPal for verification using fsockopen.

    If the response is VERIFIED then a validation check can be performed. The check_txnid and check_price functions are called to check that the correct Transaction ID and Price have been returned. The updatePayments function can finally be called to store the details of the payment in the payments table (Step 6).

    Step 5 - Functions. php

    The payments. php page calls upon a number of functions used to validate the returned data and store the response in the database.

    Step 6 - Setting Up The Payments Table

    To store payment details in the database a payments table must be created in your database. The following MYSQL code will create a payments table.

    Step 7 - Sandbox Testing / Going Live

    PayPal Sandbox offers all of the functionality of PayPal, but the information involves all "Fake accounts" created by the developer. You can create fake buyer and fake seller profiles, then test your PayPal integration through your development website.

    During the testing phase of the development process the PayPal links should be prefixed to www. sandbox. paypal. com. You can visit the PayPal Developer website and sign up for a free PayPal Sandbox account

    Once the payment process is ready to be used by real customers you will need to remove the sandbox from each PayPal link to www. paypal. com.

    That's it; you're ready to start taking payments online through your website.

    PayPal Integration - Source Files