Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling of Create Subscriber response in Aweber API #41

Open
andrewmatheson opened this issue Aug 28, 2023 · 0 comments
Open

Comments

@andrewmatheson
Copy link

andrewmatheson commented Aug 28, 2023

Describe the bug
A client is trying to use this plugin to assign new members to multiple lists in Aweber. However, the member would only ever be added to the first list. Debugging this further we were seeing what appeared to be an OAuth error with a message of:

[message] => Unable to connect to the AWeber API.  ()

This didn't seem correct as the auth was working enough to actually create the new subscriber and assign them to the first list as defined in the Addon settings. This was also accompanied by an error in the logs:

[28-Aug-2023 22:44:57 UTC] PHP Warning:  Undefined property: OAuthApplication::$error in wp-content/plugins/pmpro-aweber/includes/aweber_api/oauth_application.php on line 481

This got me looking at the code in includes/aweber_api/oauth_application.php... notably line 480 and the if statement itself:

        if (!$resp || empty( $resp->body ) ) {
            $msg  = 'Unable to connect to the AWeber API.  (' . $this->error . ')';
            $error = array('message' => $msg, 'type' => 'APIUnreachableError',
                           'documentation_url' => 'https://labs.aweber.com/docs/troubleshooting');
            throw new AWeberAPIException($error, $url);
        }

The symptoms we are seeing pointed to the 'error' property not existing which it should if in fact there was an error. However, it doesn't exist and we're only getting to that point if the '$resp' variable is empty/false or the 'body' property is empty.

To investigate the status of these variables, I added in some error_log() statements and I got the following information:

Call to makeRequest() with params: 
    $method => POST
    $url => https://api.aweber.com/1.0/accounts/12345/lists/67890/subscribers
    $data => Array
    (
        [ws.op] => create
        [email] => [email protected]
        [name] => 
        [update_existing] => true
        [status] => subscribed
    )

$oauth: Array
(
    [email] => [email protected]
    [name] => 
    [oauth_consumer_key] => ***HIDDEN***
    [oauth_nonce] => ***HIDDEN***
    [oauth_signature] => ***HIDDEN***
    [oauth_signature_method] => HMAC-SHA1
    [oauth_timestamp] => 1693262697
    [oauth_token] => ***HIDDEN***
    [oauth_version] => 1.0
    [status] => subscribed
    [update_existing] => true
    [ws.op] => create
)

$resp: CurlResponse Object
(
    [body] => 
    [headers] => Array
        (
            [Http-Version] => 1.1
            [Status-Code] => 201
            [Status] => 201 Created
            [Date] => Mon, 28 Aug 2023 22:44:57 GMT
            [Content-Type] => text/html; charset=UTF-8
            [Transfer-Encoding] => chunked
            [Connection] => keep-alive
            [Location] => https://api.aweber.com/1.0/accounts/12345/lists/67890/subscribers/1234567890
            [CF-Cache-Status] => DYNAMIC
            [Server] => cloudflare
            [CF-RAY] => 7fe014f38e92a6f4-PHX
        )
)

The oAuth variables (although hidden in the text above) were all valid (as evidenced by the fact we are getting a valid 201 response from the server). Checking the API docs for the Aweber API, we can see that the response for a Create Subscriber is a 201 response code with an empty body:

https://api.aweber.com/#tag/Subscribers/paths/~1accounts~1{accountId}~1lists~1{listId}~1subscribers/post

Which brings us back to the 'if' block in makeRequest() and the empty 'body' property check... For this particular case, an empty body is NOT an error. It is an expected response. The error handling should actually check the status code of the response not whether or not a body property is empty.

To Reproduce
Steps to reproduce the behavior:

  1. Create a membership level
  2. set up the Aweber Add-on to assign multiple lists to a member when they register
  3. Sign up as a new member using that membership level.
  4. Observe that in Aweber that new subscriber is only subscribed to the first list.

Screenshots
If applicable, please attach a screenshot to make your issue clearer.

Expected behavior
Member is added to multiple lists. The Aweber API library is enhanced to use the status codes rather than an empty 'body' property check.

Isolating the problem (mark completed items with an [x]):

  • [ x] I have deactivated other plugins and confirmed this bug occurs when only Paid Memberships Pro plugin is active.
  • [ x] This bug happens with a default WordPress theme active.
  • [ x] I can reproduce this bug consistently using the steps above.

WordPress Environment

WordPress 6.2.2
PHP 8.2.9
Divi 4.22.0

Active Plugins
- Paid Memberships Pro v2.12.2
- Paid Memberships Pro - Affiliates Add On v0.6 
- Paid Memberships Pro - AWeber Add On v1.3.3 
- User Menus v1.3.2 
- User Switching v1.7.0 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant