From 9f8c842f9e5a2bb9abb4d28069bce4a35fcb6c60 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Tue, 16 Dec 2014 11:01:01 -0500 Subject: [PATCH 01/65] Added more error handling and debug logging --- lib/Bitpay/Storage/MagentoStorage.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/Bitpay/Storage/MagentoStorage.php b/lib/Bitpay/Storage/MagentoStorage.php index 16e7f74..c9f5a58 100644 --- a/lib/Bitpay/Storage/MagentoStorage.php +++ b/lib/Bitpay/Storage/MagentoStorage.php @@ -27,7 +27,13 @@ class MagentoStorage implements StorageInterface $data = serialize($key); $encryptedData = \Mage::helper('core')->encrypt($data); $config = new \Mage_Core_Model_Config(); - $config->saveConfig($key->getId(), $encryptedData); + + if (true === isset($config) && false === empty($config)) { + $config->saveConfig($key->getId(), $encryptedData); + } else { + Mage::helper('bitpay')->debugData('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); + throw new Exception('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); + } } /** @@ -35,7 +41,7 @@ class MagentoStorage implements StorageInterface */ public function load($id) { - if (isset($this->_keys[$id])) { + if (true === isset($id) && true === isset($this->_keys[$id])) { return $this->_keys[$id]; } @@ -44,16 +50,20 @@ class MagentoStorage implements StorageInterface /** * Not in database */ - if (empty($entity)) { + if (false === isset($entity) || true === empty($entity)) { + Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' did not return the store config parameter because it was not found in the database.'); return false; } $decodedEntity = unserialize(\Mage::helper('core')->decrypt($entity)); - if (empty($decodedEntity)) { + if (false === isset($decodedEntity) || true === empty($decodedEntity)) { + Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' could not decrypt & unserialize the entity ' . $entity . '.'); return false; } + Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' successfully decrypted & unserialized the entity ' . $entity . '.'); + return $decodedEntity; } } From 99deff4007ee69779e625ae16892c909759f4785 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Tue, 16 Dec 2014 11:01:37 -0500 Subject: [PATCH 02/65] Formatting --- lib/Bitpay/Storage/MagentoStorage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Bitpay/Storage/MagentoStorage.php b/lib/Bitpay/Storage/MagentoStorage.php index c9f5a58..20f790b 100644 --- a/lib/Bitpay/Storage/MagentoStorage.php +++ b/lib/Bitpay/Storage/MagentoStorage.php @@ -51,14 +51,14 @@ class MagentoStorage implements StorageInterface * Not in database */ if (false === isset($entity) || true === empty($entity)) { - Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' did not return the store config parameter because it was not found in the database.'); + Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' did not return the store config parameter because it was not found in the database.'); return false; } $decodedEntity = unserialize(\Mage::helper('core')->decrypt($entity)); if (false === isset($decodedEntity) || true === empty($decodedEntity)) { - Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' could not decrypt & unserialize the entity ' . $entity . '.'); + Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' could not decrypt & unserialize the entity ' . $entity . '.'); return false; } From 0007eb3ec1d6b90781dead97fce7dd2a5f565011 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Tue, 16 Dec 2014 18:58:37 -0500 Subject: [PATCH 03/65] Rewrite to be more usable and helpful --- scripts/delete | 114 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 107 insertions(+), 7 deletions(-) diff --git a/scripts/delete b/scripts/delete index 695d693..931d83c 100755 --- a/scripts/delete +++ b/scripts/delete @@ -1,10 +1,110 @@ #!/usr/bin/env sh -#### # -# Script that removes old BitPay extension +# (c) 2014 BitPay, Inc. # -rm -vrf app/code/community/Bitpay/Bitcoins -rm -v app/design/frontend/base/default/layout/bitcoins.xml -rm -vrf app/etc/modules/Bitpay_Bitcoins.xml -rm -vrf lib/bitpay -rm -v shell/bitpay.php +# Shell script that locates and removes +# any previously installed BitPay Magento +# plugin files. +# +# Written by Rich Morgan + +#!/bin/bash + +old_files[0]="/lib/bitpay/bp_config_default.php" +old_files[1]="/lib/bitpay/bp_lib.php" +old_files[2]="/lib/bitpay/bp_options.php" +old_files[3]="/lib/bitpay" +old_files[4]="/app/design/frontend/base/default/template/bitcoins/iframe.phtml" +old_files[5]="/app/design/frontend/base/default/template/bitcoins" +old_files[6]="/app/design/frontend/base/default/layout/bitcoins.xml" +old_files[7]="/app/code/community/Bitpay/Bitcoins/Model/Resource/Ipn/Collection.php" +old_files[8]="/app/code/community/Bitpay/Bitcoins/Model/Resource/Ipn" +old_files[9]="/app/code/community/Bitpay/Bitcoins/Model/Resource/Ipn.php" +old_files[10]="/app/code/community/Bitpay/Bitcoins/Model/PaymentMethod.php" +old_files[11]="/app/code/community/Bitpay/Bitcoins/Model/Ipn.php" +old_files[12]="/app/code/community/Bitpay/Bitcoins/Model/Source/Speed.php" +old_files[13]="/app/code/community/Bitpay/Bitcoins/Model/Source" +old_files[14]="/app/code/community/Bitpay/Bitcoins/Model/Resource" +old_files[15]="/app/code/community/Bitpay/Bitcoins/Model" +old_files[16]="/app/code/community/Bitpay/Bitcoins/sql/Bitcoins_setup/upgrade-0.1.0-1.0.0.php" +old_files[17]="/app/code/community/Bitpay/Bitcoins/sql/Bitcoins_setup/upgrade-1.0.0-1.1.0.php" +old_files[18]="/app/code/community/Bitpay/Bitcoins/sql/Bitcoins_setup" +old_files[19]="/app/code/community/Bitpay/Bitcoins/sql" +old_files[20]="/app/code/community/Bitpay/Bitcoins/Block/Iframe.php" +old_files[21]="/app/code/community/Bitpay/Bitcoins/Block" +old_files[22]="/app/code/community/Bitpay/Bitcoins/controllers/IndexController.php" +old_files[23]="/app/code/community/Bitpay/Bitcoins/controllers" +old_files[24]="/app/code/community/Bitpay/Bitcoins/etc/config.xml" +old_files[25]="/app/code/community/Bitpay/Bitcoins/etc/system.xml" +old_files[26]="/app/code/community/Bitpay/Bitcoins/etc" +old_files[27]="/app/code/community/Bitpay/Bitcoins" +old_files[28]="/app/code/community/Bitpay" +old_files[29]="/app/etc/modules/Bitpay_Bitcoins.xml" +old_files[30]="composer.json" +old_files[31]="magento-plugin-master.zip" +old_files[32]="modman" +old_files[33]="README.md" + +echo "Looking for your Magento installation. Please stand by - this may take a few minutes while I search..." + +# In case we have multiple Magento installs on this one +# server, we will just take the first one and ask... +i=`find /usr/local/zend/apache2 -name Mage.php -type f | head -n 1 2>/dev/null` + +if [ -e $i ] +then + DIR=`dirname $i` + cd $DIR && cd ../ + mage_dir=`pwd` + echo "It looks like Magento is installed in the $mage_dir directory." + echo -n "Is this correct? (y/n) > " +else + DIR="/var/www/html/magento" + cd $DIR + mage_dir=`pwd` + echo "You don't have Magento installed or this script doesn't have permissions to view the directory it's contained in." + echo -n "Should I default to $DIR ? (y/n) > " +fi + +read answer + +if [ $answer = "y" ] +then + echo "Attempting to delete the old plugin files now. Please stand by..." + for filename in "${old_files[@]}" + do + fullname=$mage_dir$filename + if [ -e $fullname ] + then + echo " Found $fullname - removing!" + rm -vrfd $fullname + else + echo " $filename does not exist - skipping!" + fi + done + + echo -n "Process complete." + echo "" +else + echo "Okay, please enter the path you would like me to use or QUIT if you wish to abort the process." + echo -n "Full path or QUIT ? > " + read answer + if [ $answer = "QUIT" ] + then + echo "Quitting!" + else + echo "Attempting to delete the old plugin files at the directory you provided. Please stand by..." + for filename in "${old_files[@]}" + do + fullname=$answer$filename + if [ -e $fullname ] + then + echo " Found $fullname - removing!" + rm -vrfd $fullname + else + echo " $filename does not exist - skipping!" + fi + done + echo -n "Process complete." + fi +fi From cfe6e132d1716f04b45e9b858fa6d7eb25eecbac Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 11:03:02 -0500 Subject: [PATCH 04/65] Removed hardcoded debugging values Also added checks to see if files were still present after the attempted cleaning process --- scripts/delete | 68 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/scripts/delete b/scripts/delete index 931d83c..1ffb56c 100755 --- a/scripts/delete +++ b/scripts/delete @@ -8,8 +8,10 @@ # # Written by Rich Morgan -#!/bin/bash - +# For full transparency I've listed all the depricated files and folders +# related to the old plugin here for your information. This is the complete +# list of items you would want to backup and/or remove if you wanted to do +# this by hand yourself or if you just wanted a list for tracking purposes. old_files[0]="/lib/bitpay/bp_config_default.php" old_files[1]="/lib/bitpay/bp_lib.php" old_files[2]="/lib/bitpay/bp_options.php" @@ -45,11 +47,14 @@ old_files[31]="magento-plugin-master.zip" old_files[32]="modman" old_files[33]="README.md" +CLEAN="true" +RMOPTS="-vrfd" + echo "Looking for your Magento installation. Please stand by - this may take a few minutes while I search..." # In case we have multiple Magento installs on this one # server, we will just take the first one and ask... -i=`find /usr/local/zend/apache2 -name Mage.php -type f | head -n 1 2>/dev/null` +i=`find /var /usr /opt -name Mage.php -type f | head -n 1 2>/dev/null` if [ -e $i ] then @@ -57,13 +62,16 @@ then cd $DIR && cd ../ mage_dir=`pwd` echo "It looks like Magento is installed in the $mage_dir directory." - echo -n "Is this correct? (y/n) > " + echo "Is this correct? (y/n) > " else + # In case we can't find the Magento folder, we are just + # providing a default value here. This happens to be the + # default for an Ubuntu-based machine, for example. DIR="/var/www/html/magento" cd $DIR mage_dir=`pwd` echo "You don't have Magento installed or this script doesn't have permissions to view the directory it's contained in." - echo -n "Should I default to $DIR ? (y/n) > " + echo "Should I default to $mage_dir ? (y/n) > " fi read answer @@ -77,17 +85,35 @@ then if [ -e $fullname ] then echo " Found $fullname - removing!" - rm -vrfd $fullname + rm $RMOPTS $fullname else echo " $filename does not exist - skipping!" fi done - - echo -n "Process complete." + echo "File removal process complete. Checking to make sure your Magento environment was completely cleaned of old BitPay files..." + echo "" + for filename in "${old_files[@]}" + do + fullname=$mage_dir$filename + if [ -e $fullname ] + then + echo " The old plugin file $fullname is still present!" + CLEAN="false" + else + echo " $filename is not present - good!" + fi + done + if [ $CLEAN = "false" ] + then + echo "Old BitPay plugin files are still present in your Magento directory. This is likely due to this script not having permissions to delete them. You can fix this by running this script as superuser or you can remove the files by hand." + else + echo "Good! I didn't find any remaining old BitPay plugin files in your Magento directory! You can now safely install the new BitPay plugin." + fi + echo "Process complete." echo "" else echo "Okay, please enter the path you would like me to use or QUIT if you wish to abort the process." - echo -n "Full path or QUIT ? > " + echo "Full path or QUIT ? > " read answer if [ $answer = "QUIT" ] then @@ -100,11 +126,31 @@ else if [ -e $fullname ] then echo " Found $fullname - removing!" - rm -vrfd $fullname + rm $RMOPTS $fullname else echo " $filename does not exist - skipping!" fi done - echo -n "Process complete." + echo "File removal process complete. Checking to make sure your Magento environment was completely cleaned of old BitPay files..." + echo "" + for filename in "${old_files[@]}" + do + fullname=$mage_dir$filename + if [ -e $fullname ] + then + echo " The old plugin file $fullname is still present!" + CLEAN="false" + else + echo " $filename is not present - good!" + fi + done + if [ $CLEAN = "false" ] + then + echo "Old BitPay plugin files are still present in your Magento directory. This is likely due to this script not having permissions to delete them. You can fix this by running this script as superuser or you can remove the files by hand." + else + echo "Good! I didn't find any remaining old BitPay plugin files in your Magento directory! You can now safely install the new BitPay plugin." + fi + echo "Process complete." + echo "" fi fi From 44534b508a46d7b617ec84f954490ac1bdd7a155 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 12:43:50 -0500 Subject: [PATCH 05/65] Rename delete to delete.sh --- scripts/{delete => delete.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{delete => delete.sh} (100%) diff --git a/scripts/delete b/scripts/delete.sh similarity index 100% rename from scripts/delete rename to scripts/delete.sh From 7e5e84b7d15377221a23888db3cea8d52f3cdae2 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 12:55:15 -0500 Subject: [PATCH 06/65] Formatting and adding more information --- README.md | 171 ++++++++++++++++++------------------------------------ 1 file changed, 56 insertions(+), 115 deletions(-) diff --git a/README.md b/README.md index 056981c..4101cb9 100644 --- a/README.md +++ b/README.md @@ -5,130 +5,86 @@ bitpay/magento-plugin [![Build Status](https://travis-ci.org/bitpay/magento-plugin.svg?branch=master)](https://travis-ci.org/bitpay/magento-plugin) -# Brief Description -BitPay has the most powerful bitcoin infrastructure on the planet and is trusted by over 40,000 merchants. +# Description -# Detail Description +Bitcoin is a powerful new peer-to-peer platform for the next generation of financial technology. The decentralized nature of the Bitcoin network allows for a highly resilient value transfer infrastructure, and this allows merchants to gain greater profits. -Bitcoin is a powerful new peer-to-peer platform for the next generation of -financial technology. The decentralized nature of the Bitcoin network allows -for a highly resilient value transfer infrastructure, and this allows merchants -to gain greater profits. +This is because there are little to no fees for transferring Bitcoins from one person to another. Unlike other payment methods, Bitcoin payments cannot be reversed, so once you are paid you can ship! No waiting days for a payment to clear. -This is because there are little to no fees for transferring Bitcoins from one -person to another. Unlike other payment methods, Bitcoin payments cannot be -reversed, so once you are paid you can ship! No waiting days for a payment to -clear. # Requirements -* [Magento](http://magento.com/resources/system-requirements) >= 1.9.0.1 (Older version will work, but we do not test against those) -* [GMP](http://us2.php.net/gmp) You may have to install this as most servers do not come with it. -* [mcrypt](http://us2.php.net/mcrypt) Magento requires this so you're fine -* [OpenSSL](http://us2.php.net/openssl) Must be compiled with PHP -* PHP >= 5.4 +* [Magento CE](http://magento.com/resources/system-requirements) 1.9.0.1 or higher. Older versions might work, however this plugin has been validated to work against the 1.9.0.1 Community Edition release. +* [GMP](http://us2.php.net/gmp) or [BC Math](http://us2.php.net/manual/en/book.bc.php) PHP extensions. GMP is preferred for performance reasons but you may have to install this as most servers do not come with it installed by default. BC Math is commonly installed however and the plugin will fall back to this method if GMP is not found. +* [OpenSSL](http://us2.php.net/openssl) Must be compiled with PHP and is used for certain cryptographic operations. +* [PHP](http://us2.php.net/downloads.php) 5.4 or higher. This plugin will not work on PHP 5.3 and below. -# Upgrade From Version 1.x to 2.x -Merchants who have previous been using the BitPay Magento plugin will need to remove -previous plugin. This can be done by using the [scripts/delete](https://github.com/bitpay/magento-plugin/blob/master/scripts/delete) -script before installing the new plugin. +# Upgrade From Plugin Version 1.x to 2.x + +Very Important: You must complete remove any previous versions of the Bitpay Magento plugin before installing this new updated version. The plugin has been completely re-written to work with BitPay's new cryptographically secure RESTful API and will conflict with any previous plugin versions which use the old API. To help you remove the old plugin files from your system, we have created a convenient shell script for Unix/Linux/Mac OS systems which will scan your webserver for these older files and delete them. You may also remove these files by hand of course and the complete list of the files can be found in the source of the script for your convenience. You can download this delete script here: [scripts/delete.sh](https://github.com/bitpay/magento-plugin/blob/master/scripts/delete.sh). + +To use this script, simply download to your server and execute the script from a shell. You may have to mark the script executable before first use. + +```sh +chmod +x delete.sh +./delete.sh +``` + # Installation ## Magento Connect Manager -Goto [http://www.magentocommerce.com/magento-connect/bitpay-payment-method.html](http://www.magentocommerce.com/magento-connect/bitpay-payment-method.html) -and click the *Install Now* link which will give you the *Extension Key* needed -for the next step. +Goto [http://www.magentocommerce.com/magento-connect/bitpay-payment-method.html](http://www.magentocommerce.com/magento-connect/bitpay-payment-method.html) and click the *Install Now* link which will give you the *Extension Key* needed for the next step. -Once you have the key, log into you Magento Store's Admin Panel and navigate to -**System > Magento Connect > Magento Connect Manager**. +Once you have the key, log into you Magento Store's Admin Panel and navigate to **System > Magento Connect > Magento Connect Manager**. -***NOTE*** It may ask you to log in again using the same credentials that you use -to log into the Admin Panel. +***NOTE*** It may ask you to log in again using the same credentials that you use to log into the Admin Panel. All you need to do is paste the extension key and click on the *Install* button. -***WARNING*** It is good practice to backup your database before installing -extensions. Please make sure you Create Backups. +***WARNING*** It is good practice to backup your database before installing extensions. Please make sure you Create Backups. + ## Download -Visit the [Releases](https://github.com/bitpay/magento-plugin/releases) page of -this repository and download the latest version. Once this is done, you can just -unzip the contents and use any method you want to put them on your server. The -contents will mirror the Magento directory structure. +Visit the [Releases](https://github.com/bitpay/magento-plugin/releases) page of this repository and download the latest version. Once this is done, you can just unzip the contents and use any method you want to put them on your server. The contents will mirror the Magento directory structure. -***NOTE*** These files can also up uploaded using the *Magento Connect Manager* -that comes with your Magento Store +***NOTE*** These files can also up uploaded using the *Magento Connect Manager* that comes with your Magento Store + +***WARNING*** It is good practice to backup your database before installing extensions. Please make sure you Create Backups. -***WARNING*** It is good practice to backup your database before installing -extensions. Please make sure you Create Backups. ## modman -Using [modman](https://github.com/colinmollenhour/modman) you can -install the BitPay Magento Plugin. Once -you have modman installed, run `modman init` if you have not already done so. Next -just run `modman clone https://github.com/bitpay/magento-plugin.git` in the root -of the Magento installation. In this case it is `/var/www/magento`. +Using [modman](https://github.com/colinmollenhour/modman) you can install the BitPay Magento Plugin. Once you have modman installed, run `modman init` if you have not already done so. Next just run `modman clone https://github.com/bitpay/magento-plugin.git` in the root of the Magento installation. In this case it is `/var/www/magento`. -## Development - -For developers wanting to contribute to this project, it is assumed you have a -stable Magento environment to work with, and are familiar with developing for -Magento. You will need to clone this repository or fork and clone the repository -you created. - -Once you have cloned the repository, you will need to run [composer install](https://getcomposer.org/doc/00-intro.md#using-composer). -Using and setting up composer is outside the scope, however you will find the -documentation on their site comprehensive. - -Once you are done, you can then run the ``scripts/package`` script to create a -distribution files which you can find in ``build/dist``. This is the file that -you can upload to your server to unzip or do with what you will. - -If you encounter any issues or implement any updates or changes, please open an -[issue](https://github.com/bitpay/magento-plugin/issues) or submit a Pull Request. - -***NOTE*** The ``scripts/package`` file contains some configuration settings that -will need to change for different releases. If you are using this script to build -files that are for distribution, these will need to be updated. # Configuration -Configuration can be done using the Administrator section of your Megento store. -Once Logged in, you will find the configuration settings under **System > Configuration > Sales > Payment Methods**. +Configuration can be done using the Administrator section of your Megento store. Once Logged in, you will find the configuration settings under **System > Configuration > Sales > Payment Methods**. ![BitPay Magento Settings](https://raw.githubusercontent.com/bitpay/magento-plugin/master/docs/MagentoSettings.png "BitPay Megento Settings") -Here your will need to create a [pairing code](https://bitpay.com/api-tokens) using -your BitPay merchant account. Once you have a Pairing Code, put the code in the -Pairing Code field. This will take care of the rest for you. +Here your will need to create a [pairing code](https://bitpay.com/api-tokens) using your BitPay merchant account. Once you have a Pairing Code, put the code in the Pairing Code field. This will take care of the rest for you. -***NOTE*** Pairing Codes are only valid for a short period of time. If it expires -before you get to use it, you can always create a new one an use the new one. +***NOTE*** Pairing Codes are only valid for a short period of time. If it expires before you get to use it, you can always create a new one an use the new one. -***NOTE*** You will only need to do this once since each time you do this, the -extension will generate public and private keys that are used to identify you -when using the API. +***NOTE*** You will only need to do this once since each time you do this, the extension will generate public and private keys that are used to identify you when using the API. -You are also able to configure how BitPay's IPN (Instant Payment Notifications) -changes the order in your Magento store. +You are also able to configure how BitPay's IPN (Instant Payment Notifications) changes the order in your Magento store. ![BitPay Invoice Settings](https://raw.githubusercontent.com/bitpay/magento-plugin/master/docs/MagentoInvoiceSettings.png "BitPay Invoice Settings") + # Usage -Once enabled, your customers will be given the option to pay with Bitcoins. Once -they checkout they are redirected to a full screen BitPay invoice to pay for -the order. +Once enabled, your customers will be given the option to pay with Bitcoins. Once they checkout they are redirected to a full screen BitPay invoice to pay for the order. + +As a merchant, the orders in your Magento store can be treated as any other order. You may need to adjust the Invoice Settings depending on your order fulfillment. -As a merchant, the orders in your Magento store can be treated as any other -order. You may need to adjust the Invoice Settings depending on your order -fulfillment. # Support @@ -143,30 +99,19 @@ fulfillment. * [Homepage](http://magento.com) * [Documentation](http://docs.magentocommerce.com) -* [Support Forums](https://www.magentocommerce.com/support/ce/) +* [Community Edition Support Forums](https://www.magentocommerce.com/support/ce/) # Troubleshooting -1. Ensure a valid SSL certificate is installed on your server. Also ensure your - root CA cert is updated. If your CA cert is not current, you will see curl - SSL verification errors. -2. Verify that your web server is not blocking POSTs from servers it may not - recognize. Double check this on your firewall as well, if one is being used. -3. Check the `payment_bitpay.log` file for any errors during BitPay payment attempts. - If you contact BitPay support, they will ask to see the log file to help - diagnose the problem. The log file will be found inside your Magento's - `var/log/` directory. ***NOTE*** You will need to enable the debugging - setting for the extension to output information into the log file. -4. Check the version of this plugin against the official plugin repository to - ensure you are using the latest version. Your issue might have been - addressed in a newer version! See the [Releases](https://github.com/bitpay/magento-plugin/releases) - page for the latest. -5. If all else fails, send an email describing your issue **in detail** to - support@bitpay.com +1. Ensure a valid SSL certificate is installed on your server. Also ensure your root CA cert is updated. If your CA cert is not current, you will see curl SSL verification errors. +2. Verify that your web server is not blocking POSTs from servers it may not recognize. Double check this on your firewall as well, if one is being used. +3. Check the `payment_bitpay.log` file for any errors during BitPay payment attempts. If you contact BitPay support, they will ask to see the log file to help diagnose the problem. The log file will be found inside your Magento's `var/log/` directory. ***NOTE*** You will need to enable the debugging setting for the extension to output information into the log file. +4. Check the version of this plugin against the official plugin repository to ensure you are using the latest version. Your issue might have been addressed in a newer version! See the [Releases](https://github.com/bitpay/magento-plugin/releases) page or the Magento Connect store for the latest version. +5. If all else fails, send an email describing your issue **in detail** to support@bitpay.com ***TIP***: When contacting support it will help us is you provide: -* Magento Version (Found at the bottom page in the Administration section) +* Magento CE Version (Found at the bottom page in the Administration section) * Other extensions you have installed * Some extensions do not play nice * Configuration settings for the extension (Most merchants take screen grabs) @@ -175,9 +120,17 @@ fulfillment. * enabled debugging for this extension and send us `var/log/payment_bitpay.log` * Screen grabs of error message if applicable. + # Contribute -To contribute to this project, please fork and submit a pull request. +For developers wanting to contribute to this project, it is assumed you have a stable Magento environment to work with, and are familiar with developing for Magento. You will need to clone this repository or fork and clone the repository you created. + +Once you have cloned the repository, you will need to run [composer install](https://getcomposer.org/doc/00-intro.md#using-composer). Using and setting up composer is outside the scope, however you will find the documentation on their site comprehensive. You can then run the ``scripts/package`` script to create a distribution files which you can find in ``build/dist``. This is the file that you can upload to your server to unzip or do with what you will. + +If you encounter any issues or implement any updates or changes, please open an [issue](https://github.com/bitpay/magento-plugin/issues) or submit a Pull Request. + +***NOTE*** The ``scripts/package`` file contains some configuration settings that will need to change for different releases. If you are using this script to build files that are for distribution, these will need to be updated. + # License @@ -185,20 +138,8 @@ The MIT License (MIT) Copyright (c) 2011-2014 BitPay, Inc. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From e70b0fa9c3598fd7e0efe2beccfcc96bb698eb40 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 12:56:54 -0500 Subject: [PATCH 07/65] Cleaned up unused code --- tests/bootstrap.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1879b74..a2a0e1a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,7 +6,6 @@ if ($mage = realpath(__DIR__.'/../build/magento/app/Mage.php')) { require_once $mage; - //Mage::setIsDeveloperMode(true); Mage::app(); } else { exit('Could not find Mage.php'); From 0ce0cfebcadbe075a4e820f4353e8d00738d0bb9 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 13:00:20 -0500 Subject: [PATCH 08/65] Fixed incorrect target parameter --- .../template/bitpay/system/config/field/header.phtml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml b/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml index 031e411..2076431 100644 --- a/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml +++ b/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml @@ -11,7 +11,7 @@ ?> From 14d0351cd05cdc014902c59a0d42d014c5a00a9b Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 13:00:53 -0500 Subject: [PATCH 09/65] Fixed incorrect target parameter --- .../default/default/template/bitpay/info/default.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/design/adminhtml/default/default/template/bitpay/info/default.phtml b/app/design/adminhtml/default/default/template/bitpay/info/default.phtml index 89dbbf8..ab3dae6 100644 --- a/app/design/adminhtml/default/default/template/bitpay/info/default.phtml +++ b/app/design/adminhtml/default/default/template/bitpay/info/default.phtml @@ -13,6 +13,6 @@ getBitpayInvoiceUrl()): ?>

- View Invoice + View Invoice

From b40d1a60f3dc2d7e69b9ca3b7f09f58180d5908f Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 13:04:45 -0500 Subject: [PATCH 10/65] Removed unnecessary context switching --- app/design/frontend/base/default/template/bitpay/iframe.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/design/frontend/base/default/template/bitpay/iframe.phtml b/app/design/frontend/base/default/template/bitpay/iframe.phtml index a4c49ee..836804f 100644 --- a/app/design/frontend/base/default/template/bitpay/iframe.phtml +++ b/app/design/frontend/base/default/template/bitpay/iframe.phtml @@ -32,7 +32,7 @@ if ($request->getScheme() == 'https') { //?quote=", + "", { asynchronous: true, evalScripts: true, From 78e3ab0d2c0fa8708c2728144a7a3a6df93665bf Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 13:06:37 -0500 Subject: [PATCH 11/65] Removed unnecessary context switching --- .../base/default/template/bitpay/info/default.phtml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/design/frontend/base/default/template/bitpay/info/default.phtml b/app/design/frontend/base/default/template/bitpay/info/default.phtml index 444ac8b..905db79 100644 --- a/app/design/frontend/base/default/template/bitpay/info/default.phtml +++ b/app/design/frontend/base/default/template/bitpay/info/default.phtml @@ -3,7 +3,8 @@ * @license Copyright 2011-2014 BitPay Inc., MIT License * @see https://github.com/bitpay/magento-plugin/blob/master/LICENSE */ -?> -

escapeHtml($this->getMethod()->getTitle()) ?>

-getChildHtml()?> +echo '

' . $this->escapeHtml($this->getMethod()->getTitle()) . '

'; + +echo $this->getChildHtml(); +?> From 739d702c339e5b607b923ff9db6fdefe10e7568d Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 13:10:00 -0500 Subject: [PATCH 12/65] Removed unnecessary context switching --- .../default/template/bitpay/form/bitpay.phtml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/design/frontend/base/default/template/bitpay/form/bitpay.phtml b/app/design/frontend/base/default/template/bitpay/form/bitpay.phtml index 858f869..c64fa51 100644 --- a/app/design/frontend/base/default/template/bitpay/form/bitpay.phtml +++ b/app/design/frontend/base/default/template/bitpay/form/bitpay.phtml @@ -3,17 +3,14 @@ * @license Copyright 2011-2014 BitPay Inc., MIT License * @see https://github.com/bitpay/magento-plugin/blob/master/LICENSE */ -?> -getMethodCode(); + +echo ''; ?> -getMethodCode() ?> - From f35c0e06ca7491fd12a11d8991a96355e0790c0c Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 13:12:16 -0500 Subject: [PATCH 13/65] Removed unnecessary context switching --- .../bitpay/system/config/field/header.phtml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml b/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml index 2076431..72485e3 100644 --- a/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml +++ b/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml @@ -3,15 +3,16 @@ * @license Copyright 2011-2014 BitPay Inc., MIT License * @see https://github.com/bitpay/magento-plugin/blob/master/LICENSE */ -?> -' . + 'BitPay' . + 'Support' . + 'Sign Up' . + 'Login' . + ''; + ?> -
- BitPay - Support - Sign Up - Login -
From f5dc25f23c3cef2d9640d1d3bbf8a69fff5381d0 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 13:13:03 -0500 Subject: [PATCH 14/65] Escaped single quotes --- .../template/bitpay/system/config/field/header.phtml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml b/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml index 72485e3..6c74aed 100644 --- a/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml +++ b/app/design/adminhtml/default/default/template/bitpay/system/config/field/header.phtml @@ -10,9 +10,9 @@ echo '
' . 'BitPay' . - 'Support' . - 'Sign Up' . - 'Login' . + 'Support' . + 'Sign Up' . + 'Login' . '
'; ?> From b4dc639e197ba8e315da0a4a909237021c7ec279 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 13:14:50 -0500 Subject: [PATCH 15/65] Removed unnecessary context switching --- .../default/template/bitpay/info/default.phtml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/design/adminhtml/default/default/template/bitpay/info/default.phtml b/app/design/adminhtml/default/default/template/bitpay/info/default.phtml index ab3dae6..79122f2 100644 --- a/app/design/adminhtml/default/default/template/bitpay/info/default.phtml +++ b/app/design/adminhtml/default/default/template/bitpay/info/default.phtml @@ -3,16 +3,15 @@ * @license Copyright 2011-2014 BitPay Inc., MIT License * @see https://github.com/bitpay/magento-plugin/blob/master/LICENSE */ -?> - -

Ordered with BitPay

-getBitpayInvoiceUrl()): ?> -

- View Invoice -

- +echo '

Ordered with BitPay

'; + +if ($url = $this->getBitpayInvoiceUrl()) { + echo '

View Invoice

'; +} + +?> From 65a68c8f26f4dbccdca3784d282cfdb3bc5544e9 Mon Sep 17 00:00:00 2001 From: Rich Morgan Date: Wed, 17 Dec 2014 13:21:45 -0500 Subject: [PATCH 16/65] Updated information in comments --- app/code/community/Bitpay/Core/etc/system.xml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/code/community/Bitpay/Core/etc/system.xml b/app/code/community/Bitpay/Core/etc/system.xml index b009e82..905f108 100644 --- a/app/code/community/Bitpay/Core/etc/system.xml +++ b/app/code/community/Bitpay/Core/etc/system.xml @@ -28,7 +28,7 @@ - https://bitpay.com/api-tokens and put + https://bitpay.com/api-tokens and put the code that was generated in this field. Once you have paired your Mangento store you can begin accepted Bitcoins as payment on your store.]]> @@ -51,8 +51,7 @@ <label>Title</label> <comment> - What your customers will see during their checkout - experience. + What your customers will see during their checkout experience. </comment> <frontend_type>text</frontend_type> <sort_order>20</sort_order> @@ -63,7 +62,7 @@ <network translate="label"> <label>Network</label> <comment> - <![CDATA[You can sign up for a test account at <a href="https://test.bitpay.com">test.bitpay.com</a>.]]> + <![CDATA[You can sign up for a test account at <a href="https://test.bitpay.com" target="_blank">test.bitpay.com</a>.]]> </comment> <frontend_type>select</frontend_type> <source_model>bitpay/network</source_model> @@ -170,8 +169,7 @@ <invoice_paid translate="label"> <label>Paid</label> <comment> - An invoice is considered "paid" when the bitcoin - network sees a transaction. + An invoice is considered "paid" when the Bitcoin network sees a transaction. </comment> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_order_status</source_model> @@ -183,8 +181,7 @@ <invoice_confirmed translate="label"> <label>Confirmed</label> <comment> - A confirmed invoice means that the Bitcoin network - has approved the transaction. + A confirmed invoice means that the Bitcoin network has approved the transaction. </comment> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_order_status</source_model> @@ -196,8 +193,7 @@ <invoice_complete translate="label"> <label>Complete</label> <comment> - Complete invoices mean that you have gotten credit - for the payment in your BitPay merchant account. + Complete invoices mean that the funds for the sale have been confirmed and deposited into your BitPay merchant account. </comment> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_order_status</source_model> @@ -210,7 +206,7 @@ <label>Requirements</label> <frontend_model>adminhtml/system_config_form_field_heading</frontend_model> <comment> - <![CDATA[If you do not meet the requirements, this extension will fail to work.]]> + This extension will not function if you do not meet the system requirements. </comment> <sort_order>500</sort_order> <show_in_default>1</show_in_default> From b9bc6c30ed70ee5c5a947a23792ebd266c944a37 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 14:02:31 -0500 Subject: [PATCH 17/65] Added extra error handling and debugging --- .../Bitpay/Core/controllers/IpnController.php | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/app/code/community/Bitpay/Core/controllers/IpnController.php b/app/code/community/Bitpay/Core/controllers/IpnController.php index 0f832da..827101e 100644 --- a/app/code/community/Bitpay/Core/controllers/IpnController.php +++ b/app/code/community/Bitpay/Core/controllers/IpnController.php @@ -19,17 +19,19 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action */ public function indexAction() { - if (!ini_get('allow_url_fopen')) { + if (false === ini_get('allow_url_fopen')) { ini_set('allow_url_fopen', true); } $raw_post_data = file_get_contents('php://input'); - if ($raw_post_data === false) { + if (false === $raw_post_data) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController: Could not read from the php://input stream or invalid Bitpay IPN received.'); throw new Exception('Could not read from the php://input stream or invalid Bitpay IPN received.'); } Mage::helper('bitpay')->registerAutoloader(); + Mage::helper('bitpay')->debugData( array( sprintf('Incoming IPN from bitpay'), @@ -39,9 +41,21 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action ); // Magento doesn't seem to have a way to get the Request body - $ipn = json_decode($raw_post_data); + $ipn = json_decode($raw_post_data); + + if (true === empty($ipn)) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController: Could not decode the JSON payload from BitPay.'); + throw new Exception('Could not decode the JSON payload from BitPay.'); + } + + if (true === empty($ipn->id) || false === isset($ipn->posData->id)) { + Mage::helper('bitpay')->debugData(sprintf('Did not receive order ID in IPN. See IPN "%s" in database.', $mageIpn->getId())); + throw new Exception('Invalid Bitpay IPN received - did not receive order ID.'); + } + $ipn->posData = is_string($ipn->posData) ? json_decode($ipn->posData) : $ipn->posData; $ipn->buyerFields = isset($ipn->buyerFields) ? $ipn->buyerFields : new stdClass(); + Mage::helper('bitpay')->debugData($ipn); // Log IPN @@ -63,16 +77,9 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action ) )->save(); - if (empty($ipn->id) || !isset($ipn->posData->id)) { - Mage::helper('bitpay')->debugData( - sprintf('Did not receive order id in IPN. See IPN "%s" in database.', $mageIpn->getId()) - ); - throw new Exception('Invalid Bitpay IPN received.'); - } - $order = Mage::getModel('sales/order')->loadByIncrementId($ipn->posData->id); - if (!$order->getId()) { + if (false === isset($order) || true === empty($order->getId())) { Mage::helper('bitpay')->debugData('Invalid Bitpay IPN received.'); Mage::throwException('Invalid Bitpay IPN received.'); } @@ -84,27 +91,44 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action */ $invoice = Mage::getModel('bitpay/method_bitcoin')->fetchInvoice($ipn->id); + if (false === isset($invoice) || true === empty($invoice) { + Mage::helper('bitpay')->debugData('[ERROR] Could not retrieve the invoice details for the ipn ID of ' . $ipn->id); + Mage::throwException('Could not retrieve the invoice details for the ipn ID of ' . $ipn->id); + } + // Does the status match? - if ($invoice && $invoice->getStatus() != $ipn->status) { - Mage::getModel('bitpay/method_bitcoin')->debugData('IPN status and status from BitPay are different'); - Mage::throwException('There was an error processing the ipn'); + if ($invoice->getStatus() != $ipn->status) { + Mage::getModel('bitpay/method_bitcoin')->debugData('[ERROR] IPN status and status from BitPay are different.'); + Mage::throwException('There was an error processing the IPN - statuses are different.'); } // Does the price match? - if ($invoice && $invoice->getPrice() != $ipn->price) { - Mage::getModel('bitpay/method_bitcoin')>debugData('Price difference'); - Mage::throwException('There was an error processing the ipn'); + if ($invoice->getPrice() != $ipn->price) { + Mage::getModel('bitpay/method_bitcoin')>debugData('[ERROR] IPN price and invoice price are different.'); + Mage::throwException('There was an error processing the IPN - invoice price does not match the IPN price.'); } // Update the order to notifiy that it has been paid - if (in_array($invoice->getStatus(), array('paid', 'confirmed', 'complete'))) { + if (true === in_array($invoice->getStatus(), array('paid', 'confirmed', 'complete'))) { $payment = Mage::getModel('sales/order_payment')->setOrder($order); - $payment->registerCaptureNotification($invoice->getPrice()); - $order->addPayment($payment)->save(); + + if (true === isset($payment) && false === empty($payment)) { + $payment->registerCaptureNotification($invoice->getPrice()); + $order->addPayment($payment)->save(); + } else { + Mage::helper('bitpay')->debugData('[ERROR] Could not create a payment object in the Bitpay IPN controller.'); + Mage::throwException('Could not create a payment object in the Bitpay IPN controller.'); + } } // use state as defined by Merchant $state = Mage::getStoreConfig(sprintf('payment/bitpay/invoice_%s', $invoice->getStatus())); + + if (false === isset($state) || true === empty($state) { + Mage::helper('bitpay')->debugData('[ERROR] Could not retrieve the defined state parameter to update this order to in the Bitpay IPN controller.'); + Mage::throwException('Could not retrieve the defined state parameter to update this order to in the Bitpay IPN controller.'); + } + $order->addStatusToHistory( $state, sprintf('Incoming IPN status "%s" updated order state to "%s"', $invoice->getStatus(), $state) From 2bf5911860ab35a93ea863158645ab0c072045f5 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 14:05:33 -0500 Subject: [PATCH 18/65] Removed accidental newlines --- app/code/community/Bitpay/Core/controllers/IpnController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/code/community/Bitpay/Core/controllers/IpnController.php b/app/code/community/Bitpay/Core/controllers/IpnController.php index 827101e..cf99880 100644 --- a/app/code/community/Bitpay/Core/controllers/IpnController.php +++ b/app/code/community/Bitpay/Core/controllers/IpnController.php @@ -4,8 +4,6 @@ * @see https://github.com/bitpay/magento-plugin/blob/master/LICENSE */ - - /** * @route /bitpay/ipn */ From f950bf05a1352b2f0e7c3930741c4facc3f6b044 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 14:41:42 -0500 Subject: [PATCH 19/65] Added extra error handling and debugging --- .../Bitpay/Core/controllers/IndexController.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/community/Bitpay/Core/controllers/IndexController.php b/app/code/community/Bitpay/Core/controllers/IndexController.php index 2066c51..a2fdec9 100644 --- a/app/code/community/Bitpay/Core/controllers/IndexController.php +++ b/app/code/community/Bitpay/Core/controllers/IndexController.php @@ -14,19 +14,19 @@ class Bitpay_Core_IndexController extends Mage_Core_Controller_Front_Action */ public function indexAction() { - $params = $this->getRequest()->getParams(); $paid = false; - if (isset($params['paid'])) { + $params = $this->getRequest()->getParams(); + + if (true === isset($params['paid'])) { Mage::helper('bitpay')->registerAutoloader(); - Mage::helper('bitpay')->debugData( - $params - ); + Mage::helper('bitpay')->debugData($params); + } else { + Mage::helper('bitpay')->debugData('[ERROR] Could not get params from request.'); } $this->loadLayout(); + $this->getResponse()->setHeader('Content-type', 'application/json'); - $this->getResponse()->setBody( - json_encode(array('paid' => $paid)) - ); + $this->getResponse()->setBody(json_encode(array('paid' => $paid))); } } From cf8bcc53fa22cb1228c8b854893baad5778b56a4 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 14:46:14 -0500 Subject: [PATCH 20/65] Updated to use defined constants --- app/code/community/Bitpay/Core/Model/TransactionSpeed.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php index 387b37a..f8ddf27 100644 --- a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php +++ b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php @@ -16,9 +16,9 @@ class Bitpay_Core_Model_TransactionSpeed public function toOptionArray() { return array( - array('value' => self::SPEED_LOW, 'label' => Mage::helper('bitpay')->__('Low')), - array('value' => self::SPEED_MEDIUM, 'label' => Mage::helper('bitpay')->__('Medium')), - array('value' => self::SPEED_HIGH, 'label' => Mage::helper('bitpay')->__('High')), + array('value' => self::SPEED_LOW, 'label' => Mage::helper('bitpay')->__(SPEED_LOW)), + array('value' => self::SPEED_MEDIUM, 'label' => Mage::helper('bitpay')->__(SPEED_MEDIUM)), + array('value' => self::SPEED_HIGH, 'label' => Mage::helper('bitpay')->__(SPEED_HIGH)), ); } } From 7c72010beee5bc652a0b60d4008925fc98cb56d5 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 14:46:55 -0500 Subject: [PATCH 21/65] Fixed missing scope --- app/code/community/Bitpay/Core/Model/TransactionSpeed.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php index f8ddf27..a8b96db 100644 --- a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php +++ b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php @@ -16,9 +16,9 @@ class Bitpay_Core_Model_TransactionSpeed public function toOptionArray() { return array( - array('value' => self::SPEED_LOW, 'label' => Mage::helper('bitpay')->__(SPEED_LOW)), - array('value' => self::SPEED_MEDIUM, 'label' => Mage::helper('bitpay')->__(SPEED_MEDIUM)), - array('value' => self::SPEED_HIGH, 'label' => Mage::helper('bitpay')->__(SPEED_HIGH)), + array('value' => self::SPEED_LOW, 'label' => Mage::helper('bitpay')->__(self::SPEED_LOW)), + array('value' => self::SPEED_MEDIUM, 'label' => Mage::helper('bitpay')->__(self::SPEED_MEDIUM)), + array('value' => self::SPEED_HIGH, 'label' => Mage::helper('bitpay')->__(self::SPEED_HIGH)), ); } } From 1ccd5b60bf09e4ce855090be28477d44e82dcb14 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 14:53:36 -0500 Subject: [PATCH 22/65] Updated to use defined constants --- app/code/community/Bitpay/Core/Model/Status.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Status.php b/app/code/community/Bitpay/Core/Model/Status.php index c1f9a6a..b01f2fe 100644 --- a/app/code/community/Bitpay/Core/Model/Status.php +++ b/app/code/community/Bitpay/Core/Model/Status.php @@ -19,12 +19,12 @@ class Bitpay_Core_Model_Status public function toOptionArray() { return array( - array('value' => self::STATUS_NEW, 'label' => Mage::helper('bitpay')->__('New')), - array('value' => self::STATUS_PAID, 'label' => Mage::helper('bitpay')->__('Paid')), - array('value' => self::STATUS_CONFIRMED, 'label' => Mage::helper('bitpay')->__('Confirmed')), - array('value' => self::STATUS_COMPLETE, 'label' => Mage::helper('bitpay')->__('Complete')), - array('value' => self::STATUS_EXPIRED, 'label' => Mage::helper('bitpay')->__('Expired')), - array('value' => self::STATUS_INVALID, 'label' => Mage::helper('bitpay')->__('Invalid')), + array('value' => self::STATUS_NEW, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_NEW)), + array('value' => self::STATUS_PAID, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_PAID)), + array('value' => self::STATUS_CONFIRMED, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_CONFIRMED)), + array('value' => self::STATUS_COMPLETE, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_COMPLETE)), + array('value' => self::STATUS_EXPIRED, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_EXPIRED)), + array('value' => self::STATUS_INVALID, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_INVALID)), ); } } From f2323c659aa0f307cf0eaff1584a996e2e2b1bd1 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 14:54:57 -0500 Subject: [PATCH 23/65] Ucwords Formatting Fix --- app/code/community/Bitpay/Core/Model/TransactionSpeed.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php index a8b96db..751fa24 100644 --- a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php +++ b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php @@ -16,9 +16,9 @@ class Bitpay_Core_Model_TransactionSpeed public function toOptionArray() { return array( - array('value' => self::SPEED_LOW, 'label' => Mage::helper('bitpay')->__(self::SPEED_LOW)), - array('value' => self::SPEED_MEDIUM, 'label' => Mage::helper('bitpay')->__(self::SPEED_MEDIUM)), - array('value' => self::SPEED_HIGH, 'label' => Mage::helper('bitpay')->__(self::SPEED_HIGH)), + array('value' => self::SPEED_LOW, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_LOW)), + array('value' => self::SPEED_MEDIUM, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_MEDIUM)), + array('value' => self::SPEED_HIGH, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_HIGH)), ); } } From a6b2bac388f2c59b555a0c73b1c7b34977613932 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 15:42:31 -0500 Subject: [PATCH 24/65] Added extra error handling and debugging Issue #89 opened to complete TODOs. --- .../community/Bitpay/Core/Model/Observer.php | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Observer.php b/app/code/community/Bitpay/Core/Model/Observer.php index b925580..12a4ec3 100644 --- a/app/code/community/Bitpay/Core/Model/Observer.php +++ b/app/code/community/Bitpay/Core/Model/Observer.php @@ -6,61 +6,61 @@ class Bitpay_Core_Model_Observer { - /** + /* + * TODO: Why is this here? */ public function checkForRequest($observer) { } - /** + /* * Queries BitPay to update the order states in magento to make sure that * open orders are closed/canceled if the BitPay invoice expires or becomes * invalid. */ public function updateOrderStates() { - Mage::helper('bitpay')->debugData( - 'cronjob: started' - ); - $apiKey = Mage::getStoreConfig('payment/bitpay/api_key'); - if (empty($apiKey)) { - Mage::helper('bitpay')->debugData( - 'cronjob: Api Key not set.' - ); - - return; // Api Key needs to be set + if (false === isset($apiKey) || empty($apiKey)) { + Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() could not start job to update the order states because the API key was not set.'); + return; + } else { + Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() started job to query BitPay to update the existing order states.'); } - /** + /* * Get all of the orders that are open and have not received an IPN for * complete, expired, or invalid. - * - * If anyone knows of a better way to do this, please let me know */ $orders = Mage::getModel('bitpay/ipn')->getOpenOrders(); - /** + if (false === isset($orders) || empty($orders)) { + Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() could not retrieve the open orders.'); + return; + } else { + Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() successfully retrieved existing open orders.'); + } + + /* * Get all orders that have been paid using bitpay and * are not complete/closed/etc */ foreach ($orders as $order) { - /** + /* * Query BitPay with the invoice ID to get the status. We must take * care not to anger the API limiting gods and disable our access * to the API. */ $status = null; + // TODO: // Does the order need to be updated? // Yes? Update Order Status // No? continue } - Mage::helper('bitpay')->debugData( - 'cronjob: end' - ); + Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() order status update job finished.'); } /** @@ -69,6 +69,7 @@ class Bitpay_Core_Model_Observer */ public function cleanExpired() { + Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::cleanExpired() called.'); Mage::helper('bitpay')->cleanExpired(); } } From 01afabb942af85bd7775713890d61846423624b4 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 15:44:13 -0500 Subject: [PATCH 25/65] Updated to use defined constants --- app/code/community/Bitpay/Core/Model/Network.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Network.php b/app/code/community/Bitpay/Core/Model/Network.php index 159e267..df8d7fb 100644 --- a/app/code/community/Bitpay/Core/Model/Network.php +++ b/app/code/community/Bitpay/Core/Model/Network.php @@ -18,8 +18,8 @@ class Bitpay_Core_Model_Network public function toOptionArray() { return array( - array('value' => self::NETWORK_LIVENET, 'label' => Mage::helper('bitpay')->__('Livenet')), - array('value' => self::NETWORK_TESTNET, 'label' => Mage::helper('bitpay')->__('Testnet')), + array('value' => self::NETWORK_LIVENET, 'label' => Mage::helper('bitpay')->__(ucwords(self::NETWORK_LIVENET))), + array('value' => self::NETWORK_TESTNET, 'label' => Mage::helper('bitpay')->__(ucwords(self::NETWORK_TESTNET))), ); } } From 369aff6e53c0b2a98f9b26fec029ae8e63ed1a19 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 15:45:10 -0500 Subject: [PATCH 26/65] Added missing parenthesis --- app/code/community/Bitpay/Core/Model/Status.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Status.php b/app/code/community/Bitpay/Core/Model/Status.php index b01f2fe..83eeb93 100644 --- a/app/code/community/Bitpay/Core/Model/Status.php +++ b/app/code/community/Bitpay/Core/Model/Status.php @@ -19,12 +19,12 @@ class Bitpay_Core_Model_Status public function toOptionArray() { return array( - array('value' => self::STATUS_NEW, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_NEW)), - array('value' => self::STATUS_PAID, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_PAID)), - array('value' => self::STATUS_CONFIRMED, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_CONFIRMED)), - array('value' => self::STATUS_COMPLETE, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_COMPLETE)), - array('value' => self::STATUS_EXPIRED, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_EXPIRED)), - array('value' => self::STATUS_INVALID, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_INVALID)), + array('value' => self::STATUS_NEW, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_NEW))), + array('value' => self::STATUS_PAID, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_PAID))), + array('value' => self::STATUS_CONFIRMED, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_CONFIRMED))), + array('value' => self::STATUS_COMPLETE, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_COMPLETE))), + array('value' => self::STATUS_EXPIRED, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_EXPIRED))), + array('value' => self::STATUS_INVALID, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_INVALID))), ); } } From 1feedfe671538c5e32b50b62e3f46b50b36321a1 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 15:45:35 -0500 Subject: [PATCH 27/65] Added missing parenthesis --- app/code/community/Bitpay/Core/Model/TransactionSpeed.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php index 751fa24..c41356e 100644 --- a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php +++ b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php @@ -16,9 +16,9 @@ class Bitpay_Core_Model_TransactionSpeed public function toOptionArray() { return array( - array('value' => self::SPEED_LOW, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_LOW)), - array('value' => self::SPEED_MEDIUM, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_MEDIUM)), - array('value' => self::SPEED_HIGH, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_HIGH)), + array('value' => self::SPEED_LOW, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_LOW))), + array('value' => self::SPEED_MEDIUM, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_MEDIUM))), + array('value' => self::SPEED_HIGH, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_HIGH))), ); } } From 409eb02c941480364ef28f39443c8ee6731b6b44 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 15:51:29 -0500 Subject: [PATCH 28/65] Added extra error handling and debugging --- app/code/community/Bitpay/Core/Model/Invoice.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Invoice.php b/app/code/community/Bitpay/Core/Model/Invoice.php index 7733daa..bdb9ff8 100644 --- a/app/code/community/Bitpay/Core/Model/Invoice.php +++ b/app/code/community/Bitpay/Core/Model/Invoice.php @@ -24,18 +24,20 @@ class Bitpay_Core_Model_Invoice extends Mage_Core_Model_Abstract */ public function prepareWithBitpayInvoice($invoice) { + if (false === isset($invoice) || true === empty($invoice)) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); + throw new Exception('In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); + } + $this->addData( array( 'id' => $invoice->getId(), - //'updated_at' => 'NOW()', 'url' => $invoice->getUrl(), 'pos_data' => $invoice->getPosData(), 'status' => $invoice->getStatus(), 'btc_price' => $invoice->getBtcPrice(), - //'btc_due' => $invoice->getBtcDue(), 'price' => $invoice->getPrice(), 'currency' => $invoice->getCurrency()->getCode(), - //'ex_rates' => $invoice->getExRates(), 'order_id' => $invoice->getOrderId(), 'invoice_time' => $invoice->getInvoiceTime(), 'expiration_time' => $invoice->getExpirationTime(), @@ -43,7 +45,6 @@ class Bitpay_Core_Model_Invoice extends Mage_Core_Model_Abstract 'btc_paid' => $invoice->getBtcPaid(), 'rate' => $invoice->getRate(), 'exception_status' => $invoice->getExceptionStatus(), - //'token' => $invoice->getToken(), ) ); @@ -58,6 +59,11 @@ class Bitpay_Core_Model_Invoice extends Mage_Core_Model_Abstract */ public function prepateWithOrder($order) { + if (false === isset($order) || true === empty($order)) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + throw new Exception('In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + } + $this->addData( array( 'quote_id' => $order->getQuoteId(), From c29c10c599da166b6b9cd16ea34a41e2f81dc693 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 17:02:59 -0500 Subject: [PATCH 29/65] Added extra error handling and debugging --- .../Bitpay/Core/Model/Method/Bitcoin.php | 143 ++++++++++++++---- 1 file changed, 117 insertions(+), 26 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php b/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php index 0c20e7b..46810fa 100644 --- a/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php +++ b/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php @@ -12,6 +12,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac protected $_code = 'bitpay'; protected $_formBlockType = 'bitpay/form_bitpay'; protected $_infoBlockType = 'bitpay/info'; + protected $_isGateway = true; protected $_canAuthorize = true; protected $_canCapture = false; @@ -19,12 +20,14 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac protected $_isInitializeNeeded = false; protected $_canFetchTransactionInfo = false; protected $_canManagerRecurringProfiles = false; - //protected $_canUseCheckout = true; - //protected $_canUseForMultishipping = true; - //protected $_canCapturePartial = false; - //protected $_canRefund = false; - //protected $_canVoid = false; + protected $_canUseCheckout = true; + protected $_canUseForMultishipping = true; + protected $_canCapturePartial = false; + protected $_canRefund = false; + protected $_canVoid = false; + protected $_debugReplacePrivateDataKeys = array(); + protected static $_redirectUrl; /** @@ -34,29 +37,41 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ public function authorize(Varien_Object $payment, $amount) { - $this->debugData('authorizing new order'); + if (false === isset($payment) || false === isset($amount) || true === empty($payment) || true === empty($amount)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); + } + + $this->debugData('[INFO] Bitpay_Core_Model_Method_Bitcoin::authorize(): authorizing new order.'); // Create BitPay Invoice $invoice = $this->initializeInvoice(); + + if (false === isset($invoice) || true === empty($invoice)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); + } + $invoice = $this->prepareInvoice($invoice, $payment, $amount); try { $bitpayInvoice = Mage::helper('bitpay')->getBitpayClient()->createInvoice($invoice); } catch (Exception $e) { - $this->debugData($e->getMessage()); + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): ' . $e->getMessage()); $this->debugData( array( Mage::helper('bitpay')->getBitpayClient()->getRequest()->getBody(), Mage::helper('bitpay')->getBitpayClient()->getResponse()->getBody(), ) ); - Mage::throwException('Could not authorize transaction.'); + Mage::throwException('In Bitpay_Core_Model_Method_Bitcoin::authorize(): Could not authorize transaction.'); } self::$_redirectUrl = $bitpayInvoice->getUrl(); + $this->debugData( array( - 'BitPay Invoice created', + '[INFO] BitPay Invoice created', sprintf('Invoice URL: "%s"', $bitpayInvoice->getUrl()), ) ); @@ -67,7 +82,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac ->prepateWithOrder($payment->getOrder()) ->save(); - $this->debugData($bitpayInvoice->getId()); + $this->debugData('[INFO] Leaving Bitpay_Core_Model_Method_Bitcoin::authorize(): invoice id ' . $bitpayInvoice->getId()); return $this; } @@ -83,16 +98,18 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac { $token = Mage::getStoreConfig('payment/bitpay/token'); - if (empty($token)) { + if (false === isset($token) || true === empty($token)) { /** * Merchant must goto their account and create a pairing code to * enter in. */ - $this->debugData('Magento store does not have a BitPay token.'); + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::canUseCheckout(): There was an error retrieving the token store param from the database or this Magento store does not have a BitPay token.'); return false; } + $this->debugData('[INFO] Leaving Bitpay_Core_Model_Method_Bitcoin::canUseCheckout(): token obtained from storage successfully.'); + return true; } @@ -104,11 +121,33 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ public function fetchInvoice($id) { + if (false === isset($id) || true === empty($id)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): missing or invalid id parameter.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): missing or invalid id parameter.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): function called with id ' . $id); + } + Mage::helper('bitpay')->registerAutoloader(); $client = Mage::helper('bitpay')->getBitpayClient(); + + if (false === isset($client) || true === empty($client)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not obtain BitPay client.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not obtain BitPay client.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): obtained BitPay client successfully.'); + } + $invoice = $client->getInvoice($id); + if (false === isset($invoice) || true === empty($invoice)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not retrieve invoice from BitPay.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not retrieve invoice from BitPay.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): successfully retrieved invoice id ' . $id . ' from BitPay.'); + } + return $invoice; } @@ -121,9 +160,12 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ public function extractAddress($address) { - $this->debugData( - sprintf('Extracting addess') - ); + if (false === isset($address) || true === empty($address)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::extractAddress(): missing or invalid address parameter.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::extractAddress(): missing or invalid address parameter.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::extractAddress(): called with good address parameter, extracting now.'); + } $options = array(); $options['buyerName'] = $address->getName(); @@ -145,7 +187,10 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac // trim to fit API specs foreach (array('buyerName', 'buyerAddress1', 'buyerAddress2', 'buyerAddress3', 'buyerAddress4', 'buyerCity', 'buyerState', 'buyerZip', 'buyerCountry', 'buyerEmail', 'buyerPhone') as $f) { - $options[$f] = substr($options[$f], 0, 100); + if (true === isset($options[$f]) && strlen($options[$f]) > 100) { + $this->debugData('[WARNING] In Bitpay_Core_Model_Method_Bitcoin::extractAddress(): the ' . $f . ' parameter was greater than 100 characters, trimming.'); + $options[$f] = substr($options[$f], 0, 100); + } } return $options; @@ -158,9 +203,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ public function getOrderPlaceRedirectUrl() { - $this->debugData( - 'Customer wants to place the order. Create invoice and redirect user to invoice' - ); + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::getOrderPlaceRedirectUrl(): $_redirectUrl is ' . self::$_redirectUrl); return self::$_redirectUrl; } @@ -176,6 +219,14 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac Mage::helper('bitpay')->registerAutoloader(); $invoice = new Bitpay\Invoice(); + + if (false === isset($invoice) || true === empty($invoice)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::initializeInvoice(): could not construct new BitPay invoice object.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::initializeInvoice(): could not construct new BitPay invoice object.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::initializeInvoice(): constructed new BitPay invoice object successfully.'); + } + $invoice->setFullNotifications(true); $invoice->setTransactionSpeed(Mage::getStoreConfig('payment/bitpay/speed')); $invoice->setNotificationUrl(Mage::getUrl(Mage::getStoreConfig('payment/bitpay/notification_url'))); @@ -195,14 +246,15 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ private function prepareInvoice($invoice, $payment, $amount) { + if (false === isset($invoice) || true === empty($invoice) || false === isset($payment) || true === empty($payment) || false === isset($amount) || true === empty($amount)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::prepareInvoice(): missing or invalid invoice, payment or amount parameter.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::prepareInvoice(): missing or invalid invoice, payment or amount parameter.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::prepareInvoice(): entered function with good invoice, payment and amount parameters.'); + } + $invoice->setOrderId($payment->getOrder()->getIncrementId()); - $invoice->setPosData( - json_encode( - array( - 'id' => $payment->getOrder()->getIncrementId(), - ) - ) - ); + $invoice->setPosData(json_encode(array('id' => $payment->getOrder()->getIncrementId()))); $invoice = $this->addCurrencyInfo($invoice, $payment->getOrder()); $invoice = $this->addPriceInfo($invoice, $amount); @@ -220,7 +272,20 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ private function addBuyerInfo($invoice, $order) { + if (false === isset($invoice) || true === empty($invoice) || false === isset($order) || true === empty($order)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): missing or invalid invoice or order parameter.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): missing or invalid invoice or order parameter.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): function called with good invoice and order parameters.'); + } + $buyer = new Bitpay\Buyer(); + + if (false === isset($buyer) || true === empty($buyer)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): could not construct new BitPay buyer object.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): could not construct new BitPay buyer object.'); + } + $buyer->setFirstName($order->getCustomerFirstname()); $buyer->setLastName($order->getCustomerLastname()); $invoice->setBuyer($buyer); @@ -237,7 +302,20 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ private function addCurrencyInfo($invoice, $order) { + if (false === isset($invoice) || true === empty($invoice) || false === isset($order) || true === empty($order)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): missing or invalid invoice or order parameter.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): missing or invalid invoice or order parameter.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): function called with good invoice and order parameters.'); + } + $currency = new Bitpay\Currency(); + + if (false === isset($currency) || true === empty($currency)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): could not construct new BitPay currency object.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): could not construct new BitPay currency object.'); + } + $currency->setCode($order->getBaseCurrencyCode()); $invoice->setCurrency($currency); @@ -253,7 +331,20 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ private function addPriceInfo($invoice, $amount) { + if (false === isset($invoice) || true === empty($invoice) || false === isset($amount) || true === empty($amount)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): missing or invalid invoice or amount parameter.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): missing or invalid invoice or amount parameter.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): function called with good invoice and amount parameters.'); + } + $item = new \Bitpay\Item(); + + if (false === isset($item) || true === empty($item)) { + $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): could not construct new BitPay item object.'); + throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): could not construct new BitPay item object.'); + } + $item->setPrice($amount); $invoice->setItem($item); From 89a980773602a9918f56cc8dc5b3cdb89f2dc3c8 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 17:11:49 -0500 Subject: [PATCH 30/65] Added extra error handling and debugging --- .../Bitpay/Core/Model/Config/PairingCode.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Config/PairingCode.php b/app/code/community/Bitpay/Core/Model/Config/PairingCode.php index 410fd1e..a3dab51 100644 --- a/app/code/community/Bitpay/Core/Model/Config/PairingCode.php +++ b/app/code/community/Bitpay/Core/Model/Config/PairingCode.php @@ -23,25 +23,21 @@ class Bitpay_Core_Model_Config_PairingCode extends Mage_Core_Model_Config_Data */ $pairingCode = trim($this->getValue()); - if (empty($pairingCode)) { + if (true === empty($pairingCode)) { return; } - Mage::helper('bitpay')->debugData('Attempting Pair Code'); + Mage::helper('bitpay')->debugData('[INFO] In Bitpay_Core_Model_Config_PairingCode::save(): attempting to pair with BitPay with pairing code ' . $pairingCode); try { Mage::helper('bitpay')->sendPairingRequest($pairingCode); } catch (Exception $e) { - Mage::helper('bitpay')->debugData( - sprintf('Error Pairing Code "%s"', $e->getMessage()) - ); - Mage::getSingleton('core/session')->addError( - 'There was an error while trying to pair the pairing code. Please try again or enabled debug mode and send the "payment_bitpay.log" file to support.' - ); + Mage::helper('bitpay')->debugData(sprintf('[ERROR] Exception thrown while calling the sendPairingRequest() function. The specific error message is: "%s"', $e->getMessage())); + Mage::getSingleton('core/session')->addError('There was an error while trying to pair with BitPay using the pairing code '.$pairingCode.'. Please try again or enable debug mode and send the "payment_bitpay.log" file to support@bitpay.com for more help.'); return; } - Mage::getSingleton('core/session')->addSuccess('Pairing Code was successful.'); + Mage::getSingleton('core/session')->addSuccess('Pairing with BitPay was successful.'); } } From 701fc2e833638cf70396b06675eef5bc7a883d49 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Wed, 17 Dec 2014 18:11:47 -0500 Subject: [PATCH 31/65] Added extra error handling and debugging --- .../community/Bitpay/Core/Helper/Data.php | 237 ++++++++++++++---- 1 file changed, 186 insertions(+), 51 deletions(-) diff --git a/app/code/community/Bitpay/Core/Helper/Data.php b/app/code/community/Bitpay/Core/Helper/Data.php index 9f7e223..ebaff97 100644 --- a/app/code/community/Bitpay/Core/Helper/Data.php +++ b/app/code/community/Bitpay/Core/Helper/Data.php @@ -21,7 +21,9 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function debugData($debugData) { - Mage::getModel('bitpay/method_bitcoin')->debugData($debugData); + if (true === isset($debugData) && false === empty($debugData)) { + Mage::getModel('bitpay/method_bitcoin')->debugData($debugData); + } } /** @@ -70,11 +72,19 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function registerAutoloader() { - if (null === $this->_autoloaderRegistered) { - require_once Mage::getBaseDir('lib').'/Bitpay/Autoloader.php'; - \Bitpay\Autoloader::register(); - $this->_autoloaderRegistered = true; - $this->debugData('BitPay Autoloader has been registered'); + if (true === empty($this->_autoloaderRegistered)) { + $autoloader_filename = Mage::getBaseDir('lib').'/Bitpay/Autoloader.php'; + + if (true === is_file($autoloader_filename) && true === is_readable($autoloader_filename)) { + require_once $autoloader_filename; + \Bitpay\Autoloader::register(); + $this->_autoloaderRegistered = true; + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::registerAutoloader(): autoloader file was found and has been registered.'); + } else { + $this->_autoloaderRegistered = false; + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::registerAutoloader(): autoloader file was not found or is not readable. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::registerAutoloader(): autoloader file was not found or is not readable. Cannot continue!'); + } } } @@ -84,21 +94,36 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function generateAndSaveKeys() { - $this->debugData('Generating Keys'); - $this->registerAutoloader(); + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::generateAndSaveKeys(): attempting to generate new keypair and save to database.'); + + if (true === empty($this->_autoloaderRegistered)) { + $this->registerAutoloader(); + } $this->_privateKey = new Bitpay\PrivateKey('payment/bitpay/private_key'); - $this->_privateKey->generate(); + + if (false === isset($this->_privateKey) || true === empty($this->_privateKey)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay private key object. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay private key object. Cannot continue!'); + } else { + $this->_privateKey->generate(); + } $this->_publicKey = new Bitpay\PublicKey('payment/bitpay/public_key'); - $this->_publicKey - ->setPrivateKey($this->_privateKey) - ->generate(); + + if (false === isset($this->_publicKey) || true === empty($this->_publicKey)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay public key object. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay public key object. Cannot continue!'); + } else { + $this->_publicKey + ->setPrivateKey($this->_privateKey) + ->generate(); + } $this->getKeyManager()->persist($this->_publicKey); $this->getKeyManager()->persist($this->_privateKey); - $this->debugData('Keys persisted to database'); + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::generateAndSaveKeys(): key manager called to persist keypair to database.'); } /** @@ -106,36 +131,62 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function sendPairingRequest($pairingCode) { - $this->debugData( - sprintf('Sending Paring Request with pairing code "%s"', $pairingCode) - ); + if (false === isset($pairingCode) || true === empty($pairingCode)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): missing or invalid pairingCode parameter.'); + throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): missing or invalid pairingCode parameter.'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): function called with the pairingCode parameter: ' . $pairingCode); + } + + if (true === empty($this->_autoloaderRegistered)) { + $this->registerAutoloader(); + } // Generate/Regenerate keys $this->generateAndSaveKeys(); $sin = $this->getSinKey(); - $this->debugData( - sprintf('Sending Pairing Request for SIN "%s"', (string) $sin) - ); + if (false === isset($sin) || true === empty($sin)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): could not retrieve the SIN parameter. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): could not retrieve the SIN parameter. Cannot continue!'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): attempting to pair with the SIN parameter: ' . $sin); + } // Sanitize label - $label = preg_replace('/[^a-zA-Z0-9 \-\_\.]/', '', Mage::app()->getStore()->getName()); - $label = substr('Magento - '.$label, 0, 59); + $label = preg_replace('/[^a-zA-Z0-9 ]/', '', Mage::app()->getStore()->getName()); + $label = substr('Magento ' . $label, 0, 59); + + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): using the label "' . $label . '".'); $token = $this->getBitpayClient()->createToken( - array( - 'id' => (string) $sin, - 'pairingCode' => $pairingCode, - 'label' => $label, - ) - ); + array( + 'id' => (string) $sin, + 'pairingCode' => (string) $pairingCode, + 'label' => (string) $label, + ) + ); - $this->debugData('Token Obtained'); + if (false === isset($token) || true === empty($token)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): could not obtain the token from the pairing process. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): could not obtain the token from the pairing process. Cannot continue!'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): token successfully obtained.'); + } $config = new \Mage_Core_Model_Config(); - $config->saveConfig('payment/bitpay/token', $token->getToken()); - $this->debugData('Token Persisted persisted to database'); + if (false === isset($config) || true === empty($config)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): could not create new Mage_Core_Model_Config object. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): could not create new Mage_Core_Model_Config object. Cannot continue!'); + } + + if($config->saveConfig('payment/bitpay/token', $token->getToken())) { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): token saved to database.'); + } else { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): token could not be saved to database.'); + throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): token could not be saved to database.'); + } } /** @@ -143,53 +194,97 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function getSinKey() { - if (null !== $this->_sin) { + if (false === empty($this->_sin)) { return $this->_sin; } - $this->debugData('Getting SIN Key'); + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getSinKey(): attempting to get the SIN parameter.'); + + if (true === empty($this->_autoloaderRegistered)) { + $this->registerAutoloader(); + } - $this->registerAutoloader(); $this->_sin = new Bitpay\SinKey(); + + if (false === isset($this->_sin) || true === empty($this->_sin)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getSinKey(): could not create new BitPay SinKey object. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::getSinKey(): could not create new BitPay SinKey object. Cannot continue!'); + } + $this->_sin - ->setPublicKey($this->getPublicKey()) - ->generate(); + ->setPublicKey($this->getPublicKey()) + ->generate(); + + if (false === isset($this->_sin) || true === empty($this->_sin)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getSinKey(): could not generate a new SIN from the public key. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::getSinKey(): could not generate a new SIN from the public key. Cannot continue!'); + } return $this->_sin; } public function getPublicKey() { - if (null !== $this->_publicKey) { + if (true === isset($this->_publicKey) && false === empty($this->_publicKey)) { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPublicKey(): found an existing public key, returning that.'); return $this->_publicKey; } - $this->debugData('Getting Public Key'); + if (true === empty($this->_autoloaderRegistered)) { + $this->registerAutoloader(); + } + + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPublicKey(): did not find an existing public key, attempting to load one from the key manager.'); $this->_publicKey = $this->getKeyManager()->load('payment/bitpay/public_key'); - if (!$this->_publicKey) { + if (true === empty($this->_publicKey)) { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPublicKey(): could not load a public key from the key manager, generating a new one.'); $this->generateAndSaveKeys(); + } else { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPublicKey(): successfully loaded public key from the key manager, returning that.'); + return $this->_publicKey; } - return $this->_publicKey; + if (false === empty($this->_publicKey)) { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPublicKey(): successfully generated a new public key.'); + return $this->_publicKey; + } else { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getPublicKey(): could not load or generate a new public key. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::getPublicKey(): could not load or generate a new public key. Cannot continue!'); + } } public function getPrivateKey() { - if (null !== $this->_privateKey) { + if (false === empty($this->_privateKey)) { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPrivateKey(): found an existing private key, returning that.'); return $this->_privateKey; } - $this->debugData('Getting Private Key'); + if (true === empty($this->_autoloaderRegistered)) { + $this->registerAutoloader(); + } + + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPrivateKey(): did not find an existing private key, attempting to load one from the key manager.'); $this->_privateKey = $this->getKeyManager()->load('payment/bitpay/private_key'); - if (!$this->_publicKey) { + if (true === empty($this->_privateKey)) { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPrivateKey(): could not load a private key from the key manager, generating a new one.'); $this->generateAndSaveKeys(); + } else { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPrivateKey(): successfully loaded private key from the key manager, returning that.'); + return $this->_privateKey; } - return $this->_privateKey; + if (false === empty($this->_privateKey)) { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getPrivateKey(): successfully generated a new private key.'); + return $this->_privateKey; + } else { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getPrivateKey(): could not load or generate a new private key. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::getPrivateKey(): could not load or generate a new private key. Cannot continue!'); + } } /** @@ -197,10 +292,19 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function getKeyManager() { - if (null == $this->_keyManager) { - $this->registerAutoloader(); - $this->debugData('Creating instance of KeyManager'); + if (true === empty($this->_keyManager)) { + if (true === empty($this->_autoloaderRegistered)) { + $this->registerAutoloader(); + } + $this->_keyManager = new Bitpay\KeyManager(new Bitpay\Storage\MagentoStorage()); + + if (false === isset($this->_keyManager) || true === empty($this->_keyManager)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getKeyManager(): could not create new BitPay KeyManager object. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::getKeyManager(): could not create new BitPay KeyManager object. Cannot continue!'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getKeyManager(): successfully created new BitPay KeyManager object.'); + } } return $this->_keyManager; @@ -214,9 +318,19 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function getBitpay() { - if (null === $this->_bitpay) { - $this->registerAutoloader(); + if (true === empty($this->_bitpay)) { + if (true === empty($this->_autoloaderRegistered)) { + $this->registerAutoloader(); + } + $this->_bitpay = new Bitpay\Bitpay(array('bitpay' => $this->getBitpayConfig())); + + if (false === isset($this->_bitpay) || true === empty($this->_bitpay)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getBitpay(): could not create new BitPay object. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::getBitpay(): could not create new BitPay object. Cannot continue!'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getBitpay(): successfully created new BitPay object.'); + } } return $this->_bitpay; @@ -242,13 +356,23 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function getBitpayClient() { - if (null !== $this->_client) { + if (false === empty($this->_client)) { return $this->_client; } - $this->registerAutoloader(); + if (true === empty($this->_autoloaderRegistered)) { + $this->registerAutoloader(); + } $this->_client = new Bitpay\Client\Client(); + + if (false === isset($this->_client) || true === empty($this->_client)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getBitpayClient(): could not create new BitPay Client object. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::getBitpayClient(): could not create new BitPay Client object. Cannot continue!'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getBitpayClient(): successfully created new BitPay Client object.'); + } + $this->_client->setPublicKey($this->getPublicKey()); $this->_client->setPrivateKey($this->getPrivateKey()); $this->_client->setNetwork($this->getBitpay()->get('network')); @@ -260,8 +384,19 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract public function getToken() { - $this->registerAutoloader(); + if (true === empty($this->_autoloaderRegistered)) { + $this->registerAutoloader(); + } + $token = new Bitpay\Token(); + + if (false === isset($token) || true === empty($token)) { + $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getToken(): could not create new BitPay Token object. Cannot continue!'); + throw new Exception('In Bitpay_Core_Helper_Data::getToken(): could not create new BitPay Token object. Cannot continue!'); + } else { + $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getToken(): successfully created new BitPay Token object.'); + } + $token->setToken(Mage::getStoreConfig('payment/bitpay/token')); return $token; From faaf54206ae6aedbe1f3e251b462f7f31d868789 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 18 Dec 2014 21:00:28 -0500 Subject: [PATCH 32/65] Added extra error handling and debugging --- app/code/community/Bitpay/Core/Block/Info.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/code/community/Bitpay/Core/Block/Info.php b/app/code/community/Bitpay/Core/Block/Info.php index 4e003b1..765d93d 100644 --- a/app/code/community/Bitpay/Core/Block/Info.php +++ b/app/code/community/Bitpay/Core/Block/Info.php @@ -15,11 +15,22 @@ class Bitpay_Core_Block_Info extends Mage_Payment_Block_Info public function getBitpayInvoiceUrl() { $order = $this->getInfo()->getOrder(); + + if (false === isset($order) || true === empty($order)) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); + throw new Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); + } + $incrementId = $order->getIncrementId(); + if (false === isset($incrementId) || true === empty($incrementId)) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); + throw new Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); + } + $bitpayInvoice = Mage::getModel('bitpay/invoice')->load($incrementId, 'increment_id'); - if ($bitpayInvoice) { + if (true === isset($bitpayInvoice) && false === empty($bitpayInvoice)) { return $bitpayInvoice->getUrl(); } } From 4e32b0e2a9ecc9fc8259c27531208fd46c64dc07 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Tue, 30 Dec 2014 12:50:03 -0500 Subject: [PATCH 33/65] Added extra error handling and debugging TODO: Finish the iframe implementation... --- .../community/Bitpay/Core/Block/Iframe.php | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/app/code/community/Bitpay/Core/Block/Iframe.php b/app/code/community/Bitpay/Core/Block/Iframe.php index 0d1dd23..4d14734 100644 --- a/app/code/community/Bitpay/Core/Block/Iframe.php +++ b/app/code/community/Bitpay/Core/Block/Iframe.php @@ -2,6 +2,8 @@ /** * @license Copyright 2011-2014 BitPay Inc., MIT License * @see https://github.com/bitpay/magento-plugin/blob/master/LICENSE + * + * TODO: Finish this iFrame implemenation... :/ */ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment @@ -27,6 +29,12 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment /*** @var Bitpay_Core_Model_PaymentMethod ***/ $method = $this->getQuote()->getPayment()->getMethodInstance(); + + if (false === isset($method) || true === empty($method)) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not obtain an instance of the payment method.'); + throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not obtain an instance of the payment method.'); + } + $options = array_merge( array( 'currency' => $this->getQuote()->getQuoteCurrencyCode(), @@ -37,32 +45,45 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment ), $method->extractAddress($this->getQuote()->getShippingAddress()) ); - Mage::helper('bitpay')->debugData($options); + + if (false === isset($options) || true === empty($options)) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the options array.'); + throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the options array.'); + } else { + Mage::helper('bitpay')->debugData($options); + } // Mage doesn't round the total until saving and it can have more precision // at this point which would be bad for later comparing records w/ bitpay. // So round here to match what the price will be saved as: $price = round($this->getQuote()->getGrandTotal(), 4); + if (false === isset($price) || true === empty($price)) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the new rounded price.'); + throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the new rounded price.'); + } + //serialize info about the quote to detect changes $hash = $method->getQuoteHash($this->getQuote()->getId()); + if (false === isset($hash) || true === empty($hash)) { + Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the quote hash.'); + throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the quote hash.'); + } + Mage::helper('bitpay')->registerAutoloader(); + //$invoice = bpCreateInvoice($quoteId, $price, array('quoteId' => $quoteId, 'quoteHash' => $hash), $options); $invoice = array('url' => 'https://test.bitpay.com/invoice?id=5NxFkXcJbCSivtQRJa4kHP'); if (array_key_exists('error', $invoice)) { - Mage::helper('bitpay')->debugData( - array( - 'Error creating bitpay invoice', - $invoice['error'], - ) - ); + Mage::helper('bitpay')->debugData(array('Error creating bitpay invoice', $invoice['error'],)); Mage::throwException("Error creating BitPay invoice. Please try again or use another payment option."); return false; } - return $invoice['url'].'&view=iframe'; + //return $invoice['url'].'&view=iframe'; + return false; } } From 9d9215c0d4f514f12ad0ed7a7a57914f0ad38659 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Tue, 30 Dec 2014 13:02:04 -0500 Subject: [PATCH 34/65] Update CHANGELOG --- CHANGELOG | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 658af47..3aea5ff 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +2.1.2 + Added extra error handling and fixed debugging + Updated README documentation for accuracy + Re-wrote delete.sh shell script to autodetect Magento directory and + be more helpful when cleaning an old BitPay plugin from the server + 2.1.1 Bug fix sanitizing labels for token pairing Replaced GMP only requirement with GMP or BC Math requirement From 8ce288db4b0da62351841c46507858deff6fa3e8 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Tue, 30 Dec 2014 13:18:56 -0500 Subject: [PATCH 35/65] Check to see if new order email was sent and to send one if not. References GH Issue #85 --- .../Bitpay/Core/controllers/IpnController.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/code/community/Bitpay/Core/controllers/IpnController.php b/app/code/community/Bitpay/Core/controllers/IpnController.php index cf99880..7aa2daa 100644 --- a/app/code/community/Bitpay/Core/controllers/IpnController.php +++ b/app/code/community/Bitpay/Core/controllers/IpnController.php @@ -112,7 +112,16 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action if (true === isset($payment) && false === empty($payment)) { $payment->registerCaptureNotification($invoice->getPrice()); - $order->addPayment($payment)->save(); + $order->addPayment($payment); + + // If the customer has not already been notified by email + // send the notification now that there's a new order. + if (!$order->getEmailSent()) { + Mage::helper('bitpay')->debugData('[INFO] Order email not sent so I am calling $order->sendNewOrderEmail() now...'); + $order->sendNewOrderEmail(); + } + + $order->save(); } else { Mage::helper('bitpay')->debugData('[ERROR] Could not create a payment object in the Bitpay IPN controller.'); Mage::throwException('Could not create a payment object in the Bitpay IPN controller.'); From 6ba2157166d9eb0a212eefb697d2015720c1a7ab Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Tue, 30 Dec 2014 13:20:18 -0500 Subject: [PATCH 36/65] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 3aea5ff..9555da8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ 2.1.2 Added extra error handling and fixed debugging + Re-added new order email notifications Updated README documentation for accuracy Re-wrote delete.sh shell script to autodetect Magento directory and be more helpful when cleaning an old BitPay plugin from the server From 1226a523521db2de560871139f73c2e88754e14e Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Tue, 30 Dec 2014 13:24:11 -0500 Subject: [PATCH 37/65] Formatting --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4101cb9..5723c1d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ This is because there are little to no fees for transferring Bitcoins from one p # Upgrade From Plugin Version 1.x to 2.x -Very Important: You must complete remove any previous versions of the Bitpay Magento plugin before installing this new updated version. The plugin has been completely re-written to work with BitPay's new cryptographically secure RESTful API and will conflict with any previous plugin versions which use the old API. To help you remove the old plugin files from your system, we have created a convenient shell script for Unix/Linux/Mac OS systems which will scan your webserver for these older files and delete them. You may also remove these files by hand of course and the complete list of the files can be found in the source of the script for your convenience. You can download this delete script here: [scripts/delete.sh](https://github.com/bitpay/magento-plugin/blob/master/scripts/delete.sh). +***Very Important:*** You must complete remove any previous versions of the Bitpay Magento plugin before installing this new updated version. The plugin has been completely re-written to work with BitPay's new cryptographically secure RESTful API and will conflict with any previous plugin versions which use the old API. To help you remove the old plugin files from your system, we have created a convenient shell script for Unix/Linux/Mac OS systems which will scan your webserver for these older files and delete them. You may also remove these files by hand of course and the complete list of the files can be found in the source of the script for your convenience. You can download this delete script here: [scripts/delete.sh](https://github.com/bitpay/magento-plugin/blob/master/scripts/delete.sh). To use this script, simply download to your server and execute the script from a shell. You may have to mark the script executable before first use. @@ -41,20 +41,20 @@ Goto [http://www.magentocommerce.com/magento-connect/bitpay-payment-method.html] Once you have the key, log into you Magento Store's Admin Panel and navigate to **System > Magento Connect > Magento Connect Manager**. -***NOTE*** It may ask you to log in again using the same credentials that you use to log into the Admin Panel. +***NOTE:*** It may ask you to log in again using the same credentials that you use to log into the Admin Panel. All you need to do is paste the extension key and click on the *Install* button. -***WARNING*** It is good practice to backup your database before installing extensions. Please make sure you Create Backups. +***WARNING:*** It is good practice to backup your database before installing extensions. Please make sure you Create Backups. ## Download Visit the [Releases](https://github.com/bitpay/magento-plugin/releases) page of this repository and download the latest version. Once this is done, you can just unzip the contents and use any method you want to put them on your server. The contents will mirror the Magento directory structure. -***NOTE*** These files can also up uploaded using the *Magento Connect Manager* that comes with your Magento Store +***NOTE:*** These files can also up uploaded using the *Magento Connect Manager* that comes with your Magento Store -***WARNING*** It is good practice to backup your database before installing extensions. Please make sure you Create Backups. +***WARNING:*** It is good practice to backup your database before installing extensions. Please make sure you Create Backups. ## modman @@ -70,9 +70,9 @@ Configuration can be done using the Administrator section of your Megento store. Here your will need to create a [pairing code](https://bitpay.com/api-tokens) using your BitPay merchant account. Once you have a Pairing Code, put the code in the Pairing Code field. This will take care of the rest for you. -***NOTE*** Pairing Codes are only valid for a short period of time. If it expires before you get to use it, you can always create a new one an use the new one. +***NOTE:*** Pairing Codes are only valid for a short period of time. If it expires before you get to use it, you can always create a new one an use the new one. -***NOTE*** You will only need to do this once since each time you do this, the extension will generate public and private keys that are used to identify you when using the API. +***NOTE:*** You will only need to do this once since each time you do this, the extension will generate public and private keys that are used to identify you when using the API. You are also able to configure how BitPay's IPN (Instant Payment Notifications) changes the order in your Magento store. @@ -105,11 +105,11 @@ As a merchant, the orders in your Magento store can be treated as any other orde 1. Ensure a valid SSL certificate is installed on your server. Also ensure your root CA cert is updated. If your CA cert is not current, you will see curl SSL verification errors. 2. Verify that your web server is not blocking POSTs from servers it may not recognize. Double check this on your firewall as well, if one is being used. -3. Check the `payment_bitpay.log` file for any errors during BitPay payment attempts. If you contact BitPay support, they will ask to see the log file to help diagnose the problem. The log file will be found inside your Magento's `var/log/` directory. ***NOTE*** You will need to enable the debugging setting for the extension to output information into the log file. +3. Check the `payment_bitpay.log` file for any errors during BitPay payment attempts. If you contact BitPay support, they will ask to see the log file to help diagnose the problem. The log file will be found inside your Magento's `var/log/` directory. ***NOTE:*** You will need to enable the debugging setting for the extension to output information into the log file. 4. Check the version of this plugin against the official plugin repository to ensure you are using the latest version. Your issue might have been addressed in a newer version! See the [Releases](https://github.com/bitpay/magento-plugin/releases) page or the Magento Connect store for the latest version. 5. If all else fails, send an email describing your issue **in detail** to support@bitpay.com -***TIP***: When contacting support it will help us is you provide: +***TIP:*** When contacting support it will help us is you provide: * Magento CE Version (Found at the bottom page in the Administration section) * Other extensions you have installed @@ -129,7 +129,7 @@ Once you have cloned the repository, you will need to run [composer install](htt If you encounter any issues or implement any updates or changes, please open an [issue](https://github.com/bitpay/magento-plugin/issues) or submit a Pull Request. -***NOTE*** The ``scripts/package`` file contains some configuration settings that will need to change for different releases. If you are using this script to build files that are for distribution, these will need to be updated. +***NOTE:*** The ``scripts/package`` file contains some configuration settings that will need to change for different releases. If you are using this script to build files that are for distribution, these will need to be updated. # License From 8ec543dd54b7abf667d85fea2858ebbe40da24af Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 14:43:04 -0500 Subject: [PATCH 38/65] Removed logging code causing exceptions to be thrown when getBody() was called on an invalid invoice object. --- app/code/community/Bitpay/Core/Model/Method/Bitcoin.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php b/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php index 46810fa..fdf59c6 100644 --- a/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php +++ b/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php @@ -58,12 +58,6 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac $bitpayInvoice = Mage::helper('bitpay')->getBitpayClient()->createInvoice($invoice); } catch (Exception $e) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): ' . $e->getMessage()); - $this->debugData( - array( - Mage::helper('bitpay')->getBitpayClient()->getRequest()->getBody(), - Mage::helper('bitpay')->getBitpayClient()->getResponse()->getBody(), - ) - ); Mage::throwException('In Bitpay_Core_Model_Method_Bitcoin::authorize(): Could not authorize transaction.'); } From cea830617baca2c61ae6173a2a1a74947d92dd58 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 15:52:59 -0500 Subject: [PATCH 39/65] Added namespace backslash --- lib/Bitpay/Storage/MagentoStorage.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Bitpay/Storage/MagentoStorage.php b/lib/Bitpay/Storage/MagentoStorage.php index 20f790b..15f8bb2 100644 --- a/lib/Bitpay/Storage/MagentoStorage.php +++ b/lib/Bitpay/Storage/MagentoStorage.php @@ -31,7 +31,7 @@ class MagentoStorage implements StorageInterface if (true === isset($config) && false === empty($config)) { $config->saveConfig($key->getId(), $encryptedData); } else { - Mage::helper('bitpay')->debugData('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); + \Mage::helper('bitpay')->debugData('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); throw new Exception('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); } } @@ -51,18 +51,18 @@ class MagentoStorage implements StorageInterface * Not in database */ if (false === isset($entity) || true === empty($entity)) { - Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' did not return the store config parameter because it was not found in the database.'); + \Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' did not return the store config parameter because it was not found in the database.'); return false; } $decodedEntity = unserialize(\Mage::helper('core')->decrypt($entity)); if (false === isset($decodedEntity) || true === empty($decodedEntity)) { - Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' could not decrypt & unserialize the entity ' . $entity . '.'); + \Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' could not decrypt & unserialize the entity ' . $entity . '.'); return false; } - Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' successfully decrypted & unserialized the entity ' . $entity . '.'); + \Mage::helper('bitpay')->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' successfully decrypted & unserialized the entity ' . $entity . '.'); return $decodedEntity; } From f796e0a4f79eaae174dbc5642e2f7b38c57d5fd8 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 15:55:06 -0500 Subject: [PATCH 40/65] Added namespace backslash --- .../community/Bitpay/Core/Block/Iframe.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/code/community/Bitpay/Core/Block/Iframe.php b/app/code/community/Bitpay/Core/Block/Iframe.php index 4d14734..2504f59 100644 --- a/app/code/community/Bitpay/Core/Block/Iframe.php +++ b/app/code/community/Bitpay/Core/Block/Iframe.php @@ -23,7 +23,7 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment */ public function getIframeUrl() { - if (Mage::getModel('bitpay/ipn')->getQuotePaid($this->getQuote()->getId())) { + if (\Mage::getModel('bitpay/ipn')->getQuotePaid($this->getQuote()->getId())) { return 'paid'; // quote's already paid, so don't show the iframe } @@ -31,7 +31,7 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment $method = $this->getQuote()->getPayment()->getMethodInstance(); if (false === isset($method) || true === empty($method)) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not obtain an instance of the payment method.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not obtain an instance of the payment method.'); throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not obtain an instance of the payment method.'); } @@ -39,18 +39,18 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment array( 'currency' => $this->getQuote()->getQuoteCurrencyCode(), 'fullNotifications' => 'true', - 'notificationURL' => Mage::getUrl('bitpay/ipn'), - 'redirectURL' => Mage::getUrl('checkout/onepage/success'), - 'transactionSpeed' => Mage::getStoreConfig('payment/bitpay/speed'), + 'notificationURL' => \Mage::getUrl('bitpay/ipn'), + 'redirectURL' => \Mage::getUrl('checkout/onepage/success'), + 'transactionSpeed' => \Mage::getStoreConfig('payment/bitpay/speed'), ), $method->extractAddress($this->getQuote()->getShippingAddress()) ); if (false === isset($options) || true === empty($options)) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the options array.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the options array.'); throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the options array.'); } else { - Mage::helper('bitpay')->debugData($options); + \Mage::helper('bitpay')->debugData($options); } // Mage doesn't round the total until saving and it can have more precision @@ -59,7 +59,7 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment $price = round($this->getQuote()->getGrandTotal(), 4); if (false === isset($price) || true === empty($price)) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the new rounded price.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the new rounded price.'); throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the new rounded price.'); } @@ -67,18 +67,18 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment $hash = $method->getQuoteHash($this->getQuote()->getId()); if (false === isset($hash) || true === empty($hash)) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the quote hash.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the quote hash.'); throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the quote hash.'); } - Mage::helper('bitpay')->registerAutoloader(); + \Mage::helper('bitpay')->registerAutoloader(); //$invoice = bpCreateInvoice($quoteId, $price, array('quoteId' => $quoteId, 'quoteHash' => $hash), $options); $invoice = array('url' => 'https://test.bitpay.com/invoice?id=5NxFkXcJbCSivtQRJa4kHP'); if (array_key_exists('error', $invoice)) { - Mage::helper('bitpay')->debugData(array('Error creating bitpay invoice', $invoice['error'],)); - Mage::throwException("Error creating BitPay invoice. Please try again or use another payment option."); + \Mage::helper('bitpay')->debugData(array('Error creating bitpay invoice', $invoice['error'],)); + \Mage::throwException("Error creating BitPay invoice. Please try again or use another payment option."); return false; } From 5c37d24b4a83e88312f91f303135f39e1c7b8252 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 15:55:33 -0500 Subject: [PATCH 41/65] Added namespace backslash --- app/code/community/Bitpay/Core/Block/Info.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/community/Bitpay/Core/Block/Info.php b/app/code/community/Bitpay/Core/Block/Info.php index 765d93d..585e9af 100644 --- a/app/code/community/Bitpay/Core/Block/Info.php +++ b/app/code/community/Bitpay/Core/Block/Info.php @@ -17,18 +17,18 @@ class Bitpay_Core_Block_Info extends Mage_Payment_Block_Info $order = $this->getInfo()->getOrder(); if (false === isset($order) || true === empty($order)) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); throw new Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); } $incrementId = $order->getIncrementId(); if (false === isset($incrementId) || true === empty($incrementId)) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); throw new Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); } - $bitpayInvoice = Mage::getModel('bitpay/invoice')->load($incrementId, 'increment_id'); + $bitpayInvoice = \Mage::getModel('bitpay/invoice')->load($incrementId, 'increment_id'); if (true === isset($bitpayInvoice) && false === empty($bitpayInvoice)) { return $bitpayInvoice->getUrl(); From b2125500e2c85fbe126dd99d362340c3894624e8 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 15:57:07 -0500 Subject: [PATCH 42/65] Added namespace backslash --- app/code/community/Bitpay/Core/Helper/Data.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/code/community/Bitpay/Core/Helper/Data.php b/app/code/community/Bitpay/Core/Helper/Data.php index ebaff97..8eaebc7 100644 --- a/app/code/community/Bitpay/Core/Helper/Data.php +++ b/app/code/community/Bitpay/Core/Helper/Data.php @@ -22,7 +22,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract public function debugData($debugData) { if (true === isset($debugData) && false === empty($debugData)) { - Mage::getModel('bitpay/method_bitcoin')->debugData($debugData); + \Mage::getModel('bitpay/method_bitcoin')->debugData($debugData); } } @@ -31,7 +31,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function isDebug() { - return (boolean) Mage::getStoreConfig('payment/bitpay/debug'); + return (boolean) \Mage::getStoreConfig('payment/bitpay/debug'); } /** @@ -41,7 +41,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function hasTransactionSpeed() { - $speed = Mage::getStoreConfig('payment/bitpay/speed'); + $speed = \Mage::getStoreConfig('payment/bitpay/speed'); return !empty($speed); } @@ -53,7 +53,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function getNotificationUrl() { - return Mage::getUrl(Mage::getStoreConfig('payment/bitpay/notification_url')); + return \Mage::getUrl(\Mage::getStoreConfig('payment/bitpay/notification_url')); } /** @@ -63,7 +63,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract */ public function getRedirectUrl() { - return Mage::getUrl(Mage::getStoreConfig('payment/bitpay/redirect_url')); + return \Mage::getUrl(\Mage::getStoreConfig('payment/bitpay/redirect_url')); } /** @@ -73,7 +73,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract public function registerAutoloader() { if (true === empty($this->_autoloaderRegistered)) { - $autoloader_filename = Mage::getBaseDir('lib').'/Bitpay/Autoloader.php'; + $autoloader_filename = \Mage::getBaseDir('lib').'/Bitpay/Autoloader.php'; if (true === is_file($autoloader_filename) && true === is_readable($autoloader_filename)) { require_once $autoloader_filename; @@ -154,7 +154,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract } // Sanitize label - $label = preg_replace('/[^a-zA-Z0-9 ]/', '', Mage::app()->getStore()->getName()); + $label = preg_replace('/[^a-zA-Z0-9 ]/', '', \Mage::app()->getStore()->getName()); $label = substr('Magento ' . $label, 0, 59); $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): using the label "' . $label . '".'); @@ -346,7 +346,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract return array( 'public_key' => 'payment/bitpay/public_key', 'private_key' => 'payment/bitpay/private_key', - 'network' => Mage::getStoreConfig('payment/bitpay/network'), + 'network' => \Mage::getStoreConfig('payment/bitpay/network'), 'key_storage' => '\\Bitpay\\Storage\\MagentoStorage', ); } @@ -397,7 +397,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getToken(): successfully created new BitPay Token object.'); } - $token->setToken(Mage::getStoreConfig('payment/bitpay/token')); + $token->setToken(\Mage::getStoreConfig('payment/bitpay/token')); return $token; } From 74ec83fb7495f6ea0332caa6e90b1ebb57606190 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 15:57:36 -0500 Subject: [PATCH 43/65] Added namespace backslash --- app/code/community/Bitpay/Core/Model/TransactionSpeed.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php index c41356e..824c788 100644 --- a/app/code/community/Bitpay/Core/Model/TransactionSpeed.php +++ b/app/code/community/Bitpay/Core/Model/TransactionSpeed.php @@ -16,9 +16,9 @@ class Bitpay_Core_Model_TransactionSpeed public function toOptionArray() { return array( - array('value' => self::SPEED_LOW, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_LOW))), - array('value' => self::SPEED_MEDIUM, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_MEDIUM))), - array('value' => self::SPEED_HIGH, 'label' => Mage::helper('bitpay')->__(ucwords(self::SPEED_HIGH))), + array('value' => self::SPEED_LOW, 'label' => \Mage::helper('bitpay')->__(ucwords(self::SPEED_LOW))), + array('value' => self::SPEED_MEDIUM, 'label' => \Mage::helper('bitpay')->__(ucwords(self::SPEED_MEDIUM))), + array('value' => self::SPEED_HIGH, 'label' => \Mage::helper('bitpay')->__(ucwords(self::SPEED_HIGH))), ); } } From 5caa1c396266976ccabfc251fb0a8080d5cabe7a Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 15:57:57 -0500 Subject: [PATCH 44/65] Added namespace backslash --- app/code/community/Bitpay/Core/Model/Status.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Status.php b/app/code/community/Bitpay/Core/Model/Status.php index 83eeb93..829b252 100644 --- a/app/code/community/Bitpay/Core/Model/Status.php +++ b/app/code/community/Bitpay/Core/Model/Status.php @@ -19,12 +19,12 @@ class Bitpay_Core_Model_Status public function toOptionArray() { return array( - array('value' => self::STATUS_NEW, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_NEW))), - array('value' => self::STATUS_PAID, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_PAID))), - array('value' => self::STATUS_CONFIRMED, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_CONFIRMED))), - array('value' => self::STATUS_COMPLETE, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_COMPLETE))), - array('value' => self::STATUS_EXPIRED, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_EXPIRED))), - array('value' => self::STATUS_INVALID, 'label' => Mage::helper('bitpay')->__(ucwords(self::STATUS_INVALID))), + array('value' => self::STATUS_NEW, 'label' => \Mage::helper('bitpay')->__(ucwords(self::STATUS_NEW))), + array('value' => self::STATUS_PAID, 'label' => \Mage::helper('bitpay')->__(ucwords(self::STATUS_PAID))), + array('value' => self::STATUS_CONFIRMED, 'label' => \Mage::helper('bitpay')->__(ucwords(self::STATUS_CONFIRMED))), + array('value' => self::STATUS_COMPLETE, 'label' => \Mage::helper('bitpay')->__(ucwords(self::STATUS_COMPLETE))), + array('value' => self::STATUS_EXPIRED, 'label' => \Mage::helper('bitpay')->__(ucwords(self::STATUS_EXPIRED))), + array('value' => self::STATUS_INVALID, 'label' => \Mage::helper('bitpay')->__(ucwords(self::STATUS_INVALID))), ); } } From ff4ab044d5efaabf817eb3bbaabef44f602a10e6 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 15:58:49 -0500 Subject: [PATCH 45/65] Added namespace backslash --- .../community/Bitpay/Core/Model/Observer.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Observer.php b/app/code/community/Bitpay/Core/Model/Observer.php index 12a4ec3..6b0b814 100644 --- a/app/code/community/Bitpay/Core/Model/Observer.php +++ b/app/code/community/Bitpay/Core/Model/Observer.php @@ -20,26 +20,26 @@ class Bitpay_Core_Model_Observer */ public function updateOrderStates() { - $apiKey = Mage::getStoreConfig('payment/bitpay/api_key'); + $apiKey = \Mage::getStoreConfig('payment/bitpay/api_key'); if (false === isset($apiKey) || empty($apiKey)) { - Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() could not start job to update the order states because the API key was not set.'); + \Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() could not start job to update the order states because the API key was not set.'); return; } else { - Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() started job to query BitPay to update the existing order states.'); + \Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() started job to query BitPay to update the existing order states.'); } /* * Get all of the orders that are open and have not received an IPN for * complete, expired, or invalid. */ - $orders = Mage::getModel('bitpay/ipn')->getOpenOrders(); + $orders = \Mage::getModel('bitpay/ipn')->getOpenOrders(); if (false === isset($orders) || empty($orders)) { - Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() could not retrieve the open orders.'); + \Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() could not retrieve the open orders.'); return; } else { - Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() successfully retrieved existing open orders.'); + \Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() successfully retrieved existing open orders.'); } /* @@ -60,7 +60,7 @@ class Bitpay_Core_Model_Observer // No? continue } - Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() order status update job finished.'); + \Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::updateOrderStates() order status update job finished.'); } /** @@ -69,7 +69,7 @@ class Bitpay_Core_Model_Observer */ public function cleanExpired() { - Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::cleanExpired() called.'); - Mage::helper('bitpay')->cleanExpired(); + \Mage::helper('bitpay')->debugData('[INFO] Bitpay_Core_Model_Observer::cleanExpired() called.'); + \Mage::helper('bitpay')->cleanExpired(); } } From 4f1f20dde2cf292c1340cf5889a1c53b0c12c957 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 15:59:08 -0500 Subject: [PATCH 46/65] Added namespace backslash --- app/code/community/Bitpay/Core/Model/Network.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Network.php b/app/code/community/Bitpay/Core/Model/Network.php index df8d7fb..a77e475 100644 --- a/app/code/community/Bitpay/Core/Model/Network.php +++ b/app/code/community/Bitpay/Core/Model/Network.php @@ -18,8 +18,8 @@ class Bitpay_Core_Model_Network public function toOptionArray() { return array( - array('value' => self::NETWORK_LIVENET, 'label' => Mage::helper('bitpay')->__(ucwords(self::NETWORK_LIVENET))), - array('value' => self::NETWORK_TESTNET, 'label' => Mage::helper('bitpay')->__(ucwords(self::NETWORK_TESTNET))), + array('value' => self::NETWORK_LIVENET, 'label' => \Mage::helper('bitpay')->__(ucwords(self::NETWORK_LIVENET))), + array('value' => self::NETWORK_TESTNET, 'label' => \Mage::helper('bitpay')->__(ucwords(self::NETWORK_TESTNET))), ); } } From 34c4a48175e24d2ca26e19a72b49376b636de511 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 16:00:02 -0500 Subject: [PATCH 47/65] Added namespace backslash --- app/code/community/Bitpay/Core/Model/Invoice.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Invoice.php b/app/code/community/Bitpay/Core/Model/Invoice.php index bdb9ff8..186fccf 100644 --- a/app/code/community/Bitpay/Core/Model/Invoice.php +++ b/app/code/community/Bitpay/Core/Model/Invoice.php @@ -25,8 +25,8 @@ class Bitpay_Core_Model_Invoice extends Mage_Core_Model_Abstract public function prepareWithBitpayInvoice($invoice) { if (false === isset($invoice) || true === empty($invoice)) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); - throw new Exception('In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); + throw new \Exception('In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); } $this->addData( @@ -60,8 +60,8 @@ class Bitpay_Core_Model_Invoice extends Mage_Core_Model_Abstract public function prepateWithOrder($order) { if (false === isset($order) || true === empty($order)) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); - throw new Exception('In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + throw new \Exception('In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); } $this->addData( From d2f2d865a2f5b6d1e072a03bd4e296e2827f4404 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 16:03:47 -0500 Subject: [PATCH 48/65] Added namespace backslash --- .../Bitpay/Core/Model/Method/Bitcoin.php | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php b/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php index fdf59c6..e310bb6 100644 --- a/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php +++ b/app/code/community/Bitpay/Core/Model/Method/Bitcoin.php @@ -39,7 +39,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac { if (false === isset($payment) || false === isset($amount) || true === empty($payment) || true === empty($amount)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); } $this->debugData('[INFO] Bitpay_Core_Model_Method_Bitcoin::authorize(): authorizing new order.'); @@ -49,16 +49,16 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac if (false === isset($invoice) || true === empty($invoice)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); } $invoice = $this->prepareInvoice($invoice, $payment, $amount); try { - $bitpayInvoice = Mage::helper('bitpay')->getBitpayClient()->createInvoice($invoice); - } catch (Exception $e) { + $bitpayInvoice = \Mage::helper('bitpay')->getBitpayClient()->createInvoice($invoice); + } catch (\Exception $e) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): ' . $e->getMessage()); - Mage::throwException('In Bitpay_Core_Model_Method_Bitcoin::authorize(): Could not authorize transaction.'); + \Mage::throwException('In Bitpay_Core_Model_Method_Bitcoin::authorize(): Could not authorize transaction.'); } self::$_redirectUrl = $bitpayInvoice->getUrl(); @@ -71,7 +71,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac ); // Save BitPay Invoice in database for reference - $mirrorInvoice = Mage::getModel('bitpay/invoice') + $mirrorInvoice = \Mage::getModel('bitpay/invoice') ->prepareWithBitpayInvoice($bitpayInvoice) ->prepateWithOrder($payment->getOrder()) ->save(); @@ -90,7 +90,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ public function canUseCheckout() { - $token = Mage::getStoreConfig('payment/bitpay/token'); + $token = \Mage::getStoreConfig('payment/bitpay/token'); if (false === isset($token) || true === empty($token)) { /** @@ -117,18 +117,18 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac { if (false === isset($id) || true === empty($id)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): missing or invalid id parameter.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): missing or invalid id parameter.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): missing or invalid id parameter.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): function called with id ' . $id); } - Mage::helper('bitpay')->registerAutoloader(); + \Mage::helper('bitpay')->registerAutoloader(); - $client = Mage::helper('bitpay')->getBitpayClient(); + $client = \Mage::helper('bitpay')->getBitpayClient(); if (false === isset($client) || true === empty($client)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not obtain BitPay client.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not obtain BitPay client.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not obtain BitPay client.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): obtained BitPay client successfully.'); } @@ -137,7 +137,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac if (false === isset($invoice) || true === empty($invoice)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not retrieve invoice from BitPay.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not retrieve invoice from BitPay.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): could not retrieve invoice from BitPay.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::fetchInvoice(): successfully retrieved invoice id ' . $id . ' from BitPay.'); } @@ -156,7 +156,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac { if (false === isset($address) || true === empty($address)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::extractAddress(): missing or invalid address parameter.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::extractAddress(): missing or invalid address parameter.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::extractAddress(): missing or invalid address parameter.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::extractAddress(): called with good address parameter, extracting now.'); } @@ -210,21 +210,21 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac */ private function initializeInvoice() { - Mage::helper('bitpay')->registerAutoloader(); + \Mage::helper('bitpay')->registerAutoloader(); $invoice = new Bitpay\Invoice(); if (false === isset($invoice) || true === empty($invoice)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::initializeInvoice(): could not construct new BitPay invoice object.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::initializeInvoice(): could not construct new BitPay invoice object.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::initializeInvoice(): could not construct new BitPay invoice object.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::initializeInvoice(): constructed new BitPay invoice object successfully.'); } $invoice->setFullNotifications(true); - $invoice->setTransactionSpeed(Mage::getStoreConfig('payment/bitpay/speed')); - $invoice->setNotificationUrl(Mage::getUrl(Mage::getStoreConfig('payment/bitpay/notification_url'))); - $invoice->setRedirectUrl(Mage::getUrl(Mage::getStoreConfig('payment/bitpay/redirect_url'))); + $invoice->setTransactionSpeed(\Mage::getStoreConfig('payment/bitpay/speed')); + $invoice->setNotificationUrl(\Mage::getUrl(\Mage::getStoreConfig('payment/bitpay/notification_url'))); + $invoice->setRedirectUrl(\Mage::getUrl(\Mage::getStoreConfig('payment/bitpay/redirect_url'))); return $invoice; } @@ -242,7 +242,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac { if (false === isset($invoice) || true === empty($invoice) || false === isset($payment) || true === empty($payment) || false === isset($amount) || true === empty($amount)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::prepareInvoice(): missing or invalid invoice, payment or amount parameter.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::prepareInvoice(): missing or invalid invoice, payment or amount parameter.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::prepareInvoice(): missing or invalid invoice, payment or amount parameter.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::prepareInvoice(): entered function with good invoice, payment and amount parameters.'); } @@ -268,7 +268,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac { if (false === isset($invoice) || true === empty($invoice) || false === isset($order) || true === empty($order)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): missing or invalid invoice or order parameter.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): missing or invalid invoice or order parameter.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): missing or invalid invoice or order parameter.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): function called with good invoice and order parameters.'); } @@ -277,7 +277,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac if (false === isset($buyer) || true === empty($buyer)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): could not construct new BitPay buyer object.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): could not construct new BitPay buyer object.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::addBuyerInfo(): could not construct new BitPay buyer object.'); } $buyer->setFirstName($order->getCustomerFirstname()); @@ -298,7 +298,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac { if (false === isset($invoice) || true === empty($invoice) || false === isset($order) || true === empty($order)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): missing or invalid invoice or order parameter.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): missing or invalid invoice or order parameter.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): missing or invalid invoice or order parameter.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): function called with good invoice and order parameters.'); } @@ -307,7 +307,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac if (false === isset($currency) || true === empty($currency)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): could not construct new BitPay currency object.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): could not construct new BitPay currency object.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::addCurrencyInfo(): could not construct new BitPay currency object.'); } $currency->setCode($order->getBaseCurrencyCode()); @@ -327,7 +327,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac { if (false === isset($invoice) || true === empty($invoice) || false === isset($amount) || true === empty($amount)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): missing or invalid invoice or amount parameter.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): missing or invalid invoice or amount parameter.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): missing or invalid invoice or amount parameter.'); } else { $this->debugData('[INFO] In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): function called with good invoice and amount parameters.'); } @@ -336,7 +336,7 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac if (false === isset($item) || true === empty($item)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): could not construct new BitPay item object.'); - throw new Exception('In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): could not construct new BitPay item object.'); + throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::addPriceInfo(): could not construct new BitPay item object.'); } $item->setPrice($amount); From 33f6d8ba20fa13fdcef03e562839e03eb7816380 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 16:04:51 -0500 Subject: [PATCH 49/65] Added namespace backslash --- .../Bitpay/Core/Model/Config/PairingCode.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/community/Bitpay/Core/Model/Config/PairingCode.php b/app/code/community/Bitpay/Core/Model/Config/PairingCode.php index a3dab51..853452c 100644 --- a/app/code/community/Bitpay/Core/Model/Config/PairingCode.php +++ b/app/code/community/Bitpay/Core/Model/Config/PairingCode.php @@ -27,17 +27,17 @@ class Bitpay_Core_Model_Config_PairingCode extends Mage_Core_Model_Config_Data return; } - Mage::helper('bitpay')->debugData('[INFO] In Bitpay_Core_Model_Config_PairingCode::save(): attempting to pair with BitPay with pairing code ' . $pairingCode); + \Mage::helper('bitpay')->debugData('[INFO] In Bitpay_Core_Model_Config_PairingCode::save(): attempting to pair with BitPay with pairing code ' . $pairingCode); try { - Mage::helper('bitpay')->sendPairingRequest($pairingCode); - } catch (Exception $e) { - Mage::helper('bitpay')->debugData(sprintf('[ERROR] Exception thrown while calling the sendPairingRequest() function. The specific error message is: "%s"', $e->getMessage())); - Mage::getSingleton('core/session')->addError('There was an error while trying to pair with BitPay using the pairing code '.$pairingCode.'. Please try again or enable debug mode and send the "payment_bitpay.log" file to support@bitpay.com for more help.'); + \Mage::helper('bitpay')->sendPairingRequest($pairingCode); + } catch (\Exception $e) { + \Mage::helper('bitpay')->debugData(sprintf('[ERROR] Exception thrown while calling the sendPairingRequest() function. The specific error message is: "%s"', $e->getMessage())); + \Mage::getSingleton('core/session')->addError('There was an error while trying to pair with BitPay using the pairing code '.$pairingCode.'. Please try again or enable debug mode and send the "payment_bitpay.log" file to support@bitpay.com for more help.'); return; } - Mage::getSingleton('core/session')->addSuccess('Pairing with BitPay was successful.'); + \Mage::getSingleton('core/session')->addSuccess('Pairing with BitPay was successful.'); } } From a07c007a294735e15a5218c2b1a5878a4986e9b8 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 16:07:15 -0500 Subject: [PATCH 50/65] Added namespace backslash --- .../Bitpay/Core/controllers/IpnController.php | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/app/code/community/Bitpay/Core/controllers/IpnController.php b/app/code/community/Bitpay/Core/controllers/IpnController.php index 7aa2daa..b233de0 100644 --- a/app/code/community/Bitpay/Core/controllers/IpnController.php +++ b/app/code/community/Bitpay/Core/controllers/IpnController.php @@ -24,13 +24,13 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action $raw_post_data = file_get_contents('php://input'); if (false === $raw_post_data) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController: Could not read from the php://input stream or invalid Bitpay IPN received.'); - throw new Exception('Could not read from the php://input stream or invalid Bitpay IPN received.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController: Could not read from the php://input stream or invalid Bitpay IPN received.'); + throw new \Exception('Could not read from the php://input stream or invalid Bitpay IPN received.'); } - Mage::helper('bitpay')->registerAutoloader(); + \Mage::helper('bitpay')->registerAutoloader(); - Mage::helper('bitpay')->debugData( + \Mage::helper('bitpay')->debugData( array( sprintf('Incoming IPN from bitpay'), getallheaders(), @@ -42,22 +42,22 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action $ipn = json_decode($raw_post_data); if (true === empty($ipn)) { - Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController: Could not decode the JSON payload from BitPay.'); - throw new Exception('Could not decode the JSON payload from BitPay.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController: Could not decode the JSON payload from BitPay.'); + throw new \Exception('Could not decode the JSON payload from BitPay.'); } if (true === empty($ipn->id) || false === isset($ipn->posData->id)) { - Mage::helper('bitpay')->debugData(sprintf('Did not receive order ID in IPN. See IPN "%s" in database.', $mageIpn->getId())); - throw new Exception('Invalid Bitpay IPN received - did not receive order ID.'); + \Mage::helper('bitpay')->debugData(sprintf('Did not receive order ID in IPN. See IPN "%s" in database.', $mageIpn->getId())); + throw new \Exception('Invalid Bitpay IPN received - did not receive order ID.'); } $ipn->posData = is_string($ipn->posData) ? json_decode($ipn->posData) : $ipn->posData; $ipn->buyerFields = isset($ipn->buyerFields) ? $ipn->buyerFields : new stdClass(); - Mage::helper('bitpay')->debugData($ipn); + \Mage::helper('bitpay')->debugData($ipn); // Log IPN - $mageIpn = Mage::getModel('bitpay/ipn')->addData( + $mageIpn = \Mage::getModel('bitpay/ipn')->addData( array( 'invoice_id' => isset($ipn->id) ? $ipn->id : '', 'url' => isset($ipn->url) ? $ipn->url : '', @@ -75,11 +75,11 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action ) )->save(); - $order = Mage::getModel('sales/order')->loadByIncrementId($ipn->posData->id); + $order = \Mage::getModel('sales/order')->loadByIncrementId($ipn->posData->id); if (false === isset($order) || true === empty($order->getId())) { - Mage::helper('bitpay')->debugData('Invalid Bitpay IPN received.'); - Mage::throwException('Invalid Bitpay IPN received.'); + \Mage::helper('bitpay')->debugData('Invalid Bitpay IPN received.'); + \Mage::throwException('Invalid Bitpay IPN received.'); } /** @@ -87,28 +87,28 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action * match up and no one is using an automated tool to post IPN's to merchants * store. */ - $invoice = Mage::getModel('bitpay/method_bitcoin')->fetchInvoice($ipn->id); + $invoice = \Mage::getModel('bitpay/method_bitcoin')->fetchInvoice($ipn->id); if (false === isset($invoice) || true === empty($invoice) { - Mage::helper('bitpay')->debugData('[ERROR] Could not retrieve the invoice details for the ipn ID of ' . $ipn->id); - Mage::throwException('Could not retrieve the invoice details for the ipn ID of ' . $ipn->id); + \Mage::helper('bitpay')->debugData('[ERROR] Could not retrieve the invoice details for the ipn ID of ' . $ipn->id); + \Mage::throwException('Could not retrieve the invoice details for the ipn ID of ' . $ipn->id); } // Does the status match? if ($invoice->getStatus() != $ipn->status) { - Mage::getModel('bitpay/method_bitcoin')->debugData('[ERROR] IPN status and status from BitPay are different.'); - Mage::throwException('There was an error processing the IPN - statuses are different.'); + \Mage::getModel('bitpay/method_bitcoin')->debugData('[ERROR] IPN status and status from BitPay are different.'); + \Mage::throwException('There was an error processing the IPN - statuses are different.'); } // Does the price match? if ($invoice->getPrice() != $ipn->price) { - Mage::getModel('bitpay/method_bitcoin')>debugData('[ERROR] IPN price and invoice price are different.'); - Mage::throwException('There was an error processing the IPN - invoice price does not match the IPN price.'); + \Mage::getModel('bitpay/method_bitcoin')>debugData('[ERROR] IPN price and invoice price are different.'); + \Mage::throwException('There was an error processing the IPN - invoice price does not match the IPN price.'); } // Update the order to notifiy that it has been paid if (true === in_array($invoice->getStatus(), array('paid', 'confirmed', 'complete'))) { - $payment = Mage::getModel('sales/order_payment')->setOrder($order); + $payment = \Mage::getModel('sales/order_payment')->setOrder($order); if (true === isset($payment) && false === empty($payment)) { $payment->registerCaptureNotification($invoice->getPrice()); @@ -117,23 +117,23 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action // If the customer has not already been notified by email // send the notification now that there's a new order. if (!$order->getEmailSent()) { - Mage::helper('bitpay')->debugData('[INFO] Order email not sent so I am calling $order->sendNewOrderEmail() now...'); + \Mage::helper('bitpay')->debugData('[INFO] Order email not sent so I am calling $order->sendNewOrderEmail() now...'); $order->sendNewOrderEmail(); } $order->save(); } else { - Mage::helper('bitpay')->debugData('[ERROR] Could not create a payment object in the Bitpay IPN controller.'); - Mage::throwException('Could not create a payment object in the Bitpay IPN controller.'); + \Mage::helper('bitpay')->debugData('[ERROR] Could not create a payment object in the Bitpay IPN controller.'); + \Mage::throwException('Could not create a payment object in the Bitpay IPN controller.'); } } // use state as defined by Merchant - $state = Mage::getStoreConfig(sprintf('payment/bitpay/invoice_%s', $invoice->getStatus())); + $state = \Mage::getStoreConfig(sprintf('payment/bitpay/invoice_%s', $invoice->getStatus())); if (false === isset($state) || true === empty($state) { - Mage::helper('bitpay')->debugData('[ERROR] Could not retrieve the defined state parameter to update this order to in the Bitpay IPN controller.'); - Mage::throwException('Could not retrieve the defined state parameter to update this order to in the Bitpay IPN controller.'); + \Mage::helper('bitpay')->debugData('[ERROR] Could not retrieve the defined state parameter to update this order to in the Bitpay IPN controller.'); + \Mage::throwException('Could not retrieve the defined state parameter to update this order to in the Bitpay IPN controller.'); } $order->addStatusToHistory( From 4b71f46ea4cbe7fd75589d743e707a775653ab2e Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 5 Jan 2015 16:07:49 -0500 Subject: [PATCH 51/65] Added namespace backslash --- .../community/Bitpay/Core/controllers/IndexController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/community/Bitpay/Core/controllers/IndexController.php b/app/code/community/Bitpay/Core/controllers/IndexController.php index a2fdec9..1bfbb0e 100644 --- a/app/code/community/Bitpay/Core/controllers/IndexController.php +++ b/app/code/community/Bitpay/Core/controllers/IndexController.php @@ -18,10 +18,10 @@ class Bitpay_Core_IndexController extends Mage_Core_Controller_Front_Action $params = $this->getRequest()->getParams(); if (true === isset($params['paid'])) { - Mage::helper('bitpay')->registerAutoloader(); - Mage::helper('bitpay')->debugData($params); + \Mage::helper('bitpay')->registerAutoloader(); + \Mage::helper('bitpay')->debugData($params); } else { - Mage::helper('bitpay')->debugData('[ERROR] Could not get params from request.'); + \Mage::helper('bitpay')->debugData('[ERROR] Could not get params from request.'); } $this->loadLayout(); From 667357b039fe23e02e7e49876d20950f103961f9 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 16:15:35 -0500 Subject: [PATCH 52/65] Removed bad function call to non-object --- .../Bitpay/Core/controllers/IpnController.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/code/community/Bitpay/Core/controllers/IpnController.php b/app/code/community/Bitpay/Core/controllers/IpnController.php index b233de0..717d90f 100644 --- a/app/code/community/Bitpay/Core/controllers/IpnController.php +++ b/app/code/community/Bitpay/Core/controllers/IpnController.php @@ -30,13 +30,7 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action \Mage::helper('bitpay')->registerAutoloader(); - \Mage::helper('bitpay')->debugData( - array( - sprintf('Incoming IPN from bitpay'), - getallheaders(), - $raw_post_data, - ) - ); + \Mage::helper('bitpay')->debugData(array(sprintf('Incoming IPN from bitpay'),$raw_post_data,)); // Magento doesn't seem to have a way to get the Request body $ipn = json_decode($raw_post_data); @@ -47,7 +41,7 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action } if (true === empty($ipn->id) || false === isset($ipn->posData->id)) { - \Mage::helper('bitpay')->debugData(sprintf('Did not receive order ID in IPN. See IPN "%s" in database.', $mageIpn->getId())); + \Mage::helper('bitpay')->debugData(sprintf('Did not receive order ID in IPN: ', $ipn); throw new \Exception('Invalid Bitpay IPN received - did not receive order ID.'); } From e9f4c9fe2fdc5969ea352e5697a9af9efd55f37b Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 16:19:41 -0500 Subject: [PATCH 53/65] More informative error message --- .../community/Bitpay/Core/controllers/IndexController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/community/Bitpay/Core/controllers/IndexController.php b/app/code/community/Bitpay/Core/controllers/IndexController.php index 1bfbb0e..6e9a0b2 100644 --- a/app/code/community/Bitpay/Core/controllers/IndexController.php +++ b/app/code/community/Bitpay/Core/controllers/IndexController.php @@ -21,12 +21,14 @@ class Bitpay_Core_IndexController extends Mage_Core_Controller_Front_Action \Mage::helper('bitpay')->registerAutoloader(); \Mage::helper('bitpay')->debugData($params); } else { - \Mage::helper('bitpay')->debugData('[ERROR] Could not get params from request.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IndexController::indexAction(), Could not get parameters from HTTP request.'); } $this->loadLayout(); $this->getResponse()->setHeader('Content-type', 'application/json'); + + // ? $this->getResponse()->setBody(json_encode(array('paid' => $paid))); } } From 5f95611d495f50dded3b5de6f991ef2018f02403 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 16:40:41 -0500 Subject: [PATCH 54/65] Added missing parenthesis & updated error msgs --- .../Bitpay/Core/controllers/IpnController.php | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app/code/community/Bitpay/Core/controllers/IpnController.php b/app/code/community/Bitpay/Core/controllers/IpnController.php index 717d90f..cce0b7f 100644 --- a/app/code/community/Bitpay/Core/controllers/IpnController.php +++ b/app/code/community/Bitpay/Core/controllers/IpnController.php @@ -24,25 +24,25 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action $raw_post_data = file_get_contents('php://input'); if (false === $raw_post_data) { - \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController: Could not read from the php://input stream or invalid Bitpay IPN received.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController::indexAction(), Could not read from the php://input stream or invalid Bitpay IPN received.'); throw new \Exception('Could not read from the php://input stream or invalid Bitpay IPN received.'); } \Mage::helper('bitpay')->registerAutoloader(); - \Mage::helper('bitpay')->debugData(array(sprintf('Incoming IPN from bitpay'),$raw_post_data,)); + \Mage::helper('bitpay')->debugData(array(sprintf('[INFO] In Bitpay_Core_IpnController::indexAction(), Incoming IPN message from BitPay: '),$raw_post_data,)); // Magento doesn't seem to have a way to get the Request body $ipn = json_decode($raw_post_data); if (true === empty($ipn)) { - \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController: Could not decode the JSON payload from BitPay.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController::indexAction(), Could not decode the JSON payload from BitPay.'); throw new \Exception('Could not decode the JSON payload from BitPay.'); } if (true === empty($ipn->id) || false === isset($ipn->posData->id)) { - \Mage::helper('bitpay')->debugData(sprintf('Did not receive order ID in IPN: ', $ipn); - throw new \Exception('Invalid Bitpay IPN received - did not receive order ID.'); + \Mage::helper('bitpay')->debugData(sprintf('[ERROR] In Bitpay_Core_IpnController::indexAction(), Did not receive order ID in IPN: ', $ipn)); + throw new \Exception('Invalid Bitpay payment notification message received - did not receive order ID.'); } $ipn->posData = is_string($ipn->posData) ? json_decode($ipn->posData) : $ipn->posData; @@ -72,7 +72,7 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action $order = \Mage::getModel('sales/order')->loadByIncrementId($ipn->posData->id); if (false === isset($order) || true === empty($order->getId())) { - \Mage::helper('bitpay')->debugData('Invalid Bitpay IPN received.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController::indexAction(), Invalid Bitpay IPN received.'); \Mage::throwException('Invalid Bitpay IPN received.'); } @@ -83,21 +83,21 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action */ $invoice = \Mage::getModel('bitpay/method_bitcoin')->fetchInvoice($ipn->id); - if (false === isset($invoice) || true === empty($invoice) { - \Mage::helper('bitpay')->debugData('[ERROR] Could not retrieve the invoice details for the ipn ID of ' . $ipn->id); + if (false === isset($invoice) || true === empty($invoice)) { + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController::indexAction(), Could not retrieve the invoice details for the ipn ID of ' . $ipn->id); \Mage::throwException('Could not retrieve the invoice details for the ipn ID of ' . $ipn->id); } // Does the status match? if ($invoice->getStatus() != $ipn->status) { - \Mage::getModel('bitpay/method_bitcoin')->debugData('[ERROR] IPN status and status from BitPay are different.'); - \Mage::throwException('There was an error processing the IPN - statuses are different.'); + \Mage::getModel('bitpay/method_bitcoin')->debugData('[ERROR] In Bitpay_Core_IpnController::indexAction(), IPN status and status from BitPay are different. Rejecting this IPN!'); + \Mage::throwException('There was an error processing the IPN - statuses are different. Rejecting this IPN!'); } // Does the price match? if ($invoice->getPrice() != $ipn->price) { - \Mage::getModel('bitpay/method_bitcoin')>debugData('[ERROR] IPN price and invoice price are different.'); - \Mage::throwException('There was an error processing the IPN - invoice price does not match the IPN price.'); + \Mage::getModel('bitpay/method_bitcoin')>debugData('[ERROR] In Bitpay_Core_IpnController::indexAction(), IPN price and invoice price are different. Rejecting this IPN!'); + \Mage::throwException('There was an error processing the IPN - invoice price does not match the IPN price. Rejecting this IPN!'); } // Update the order to notifiy that it has been paid @@ -111,13 +111,13 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action // If the customer has not already been notified by email // send the notification now that there's a new order. if (!$order->getEmailSent()) { - \Mage::helper('bitpay')->debugData('[INFO] Order email not sent so I am calling $order->sendNewOrderEmail() now...'); + \Mage::helper('bitpay')->debugData('[INFO] In Bitpay_Core_IpnController::indexAction(), Order email not sent so I am calling $order->sendNewOrderEmail() now...'); $order->sendNewOrderEmail(); } $order->save(); } else { - \Mage::helper('bitpay')->debugData('[ERROR] Could not create a payment object in the Bitpay IPN controller.'); + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController::indexAction(), Could not create a payment object in the Bitpay IPN controller.'); \Mage::throwException('Could not create a payment object in the Bitpay IPN controller.'); } } @@ -125,14 +125,14 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action // use state as defined by Merchant $state = \Mage::getStoreConfig(sprintf('payment/bitpay/invoice_%s', $invoice->getStatus())); - if (false === isset($state) || true === empty($state) { - \Mage::helper('bitpay')->debugData('[ERROR] Could not retrieve the defined state parameter to update this order to in the Bitpay IPN controller.'); + if (false === isset($state) || true === empty($state)) { + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_IpnController::indexAction(), Could not retrieve the defined state parameter to update this order to in the Bitpay IPN controller.'); \Mage::throwException('Could not retrieve the defined state parameter to update this order to in the Bitpay IPN controller.'); } $order->addStatusToHistory( $state, - sprintf('Incoming IPN status "%s" updated order state to "%s"', $invoice->getStatus(), $state) + sprintf('[INFO] In Bitpay_Core_IpnController::indexAction(), Incoming IPN status "%s" updated order state to "%s"', $invoice->getStatus(), $state) )->save(); } } From 154679c0adef9a5aaae25a723430a597520ab8db Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 16:58:50 -0500 Subject: [PATCH 55/65] Added CDATA wrapping for all comments. --- app/code/community/Bitpay/Core/etc/system.xml | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/code/community/Bitpay/Core/etc/system.xml b/app/code/community/Bitpay/Core/etc/system.xml index 905f108..86a14ed 100644 --- a/app/code/community/Bitpay/Core/etc/system.xml +++ b/app/code/community/Bitpay/Core/etc/system.xml @@ -28,9 +28,8 @@ <pairing_code translate="label"> <label>Pairing Code</label> <comment> - <![CDATA[Create a pairing code for your account at <a href="https://bitpay.com/api-tokens" target="_blank">https://bitpay.com/api-tokens</a> and put - the code that was generated in this field. Once you have paired your Mangento store you can begin accepted Bitcoins as payment - on your store.]]> + <![CDATA[You must first create a pairing code for your BitPay Merchant account at <a href="https://bitpay.com/api-tokens" target="_blank">https://bitpay.com/api-tokens</a> and copy/paste + that code here. Once you have successfully paired this Magento store with your BitPay Merchant account, you can begin accepting Bitcoins as payment.]]> </comment> <frontend_type>text</frontend_type> <backend_model>bitpay/config_pairingCode</backend_model> @@ -51,7 +50,7 @@ <title translate="label"> <label>Title</label> <comment> - What your customers will see during their checkout experience. + <![CDATA[This is the payment method name your customers will see during checkout.]]> </comment> <frontend_type>text</frontend_type> <sort_order>20</sort_order> @@ -73,7 +72,9 @@ </network> <debug translate="label"> <label>Debug</label> - <comment>By enabling this, it will output more verbose information in log files.</comment> + <comment> + <![CDATA[By enabling this, it will output more verbose information in log files.]]> + </comment> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_yesno</source_model> <sort_order>40</sort_order> @@ -105,7 +106,9 @@ <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> - <comment><![CDATA[Determines when a BitPay payment confirmation is sent.<br /><strong>High:</strong> an invoice is confirmed immediately when payment received.<br /><strong>Medium:</strong> an invoice is confirmed after 1 block confirmation by the network (~10 mins).<br /><strong>Low:</strong> an invoice is confirmed after 6 block confirmations by the network (~1 hour).<br />The default and safest setting is "Low". A "High" setting is quicker to generate a payment confirmation but is riskier since the transaction could have not been officially confirmed by the Bitcoin network itself.]]></comment> + <comment> + <![CDATA[Determines when a BitPay payment confirmation is sent.<br /><strong>High:</strong> an invoice is confirmed immediately when payment received.<br /><strong>Medium:</strong> an invoice is confirmed after 1 block confirmation by the Bitcoin network (~10 mins).<br /><strong>Low:</strong> an invoice is confirmed after 6 block confirmations by the Bitcoin network (~1 hour).<br />The default and safest setting is "Low". A "High" setting is quicker to generate a payment confirmation but is riskier since the transaction could have not been officially confirmed by the Bitcoin network itself.]]> + </comment> </speed> <mage_settings_heading> <label>Magento Specific Settings</label> @@ -169,7 +172,7 @@ <invoice_paid translate="label"> <label>Paid</label> <comment> - An invoice is considered "paid" when the Bitcoin network sees a transaction. + <![CDATA[An invoice is considered "paid" when the Bitcoin network sees a transaction.]]> </comment> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_order_status</source_model> @@ -181,7 +184,7 @@ <invoice_confirmed translate="label"> <label>Confirmed</label> <comment> - A confirmed invoice means that the Bitcoin network has approved the transaction. + <![CDATA[A confirmed invoice means that the Bitcoin network has approved the transaction.]]> </comment> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_order_status</source_model> @@ -193,7 +196,7 @@ <invoice_complete translate="label"> <label>Complete</label> <comment> - Complete invoices mean that the funds for the sale have been confirmed and deposited into your BitPay merchant account. + <![CDATA[A completed BitPay invoice indicates the payment for the invoice has been fully confirmed by the Bitcoin network and the funds have been deposited into your BitPay Merchant account.]]> </comment> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_order_status</source_model> @@ -206,7 +209,7 @@ <label>Requirements</label> <frontend_model>adminhtml/system_config_form_field_heading</frontend_model> <comment> - This extension will not function if you do not meet the system requirements. + <![CDATA[This extension will not function if you do not meet the system requirements.]]> </comment> <sort_order>500</sort_order> <show_in_default>1</show_in_default> From 789b24b7b20c4e53fe9a7bb2659965a1f665f526 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 16:59:58 -0500 Subject: [PATCH 56/65] Fixed invalid parameter check. --- app/code/community/Bitpay/Core/controllers/IpnController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Bitpay/Core/controllers/IpnController.php b/app/code/community/Bitpay/Core/controllers/IpnController.php index cce0b7f..947a077 100644 --- a/app/code/community/Bitpay/Core/controllers/IpnController.php +++ b/app/code/community/Bitpay/Core/controllers/IpnController.php @@ -40,7 +40,7 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action throw new \Exception('Could not decode the JSON payload from BitPay.'); } - if (true === empty($ipn->id) || false === isset($ipn->posData->id)) { + if (true === empty($ipn->id) || false === isset($ipn->posData)) { \Mage::helper('bitpay')->debugData(sprintf('[ERROR] In Bitpay_Core_IpnController::indexAction(), Did not receive order ID in IPN: ', $ipn)); throw new \Exception('Invalid Bitpay payment notification message received - did not receive order ID.'); } From 9a96cd9e7ad05453ba083a131cac8460e0ee1930 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 17:02:16 -0500 Subject: [PATCH 57/65] Added namespace backslash --- app/code/community/Bitpay/Core/Block/Info.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Bitpay/Core/Block/Info.php b/app/code/community/Bitpay/Core/Block/Info.php index 585e9af..32761bb 100644 --- a/app/code/community/Bitpay/Core/Block/Info.php +++ b/app/code/community/Bitpay/Core/Block/Info.php @@ -18,14 +18,14 @@ class Bitpay_Core_Block_Info extends Mage_Payment_Block_Info if (false === isset($order) || true === empty($order)) { \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); - throw new Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); + throw new \Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); } $incrementId = $order->getIncrementId(); if (false === isset($incrementId) || true === empty($incrementId)) { \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); - throw new Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); + throw new \Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); } $bitpayInvoice = \Mage::getModel('bitpay/invoice')->load($incrementId, 'increment_id'); From dad4e6a1054dce894c6cb6b4a1226963a9dfbab4 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 17:03:16 -0500 Subject: [PATCH 58/65] Added namespace backslash --- app/code/community/Bitpay/Core/Block/Iframe.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/community/Bitpay/Core/Block/Iframe.php b/app/code/community/Bitpay/Core/Block/Iframe.php index 2504f59..b2cd580 100644 --- a/app/code/community/Bitpay/Core/Block/Iframe.php +++ b/app/code/community/Bitpay/Core/Block/Iframe.php @@ -32,7 +32,7 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment if (false === isset($method) || true === empty($method)) { \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not obtain an instance of the payment method.'); - throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not obtain an instance of the payment method.'); + throw new \Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not obtain an instance of the payment method.'); } $options = array_merge( @@ -48,7 +48,7 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment if (false === isset($options) || true === empty($options)) { \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the options array.'); - throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the options array.'); + throw new \Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the options array.'); } else { \Mage::helper('bitpay')->debugData($options); } @@ -60,7 +60,7 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment if (false === isset($price) || true === empty($price)) { \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the new rounded price.'); - throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the new rounded price.'); + throw new \Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the new rounded price.'); } //serialize info about the quote to detect changes @@ -68,7 +68,7 @@ class Bitpay_Core_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment if (false === isset($hash) || true === empty($hash)) { \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not get the quote hash.'); - throw new Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the quote hash.'); + throw new \Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): Could not merge the quote hash.'); } \Mage::helper('bitpay')->registerAutoloader(); From 9ae3f0581ce73a6d1a043e8b992510037516d55c Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 17:09:03 -0500 Subject: [PATCH 59/65] Added error handling and debugging --- .../Block/Adminhtml/System/Config/Form/Field/Extension.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/code/community/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Extension.php b/app/code/community/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Extension.php index 3e0ec96..812836a 100644 --- a/app/code/community/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Extension.php +++ b/app/code/community/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Extension.php @@ -15,9 +15,14 @@ class Bitpay_Core_Block_Adminhtml_System_Config_Form_Field_Extension extends Mag */ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) { + if (false === isset($element) || true === empty($element)) { + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Adminhtml_System_Config_Form_Field_Extension::_getElementHtml(): Missing or invalid $element parameter passed to function.'); + throw new \Exception('In Bitpay_Core_Block_Adminhtml_System_Config_Form_Field_Extension::_getElementHtml(): Missing or invalid $element parameter passed to function.'); + } + $phpExtension = $element->getFieldConfig()->php_extension; - if (in_array($phpExtension, get_loaded_extensions())) { + if (true === in_array($phpExtension, get_loaded_extensions())) { return 'Installed'; } From d7d0cd58517a6de6615eac43bf3fa1127550ef1d Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 17:10:53 -0500 Subject: [PATCH 60/65] Added error handling and debugging --- .../Core/Block/Adminhtml/System/Config/Form/Field/Header.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/community/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Header.php b/app/code/community/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Header.php index 2b9454a..80ab46f 100644 --- a/app/code/community/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Header.php +++ b/app/code/community/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Header.php @@ -23,6 +23,11 @@ class Bitpay_Core_Block_Adminhtml_System_Config_Form_Field_Header extends Mage_A */ public function render(Varien_Data_Form_Element_Abstract $element) { + if (false === isset($element) || true === empty($element)) { + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Adminhtml_System_Config_Form_Field_Header::render(): Missing or invalid $element parameter passed to function.'); + throw new \Exception('In Bitpay_Core_Block_Adminhtml_System_Config_Form_Field_Header::render(): Missing or invalid $element parameter passed to function.'); + } + return $this->toHtml(); } } From 8b5ea763f35d5aa507231ee61eae46f3fda09b51 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 17:21:15 -0500 Subject: [PATCH 61/65] Added error handling and debugging --- app/code/community/Bitpay/Core/Block/Form/Bitpay.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/code/community/Bitpay/Core/Block/Form/Bitpay.php b/app/code/community/Bitpay/Core/Block/Form/Bitpay.php index 0dce41c..9c52ebf 100644 --- a/app/code/community/Bitpay/Core/Block/Form/Bitpay.php +++ b/app/code/community/Bitpay/Core/Block/Form/Bitpay.php @@ -8,7 +8,15 @@ class Bitpay_Core_Block_Form_Bitpay extends Mage_Payment_Block_Form { protected function _construct() { + $payment_template = 'bitpay/form/bitpay.phtml'; + parent::_construct(); - $this->setTemplate('bitpay/form/bitpay.phtml'); + + if (true === file_exists($payment_template) && true === is_readable($payment_template)) { + $this->setTemplate($payment_template); + } else { + \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Form_Bitpay::_construct(): HTML payment template missing or unreadable.'); + throw new \Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): HTML payment template missing or unreadable.'); + } } } From f2166063620c3d9abee35e7a478f0c72c913d8d2 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 17:25:24 -0500 Subject: [PATCH 62/65] Added namespace backslash --- .../community/Bitpay/Core/Helper/Data.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/code/community/Bitpay/Core/Helper/Data.php b/app/code/community/Bitpay/Core/Helper/Data.php index 8eaebc7..206bd39 100644 --- a/app/code/community/Bitpay/Core/Helper/Data.php +++ b/app/code/community/Bitpay/Core/Helper/Data.php @@ -83,7 +83,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract } else { $this->_autoloaderRegistered = false; $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::registerAutoloader(): autoloader file was not found or is not readable. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::registerAutoloader(): autoloader file was not found or is not readable. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::registerAutoloader(): autoloader file was not found or is not readable. Cannot continue!'); } } } @@ -104,7 +104,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($this->_privateKey) || true === empty($this->_privateKey)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay private key object. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay private key object. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay private key object. Cannot continue!'); } else { $this->_privateKey->generate(); } @@ -113,7 +113,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($this->_publicKey) || true === empty($this->_publicKey)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay public key object. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay public key object. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::generateAndSaveKeys(): could not create new Bitpay public key object. Cannot continue!'); } else { $this->_publicKey ->setPrivateKey($this->_privateKey) @@ -133,7 +133,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract { if (false === isset($pairingCode) || true === empty($pairingCode)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): missing or invalid pairingCode parameter.'); - throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): missing or invalid pairingCode parameter.'); + throw new \Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): missing or invalid pairingCode parameter.'); } else { $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): function called with the pairingCode parameter: ' . $pairingCode); } @@ -148,7 +148,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($sin) || true === empty($sin)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): could not retrieve the SIN parameter. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): could not retrieve the SIN parameter. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): could not retrieve the SIN parameter. Cannot continue!'); } else { $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): attempting to pair with the SIN parameter: ' . $sin); } @@ -169,7 +169,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($token) || true === empty($token)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): could not obtain the token from the pairing process. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): could not obtain the token from the pairing process. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): could not obtain the token from the pairing process. Cannot continue!'); } else { $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): token successfully obtained.'); } @@ -178,14 +178,14 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($config) || true === empty($config)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): could not create new Mage_Core_Model_Config object. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): could not create new Mage_Core_Model_Config object. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): could not create new Mage_Core_Model_Config object. Cannot continue!'); } if($config->saveConfig('payment/bitpay/token', $token->getToken())) { $this->debugData('[INFO] In Bitpay_Core_Helper_Data::sendPairingRequest(): token saved to database.'); } else { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::sendPairingRequest(): token could not be saved to database.'); - throw new Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): token could not be saved to database.'); + throw new \Exception('In Bitpay_Core_Helper_Data::sendPairingRequest(): token could not be saved to database.'); } } @@ -208,7 +208,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($this->_sin) || true === empty($this->_sin)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getSinKey(): could not create new BitPay SinKey object. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::getSinKey(): could not create new BitPay SinKey object. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::getSinKey(): could not create new BitPay SinKey object. Cannot continue!'); } $this->_sin @@ -217,7 +217,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($this->_sin) || true === empty($this->_sin)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getSinKey(): could not generate a new SIN from the public key. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::getSinKey(): could not generate a new SIN from the public key. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::getSinKey(): could not generate a new SIN from the public key. Cannot continue!'); } return $this->_sin; @@ -251,7 +251,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract return $this->_publicKey; } else { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getPublicKey(): could not load or generate a new public key. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::getPublicKey(): could not load or generate a new public key. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::getPublicKey(): could not load or generate a new public key. Cannot continue!'); } } @@ -283,7 +283,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract return $this->_privateKey; } else { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getPrivateKey(): could not load or generate a new private key. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::getPrivateKey(): could not load or generate a new private key. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::getPrivateKey(): could not load or generate a new private key. Cannot continue!'); } } @@ -301,7 +301,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($this->_keyManager) || true === empty($this->_keyManager)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getKeyManager(): could not create new BitPay KeyManager object. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::getKeyManager(): could not create new BitPay KeyManager object. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::getKeyManager(): could not create new BitPay KeyManager object. Cannot continue!'); } else { $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getKeyManager(): successfully created new BitPay KeyManager object.'); } @@ -327,7 +327,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($this->_bitpay) || true === empty($this->_bitpay)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getBitpay(): could not create new BitPay object. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::getBitpay(): could not create new BitPay object. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::getBitpay(): could not create new BitPay object. Cannot continue!'); } else { $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getBitpay(): successfully created new BitPay object.'); } @@ -368,7 +368,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($this->_client) || true === empty($this->_client)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getBitpayClient(): could not create new BitPay Client object. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::getBitpayClient(): could not create new BitPay Client object. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::getBitpayClient(): could not create new BitPay Client object. Cannot continue!'); } else { $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getBitpayClient(): successfully created new BitPay Client object.'); } @@ -392,7 +392,7 @@ class Bitpay_Core_Helper_Data extends Mage_Core_Helper_Abstract if (false === isset($token) || true === empty($token)) { $this->debugData('[ERROR] In Bitpay_Core_Helper_Data::getToken(): could not create new BitPay Token object. Cannot continue!'); - throw new Exception('In Bitpay_Core_Helper_Data::getToken(): could not create new BitPay Token object. Cannot continue!'); + throw new \Exception('In Bitpay_Core_Helper_Data::getToken(): could not create new BitPay Token object. Cannot continue!'); } else { $this->debugData('[INFO] In Bitpay_Core_Helper_Data::getToken(): successfully created new BitPay Token object.'); } From 231e948034a23e1e402fb790dcdd355c203ffbf4 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 17:30:39 -0500 Subject: [PATCH 63/65] Added namespace backslash --- lib/Bitpay/Storage/MagentoStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Bitpay/Storage/MagentoStorage.php b/lib/Bitpay/Storage/MagentoStorage.php index 15f8bb2..7368cfb 100644 --- a/lib/Bitpay/Storage/MagentoStorage.php +++ b/lib/Bitpay/Storage/MagentoStorage.php @@ -32,7 +32,7 @@ class MagentoStorage implements StorageInterface $config->saveConfig($key->getId(), $encryptedData); } else { \Mage::helper('bitpay')->debugData('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); - throw new Exception('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); + throw new \Exception('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); } } From c452db1732082dd89c4c8e06b4a34a2b0d5bc2e9 Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Thu, 8 Jan 2015 17:33:25 -0500 Subject: [PATCH 64/65] Formatting --- app/etc/modules/Bitpay_Core.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/etc/modules/Bitpay_Core.xml b/app/etc/modules/Bitpay_Core.xml index 86c25cc..896fa96 100644 --- a/app/etc/modules/Bitpay_Core.xml +++ b/app/etc/modules/Bitpay_Core.xml @@ -6,13 +6,13 @@ */ --> <config> - <modules> - <Bitpay_Core> - <active>true</active> - <codePool>community</codePool> - <depends> - <Mage_Payment /> - </depends> - </Bitpay_Core> - </modules> + <modules> + <Bitpay_Core> + <active>true</active> + <codePool>community</codePool> + <depends> + <Mage_Payment /> + </depends> + </Bitpay_Core> + </modules> </config> From 7aea57bed0e5b8276a39a44a7c23ec98e328145f Mon Sep 17 00:00:00 2001 From: Rich Morgan <ionux@users.noreply.github.com> Date: Mon, 12 Jan 2015 13:28:54 -0500 Subject: [PATCH 65/65] Removed template file check This was causing an unecessary error during checkout. --- app/code/community/Bitpay/Core/Block/Form/Bitpay.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/code/community/Bitpay/Core/Block/Form/Bitpay.php b/app/code/community/Bitpay/Core/Block/Form/Bitpay.php index 9c52ebf..78bd184 100644 --- a/app/code/community/Bitpay/Core/Block/Form/Bitpay.php +++ b/app/code/community/Bitpay/Core/Block/Form/Bitpay.php @@ -11,12 +11,7 @@ class Bitpay_Core_Block_Form_Bitpay extends Mage_Payment_Block_Form $payment_template = 'bitpay/form/bitpay.phtml'; parent::_construct(); - - if (true === file_exists($payment_template) && true === is_readable($payment_template)) { - $this->setTemplate($payment_template); - } else { - \Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Block_Form_Bitpay::_construct(): HTML payment template missing or unreadable.'); - throw new \Exception('In Bitpay_Core_Block_Iframe::getIframeUrl(): HTML payment template missing or unreadable.'); - } + + $this->setTemplate($payment_template); } }