diff --git a/assets/js/admin-ajax.js b/assets/js/admin-ajax.js
index 04092e6..49c7f67 100755
--- a/assets/js/admin-ajax.js
+++ b/assets/js/admin-ajax.js
@@ -45,9 +45,12 @@ jQuery(document).ready(function ($) {
$('.give-aweber-list-wrap').empty().append(res.data.lists);
}
- refresh_button.hide();
+ //refresh_button.hide();
spinner.removeClass('is-active');
}
+ },
+ error: function (res) {
+ console.error({aweberListErrorResponse: res});
}
});
});
diff --git a/give-aweber.php b/give-aweber.php
index 2bf520b..811eddf 100755
--- a/give-aweber.php
+++ b/give-aweber.php
@@ -10,6 +10,8 @@
*/
//Define constants.
+use Give\Log\Log;
+
if ( ! defined( 'GIVE_AWEBER_VERSION' ) ) {
define( 'GIVE_AWEBER_VERSION', '1.0.4' );
}
@@ -442,6 +444,8 @@ public function render_metabox() {
$override_option = get_post_meta( $post->ID, '_give_' . $this->id . '_override_option', true );
$checked_option = get_post_meta( $post->ID, '_give_' . $this->id . '_checked_default', true );
+
+
//Start the buffer.
ob_start(); ?>
@@ -625,6 +629,9 @@ public function save_metabox( $post_id ) {
public function get_lists() {
$lists_data = get_transient( 'give_aweber_lists' );
+ $lists_not_found = array(
+ 'unknown' => __( 'No lists found', 'give-aweber' )
+ );
if ( false === $lists_data ) {
@@ -633,7 +640,7 @@ public function get_lists() {
$aweber = $this->get_authenticated_instance();
if ( ! is_object( $aweber ) || false === ( $secrets = get_option( 'give_aweber_secrets' ) ) ) {
- return array();
+ return $lists_not_found;
}
$account = $aweber->getAccount( $secrets['access_key'], $secrets['access_secret'] );
@@ -648,7 +655,7 @@ public function get_lists() {
} catch ( Exception $e ) {
- $this->lists = array();
+ $this->lists = $lists_not_found;
}
@@ -781,7 +788,8 @@ public function show_subscribe_checkbox( $form_id ) {
*/
public function get_authenticated_instance() {
- $authorization_code = isset( $this->give_options['give_aweber_api'] ) ? trim( $this->give_options['give_aweber_api'] ) : '';
+ //$authorization_code = isset( $this->give_options['give_aweber_api'] ) ? trim( $this->give_options['give_aweber_api'] ) : '';
+ $authorization_code = give_get_option('give_aweber_api', '');
$msg = '';
if ( ! empty( $authorization_code ) ) {
@@ -798,6 +806,9 @@ public function get_authenticated_instance() {
$msg = $options;
try {
+ if (!$this->validate_auth_code()){
+ throw new \RuntimeException('AWeber API Error: Authorization code does not match stored credentials.');
+ }
$api = new AWeberAPI( $options['consumer_key'], $options['consumer_secret'] );
@@ -805,7 +816,16 @@ public function get_authenticated_instance() {
$api = false;
- }
+ } catch ( RuntimeException $exc ) {
+ Log::error( 'AWeber API Error (Exception): ' . $exc->getMessage() );
+
+ delete_transient( 'give_aweber_lists' );
+ give_delete_option('give_aweber_list');
+ delete_option( 'give_aweber_secrets' );
+
+ $api = false;
+
+ }
return $api;
@@ -817,6 +837,8 @@ public function get_authenticated_instance() {
} catch ( AWeberAPIException $exc ) {
+ Log::error( 'AWeber API Error (AWeberAPIException): ' . $exc->getMessage() );
+
list( $consumer_key, $consumer_secret, $access_key, $access_secret ) = null;
//make error messages customer friendly.
@@ -826,10 +848,12 @@ public function get_authenticated_instance() {
$error_code = " ($descr)";
} catch ( AWeberOAuthDataMissing $exc ) {
+ Log::error( 'AWeber API Error (AWeberOAuthDataMissing): ' . $exc->getMessage() );
list( $consumer_key, $consumer_secret, $access_key, $access_secret ) = null;
} catch ( AWeberException $exc ) {
+ Log::error( 'AWeber API Error (AWeberException): ' . $exc->getMessage() );
list( $consumer_key, $consumer_secret, $access_key, $access_secret ) = null;
@@ -848,7 +872,7 @@ public function get_authenticated_instance() {
$msg .= __( 'Authorization code entered was:', 'give-aweber' ) . '
' . $authorization_code;
}
- $msg .= __( 'Please make sure you entered the complete authorization code and try again.', 'give-aweber' );
+ $msg .= '
' . __( 'Please make sure you entered the complete authorization code and try again.', 'give-aweber' );
$msg .= '';
@@ -865,6 +889,8 @@ public function get_authenticated_instance() {
}
}
} else {
+ delete_transient( 'give_aweber_lists' );
+ give_delete_option('give_aweber_list');
delete_option( 'give_aweber_secrets' );
}
@@ -881,8 +907,8 @@ public function get_authenticated_instance() {
* @param $value
*/
public function aweber_list_select( $field, $value ) {
-
$lists = $this->get_lists();
+ $give_aweber_response = get_option('give_aweber_response');
ob_start();
?>
@@ -893,6 +919,9 @@ public function aweber_list_select( $field, $value ) {