Ir para o conteúdo


Foto:

Integrar paypal em site


  • Por favor, faça o login para responder
2 respostas neste tópico

#1 leandro_nirv

leandro_nirv

    Newbie

  • Members
  • Pip
  • 1 posts

Postado 12 March 2012 - 03:34 AM

Oi pessoal, tenho um problema, tenho um site de empregos, ele possui um sistema de pagamento via paypal, mas nao sei configurar e o link não esta funcionando, creio que este sistema esta antigo..., o que eu entendi ele pega as variaveis tipo dados do plano, usuario_cliente passa para o o site de pagamentos, e devolve para notify.php que grava o plano no mysql, ta aí o code se vcs entederem um pouco me da uma luz. to precisando muito




Pagamento.php
<?
while($a1 = mysql_fetch_array($r1))
{
 if($a1[price] > 0)
 {</p><p>  $pname = urlencode($a1[PlanName]);
 echo "
 <tr>
 <td width=170>
 <b>$a1[PlanName]</b>
 <ul>
 <li>$a1[postings] cadastro de vagas; </li>
 <li>$a1[reviews] visualizações de currículos; </li>
 <li><b>Preço: <font color=#336699>$a1[price] </font</b></li>
 </ul>
 </td></p><p> <td width=300>
  <table align=center width=300>
  <tr>
    <td width=150 align=center></p><p>  <a href=\"<a href='http://demo.epaysoft.info/handle.php?merchantAccount=$aset[paypal]&amount=$a1[price]&item_id=$a1[PlanName]|$a1[PlanID]|$a1[price]|$_SESSION[ename]|$a1[email]&return_url=http://$_SERVER[HTTP_HOST]$dir/employers/thanks.php&notify_url=http://$_SERVER[HTTP_HOST]$dir/employers/notify.php\"><img'>http://demo.epaysoft.info/handle.php?merchantAccount=$aset[paypal]&amount=$a1[price]&item_id=$a1[PlanName]|$a1[PlanID]|$a1[price]|$_SESSION[ename]|$a1[email]&return_url=http://$_SERVER[HTTP_HOST]$dir/employers/thanks.php&notify_url=http://$_SERVER[HTTP_HOST]$dir/employers/notify.php\"><img</a> src=\"<a href="http://images.paypal.com/images/x-click-but01.gif\">http://images.paypal.com/images/x-click-but01.gif\</a>" border=\"0\" name=\"submit\" alt=\"Pague pelo epayBrasil é fácil, rápido e seguro!\"></a>";</p><p>  echo "</td>\n</tr>\n\n";</p><p>
  echo "</table>
 </td></p><p></tr>";
 }
 else
 {
 echo "
 <tr>
 <td>
 <b>$a1[PlanName]</b>
 <ul>
 <li>$a1[postings] cadastro de vagas; </li>
 <li>$a1[reviews] visualizações de currículos; </li>
 <li><b>Preço: <font color=#336699>$a1[price] </font</b></li>
 </ul>
 </td></p><p> <td>
 <form action=pay2.php method=post>
 <input type=hidden name=plan value=\"$a1[PlanName]\">
 <input type=hidden name=reviews value=\"$a1[reviews]\">
 <input type=hidden name=postings value=\"$a1[postings]\">
 <input type=hidden name=price value=\"$a1[price]\">
 <input type=submit value=\"Grátis - Clique aqui\" style=\"font-family: Verdana; font-size: 8pt; font-weight: bold; background-color: #F5F5F5\">
 </form>
 </td>";
 }
 
}</p><p>?></p><p></table>
</body>
</html>

Notify.php

<?php</p><p>#########################################################
#    Copyright © EliteWeaver UK All rights reserved.    #
#########################################################
#                                                       #
#  Program         : IPN Development Handler            #
#  Author          : Marcus Cicero                      #
#  File            : notify.php                         #
#  Function        : Skeleton IPN Handler               #
#  Version         : 2.0                                #
#  Last Modified   : 09/20/2003                         #
#  Copyright ©     : EliteWeaver UK                     #
#                                                       #
#########################################################
#    THIS SCRIPT IS FREEWARE AND IS NOT FOR RE-SALE!    #
#########################################################
#              END USER LICENCE AGREEMENT               #
# Redistribution and  use in source and/or binary forms #
# with or without  modification, are permitted provided #
# that the above copyright notice is  reproduced in the #
# script, documentation and/or any other materials that #
# may  have been provided in the original distribution. #
#########################################################
#    Copyright © EliteWeaver UK All rights reserved.    #
#########################################################</p><p> </p><p>// IPN validation modes, choose: 1 or 2</p><p>$postmode=1;</p><p>           //* 1 = Live Via PayPal Network
           //* 2 = Test Via EliteWeaver UK</p><p> </p><p>// Debugger, 1 = on and 0 = off</p><p>$debugger=1;</p><p> </p><p>// Convert super globals on older php builds</p><p> if (phpversion() <= '4.0.6')
 {
  $_SERVER = ($HTTP_SERVER_VARS);
  $_POST = ($HTTP_POST_VARS); }</p><p> </p><p>// No ipn post means this script does not exist</p><p> if (<a href="mailto:!@$_POST['txn_type'">!@$_POST['txn_type'</a>])
 {
  @header("Status: 404 Not Found"); exit; }</p><p> else
 {
  @header("Status: 200 OK");  // Prevents ipn reposts on some servers</p><p> </p><p>// Add "cmd" to prepare for post back validation
// Read the ipn post from paypal or eliteweaver uk
// Fix issue with php magic quotes enabled on gpc
// Apply variable antidote (replaces array filter)
// Destroy the original ipn post (security reason)
// Reconstruct the ipn string ready for the post</p><p>
  $postipn = 'cmd=_notify-validate'; // Notify validate</p><p> foreach ($_POST as $ipnkey => $ipnval)
 {
 if (get_magic_quotes_gpc())
  $ipnval == stripslashes ($ipnval); // Fix issue with magic quotes
 if (!eregi("^[_0-9a-z-]{1,30}{:content:}quot;,$ipnkey)
 || !strcasecmp ($ipnkey, 'cmd'))
 { // ^ Antidote to potential variable injection and poisoning
 unset ($ipnkey); unset ($ipnval); } // Eliminate the above
 if (@$ipnkey != '') { // Remove empty keys (not values)
  @$_PAYPAL[$ipnkey] = $ipnval; // Assign data to new global array
 unset ($_POST); // Destroy the original ipn post array, sniff...</p><p>  <a href="mailto:$postipn.='&'.@$ipnkey.'='.urlencode(@$ipnval">$postipn.='&'.@$ipnkey.'='.urlencode(@$ipnval</a>); }} // Notify string
  $error=0; // No errors let's hope it's going to stays like this!</p><p> </p><p>// IPN validation mode 1: Live Via PayPal Network</p><p> if ($postmode == 1)
 {
  $domain = "<a href="http://www.paypal.com">www.paypal.com</a>"; }</p><p>// IPN validation mode 2: Test Via EliteWeaver UK</p><p> elseif ($postmode == 2)
 {
  $domain = "<a href="http://www.eliteweaver.co.uk">www.eliteweaver.co.uk</a>"; }</p><p>// IPN validation mode was not set to 1 or 2</p><p> else
 {
  $error=1;
  $bmode=1;
 if ($debugger) debugInfo(); }</p><p>
@set_time_limit(60); // Attempt to double default time limit incase we switch to Get</p><p> </p><p>// Post back the reconstructed instant payment notification</p><p>  $socket = @fsockopen($domain,80,$errno,$errstr,30);
  $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
  $header.= "User-Agent: PHP/".phpversion()."\r\n";
  $header.= "Referer: ".$_SERVER['HTTP_HOST'].
  $_SERVER['PHP_SELF'].@$_SERVER['QUERY_STRING']."\r\n";
  $header.= "Server: ".$_SERVER['SERVER_SOFTWARE']."\r\n";
  $header.= "Host: ".$domain.":80\r\n";
  $header.= "Content-Type: application/x-www-form-urlencoded\r\n";
  $header.= "Content-Length: ".strlen($postipn)."\r\n";
  $header.= "Accept: */*\r\n\r\n";</p><p>//* Note: "Connection: Close" is not required using HTTP/1.0</p><p> </p><p>// Problem: Now is this your firewall or your ports?</p><p>            if (!$socket && !$error)
            {</p><p>// Switch to a Get request for a last ditch attempt!</p><p>  $getrq=1;</p><p> if (phpversion() >= '4.3.0'
 && function_exists('file_get_contents'))
 {} // Checking for a new function
 else
 { // No? We'll create it instead</p><p>function file_get_contents($ipnget) {
  $ipnget = @file($ipnget);
 return $ipnget[0];
  }}</p><p>                   $response = @file_get_contents('http://'.$domain.':80/cgi-bin/webscr?'.$postipn);</p><p> if (!$response)
 {
  $error=1;
  $getrq=0;</p><p> if ($debugger) debugInfo();
 // If this is as far as you get then you need a new web host!
   }}</p><p> </p><p>// If no problems have occured then we proceed with the processing</p><p> else
 {
  @fputs ($socket,$header.$postipn."\r\n\r\n"); // Required on some environments
 while (!feof($socket))
 {
  $response = fgets ($socket,1024); }}
  $response = trim ($response); // Also required on some environments</p><p> </p><p>// uncomment '#' to assign posted variables to local variables
extract($_PAYPAL); // if globals is on they are already local</p><p>// and/or >>></p><p>// refer to each ipn variable by reference (recommended)
// $_PAYPAL['receiver_email']; etc... (see: ipnvars.txt)</p><p> </p><p>// IPN was confirmed as both genuine and VERIFIED</p><p> if (!strcmp ($response, "VERIFIED"))
 {
  if(variableAudit('payment_status','Completed'))
  {
   //include the DB connection
   include_once("../conn.php");</p><p>   $info = explode("|", $custom);</p><p>   $epayname = $info[2];</p><p>
   $q = "select * from job_plan where PlanID = \"$info[0]\"";
   $r = mysql_query($q) or die(mysql_error());
   $a = mysql_fetch_array($r);</p><p>   $q1 = "update job_employer_info set plan = \"$a[PlanName]\", JS_number = \"$a[reviews]\", JP_number = \"$a[postings]\" where ename = \"$epayname\"";
   $r1 = mysql_query($q1) or die(mysql_error());</p><p>   $qm = "select CompanyEmail from job_employer_info where ename = \"$epayname\" ";
   $rqm = mysql_query($qm) or die(mysql_error());
   $am = mysql_fetch_array($rqm);</p><p>   $to = $am[0];
   $subject = "Your employer plan at $_SERVER[HTTP_HOST]";
   $message = "Hello,\n here is your employer plan information at $_SERVER[HTTP_HOST]:\n\n Plan name: $a[PlanName]\n Number of resume viewing: $a[reviews]\n Number of Job Offer postings: $a[postings]\n\n$_SERVER[HTTP_HOST] Team";
   $from = "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>";</p><p>   mail($to, $subject, $message, $from);</p><p>  }
 }
// Check that the "payment_status" variable is: Completed
// If it is Pending you may want to inform your customer?
// Check your db to ensure this "txn_id" is not a duplicate
// You may want to check "payment_gross" or "mc_gross" matches listed prices?
// You definately want to check the "receiver_email" or "business" is yours
// Update your db and process this payment accordingly</p><p>//***************************************************************//
//* Tip: Use the internal auditing function to do some of this! *//
//* **************************************************************************************//
//* Help: if(variableAudit('mc_gross','0.01') &&      *//
//*       variableAudit('receiver_email','paypal@domain.com') &&     *//
//*       variableAudit('payment_status','Completed')){ $do_this; } else { do_that; } *//
//****************************************************************************************//</p><p> </p><p>
// IPN was not validated as genuine and is INVALID</p><p> elseif (!strcmp ($response, "INVALID"))
 {</p><p>// Check your code for any post back validation problems
// Investigate the fact that this could be a spoofed IPN
// If updating your db, ensure this "txn_id" is not a duplicate
   }</p><p> </p><p> else
 { // Just incase something serious should happen!
   }}</p><p> if ($debugger) debugInfo();</p><p> </p><p>#########################################################
#     Inernal Functions : variableAudit & debugInfo     #
#########################################################</p><p> </p><p>// Function: variableAudit
// Easy LOCAL to IPN variable comparison 
// Returns 1 for match or 0 for mismatch</p><p>function variableAudit($v,$c)
{
 global  $_PAYPAL;
    if (!strcasecmp($_PAYPAL[$v],$c)) 
    { return 1; } else { return 0; } 
} </p><p> </p><p>// Function: debugInfo
// Displays debug info 
// Set $debugger to 1</p><p>function debugInfo()
{
 global  $_PAYPAL,
  $postmode,
  $socket,
  $error,
  $postipn,
  $getrq,
  $response;</p><p>  $ipnc = strlen($postipn)-21;
  $ipnv = count($_PAYPAL)+1;</p><p> @flush();
 @header('Cache-control: private'."\r\n");
 @header('Content-Type: text/plain'."\r\n");
 @header('Content-Disposition: inline; filename=debug.txt'."\r\n");
 @header('Content-transfer-encoding: ascii'."\r\n");
 @header('Pragma: no-cache'."\r\n");
 @header('Expires: 0'."\r\n\r\n");
 echo '#########################################################'."\r\n";
 echo '#    Copyright © EliteWeaver UK All rights reserved.    #'."\r\n";
 echo '#########################################################'."\r\n";
 echo '#              END USER LICENCE AGREEMENT               #'."\r\n";
 echo '# Redistribution and  use in source and/or binary forms #'."\r\n";
 echo '# with or without  modification, are permitted provided #'."\r\n";
 echo '# that the above copyright notice is  reproduced in the #'."\r\n";
 echo '# script, documentation and/or any other materials that #'."\r\n";
 echo '# may  have been provided in the original distribution. #'."\r\n";
 echo '#########################################################'."\r\n";
 echo '# <-- PayPal IPN Variable Output & Status Debugger! --> #'."\r\n";
 echo '#########################################################'."\r\n\r\n";
 if (phpversion() >= '4.3.0' && $socket)
 {
 echo 'Socket Status: '."\r\n\r\n";
 print_r (socket_get_status($socket));
 echo "\r\n\r\n"; }
 echo 'PayPal IPN: '."\r\n\r\n";
 print_r($_PAYPAL);
 echo "\r\n\r\n".'Validation String: '."\r\n\r\n".wordwrap($postipn, 64, "\r\n", 1);
 echo "\r\n\r\n\r\n".'Validation Info: '."\r\n";
 echo "\r\n\t".'PayPal IPN String Length Incoming => '.$ipnc."\r\n";
 echo "\t".'PayPal IPN String Length Outgoing => '.strlen($postipn)."\r\n";
 echo "\t".'PayPal IPN Variable Count Incoming => ';
 print_r(count($_PAYPAL));
 echo "\r\n\t".'PayPal IPN Variable Count Outgoing => '.$ipnv."\r\n";
 if ($postmode == 1)
 {
 echo "\r\n\t".'IPN Validation Mode => Live -> PayPal, Inc.'; }
 elseif ($postmode == 2)
 {
 echo "\r\n\t".'IPN Validation Mode => Test -> EliteWeaver.'; }
 else
 {
 echo "\r\n\t".'IPN Validation Mode => Incorrect Mode Set!'; }
 echo "\r\n\r\n\t\t".'IPN Validate Response => '.$response;
 if (!$getrq && !$error)
 {
 echo "\r\n\t\t".'IPN Validate Method => POST (success)'."\r\n\r\n"; }
 elseif ($getrq && !$error)
 {
 echo "\r\n\t\t".'IPN Validate Method => GET (success)'."\r\n\r\n"; }
 elseif ($bmode)
 {
 echo "\r\n\t\t".'IPN Validate Method => NONE (stupid)'."\r\n\r\n"; }
 elseif ($error)
 {
 echo "\r\n\t\t".'IPN Validate Method => BOTH (failed)'."\r\n\r\n"; }
 else
 {
 echo "\r\n\t\t".'IPN Validate Method => BOTH (unknown)'."\r\n\r\n"; }
 echo '#########################################################'."\r\n";
 echo '#    THIS SCRIPT IS FREEWARE AND IS NOT FOR RE-SALE!    #'."\r\n";
 echo '#########################################################'."\r\n\r\n";
 @flush();</p><p>}</p><p>
// Terminate the socket connection (if open) and exit</p><p> @fclose ($socket); exit;</p><p>
#########################################################
#    Copyright © EliteWeaver UK All rights reserved.    #
#########################################################
#              END USER LICENCE AGREEMENT               #
# Redistribution and  use in source and/or binary forms #
# with or without  modification, are permitted provided #
# that the above copyright notice is  reproduced in the #
# script, documentation and/or any other materials that #
# may  have been provided in the original distribution. #
#########################################################
#    THIS SCRIPT IS FREEWARE AND IS NOT FOR RE-SALE!    #
#########################################################</p><p>?>







Imagem postada

comprar plano

#2 Joao Batista Neto

Joao Batista Neto

    Verschränkung

  • Administrators
  • 89 posts
  • LocationFranca/SP

Postado 15 March 2012 - 01:39 PM

Leandro,

Quando seu cliente escolher pagar com PayPal, ele será direcionado para o ambiente seguro do PayPal. Se ele já possuir uma conta, ele fará login e efetuará o pagamento.

Ao fazer a integração, você pode configurar um endereço para receber as notificações instantâneas de pagamento, que o PayPal enviará via POST sempre que um status de uma transação mudar.

Você encontrará informações sobre como implementar um manipulador para o IPN nesse link: https://www.paypal-b...to-instantaneo/
João Batista Neto
Desenvolvedor engenheiro de aplicações web

#3 Edluise Costa

Edluise Costa

    Member

  • Members
  • PipPip
  • 10 posts

Postado 17 March 2012 - 03:05 PM

Leandro,

Quando seu cliente escolher pagar com PayPal, ele será direcionado para o ambiente seguro do PayPal. Se ele já possuir uma conta, ele fará login e efetuará o pagamento.

Ao fazer a integração, você pode configurar um endereço para receber as notificações instantâneas de pagamento, que o PayPal enviará via POST sempre que um status de uma transação mudar.

Você encontrará informações sobre como implementar um manipulador para o IPN nesse link: https://www.paypal-b...to-instantaneo/


João,

O cliente é obrigado a ter uma conta no paypal para poder fazer o pagamento?!


Obrigado




0 usuário(s) está(ão) lendo este tópico

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)