public static function _doUrlRequest($httpVerb, $url, $requestBody = null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpVerb); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_ENCODING, 'gzip'); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml', 'User-Agent: Braintree PHP Library ' . Braintree_Version::get(), 'X-ApiVersion: ' . Braintree_Configuration::API_VERSION)); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, Braintree_Configuration::publicKey() . ':' . Braintree_Configuration::privateKey()); // curl_setopt($curl, CURLOPT_VERBOSE, true); if (Braintree_Configuration::sslOn()) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($curl, CURLOPT_CAINFO, Braintree_Configuration::caFile()); } if (!empty($requestBody)) { curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if (Braintree_Configuration::sslOn()) { if ($httpStatus == 0) { throw new Braintree_Exception_SSLCertificate(); } } return array('status' => $httpStatus, 'body' => $response); }
/** * Inform the user there version will not work * @return string */ private function getVersionHtml() { if (@class_exists('Braintree_Version')) { $version = Braintree_Version::get(); if ($version < 2.32) { return ' <span style="color: red;">' . $version . '</span><br /> <small> <strong>Warning:</strong> Our payment methods will not work with a version of the Braintree lib files older than 2.32.0. You\'ll have to upgrade, please download the newer version <a href="https://developers.braintreepayments.com/javascript+php/sdk/server/setup">here</a>. Once you\'ve downloaded it please replace the file <strong>/lib/Braintree.php</strong> and the folder <strong>/lib/Braintree/</strong> with the newer versions within the archive. </small>'; } else { return '<span style="color: green;">' . $version . '</span>'; } } else { return '<span style="color: red;font-weight: bold;">Not Installed</span>'; } }
public function _doUrlRequest($httpVerb, $url, $requestBody = null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpVerb); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_ENCODING, 'gzip'); $headers = $this->_getHeaders($curl); $headers[] = 'User-Agent: Braintree PHP Library ' . Braintree_Version::get(); $headers[] = 'X-ApiVersion: ' . Braintree_Configuration::API_VERSION; $authorization = $this->_getAuthorization(); if (isset($authorization['user'])) { curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, $authorization['user'] . ':' . $authorization['password']); } else { if (isset($authorization['token'])) { $headers[] = 'Authorization: Bearer ' . $authorization['token']; } } curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // curl_setopt($curl, CURLOPT_VERBOSE, true); if ($this->_config->sslOn()) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($curl, CURLOPT_CAINFO, $this->_config->caFile()); } if (!empty($requestBody)) { curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($this->_config->sslOn()) { if ($httpStatus == 0) { throw new Braintree_Exception_SSLCertificate(); } } return array('status' => $httpStatus, 'body' => $response); }
/** * Validate the credentials once, this is used during the payment methods available check * * @return bool */ public function validateCredentialsOnce() { // Check to see if it's been validated yet if (is_null($this->validated)) { // Check the Braintree lib version is above 2.32, as this is when 3D secure appeared if (Braintree_Version::get() < 2.32) { $this->validated = false; } else { // Check that the module is fully setup if (!Mage::getStoreConfig(Gene_Braintree_Model_Wrapper_Braintree::BRAINTREE_ENVIRONMENT_PATH) || !Mage::getStoreConfig(Gene_Braintree_Model_Wrapper_Braintree::BRAINTREE_MERCHANT_ID_PATH) || !Mage::getStoreConfig(Gene_Braintree_Model_Wrapper_Braintree::BRAINTREE_PUBLIC_KEY_PATH) || !Mage::getStoreConfig(Gene_Braintree_Model_Wrapper_Braintree::BRAINTREE_PRIVATE_KEY_PATH)) { // If not the payment methods aren't available $this->validated = false; } else { // Attempt to validate credentials try { // Passing true will cause the system to rethrow exceptions if (Mage::getModel('gene_braintree/wrapper_braintree')->validateCredentials(false, false, false, true)) { // Mark our flag as true $this->validated = true; } else { // Mark our flag as false, this shouldn't even return false it should always throw an // Exception but just in case $this->validated = false; } } catch (Exception $e) { // If it fails log it Gene_Braintree_Model_Debug::log('CRITICAL ERROR: The system was unable to connect to Braintree, error is below'); Gene_Braintree_Model_Debug::log($e); // If the validateCredentials throws an exception it has failed $this->validated = false; } } } } return $this->validated; }
function braintree_cc() { global $order; $this->signature = 'braintree|braintree_cc|1.1|2.3'; $this->api_version = '1'; $this->code = 'braintree_cc'; $this->title = MODULE_PAYMENT_BRAINTREE_CC_TEXT_TITLE; $this->public_title = MODULE_PAYMENT_BRAINTREE_CC_TEXT_PUBLIC_TITLE; $this->description = MODULE_PAYMENT_BRAINTREE_CC_TEXT_DESCRIPTION; $this->sort_order = defined('MODULE_PAYMENT_BRAINTREE_CC_SORT_ORDER') ? MODULE_PAYMENT_BRAINTREE_CC_SORT_ORDER : 0; $this->enabled = defined('MODULE_PAYMENT_BRAINTREE_CC_STATUS') && MODULE_PAYMENT_BRAINTREE_CC_STATUS == 'True' ? true : false; $this->order_status = defined('MODULE_PAYMENT_BRAINTREE_CC_ORDER_STATUS_ID') && (int) MODULE_PAYMENT_BRAINTREE_CC_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_BRAINTREE_CC_ORDER_STATUS_ID : 0; if (defined('MODULE_PAYMENT_BRAINTREE_CC_STATUS')) { if (MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER == 'Sandbox') { $this->title .= ' [Sandbox]'; $this->public_title .= ' (' . $this->code . '; Sandbox)'; } } $braintree_error = null; if (version_compare(PHP_VERSION, '5.2.1', '<')) { $braintree_error = sprintf(MODULE_PAYMENT_BRAINTREE_CC_ERROR_ADMIN_PHP, '5.2.1'); } if (!isset($braintree_error)) { $requiredExtensions = array('xmlwriter', 'SimpleXML', 'openssl', 'dom', 'hash', 'curl'); $exts = array(); foreach ($requiredExtensions as $ext) { if (!extension_loaded($ext)) { $exts[] = $ext; } } if (!empty($exts)) { $braintree_error = sprintf(MODULE_PAYMENT_BRAINTREE_CC_ERROR_ADMIN_PHP_EXTENSIONS, implode('<br />', $exts)); } } if (!isset($braintree_error) && defined('MODULE_PAYMENT_BRAINTREE_CC_STATUS')) { if (!tep_not_null(MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ID) || !tep_not_null(MODULE_PAYMENT_BRAINTREE_CC_PUBLIC_KEY) || !tep_not_null(MODULE_PAYMENT_BRAINTREE_CC_PRIVATE_KEY) || !tep_not_null(MODULE_PAYMENT_BRAINTREE_CC_CLIENT_KEY)) { $braintree_error = MODULE_PAYMENT_BRAINTREE_CC_ERROR_ADMIN_CONFIGURATION; } } if (!isset($braintree_error) && defined('MODULE_PAYMENT_BRAINTREE_CC_STATUS')) { $ma_error = true; if (tep_not_null(MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ACCOUNTS)) { $mas = explode(';', MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ACCOUNTS); foreach ($mas as $a) { $ac = explode(':', $a, 2); if (isset($ac[1]) && $ac[1] == DEFAULT_CURRENCY) { $ma_error = false; break; } } } if ($ma_error === true) { $braintree_error = sprintf(MODULE_PAYMENT_BRAINTREE_CC_ERROR_ADMIN_MERCHANT_ACCOUNTS, DEFAULT_CURRENCY); } } if (!isset($braintree_error)) { if (!class_exists('Braintree')) { include 'braintree_cc/Braintree.php'; } spl_autoload_register('tep_braintree_autoloader'); $this->api_version .= ' [' . Braintree_Version::get() . ']'; } else { $this->description = '<div class="secWarning">' . $braintree_error . '</div>' . $this->description; $this->enabled = false; } if (isset($order) && is_object($order)) { $this->update_status(); } }