/** * Send a HTTP GET request to PayPal's NVP API and return the response. * Settings from Yii::app()->getModule('payPal') is used for authentication * and API version. * * Get variables are urlencoded, and imploded using self::urlencode() and * self::implode(). * * Failure ACKs received from PayPal is logged. * * @param array $getVars Assoc array (NVP values as specified by PayPal NVP API) * @return mixed Assoc array on success, false on failure * @throws CException Unrecognized response */ public static function nvpRequest($getVars) { $module = Yii::app()->getModule('payPal'); // Prepare NVP $getVars['VERSION'] = PayPalModule::VERSION; foreach ($module->account->getNvp() as $k => $v) { $getVars[$k] = $v; } // Sent HTTP GET request $getStr = self::urlencode($getVars); $getStr = self::implode("&", $getStr); $response = PPUtils::httpGet(self::getUrl(self::NVP), $getStr, true); // Return false on HTTP error if ($response['status'] === false) { return false; } $ack = $response['httpParsedResponseAr']['ACK']; // Log and return false on PayPal failures / warnings if ($ack == "Failure" || $ack == "FailureWithWarning" || $ack == "Warning") { Yii::log("NVP request failed" . "\nRequest:{$getStr}" . "\nResponse:" . self::implode("&", $response['httpParsedResponseAr']), "error", "payPal.helpers.PPUtils"); return false; } // Return response on success if ($ack == "Success" || $ack == "SuccessWithWarning") { return $response['httpParsedResponseAr']; } // Log error and throw exception on unrecognized response $message = "Received unrecognized response"; Yii::log($message . "\nRequest:{$getStr}" . "\nResponse:" . self::implode("&", $response['httpParsedResponseAr']), "error", "payPal.helpers.PPUtils"); throw new CException($message); }