when you want to transaction through paypal, there are 2(two) situation created

situation 1: Suppose you have a paypal account.You want to sell something and want to make money transaction through paypal. Now there are a critical situation. When someone buy your product through paypal, suppose a software, you want that automatically a license key will send to that user if payment make successful. So, here is the integration process step by step: Put this code in your site:

 <form id=”formpay” action=”https://www.paypal.com/cgi-bin/webscr” method=”POST” >
<input type=”hidden” name=”cmd” value=”_xclick”>
<input type=”hidden” name=”business” value=”yourpaypalemail@email.com”>
<input type=”hidden” name=”item_name” value=”name of the item”>
<input type=”hidden” name=”item_number” value=”1″>
<input type=”hidden” name=”no_shipping” value=”1″>
<input type=”hidden” name=”return” value=”http://yoursite.com/success”>
<input type=”hidden” name=”notify_url” value=”http://yoursite.com/notifyme”>
<input type=”hidden” name=”currency_code” value=”USD”>
<input type=”hidden” name=”amount” value=”4″>
<input type=”image” src=”http://www.paypal.com/en_US/i/btn/x-click-but01.gif” name=”submit” alt=”Make payments with PayPal - it’s fast, free and secure!”>
</form>

This is the html code, that makes a visual paypal button in your site. Look carefully, the action of form remain same as here. If you want a normal buy button, then input name “cmd” its value should be =”_xclick”. input name “business” it’s value should be the email address you registered in paypal. Input name amount contains the price you set as a value. Now the most important input fields are “return” and “notify_url”. “return” field contains that url address, when purchase become successful and you want to show user some message like “congratulation, your purchase is successful”. As soon as purchase makes complete paypal dump some values to your “notify_url”. So, in this field, you should put that url of your site that makes some changes like database update or send any special email.

Now download this free code : http://www.hotscripts.com/Detailed/46734.html After downloading, unzip the zip file. You’ll get two php files. Now copy this file paypal.class.php into your project. Suppose your notify_url field is: http://abdullah.com/notify.php
Now write this code in notify.php

<?php
require_once(’paypal.class.php’);  // include the class file
$p = new paypal_class;             // initiate an instance of the class
if ($p->validate_ipn()) {
// Payment has been recieved and IPN is verified.  This is where you
// update your database to activate or process the order, or setup
// the database with the user’s order details, email an administrator,
// etc.  You can access a slew of information via the ipn_data() array.
// Check the paypal documentation for specifics on what information
// is available in the IPN POST variables.  Basically, all the POST vars
// which paypal sends, which we send back for validation, are now stored
// in the ipn_data() array.
// For this example, we’ll just email ourselves ALL the data.
$subject = ‘Instant Payment Notification - Recieved Payment’;
$to = ‘YOUR EMAIL ADDRESS HERE’;    //  your email
$body =  “An instant payment notification was successfully recieved\n”;
$body .= “from “.$p->ipn_data['payer_email'].” on “.date(’m/d/Y’);
$body .= ” at “.date(’g:i A’).”\n\nDetails:\n”;
foreach ($p->ipn_data as $key => $value) { $body .= “\n$key: $value”; }
mail($to, $subject, $body);
}
?>

So, if $p->validate_ipn() returns true, that means payment verified and you received the payment. And if it returns false, then you’ve to consider that for some reason payment doesn’t make successful.

situation 2: Suppose you want to make a subscription form. Subscripted fee may be charged daily, weekly, monthly or yearly. Suppose you want a yearly subscription form. So, any user who pays you, he have to pay yearly, otherwise his membership will cancel.
Solution: Here is the html code for the form. Look the changes. form action remains same as above. input field cmd is changed. Look the value of it. 5 new input field added here. For subscription form, notify_url be the same and you could use the paypal.class.php and like the previous way, you could check whether payment makes successful or not.

<form id=”fromsub” action=”https://www.paypal.com/cgi-bin/webscr” method=”POST” >
<input type=”hidden” name=”cmd” value=”_xclick-subscriptions”>
<input type=”hidden” name=”business” value=”yourpaypalemail@email.com”>
<input type=”hidden” name=”item_name” value=”name of the item”>
<input type=”hidden” name=”item_number” value=”1″>
<input type=”hidden” name=”no_shipping” value=”1″>
<input type=”hidden” name=”return” value=”http://yoursite.com/success”>
<input type=”hidden” name=”notify_url” value=”http://yoursite.com/notifyme”>
<input type=”hidden” name=”currency_code” value=”USD”>
<input type=”hidden” name=”amount” value=”4″>
<input type=”hidden” name=”a3″ value=”5″>
<input type=”hidden” name=”p3″ value=”1″>
<input type=”hidden” name=”t3″ value=”Y”>
<input type=”hidden” name=”src” value=”1″>
<input type=”hidden” name=”sra” value=”1″>
<input type=”image” src=”https://www.paypal.com/images/x-click-but20.gif” name=”submit” alt=”Make payments with PayPal - it’s fast, free and secure!”>
</form>

HTML Variables for PayPal Subscriptions

Variable Name

Required or Optional

Description

“post” action

Required

Must be set to “https://www.paypal.com/cgi-bin/webscr”

cmd

Required

Must be set to “_xclick-subscriptions”

business

Required

This is your PayPal ID, or email address. This email address must be confirmed and linked to your Verified Business or Premier

account

item_name

Optional

Description of item being sold (maximum 127 characters). If you are collecting aggregate payments, this can include a summary of all items purchased, tracking numbers, or generic terms such as “subscription.” If omitted, customer will see a field in which they have the option of entering an Item Name

return

Optional

An internet URL where the user will be returned after completing the payment. For example, a URL on your site that hosts a “Information on your new subscription” page. If omitted, users will be taken to the PayPal site

rm Optional Return URL behavior. If set to “1” and if a “return” value is
submitted, upon completion of the payment the buyer will be sent
back to the return URL using a GET method, and no transaction
variables will be submitted. If set to “2” and if a “return” value is
submitted, the buyer will be sent back to the return URL using a
POST method, to which all available transaction variables will
also be posted. If omitted or set to “0”, GET methods will be used
for all Subscriptions transactions and Buy Now, Donations, or
PayPal Shopping Cart transactions in which IPN is not enabled.
POST methods with variables will be used for the rest
cancel_retu Optional An internet URL where the user will be returned if payment is
rn cancelled. For example, a URL on your site which hosts a
“Payment Cancelled” page. If if omitted, users will be taken to
the PayPal site
a1 Optional Trial amount 1. This is the price of the first trial period. For a free
trial, use a value of 0
p1 Optional Trial period 1. This is the length of the first trial period. The number is modified by the trial period 1 units (t1, below)
t1 Optional Trial period 1 units. This is the units of trial period 1 (p1, above).
Acceptable values are: D (days), W (weeks), M (months), Y
(years)
a2 Optional Trial amount 2. This is the price of the second trial period
p2 Optional Trial period 2. This is the length of the second trial period. The number is modified by the trial period 1 units (t2, below)
t2 Optional Trial period 2 units. This is the units of trial period 2 (p2, above).
Acceptable values are: D (days), W (weeks), M (months), Y
(years)
a3 Required Regular rate. This is the price of the subscription
p3 Required Regular billing cycle. This is the length of the billing cycle. The number is modified by the regular billing cycle units (t3, below)
t3 Required [required] Regular billing cycle units. This is the units of the
regular billing cycle (p3, above) Acceptable values are: D (days),
W (weeks), M (months), Y (years)
src Optional Recurring payments. If set to “1,” the payment will recur unless
your customer cancels the subscription before the end of the
billing cycle. If omitted, the subscription payment will not recur
at the end of the billing cycle
Advertisement