Esempio n. 1
0
 public function run()
 {
     $event = new PPEvent($this);
     /* If transaction id is missing, it's logged and a failure event is raised */
     // 2010-10-28: TESTED OK
     //		if (!isset($_POST['txn_id'])) {
     //			$event->msg = "IPN Listner recieved an HTTP request without a Transaction ID.";
     //			Yii::log($event->msg, "error", "payPal.controllers.ipn.PPIpnAction");
     //			$this->onFailure($event);
     //			return;
     //		}
     /** Send IPN Request (HTTP POST) to PayPal **/
     // 2010-10-28: TESTED OK
     $event->requestAr = array_merge(array("cmd" => "_notify-validate"), $_POST);
     $postVars = PPUtils::implode('&', PPUtils::urlencode($event->requestAr));
     $response = PPUtils::httpPost(PPUtils::getUrl(PPUtils::IPN), $postVars, false);
     /** If IPN request fails it is logged and a failure event is raised **/
     // 2010-10-28: TESTED OK
     if ($response["status"] == false) {
         $respstr = print_r($response, true);
         Yii::log($respstr, "error", "payPal.controllers.ipn.PPIpnAction");
         $event->msg = "HTTP POST request to PayPal failed";
         Yii::log("{$event->msg}\nRequest:\n{$postVars}", "error", "payPal.controllers.ipn.PPIpnAction");
         $this->onFailure($event);
         return;
     }
     // It will only be one line in the response
     $event->responseAr = explode("\n", $response["httpResponse"]);
     /** If PayPal is unable to verify a request it is logged and a failure event is raised **/
     // 2010-10-28: TESTED OK
     if (count($event->responseAr) < 1 || $event->responseAr[0] != 'VERIFIED') {
         $event->msg = "IPN request failed";
         Yii::log("{$event->msg}\nRequest:\n{$postVars}\nResponse:\n{$response["httpResponse"]}", "error", "payPal.controllers.ipn.PPIpnAction");
         $this->onFailure($event);
         return;
     }
     /** Log successfull request and raise a onRequest event */
     // 2010-10-28: TESTED OK
     $event->details = $event->requestAr;
     $event->msg = "Successfull IPN request";
     Yii::log("{$event->msg}\nRequest:\n{$postVars}\nResponse:\n{$response["httpResponse"]}", "info", "payPal.controllers.ipn.PPIpnAction");
     $this->onRequest($event);
 }
Esempio n. 2
0
 private static function log($msg, $level, $requestAr = null, $responseAr = null)
 {
     if ($requestAr != null) {
         $msg .= "\nRequest: " . PPUtils::implode("&", $requestAr);
     }
     if ($responseAr != null) {
         $msg .= "\nResponse: " . PPUtils::implode("&", $responseAr);
     }
     Yii::log($msg, $level, "payPal.components.PPButtonManager");
 }
Esempio n. 3
0
 public function run()
 {
     $event = new PPEvent($this);
     /** If transaction id is missing, it's logged and a failure event is raised **/
     // 2010-10-28: TESTED OK
     if (!isset($_GET['tx'])) {
         $event->msg = "PDT received an HTTP GET request without a transaction ID.";
         Yii::log($event->msg, "error", "payPal.controllers.pdt.PPPdtAction");
         $this->onFailure($event);
         return;
     }
     /** Send PDT Request to PayPal **/
     // 2010-10-28: TESTED OK
     $event->requestAr = array('cmd' => '_notify-synch', 'tx' => $_GET['tx'], 'at' => Yii::app()->getModule('payPal')->account->identityToken);
     $getVars = PPUtils::implode('&', PPUtils::urlencode($event->requestAr));
     $response = PPUtils::httpPost(PPUtils::getUrl(PPUtils::PDT), $getVars, false);
     /** If PDT request fails it is logged and a failure event is raised **/
     // 2010-10-28: TESTED OK
     if ($response["status"] == false) {
         $event->msg = "HTTP POST request to PayPal failed";
         Yii::log("{$event->msg}\nRequest:\n{$getVars}", "error", "payPal.controllers.pdt.PPPdtAction");
         $this->onFailure($event);
         return;
     }
     $responseAr = explode("\n", $response['httpResponse']);
     /** If PayPal is unable to verify a request it is logged and a failure event is raised **/
     // 2010-10-28: TESTED OK
     if (count($responseAr) < 1 || $responseAr[0] != 'SUCCESS') {
         $event->msg = "PDT request failed";
         Yii::log("{$event->msg}\nRequest:\n{$getVars}\nResponse:\n{$response["httpResponse"]}", "error", "payPal.controllers.pdt.PPPdtAction");
         $this->onFailure($event);
         return;
     }
     /** URL decode and write result into assoc array **/
     // 2010-10-28: TESTED OK
     for ($i = 1; $i < count($responseAr); $i++) {
         $row = explode('=', $responseAr[$i]);
         if (count($row) > 1) {
             $event->responseAr[urldecode($row[0])] = urldecode($row[1]);
         }
     }
     /** Log successfull request and raise a onRequest event */
     // 2010-10-28: TESTED OK
     $event->details = $event->responseAr;
     $event->msg = "Successfull PDT request";
     Yii::log("{$event->msg}\nRequest:\n{$getVars}\nResponse:\n{$response["httpResponse"]}", "info", "payPal.controllers.pdt.PPPdtAction");
     $this->onRequest($event);
 }