Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

ctlima

Paypal para Pagseguro

Recommended Posts

Olá pessoal

 

tenho um script de serviços online, com assinatura mensal para usuários pagantes, sistema com retorno automático em meu pequeno site que funciona com o paypal, gostaria de altera-lo pra usar o pagseguro:

 

Alguém poderia me ajudar ??

 

já tentei substituir as variáveis, mas não funciona...

 

 

O módulo do paypal é esse abaixo, será que alguém poderia me ajudar ?

 

<?php

$data = array(
	'name' => 'PayPal',
	'label' => 'paypal',
	'settings' => array(
		array(
			'name' => 'Email address',
			'label' => 'paypal_email',
			'type' => 'email',
			'items' => array(),
			'value' => '',
			'help' => 'Type in your PayPal email address.',
		),
		array(
			'name' => 'Currency',
			'label' => 'paypal_currency',
			'type' => 'select',
			'items' => array(
				'AUD' => '(AUD) Australian Dollar',
				'BRL' => '(BRL) Brazilian Real',
				'CAD' => '(CAD) Canadian Dollar',
				'CZK' => '(CZK) Czech Koruna',
				'DKK' => '(DKK) Danish Krone',
				'EUR' => '(EUR) Euro',
				'HKD' => '(HKD) Hong Kong Dollar',
				'HUF' => '(HUF) Hungarian Forint',
				'ILS' => '(ILS) Israeli New Sheqel',
				'JPY' => '(JPY) Japanese Yen',
				'MYR' => '(MYR) Malaysian Ringgit',
				'MXN' => '(MXN) Mexican Peso',
				'NOK' => '(NOK) Norwegian Krone',
				'NZD' => '(NZD) New Zealand Dollar',
				'PHP' => '(PHP) Philippine Peso',
				'PLN' => '(PLN) Polish Zloty',
				'GBP' => '(GBP) Pound Sterling',
				'SGD' => '(SGD) Singapore Dollar',
				'SEK' => '(SEK) Swedish Krona',
				'CHF' => '(CHF) Swiss Franc',
				'TWD' => '(TWD) Taiwan New Dollar',
				'THB' => '(THB) Thai Baht',
				'USD' => '(USD) U.S. Dollar',
			),
			'value' => '',
			'help' => 'Select preferred currency.',
		),
	),
);


//------------------------------------------------
// Payment form
//------------------------------------------------
function paypal_payment_form($package_id, $package_name, $package_amount, $package_group_id, $package_credits, $package_term_length, $package_term_type, $package_recurring)
{
	global $DB, $PREFS, $SESSION, $LANG, $TEMPLATE;


	paypal_fetch_settings();


	$post_url = $PREFS->conf['debug'] == 2 ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';
	$notify_url = $PREFS->conf['fancy_urls'] ? 'account/upgrade/ipn/paypal/' : 'index.php?m=account_upgrade&p=ipn&id=paypal';
	$return_url = $PREFS->conf['fancy_urls'] ? 'account/upgrade/success/' : 'index.php?m=account_upgrade&p=success';
	$cancel_url = $PREFS->conf['fancy_urls'] ? 'account/upgrade/' : 'index.php?m=account_upgrade';


    if ( $package_term_type == 1 ) {
        $package_term_type = "D";
	}
    elseif ( $package_term_type == 2 ) {
        $package_term_type = "M";
	}
    elseif ( $package_term_type == 3 ) {
        $package_term_type = "Y";
	}


	if ( $package_recurring ) {
		$html = '
		<form name="paypal_payment_form" method="post" action="'.$post_url.'">
			<input type="image" src="'.VIR_PATH.'media/paypal_button.gif" name="submit" />
			<input type="hidden" name="cmd" value="_xclick-subscriptions" />
			<input type="hidden" name="src" value="1" />
			<input type="hidden" name="sra" value="1" />
			<input type="hidden" name="quantity" value="1" />
			<input type="hidden" name="no_note" value="1" />
			<input type="hidden" name="no_shipping" value="1" />
			<input type="hidden" name="rm" value="2" />
			<input type="hidden" name="charset" value="utf8" />
			<input type="hidden" name="p3" value="'.$package_term_length.'" />
			<input type="hidden" name="t3" value="'.$package_term_type.'" />
			<input type="hidden" name="business" value="'.$PREFS->conf['gateways']['paypal']['paypal_email'].'" />
			<input type="hidden" name="item_name" value="'.htmlentities2utf8($package_name).'" />
			<input type="hidden" name="item_number" value="'.$SESSION->conf['member_id'].'" />
			<input type="hidden" name="custom" value="'.$package_id.'" />
			<input type="hidden" name="a3" value="'.$package_amount.'" />
			<input type="hidden" name="currency_code" value="'.$PREFS->conf['gateways']['paypal']['paypal_currency'].'" />
			<input type="hidden" name="cancel_return" value="'.VIR_PATH.$cancel_url.'" />
			<input type="hidden" name="return" value="'.VIR_PATH.$return_url.'" />
			<input type="hidden" name="notify_url" value="'.VIR_PATH.$notify_url.'" />
		</form>';
	}
	else {
		$html = '
		<form name="paypal_payment_form" method="post" action="'.$post_url.'">
			<input type="image" src="'.VIR_PATH.'media/paypal_button.gif" name="submit" />
			<input type="hidden" name="cmd" value="_xclick" />
			<input type="hidden" name="quantity" value="1" />
			<input type="hidden" name="no_note" value="1" />
			<input type="hidden" name="no_shipping" value="1" />
			<input type="hidden" name="rm" value="2" />
			<input type="hidden" name="charset" value="utf8" />
			<input type="hidden" name="business" value="'.$PREFS->conf['gateways']['paypal']['paypal_email'].'" />
			<input type="hidden" name="item_name" value="'.htmlentities2utf8($package_name).'" />
			<input type="hidden" name="item_number" value="'.$SESSION->conf['member_id'].'" />
			<input type="hidden" name="custom" value="'.$package_id.'" />
			<input type="hidden" name="amount" value="'.$package_amount.'" />
			<input type="hidden" name="currency_code" value="'.$PREFS->conf['gateways']['paypal']['paypal_currency'].'" />
			<input type="hidden" name="cancel_return" value="'.VIR_PATH.$cancel_url.'" />
			<input type="hidden" name="return" value="'.VIR_PATH.$return_url.'" />
			<input type="hidden" name="notify_url" value="'.VIR_PATH.$notify_url.'" />
		</form>';
	}

	return $html;
}


//------------------------------------------------
// Process payment
//------------------------------------------------
function paypal_ipn()
{
	global $DB, $PREFS, $SESSION, $LANG, $TEMPLATE;


	if ( !count($_POST) ) return;
	paypal_fetch_settings();


	$success = 0;
	$postipn = 'cmd=_notify-validate';
	foreach ($_POST as $key => $value)
	{
		$value = urlencode(stripslashes($value));
		$postipn .= "&$key=$value";
	}


	$socket = @fsockopen(($PREFS->conf['debug'] == 2 ? "www.sandbox.paypal.com" : "www.paypal.com"), 80, $errno, $errstr, 30);
	if ( !$socket ) return;


	$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
	$header.= "Host: " . ($PREFS->conf['debug'] == 2 ? "www.sandbox.paypal.com" : "www.paypal.com") . "\r\n";
	$header.= "Content-Type: application/x-www-form-urlencoded\r\n";
	$header.= "Content-Length: ".strlen($postipn)."\r\n\r\n";


	@fputs($socket, $header.$postipn);
	while(!feof($socket))
	{
		$reply = @fgets($socket, 1024);
		$reply = @trim($reply);
	}

	@fclose ($socket);
	if ( strtolower($reply) != "verified" ) return;


	$member_id = isset($_POST['item_number']) ? intval($_POST['item_number']) : '';
	$package_id = isset($_POST['custom']) ? intval($_POST['custom']) : '';
	$txn_id = isset($_POST['txn_id']) ? mysql_real_escape_string($_POST['txn_id']) : '';
	$payment_amount = isset($_POST['mc_gross']) ? $_POST['mc_gross'] : '';
	$payment_currency = isset($_POST['mc_currency']) ? $_POST['mc_currency'] : '';


	if ( strtolower($_POST['payment_status']) != "completed" || ( strtolower($_POST['txn_type']) != "subscr_payment" && strtolower($_POST['txn_type']) != "web_accept") ) return;
	if ( strtolower($_POST['receiver_email']) != strtolower($PREFS->conf['gateways']['paypal']['paypal_email']) && strtolower($_POST['business']) != strtolower($PREFS->conf['gateways']['paypal']['paypal_email']) ) return;


	$result = $DB->query("SELECT * FROM " . DB_PREFIX . "packages WHERE package_id='$package_id' LIMIT 1");
	if ( !$DB->num_rows($result) ) return;
	$obj = $DB->fetch_object($result);

	$package_price = $obj->price;
	$package_term = $obj->term;
	$package_type = $obj->termtype;
	$package_credits = $obj->credits;
	$new_group_id = $obj->group_id;


	$result = $DB->query("SELECT order_id FROM " . DB_PREFIX . "orders WHERE txn_id='paypal".$txn_id."' LIMIT 1");
	if ( $DB->num_rows($result) ) return;


	if ( $payment_amount != $package_price  ||  strtolower($payment_currency) != strtolower($PREFS->conf['gateways']['paypal']['paypal_currency']) ) return;


	$DB->query("INSERT INTO " . DB_PREFIX . "orders (member_id, txn_id, paymentdate, amount, credits, term, termtype)
				VALUES('$member_id', 'paypal".$txn_id."', '" . time() . "', '$package_price', '$package_credits', '$package_term', '$package_type')");

	set_membership_term($member_id, $new_group_id, $package_type, $package_term, $package_credits);
}


//------------------------------------------------
// Fetch settings
//------------------------------------------------
function paypal_fetch_settings()
{
	global $DB, $PREFS;

	$result = $DB->query("SELECT * FROM " . DB_PREFIX . "payment_gateways WHERE label='paypal' LIMIT 1");

	if ($DB->num_rows($result))
	{
		$obj = $DB->fetch_object($result);
		$PREFS->conf['gateways']['paypal'] = @unserialize($obj->settings);
	}
}


?>

Pago R$50 pra quem fizer funcionar....

Compartilhar este post


Link para o post
Compartilhar em outros sites

ctlima,

 

Substituir valores e variáveis realmente não vai fazer funcionar. Você precisa adaptar o seu plugin aos procedimentos do PagSeguro, todo o fluxo. Apesar de o serviço ser muito parecido, muita coisa muda no fluxo de pagamento.

 

Abs

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.