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

Unsubscribing via mailchimp unsubscribe link and resubscribing via Sylius throws an error #90

Open
pschuler21 opened this issue Jan 16, 2023 · 2 comments

Comments

@pschuler21
Copy link

User Story

No. 1: As a newsletter subscriber, I want to unsubscribe via the link in a Mailchimp mail in the footer, as it is easier than logging into the shop account of the given vendor.

No. 2: As the same customer, I may want to subscribe to the newsletter again within Sylius shop, as I changed my mind.

Problem

unsubscribing via the Mailchimp link in the footer and subscribing again via Sylius throws an error

Mailchimp error: {"message":"Response status is 400 instead of subscribed.","response":{"title":"Member In Compliance State","status":400,"detail":"[email protected] is in a compliance state due to unsubscribe, bounce, or compliance review and cannot be subscribed."

Suggested solution

this Stackoverflow thread suggests to first check and change the user status on Mailchimp before attempting to change the user's subscription state
https://stackoverflow.com/questions/42990336/mailchimp-how-can-i-tell-if-a-user-has-unsubscribed-themselves

@lruozzi9
Copy link
Contributor

Hey! We have also been experiencing this error for some time. In reality, there is no "solution"!
These errors occur when a contact has been deleted from a list (not archived) or when they have unsubscribed autonomously from the link in the newsletter email.
Due to GDPR, Mailchimp does not allow you (admin) to resubscribe these contacts autonomously, the only way is to create a Mailchimp landing page form and allow them to resubscribe from there.
On the plugin side, what could be done is to warn the user of this situation. We solved it in this way:

  1. We have created a landing page for each audience
  2. We have forked the Newsletter action and we have changed like this:
try {
    $this->client->subscribeEmail($audience, $email);
} catch (ClientException $clientException) {
    if ($this->isContactDeletedOrUnsubscribedException($clientException)) {
        return $this->json(
            $this->translator->trans('setono_sylius_mailchimp.ui.already_subscribed', [
                '{link}' => $this->getResubscribeAudienceFormLink($audience),
            ]),
            422,
            [$clientException->getMessage()],
        );
    }

    throw $clientException;
} catch (\Throwable $t) {
    return $this->json(
        $this->translator->trans('setono_sylius_mailchimp.ui.generic_error'),
        422,
        [$t->getMessage()],
    );
}
private function isContactDeletedOrUnsubscribedException(ClientException $clientException): bool
{
    if ($clientException->getStatusCode() !== 400) {
        return false;
    }
    // Deleted contacts
    if (str_starts_with($clientException->getMessage(), 'Forgotten Email Not Subscribed:')) {
        return true;
    }
    // Unsubscribed contacts
    if (str_starts_with($clientException->getMessage(), 'Member In Compliance State:')) {
        return true;
    }

    return false;
}
  1. In the newsletter form we place the message JSON field from the response in an HTML container to the whole error message. In the first error case, the translation message looks like: We are sorry, but it looks like your email was already subscribed to our newsletter. To comply with GDPR, you must re-subscribe by ensuring the external provider that you want to do so. You can do this by accessing <a href="{link}" target="_blank" rel="noopener noreferer">this link</a> and re-entering your email. Thank you!. You should map the right landing page with the right audience.

@pschuler21
Copy link
Author

Appreciate your answer and solution @lruozzi9. I understand these boundaries come from Mailchimp. Your approach sounds like a viable workaround.

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

2 participants