1) Creati una cartella (chiamala tipo paypal) e ci metti un file php (chiamalo per esempio paypal_donation.php), questa sarebbe una classe per paypal già fatta e semplificata che trovai tempo fa su internet.
PHP:
<?php
class Donation {
private $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_donations';
private $options = array (
'item_name' => '',
'amount' => '',
'currency_code' => 'EUR',
'business' => '',
'rm' => 2,
'cbt' => 'Ritorna al sito',
'return' => '',
'cancel_return' => '',
'notify_url' => ''
);
private $status = null;
public function set_request_options($options) {
if (! is_array ( $options ))
exit ( "Options argument must be an array" );
if (! (isset ( $options ['item_name'] ) and isset ( $options ['amount'] ) and isset ( $options ['business'] ) and isset ( $options ['return'] ) and isset ( $options ['cancel_return'] )))
exit ( "Wrong argument passed" );
$this->options = array_merge ( $this->options, $options );
$this->status = 'options_checked';
$this->_buildurl ();
}
public function do_request() {
if ($this->status === 'options_checked') {
$url = $this->url;
header ( "Location: $url" );
exit ();
}
}
private function _buildurl() {
if ($this->status === 'options_checked') {
foreach ( $this->options as $k => $v ) {
$this->url .= '&' . $k . "=" . $v;
}
}
}
public function ipn() {
$host = gethostbyaddr ( $_SERVER ['REMOTE_ADDR'] );
if (!($host == "ipn.paypal.com" OR $host == "ipn.sandbox.paypal.com" OR $host == "paypal.com" OR $host == "sandbox.paypal.com")) {
return FALSE;
} else {
if ($_POST) {
$return = $_POST;
return $return;
} else {
return FALSE;
}
}
}
}
2) Sempre in quella cartella (paypal) ci metti vari file php che ti permetteranno di fare il redirect alla pagina pagamento (serviranno ai bottoni).
Tipo crea 1euro.php
PHP:
<?php
require_once 'paypal_donation.php'; //nome del file che contiene la classe
$options = array(
'item_name'=>'NomeDelOggettoDaVendere',
'amount'=>'1', // Quantità di denaro (1=1euro)
'business'=>'[email protected]',
'return'=>'http://sitotuo.lol/shop/index.php',
'notify_url'=>'http://sitotuo.lol/shop/controllo.php', //Link del controllo pagamento
'custom'=>'IlTuoNome', //Campo che potete usare come volete, per esempio per il nome dell'utente
'cancel_return'=>'http://sitotuo.lol/shop/index.php'); // Redirect se cancellano ordine
$paypal = new Donation();
$paypal->set_request_options($options); //Imposta le opzioni
$paypal->do_request(); //Esegue il redirect a paypal
Per i bottoni basta che usi <a href="1euro.php"><img src="ImmagineBottone.png"></a> ecc..
3) Ora creiamo un file php che controllerà il pagamento se è stato effettuato o no, e in caso positivo farà "qualcosa"..
Lo dobbiamo chiamare controllo.php perché sopra abbiamo messo questo link..
'notify_url'=>'
http://sitotuo.lol/shop/controllo.php', //Link del controllo pagamento
PHP:
<?php
require_once 'paypal/paypal_donation.php';
$paypal = new Donation();
$return = $paypal->ipn();
if($return){
$nome_utente = $return['custom'];
// Codice PHP eseguito dopo la verifica
.....
.....
Devi solo implementarlo al meglio in base al tuo sito, scusami se non mi sono spiegato troppo bene, ma vado di fretta..
Comunque questo che ti ho mostrato è uno dei più semplici script php che sfruttano le api paypal, in ogni modo con un po di pazienza si possono aggiungere anche altre funzioni come registrare dati pagamento su una tabella del database ecc..
Se hai problemi ti posso dare anche una mano su skype, ciao!