本文介绍了IPN模拟器返回错误“由于HTTP错误,我们无法发送IPN:500:内部服务器错误”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试将Paypal与我的网站集成。所以我从我的朋友那里得到了一些脚本,但每当我尝试测试notify_url时,它总会返回此错误。 由于HTTP错误,我们无法发送IPN:500:内部服务器错误。 这是我用于集成的脚本,PaypalObject.php <?php require_once ' ../ Functions / Database.php'; $ sendPayData = array( METHOD => BMCreateButton , VERSION => 65.2, USER => uttam2_api1.shop.com, PWD => PNCWS3M7K5MVF4E7, SIGNATURE => AFcWxV21C7fd0v3bYYYRCpSSRl31AVPqL7gWOG.x2DZiTRtu-E。 xAFPJ, BUTTONCODE => ENCRYPTED, BUTTONTYPE => BUYNOW, BUTTONSUBTYPE => SERVICES, BUTTONCOUNTRY => IN, 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://wrathoftitans.net/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 [' 点']); $ sendPayData [sprintf(' L_OPTION0PRICE%d', $ i )] = $ point [' price']; } $ sendPayData [ L_TEXTBOX0] = 帐户; $ context = stream_context_create(array( ' http' =>数组( ' method' => ' POST' , ' header' => 内容类型:application / x-www-form-urlencoded\r\ n, ' content' => http_build_query($ sendPayData), ' timeout' => 10, ), )); $ response = file_get_contents( https://api-3t.sandbox.paypal.com/nvp/,真实,$上下文); parse_str($ response,$ output); $ button = str_replace( \\, ,$ output [ WEBSITECODE]); print $ button ; ?> 这是监听器脚本DonateListener.php <?php require_once ' DonateIPNHandler.php'; require_once ' InstantPaymentNotification.php'; $ ipn = new InstantPaymentNotification(真的); $ ipn-> setIPNHandler( new DonateIPNHandler()); $ ipn-> listen(); ?> 这是InstantPaymentNotification.php <?php / * * * ObservadordeNotificaçõesdePagamentoInstantâneo * / 类 InstantPaymentNotification { / * * * @var string * / private $ endpoint = ' https://www.paypal.com'; / * * * @var IPNHandler * / private $ ipnHandler ; / * * * Constroi o objetoquereceberáasas notificaçõesdepagamento *instantâneas做PayPal .. * @param boolean $ sandbox定义seseráutilizadoo Sandbox * @throws InvalidArgumentException * / 公共函数__construct( $ sandbox = true){ if ( $ sandbox === true){ $ this-> endpoint = ' https://www.sandbox.paypal.com'; } $ this-> endpoint。= ' / cgi-bin / webscr?cmd = _notify-validate'; } / * * * Aguardapornotificaçõesdepagamentopustantânea; Caso uma nova *notificaçãosejarecebida,faz averificaçãoenotifica um manipulador * com o status(verificadaounão)e a mensagem recebida。 * @see InstantPaymentNotification :: setIPNHandler() * @throws BadMethodCallException Casoométodoshajachamado antes * de um manipulador ter sido definido ou nenhum email de recebedor * tenha sido informado。 * / 公共函数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->句柄( $ response == ' 已验证', $ _ POST ); } } } } else { throw new BadMethodCallException(' Nenhum manipulador de mensagem ou email foi definido'); } } / * * *定义o objeto queirámantruralasnotificaçõesdepagamento *instantâneasenviadaspelo PayPal。 * @param IPNHandler $ ipnHandler * / 公共函数setIPNHandler(IPNHandler $ ipnHandler ){ $ this-> ipnHandler = $ ipnHandler ; } } ?> 这是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数组$ message * @see IPNHandler :: handle() * / 公共函数句柄( $ isVerified ,array $ message ){ if ( $ isVerified ){ if ( $ message [' receiver_email'] == ' [email protected]'){ // file_put_conte nts('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' =>数组( ' 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 { 公共函数句柄( $ isVerified ,array $ message ); } ?> 这是PaypalPayment.php <?php class PaypalPayment { / * * * @var PDO * / private $ db ; / * * * @var PDOStatement * / private $ query ; / * * * @var Boolean * / private $ isStored = false; / * * *账户/点信息 * @var数组 * / private $ _ toDispatch = array(); 公共函数__construct(PDO $ dbConnection ){ $ this- > db = $ dbConnection ; $ this-> db-> setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION); $ this-> db-> setAttribute(PDO :: ATTR_TIMEOUT, 5 ); $ this-> db-> setAttribute(PDO :: ATTR_PERSISTENT,false); } 公共函数isValid(array $ data ){ $ item = isset( $ data [ item_name])? $ data [ item_name]: null ; $ check = isset( $ data [ 检查])? $ data [ check]: null ; if (!is_null( $ item )&&!is_null ( $ check )){ $ currency = isset( $ data [ mc_currency])? $ data [ mc_currency]: null ; if (!is_null( $ currency )&&!empty ( $ currency )){ $ pt = isset( $ data [ acct] [ dpoints])? (int) $ data [ acct] [ dpoints]: 0 ; if (is_numeric( $ pt )和( $ pt > 0 )){ $ gross = isset( $ data [ 总])? $ data [ gross]: null ; $ fields = array(' itemName',' checkName',' currency',' amount' ,' points'); $ this-> query = $ this-> db-> prepare(' SELECT * FROM`t_payment_validate` WHERE`' .inlodede(' `=?AND'', $ fields )。' `=?' ); $ this-> query-> bindValue( 1 , $ item ,PDO :: PARAM_STR); $ this-> query-> bindValue( 2 , $ check ,PDO :: PARAM_STR); $ this-> query-> bindValue( 3 , $ currency ,PDO :: PARAM_STR); $ this-> query-> bindValue( 4 , $ gross ,PDO :: PARAM_STR); $ this-> query-> bindValue( 5 , $ pt ,PDO :: PARAM_INT); $ this-> query-> execute(); $ _ objectFetched = $ this-> query-> fetch(PDO :: FETCH_ASSOC); return 数组( ' objectID' => $ _ objectFetched [' vid'], ' isValid' =>($ this-> query-> rowCount()=== 1 && $ this-> canHandlePaymentID ( $ data [ ID] ))?true:false ); } } } 返回虚假 } 公共函数storePayment(数组 $ data ){ $ _ validate = $ this-> isValid( $ data ); if ( $ _ validate [ isValid] === true){ // 重新检查 $ name = sprintf(' %s%s', $ data [ first_name], $ data [ last_name]); $fields = array ( 'name' , 'country' , 'city' , 'paymentStatus' , 'account' , 'email' , 'points' , 'amount' , 'currency' , 'status' , 'paymentID' ) ; $this->query = $this->db->prepare ( 'INSERT INTO `t_payments` ( `'. implode ( '`, `' , $fields ) .'` ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )' ) ; $this->query->bindValue ( 1 , $name , PDO::PARAM_STR ) ; $this->query->bindValue ( 2 , $data [ \"address_country\" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 3 , $data [ \"address_city\" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 4 , $data [ \"payment_status\" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 5 , $data [ \"acct\" ] [ \"account\" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 6 , $data [ \"email\" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 7 , $data [ \"acct\" ] [ \"dpoints\" ] , PDO::PARAM_INT ) ; $this->query->bindValue ( 8 , $data [ \"gross\" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 9 , $data [ \"mc_currency\" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 10 , \"Stored\" , PDO::PARAM_STR ) ; $this->query->bindValue ( 11 , $data [ \"ID\" ] , PDO::PARAM_STR ) ; $this->query->execute ( ) ; $this->_toDispatch = array ( 'account' => $data [ \"acct\" ] [ \"account\" ] , 'password' => $data [ \"acct\" ] [ \"password\" ] , 'points' => intval ( $data [ \"acct\" ] [ \"dpoints\" ] ) , '_objectID' => $this->db->lastInsertId ( ) ) ; $this->isStored = true ; } return $this ; } public function canHandlePaymentID ( $paymentID ) { $this->query = $this->db->prepare ( 'SELECT COUNT(*) AS `count` FROM `db_misc`.`t_payments` WHERE `paymentID` = :paymentID' ) ; $this->query->bindParam ( ':paymentID' , $paymentID , PDO::PARAM_STR ) ; $this->query->execute ( ) ; $data = $this->query->fetch ( PDO::FETCH_ASSOC ) ; return ( $data [ 'count' ] >= 1 ? false : true ) ; } public function dispatch ( ) { if ( $this->isStored === true ) { $this->query = $this->db->prepare ( 'SELECT * FROM `db_account`.`t_account` WHERE `name` = :name' ) ; $this->query->bindParam ( ':name' , $this->_toDispatch [ \"account\" ] , PDO::PARAM_STR ) ; $this->query->execute ( ) ; if ( $this->query->rowCount ( ) >= 1 ) { $data = $this->query->fetch ( PDO::FETCH_OBJ ) ; $this->query = $this->db->prepare ( 'UPDATE `db_account`.`t_account` SET `dp` = ( `dp` + :points ) WHERE `name` = :name' ) ; $this->query->bindParam ( ':name' , $this->_toDispatch [ \"account\" ] , PDO::PARAM_STR ) ; $this->query->bindParam ( ':points' , $this->_toDispatch [ \"points\" ] , PDO::PARAM_INT ) ; $this->query->execute ( ) ; $this->db->query ( 'UPDATE `t_payments` SET `status` = \"Dispatched\" WHERE `pid` = \"'. $this->_toDispatch [ \"_objectID\" ] .'\"' ) ; $this->query = $this->db->query ( 'SELECT * FROM `db_game`.`t_user` WHERE `accountid` = \"'. $data->accountid .'\"' ) ; foreach ( $this->query->fetchALl ( PDO::FETCH_OBJ ) as $character ) { $userName = $character [ 'name' ] ; $points = $this->_toDispatch [ \"points\" ] ; $message = sprintf ( 'Hello %s, You Have Recived %d D-Point%s' , $userName , $points , ( $points > 1 ) ? 's' : null ) ; $this->query = $this->db->prepare ( 'INSERT INTO `t_game_notification` ( `userName` , `message` ) VALUES ( :user , :message )' ) ; $this->query->bindParam ( ':user' , $userName , PDO::PARAM_STR ) ; $this->query->bindParam ( ':message' , $message , PDO::PARAM_STR ) ; $this->query->execute ( ) ; } $this->isStored = false ; $this->_toDispatch = array ( ) ; return true ; } else { $this->db->query ( 'UPDATE `t_payments` SET `status` = \"Invalid Account\" WHERE `pid` = \"'. $this->_toDispatch [ \"_objectID\" ] .'\"' ) ; return false ; } } else { return false ; } } } ?> This scripts should work like if buyer make successful payment then he will directly receive one message that you have purchase item(whatever he buy). and Buyer will receive the item for what he paid. and also this script should make some Entry in my Database. can someone help me to find whats the trouble in this all? 解决方案 sendPayData = array( \"METHOD\" => \"BMCreateButton\" , \"VERSION\" => \"65.2\" , \"USER\" => \"uttam2_api1.shop.com\" , \"PWD\" => \"PNCWS3M7K5MVF4E7\" , \"SIGNATURE\" => \"A FcWxV21C7fd0v3bYYYRCpSSRl31AVPqL7gWOG.x2DZiTRtu-E.xAFPJ\" , \"BUTTONCODE\" => \"ENCRYPTED\" , \"BUTTONTYPE\" => \"BUYNOW\" , \"BUTTONSUBTYPE\" => \"SERVICES\", \"BUTTONCOUNTRY\" => \"IN\", \"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://wrathoftitans.net/Paypal/DonateListener.php\"); db = GetDatabaseConnection ( 'db_misc' ) ; points =I am trying to integrate Paypal with my website. So i got some script from my friend but whenever i try to test notify_url its always returning this error. "We Could not send an IPN due to an HTTP error: 500: Internal Server Error."this is my scripts which i used for integration, PaypalObject.php<?phprequire_once '../Functions/Database.php' ;$sendPayData = array( "METHOD" => "BMCreateButton" ,"VERSION" => "65.2" ,"USER" => "uttam2_api1.shop.com" ,"PWD" => "PNCWS3M7K5MVF4E7" ,"SIGNATURE" => "AFcWxV21C7fd0v3bYYYRCpSSRl31AVPqL7gWOG.x2DZiTRtu-E.xAFPJ" ,"BUTTONCODE" => "ENCRYPTED" ,"BUTTONTYPE" => "BUYNOW" , "BUTTONSUBTYPE" => "SERVICES", "BUTTONCOUNTRY" => "IN","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://wrathoftitans.net/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" ;$context = stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'content' => http_build_query($sendPayData), 'timeout' => 10, ),));$response = file_get_contents("https://api-3t.sandbox.paypal.com/nvp/",true,$context);parse_str($response, $output);$button = str_replace("\\","",$output["WEBSITECODE"]);print $button;?> this is Listener script DonateListener.php<?php require_once 'DonateIPNHandler.php' ; require_once 'InstantPaymentNotification.php' ; $ipn = new InstantPaymentNotification ( true ) ; $ipn->setIPNHandler ( new DonateIPNHandler ( ) ) ; $ipn->listen ( ) ;?>this is InstantPaymentNotification.php<?php /** * Observador de Notificações de Pagamento Instantâneo */ class InstantPaymentNotification { /** * @var string */ private $endpoint = 'https://www.paypal.com' ; /** * @var IPNHandler */ private $ipnHandler ; /** * Constroi o objeto que receberá as notificações de pagamento * instantâneas do PayPal.. * @param boolean $sandbox Define se será utilizado o Sandbox * @throws InvalidArgumentException */ public function __construct ( $sandbox = true ) { if ( $sandbox === true ) { $this->endpoint = 'https://www.sandbox.paypal.com' ; } $this->endpoint .= '/cgi-bin/webscr?cmd=_notify-validate' ; } /** * Aguarda por notificações de pagamento instantânea; Caso uma nova * notificação seja recebida, faz a verificação e notifica um manipulador * com o status (verificada ou não) e a mensagem recebida. * @see InstantPaymentNotification::setIPNHandler() * @throws BadMethodCallException Caso o método seja chamado antes * de um manipulador ter sido definido ou nenhum email de recebedor * tenha sido informado. */ 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' ) ; } } /** * Define o objeto que irá manipular as notificações de pagamento * instantâneas enviadas pelo PayPal. * @param IPNHandler $ipnHandler */ public function setIPNHandler ( IPNHandler $ipnHandler ) { $this->ipnHandler = $ipnHandler ; } }?>This is 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' ] == '[email protected]' ) { //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 ( ) ; } } } } }?>This is IPNHandler.php<?php interface IPNHandler { public function handle ( $isVerified , array $message ) ; }?>This is PaypalPayment.php<?php class PaypalPayment { /** * @var PDO */ private $db ; /** * @var PDOStatement */ private $query ; /** * @var Boolean */ private $isStored = false ; /** * Account/Point Info * @var array */ private $_toDispatch = array ( ) ; public function __construct ( PDO $dbConnection ) { $this->db = $dbConnection ; $this->db->setAttribute ( PDO::ATTR_ERRMODE , PDO::ERRMODE_EXCEPTION ) ; $this->db->setAttribute ( PDO::ATTR_TIMEOUT , 5 ) ; $this->db->setAttribute ( PDO::ATTR_PERSISTENT , false ) ; } public function isValid ( array $data ) { $item = isset ( $data [ "item_name" ] ) ? $data [ "item_name" ] : null ; $check = isset ( $data [ "check" ] ) ? $data [ "check" ] : null ; if ( ! is_null ( $item ) && ! is_null ( $check ) ) { $currency = isset ( $data [ "mc_currency" ] ) ? $data [ "mc_currency" ] : null ; if ( ! is_null ( $currency ) && ! empty ( $currency ) ) { $pt = isset ( $data [ "acct" ] [ "dpoints" ] ) ? (int) $data [ "acct" ] [ "dpoints" ] : 0 ; if ( is_numeric ( $pt ) and ( $pt > 0 ) ) { $gross = isset ( $data [ "gross" ] ) ? $data [ "gross" ] : null ; $fields = array ( 'itemName' , 'checkName' , 'currency' , 'amount' , 'points' ) ; $this->query = $this->db->prepare ( 'SELECT * FROM `t_payment_validate` WHERE `' . implode ( '` = ? AND `' , $fields ) . '` = ?' ) ; $this->query->bindValue ( 1 , $item , PDO::PARAM_STR ) ; $this->query->bindValue ( 2 , $check , PDO::PARAM_STR ) ; $this->query->bindValue ( 3 , $currency , PDO::PARAM_STR ) ; $this->query->bindValue ( 4 , $gross , PDO::PARAM_STR ) ; $this->query->bindValue ( 5 , $pt , PDO::PARAM_INT ) ; $this->query->execute ( ) ; $_objectFetched = $this->query->fetch ( PDO::FETCH_ASSOC ) ; return array ( 'objectID' => $_objectFetched [ 'vid' ] , 'isValid' => ( $this->query->rowCount ( ) === 1 && $this->canHandlePaymentID ( $data [ "ID" ] ) ) ? true : false ) ; } } } return false ; } public function storePayment ( array $data ) { $_validate = $this->isValid ( $data ) ; if ( $_validate [ "isValid" ] === true ) { // do recheck $name = sprintf ( '%s %s' , $data [ "first_name" ] , $data [ "last_name" ] ) ; $fields = array ( 'name' , 'country' , 'city' , 'paymentStatus' , 'account' , 'email' , 'points' , 'amount' , 'currency' , 'status' , 'paymentID' ) ; $this->query = $this->db->prepare ( 'INSERT INTO `t_payments` ( `'. implode ( '`, `' , $fields ) .'` ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )' ) ; $this->query->bindValue ( 1 , $name , PDO::PARAM_STR ) ; $this->query->bindValue ( 2 , $data [ "address_country" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 3 , $data [ "address_city" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 4 , $data [ "payment_status" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 5 , $data [ "acct" ] [ "account" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 6 , $data [ "email" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 7 , $data [ "acct" ] [ "dpoints" ] , PDO::PARAM_INT ) ; $this->query->bindValue ( 8 , $data [ "gross" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 9 , $data [ "mc_currency" ] , PDO::PARAM_STR ) ; $this->query->bindValue ( 10 , "Stored" , PDO::PARAM_STR ) ; $this->query->bindValue ( 11 , $data [ "ID" ] , PDO::PARAM_STR ) ; $this->query->execute ( ) ; $this->_toDispatch = array ( 'account' => $data [ "acct" ] [ "account" ] , 'password' => $data [ "acct" ] [ "password" ] , 'points' => intval ( $data [ "acct" ] [ "dpoints" ] ) , '_objectID' => $this->db->lastInsertId ( ) ) ; $this->isStored = true ; } return $this ; } public function canHandlePaymentID ( $paymentID ) { $this->query = $this->db->prepare ( 'SELECT COUNT(*) AS `count` FROM `db_misc`.`t_payments` WHERE `paymentID` = :paymentID' ) ; $this->query->bindParam ( ':paymentID' , $paymentID , PDO::PARAM_STR ) ; $this->query->execute ( ) ; $data = $this->query->fetch ( PDO::FETCH_ASSOC ) ; return ( $data [ 'count' ] >= 1 ? false : true ) ; } public function dispatch ( ) { if ( $this->isStored === true ) { $this->query = $this->db->prepare ( 'SELECT * FROM `db_account`.`t_account` WHERE `name` = :name' ) ; $this->query->bindParam ( ':name' , $this->_toDispatch [ "account" ] , PDO::PARAM_STR ) ; $this->query->execute ( ) ; if ( $this->query->rowCount ( ) >= 1 ) { $data = $this->query->fetch ( PDO::FETCH_OBJ ) ; $this->query = $this->db->prepare ( 'UPDATE `db_account`.`t_account` SET `dp` = ( `dp` + :points ) WHERE `name` = :name' ) ; $this->query->bindParam ( ':name' , $this->_toDispatch [ "account" ] , PDO::PARAM_STR ) ; $this->query->bindParam ( ':points' , $this->_toDispatch [ "points" ] , PDO::PARAM_INT ) ; $this->query->execute ( ) ; $this->db->query ( 'UPDATE `t_payments` SET `status` = "Dispatched" WHERE `pid` = "'. $this->_toDispatch [ "_objectID" ] .'"' ) ; $this->query = $this->db->query ( 'SELECT * FROM `db_game`.`t_user` WHERE `accountid` = "'. $data->accountid .'"' ) ; foreach ( $this->query->fetchALl ( PDO::FETCH_OBJ ) as $character ) { $userName = $character [ 'name' ] ; $points = $this->_toDispatch [ "points" ] ; $message = sprintf ( 'Hello %s, You Have Recived %d D-Point%s' , $userName , $points , ( $points > 1 ) ? 's' : null ) ; $this->query = $this->db->prepare ( 'INSERT INTO `t_game_notification` ( `userName` , `message` ) VALUES ( :user , :message )' ) ; $this->query->bindParam ( ':user' , $userName , PDO::PARAM_STR ) ; $this->query->bindParam ( ':message' , $message , PDO::PARAM_STR ) ; $this->query->execute ( ) ; } $this->isStored = false ; $this->_toDispatch = array ( ) ; return true ; } else { $this->db->query ( 'UPDATE `t_payments` SET `status` = "Invalid Account" WHERE `pid` = "'. $this->_toDispatch [ "_objectID" ] .'"' ) ; return false ; } } else { return false ; } } }?>This scripts should work like if buyer make successful payment then he will directly receive one message that you have purchase item(whatever he buy). and Buyer will receive the item for what he paid. and also this script should make some Entry in my Database. can someone help me to find whats the trouble in this all? 解决方案 sendPayData = array( "METHOD" => "BMCreateButton" ,"VERSION" => "65.2" ,"USER" => "uttam2_api1.shop.com" ,"PWD" => "PNCWS3M7K5MVF4E7" ,"SIGNATURE" => "AFcWxV21C7fd0v3bYYYRCpSSRl31AVPqL7gWOG.x2DZiTRtu-E.xAFPJ" ,"BUTTONCODE" => "ENCRYPTED" ,"BUTTONTYPE" => "BUYNOW" , "BUTTONSUBTYPE" => "SERVICES", "BUTTONCOUNTRY" => "IN","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://wrathoftitans.net/Paypal/DonateListener.php");db = GetDatabaseConnection ( 'db_misc' ) ; points = 这篇关于IPN模拟器返回错误“由于HTTP错误,我们无法发送IPN:500:内部服务器错误”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-05 05:02