开发者

PayPal integration inside site for different accounts

I'm building simple selling site where any user ( seller ) can upload photo and sell it to other users ( buyers )

Seller needs to write his PayPal account when he register, so when buyer order image he get transferred to paypal site, even if he doesn't have PayPal to use outside Card ( that page you often see when you paying something with paypal ), and when buyer pay send those funds to seller and transfer buyer back to site and confirm payment. When php confirm payment he enable buyer to download image.

Is this possible, and how?

Can someone write me or simple script or tell me where to find examples for this... It's spread around the web, so anyone should no this开发者_StackOverflow...

Thank you!


You wouldn't need to store his paypal account when he registers.

And PayPal has written tonnes of infomation in their support sections.

Look up PayPal IPN.


Here is first step, creating form, put it where you want your BUY button to be, it can be on any page, you can create it by buttons wizard on PayPal site, just add this notify_url hidden input. You can edit those fields with php entering amount, item_name, business email, custom...

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="any-email-you-want@domain.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Item Name">
<input type="hidden" name="item_number" value="150">
<input type="hidden" name="amount" value="100.00">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="tax_rate" value="0.000">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="custom" value="user_id_goes_here">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="notify_url" value="http://checking-url-goes-here/file.php">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Second step, checking is it valid payment, file.php ( or any file URL you specify in notify_url hidden input in form above ) :

<?php

$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {

//ERROR READING PAGE - CODE ERROR

} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

//VALID CODE, DO WHATEVER YOU WANT WITH IT HERE, PAYMENT IS CONFIRMED...

}
else if (strcmp ($res, "INVALID") == 0) {

//INVALID CODE

}
}

?>

You can test this code inside: https://developer.paypal.com/ ( PayPal Sandbox ) just replace

www.paypal.com

with

www.sandbox.paypal.com

( you can find it at two places ).

And that's it...

I was asking for this directions, and no one want to direct me here...

I even get -2 rating for this question, but none of those minuses was smart enough to write me those examples, as I ask for...

And I'm the one who deserve minuses?

( I hope someone will find those examples useful )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜