需要Paypal IPN脚本的一些帮助 [英] Need some help with Paypal IPN script
问题描述
Hello CodeProject,
我有一些Paypal IPN脚本的脚本,但它根本不起作用,但我确信这个脚本对我很有用。
这里是这个脚本
这是显示所有内容的主文件
Index.php: -
< script 类型 = text / javascript >
$( window )。on(' load', function (){
var _defaultContent = $(' #paypal-load')。 html();
$ .ajax({
async : true ,
cache: false ,
data: new Object(),
成功: function (内容){
var _response = $(' < center />')。 HTML(内容);
$(' #paypal-load')。html(_response.hide()) ;
$(' #paypal-load')。find(' center')。fadeIn();
},
url:' <?php echo BaseURLConcat(' Paypal /PaypalObject.php' )?>'
});
$(' input [type =image] [name =submit]')。live(' 点击',功能(e){
var src = $( this )。attr(' src');
var account = $(' input [name =os1] [type =text]') ;
if (account.val()。toString()。length === 0 ){
$(' #response')。html(' < span class =inline-help> 帐号不能是。空< /跨度>'跨度>);
account.focus();
} 其他 {
var status = 假跨度>;
$ .post(' <?php echo BaseURLConcat(' check-account.php ' )?>',{
' isAjax':' true',
' account':account.val()
} , function (data){
var resp = data;
if (resp == ' false'){
$(' #response')。html(' < span class =inline-help> Account ' + account.val()+ ' 不存在,请插入您的有效帐户。< / span>');
account.val( new String ());
} else {
$(' #response')。html( new String ());
$(' #paypal-load center form')。submit();
}
});
}
e.preventDefault();
});
});
< / script >
PAYPAL_OBJECT.PHP(这是链接的文件index.php): -
<?php
require_once ' ../ Functions / Database.php';
$ sendPayData = array(
METHOD => BMCreateButton,
VERSION => 65.2,
USER => ; frozentalisman_api1.gmail.com,
PWD => B2PBUNCKASY8GSQZ,
SIGNATURE => AbPDCHpF-e45tePhvejMCawkga.bAXLdJIfnQ qAbBxpaOu5FbKjXuY90,
BUTTONCODE => ENCRYPTED,
BUTTONTYPE => BUYNOW,
BUTTONSUBTYPE => SERVICES,
BUTTONCOUNTRY => RO,
BUTTONIMAGE => reg,
BUYNOWTEXT => BUYNOW,
L_BUTTONVAR1 => item_name =冷冻护身符D-Points,
L_BUTTONVAR2 => currency_code = USD,
L_BUTTONVAR3 => no_shipping = 2,
L_BUTTONVAR4 => no_note = 1,
L_BUTTONVAR5 => notify_url = http://frozentalisman.com/Paypal/DonateListener.php,
);
$ db = GetDatabaseConnection(' db_misc');
$ points = $ db-> query(' SELECT * FROM`t_point_sale`ORDER BY`points`') - > fetchAll(PDO :: FETCH_ASSOC);
$ sendPayData [ OPTION0NAME] = D-Points;
foreach ( $ points as $ i => $ point ){
$ sendPayData [sprintf(' L_OPTION0SELECT%d', $ i )] = sprintf(' %d D-Points', $ point [' points' ]);
$ sendPayData [sprintf(' L_OPTION0PRICE% d', $ i )] = $ point [' price'];
}
$ sendPayData [ L_TEXTBOX0] = 帐户;
$ curl = curl_init();
curl_setopt( $ curl ,CURLOPT_RETURNTRANSFER,true);
curl_setopt( $ curl ,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt( $ curl ,CURLOPT_URL,' https://api-3t.paypal.com/nvp?' .http_build_query( $ sendPayData ));
$ nvpPayReturn = curl_exec( $ curl );
curl_close( $ curl );
$ output = array();
parse_str( $ nvpPayReturn , $ output );
if (isset( $ output [ WEBSITECODE])){
$ html = < span class =code-sdkkeyword> $ output [ WEBSITECODE];
echo $ html ;
}
DONATELISTENER.PHP: -
< pre lang =PHP> <?php
require_once ' < span class =code-string> DonateIPNHandler.php';
require_once ' InstantPaymentNotification.php';
$ ipn = new InstantPaymentNotification(true);
$ ipn-> setIPNHandler( new DonateIPNHandler());
$ ipn-> listen();
DonateIPNHandler.php: -
<?php
require_once ' IPNHandler.php';
require_once ' ../ Functions / Database.php';
require_once ' PaypalPayment.php';
/ * *
* Manipulador de exemplodeNotificaçãodePagamento
*Instantâneo
* /
class DonateIPNHandler实现IPNHandler {
private $ db , $ query ;
/ * *
* @param boolean $ isVerified
* @param array $消息
* @see IPNHandler :: handle()
* /
公共函数句柄( $ isVerified ,数组 $ message ){
if ( $ isVerified ){
if ( $ message [' receiver_email'] == ' frozentalisman@gmail.com'){
// file_put_contents('test.text ',print_r($ message,true),FIL E_APPEND);
$ data =数组(
' < span class =code-string> first_name' => $ message [' first_name'],
' last_name' => $ message [' last_name'],
' address_country' => $ message [' address_country'],
' address_city' => $ message [' address_city'],
' 数量' => (int) $ message [' quantity'],
' payment_status' => $ message [' payment_status'],
' item_name' => $ message [' item_name'],
' mc_currency' => $ message [' mc_currency'],
' gross' => $ message [' payment_gross'],
' acct' =>数组(
' account' => $ message [' option_selection2'],
' dpoints' => preg_replace(' / [^ \d] /', null , $ message [' option_selection1'])
),
' check' => $ message [' option_selection1'],
' email' => $ message [' payer_email'],
' ID' => $ message [' ipn_track_id']
);
$ paypalPayment = new PaypalPayment(GetDatabaseConnection( ' db_misc'));
$ _ validate = $ paypalPayment-> isValid( $ data );
if ( $ _ validate [ isValid] === true){
$ paypalPayment-> storePayment( $ data ) - > dispatch();
}
}
}
}
}
InstantPaymentNotification.php: -
<?php
class InstantPaymentNotification {
private $ endpoint = ' https://www.paypal.com';
公共函数__construct( $ sandbox = false){
if ( $ sandbox === false){
$ this-> endpoint = ' https://www.sandbox.paypal.com';
}
$ this-> endpoint。= ' / cgi-bin / webscr?cmd = _notify-validate';
}
public function listen(){
if ($ this-> ipnHandler!== null ){
if ($ _SERVER [' REQUEST_METHOD'] == ' POST'){
if (filter_input(INPUT_POST,' receiver_email',FILTER_VALIDATE_EMAIL)){
$ curl = curl_init();
curl_setopt( $ curl ,CURLOPT_URL,$ this-> endpoint);
curl_setopt( $ curl ,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt( $ curl ,CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ curl ,CURLOPT_POST, 1 );
curl_setopt( $ curl ,CURLOPT_POSTFIELDS,http_build_query( $ _ POST ));
$ response = curl_exec( $ curl );
$ error = curl_error( $ curl );
$ errno = curl_errno( $ curl );
curl_close( $ curl );
if (空( $ error )&&& $ errno == 0 ){
$ this-> ipnHandler-> handle( $ response == ' 已验证', $ _ POST );
}
}
}
} 其他 {
throw new BadMethodCallException(' Nenhum manipulador de mensagem ou email foi definido');
}
}
公共函数setIPNHandler(IPNHandler $ ipnHandler ){
$ this-> ipnHandler = $ ipnHandler ;
}
}
DonateIPNHandler.php: -
<?php
require_once ' IPNHandler.php';
require_once ' ../ Functions / Database.php';
require_once ' PaypalPayment.php';
class DonateIPNHandler实现IPNHandler {
private $ db , $ query ;
公共函数句柄( $ isVerified ,array $ message ){
if ( $ isVerified ){
if ( $ message [' receiver_email' ] == ' frozentalisman@gmail.com'){
// file_put_contents('test.text',print_r($ message,true),FILE_APPEND);
$ data = array(
' first_name' => $ message [' first_name'],
' last_name' => $ message [' last_name'],
' address_country' => $ message [' address_country'],
' address_city' => $ message [' address_city'],
' 数量' => (int) $ message [' quantity'],
' payment_status' => $ message [' payment_status'],
' item_name' => $ message [' item_name'],
' mc_currency' => $ message [' mc_currency'],
' gross' => $ message [' payment_gross'],
' acct' =>数组(
' account' => $ message [' option_selection2'],
' dpoints' => preg_replace(' / [^ \d] /', null , $ message [' option_selection1'])
),
' check' => $ message [' option_selection1'],
' email' => $ message [' payer_email'],
' ID' => $ message [' ipn_track_id']
);
$ paypalPayment = new PaypalPayment(GetDatabaseConnection( ' db_misc'));
$ _ validate = $ paypalPayment-> isValid( $ data );
if ( $ _ validate [ isValid] === true){
$ paypalPayment-> storePayment( $ data )->dispatch ( ) ;
}
}
}
}
}
IPNHandler.php :-
<?php
interface IPNHandler {
public function handle ( $isVerified , array $message ) ;
}
This is all script which contains Paypal things :)
Here is explanation how this all works. :-
User Purchase Points with Paypal and he will get automatically Points. so its just one kind of IPN Buttons, but i am not sure if it is just that.
i can attach files if need please help me to make it work.
hope its not too long :)
and thanks in advance for help..
(window).on('load', function(){
var _defaultContent =
('#paypal-load').html();
.ajax({
async : true ,
cache : false ,
data : new Object ( ) ,
success : function ( content ) {
var _response =
Hello CodeProject,
I have some scripts for Paypal IPN scripts, but it's not working at all, but i am sure this script is useful for me.
Here is this scripts
This is main file which display all content
Index.php :-
<script type="text/javascript">
$(window).on('load', function(){
var _defaultContent = $('#paypal-load').html();
$.ajax({
async : true ,
cache : false ,
data : new Object ( ) ,
success : function ( content ) {
var _response = $('<center />').html(content);
$('#paypal-load').html(_response.hide());
$('#paypal-load').find('center').fadeIn();
} ,
url : '<?php echo BaseURLConcat ( 'Paypal/PaypalObject.php' ) ?>'
});
$('input[type="image"][name="submit"]').live('click',function(e){
var src = $(this).attr('src');
var account = $('input[name="os1"][type="text"]');
if(account.val().toString().length === 0){
$('#response').html('<span class="inline-help">The account number cannot be empty.</span>');
account.focus();
}else{
var status = false;
$.post('<?php echo BaseURLConcat('check-account.php') ?>',{
'isAjax' : 'true' ,
'account' : account.val()
},function(data){
var resp = data ;
if(resp == 'false'){
$('#response').html('<span class="inline-help">Account '+account.val()+' does not exists, please insert your valid account.</span>');
account.val(new String());
} else {
$('#response').html(new String());
$('#paypal-load center form').submit();
}
}) ;
}
e.preventDefault();
});
});
</script>
PAYPAL_OBJECT.PHP (This is the file which linked on index.php) :-
<?php
require_once '../Functions/Database.php' ;
$sendPayData = array (
"METHOD" => "BMCreateButton" ,
"VERSION" => "65.2" ,
"USER" => "frozentalisman_api1.gmail.com" ,
"PWD" => "B2PBUNCKASY8GSQZ" ,
"SIGNATURE" => "AbPDCHpF-e45tePhvejMCawkga.bAXLdJIfnQqAbBxpaOu5FbKjXuY90" ,
"BUTTONCODE" => "ENCRYPTED" ,
"BUTTONTYPE" => "BUYNOW" ,
"BUTTONSUBTYPE" => "SERVICES" ,
"BUTTONCOUNTRY" => "RO" ,
"BUTTONIMAGE" => "reg" ,
"BUYNOWTEXT" => "BUYNOW" ,
"L_BUTTONVAR1" => "item_name=Frozen Talisman D-Points" ,
"L_BUTTONVAR2" => "currency_code=USD" ,
"L_BUTTONVAR3" => "no_shipping=2" ,
"L_BUTTONVAR4" => "no_note=1" ,
"L_BUTTONVAR5" => "notify_url=http://frozentalisman.com/Paypal/DonateListener.php" ,
) ;
$db = GetDatabaseConnection ( 'db_misc' ) ;
$points = $db->query ( 'SELECT * FROM `t_point_sale` ORDER BY `points`' )->fetchAll ( PDO::FETCH_ASSOC ) ;
$sendPayData [ "OPTION0NAME" ] = "D-Points" ;
foreach ( $points as $i => $point ) {
$sendPayData [ sprintf ( 'L_OPTION0SELECT%d' , $i ) ] = sprintf ( '%d D-Points' , $point [ 'points' ] ) ;
$sendPayData [ sprintf ( 'L_OPTION0PRICE%d' , $i ) ] = $point [ 'price' ] ;
}
$sendPayData [ "L_TEXTBOX0" ] = "Account" ;
$curl = curl_init ( ) ;
curl_setopt ( $curl , CURLOPT_RETURNTRANSFER , true ) ;
curl_setopt ( $curl , CURLOPT_SSL_VERIFYPEER , false ) ;
curl_setopt ( $curl , CURLOPT_URL , 'https://api-3t.paypal.com/nvp?' . http_build_query ( $sendPayData ) ) ;
$nvpPayReturn = curl_exec ( $curl ) ;
curl_close ( $curl ) ;
$output = array ( ) ;
parse_str ( $nvpPayReturn , $output ) ;
if ( isset ( $output [ "WEBSITECODE" ] ) ) {
$html = $output [ "WEBSITECODE" ] ;
echo $html ;
}
DONATELISTENER.PHP :-
<?php
require_once 'DonateIPNHandler.php' ;
require_once 'InstantPaymentNotification.php' ;
$ipn = new InstantPaymentNotification ( true ) ;
$ipn->setIPNHandler ( new DonateIPNHandler ( ) ) ;
$ipn->listen ( ) ;
DonateIPNHandler.php :-
<?php
require_once 'IPNHandler.php' ;
require_once '../Functions/Database.php' ;
require_once 'PaypalPayment.php' ;
/**
* Manipulador de exemplo de Notificação de Pagamento
* Instantâneo
*/
class DonateIPNHandler implements IPNHandler {
private $db , $query ;
/**
* @param boolean $isVerified
* @param array $message
* @see IPNHandler::handle()
*/
public function handle ( $isVerified , array $message ) {
if ( $isVerified ) {
if ( $message [ 'receiver_email' ] == 'frozentalisman@gmail.com' ) {
//file_put_contents('test.text', print_r($message, true), FILE_APPEND);
$data = array (
'first_name' => $message [ 'first_name' ] ,
'last_name' => $message [ 'last_name' ] ,
'address_country' => $message [ 'address_country' ] ,
'address_city' => $message [ 'address_city' ] ,
'quantity' => ( int ) $message [ 'quantity' ] ,
'payment_status' => $message [ 'payment_status' ] ,
'item_name' => $message [ 'item_name' ] ,
'mc_currency' => $message [ 'mc_currency' ] ,
'gross' => $message [ 'payment_gross' ] ,
'acct' => array (
'account' => $message [ 'option_selection2' ] ,
'dpoints' => preg_replace ( '/[^\d]/' , null , $message [ 'option_selection1' ] )
) ,
'check' => $message [ 'option_selection1' ] ,
'email' => $message [ 'payer_email' ] ,
'ID' => $message [ 'ipn_track_id' ]
) ;
$paypalPayment = new PaypalPayment ( GetDatabaseConnection ( 'db_misc' ) ) ;
$_validate = $paypalPayment->isValid ( $data ) ;
if ( $_validate [ "isValid" ] === true ) {
$paypalPayment->storePayment ( $data )->dispatch ( ) ;
}
}
}
}
}
InstantPaymentNotification.php :-
<?php
class InstantPaymentNotification {
private $endpoint = 'https://www.paypal.com' ;
public function __construct ( $sandbox = false ) {
if ( $sandbox === false ) {
$this->endpoint = 'https://www.sandbox.paypal.com' ;
}
$this->endpoint .= '/cgi-bin/webscr?cmd=_notify-validate' ;
}
public function listen () {
if ( $this->ipnHandler !== null ) {
if ( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) {
if ( filter_input ( INPUT_POST , 'receiver_email' , FILTER_VALIDATE_EMAIL ) ) {
$curl = curl_init ( ) ;
curl_setopt ( $curl , CURLOPT_URL , $this->endpoint ) ;
curl_setopt ( $curl , CURLOPT_SSL_VERIFYPEER , false ) ;
curl_setopt ( $curl , CURLOPT_RETURNTRANSFER , 1 ) ;
curl_setopt ( $curl , CURLOPT_POST , 1 ) ;
curl_setopt ( $curl , CURLOPT_POSTFIELDS , http_build_query ( $_POST ) ) ;
$response = curl_exec ( $curl ) ;
$error = curl_error ( $curl ) ;
$errno = curl_errno ( $curl ) ;
curl_close ( $curl ) ;
if ( empty ( $error ) && $errno == 0 ) {
$this->ipnHandler->handle ( $response == 'VERIFIED' , $_POST ) ;
}
}
}
} else {
throw new BadMethodCallException ( 'Nenhum manipulador de mensagem ou email foi definido' ) ;
}
}
public function setIPNHandler ( IPNHandler $ipnHandler ) {
$this->ipnHandler = $ipnHandler ;
}
}
DonateIPNHandler.php :-
<?php
require_once 'IPNHandler.php' ;
require_once '../Functions/Database.php' ;
require_once 'PaypalPayment.php' ;
class DonateIPNHandler implements IPNHandler {
private $db , $query ;
public function handle ( $isVerified , array $message ) {
if ( $isVerified ) {
if ( $message [ 'receiver_email' ] == 'frozentalisman@gmail.com' ) {
//file_put_contents('test.text', print_r($message, true), FILE_APPEND);
$data = array (
'first_name' => $message [ 'first_name' ] ,
'last_name' => $message [ 'last_name' ] ,
'address_country' => $message [ 'address_country' ] ,
'address_city' => $message [ 'address_city' ] ,
'quantity' => ( int ) $message [ 'quantity' ] ,
'payment_status' => $message [ 'payment_status' ] ,
'item_name' => $message [ 'item_name' ] ,
'mc_currency' => $message [ 'mc_currency' ] ,
'gross' => $message [ 'payment_gross' ] ,
'acct' => array (
'account' => $message [ 'option_selection2' ] ,
'dpoints' => preg_replace ( '/[^\d]/' , null , $message [ 'option_selection1' ] )
) ,
'check' => $message [ 'option_selection1' ] ,
'email' => $message [ 'payer_email' ] ,
'ID' => $message [ 'ipn_track_id' ]
) ;
$paypalPayment = new PaypalPayment ( GetDatabaseConnection ( 'db_misc' ) ) ;
$_validate = $paypalPayment->isValid ( $data ) ;
if ( $_validate [ "isValid" ] === true ) {
$paypalPayment->storePayment ( $data )->dispatch ( ) ;
}
}
}
}
}
IPNHandler.php :-
<?php
interface IPNHandler {
public function handle ( $isVerified , array $message ) ;
}
This is all script which contains Paypal things :)
Here is explanation how this all works. :-
User Purchase Points with Paypal and he will get automatically Points. so its just one kind of IPN Buttons, but i am not sure if it is just that.
i can attach files if need please help me to make it work.
hope its not too long :)
and thanks in advance for help..
(window).on('load', function(){ var _defaultContent =
('#paypal-load').html();
.ajax({ async : true , cache : false , data : new Object ( ) , success : function ( content ) { var _response =
这篇关于需要Paypal IPN脚本的一些帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!