Skip to content

Commit

Permalink
Merge pull request #38 from commonknowledge/feature/ck-3661-integrati…
Browse files Browse the repository at this point in the history
…on-with-mailchimp

feat: add mailchimp integration
  • Loading branch information
conatus authored Oct 8, 2024
2 parents 92611cc + 0c78029 commit 614e936
Show file tree
Hide file tree
Showing 13 changed files with 687 additions and 366 deletions.
3 changes: 2 additions & 1 deletion packages/join-block/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"auth0/auth0-php": "^8.3.1",
"http-interop/http-factory-guzzle": "^1.2",
"chargebee/chargebee-php": "^3.23",
"stripe/stripe-php": "^15.8"
"stripe/stripe-php": "^16.1",
"mailchimp/marketing": "^3.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5",
Expand Down
116 changes: 115 additions & 1 deletion packages/join-block/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion packages/join-block/join.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use CommonKnowledge\JoinBlock\Blocks;
use CommonKnowledge\JoinBlock\Exceptions\SubscriptionExistsException;
use CommonKnowledge\JoinBlock\Services\GocardlessService;
use CommonKnowledge\JoinBlock\Services\MailchimpService;
use CommonKnowledge\JoinBlock\Settings;
use Monolog\Logger;
use Monolog\Processor\WebProcessor;
Expand Down Expand Up @@ -301,7 +302,7 @@

$data = json_decode($request->get_body(), true);

$joinBlockLog->info('Here is your data dump', $data);
$joinBlockLog->info('Here is your Stripe data dump', $data);

/* Try catch around this */
$subscription = Subscription::create([
Expand Down Expand Up @@ -347,6 +348,36 @@
];
}
));

register_rest_route('join/v1', '/mailchimp', array(
'methods' => 'POST',
'permission_callback' => function ($req) {
return true;
},
'callback' => function (WP_REST_Request $request) {
global $joinBlockLog;

$data = json_decode($request->get_body(), true);

if (empty($data['email'])) {
$joinBlockLog->error('Email missing in Mailchimp join request');
return new WP_REST_Response(['status' => 'invalid request'], 400);
}

$email = $data['email'];
$joinBlockLog->info("Processing Mailchimp signup request for $email");

try {
MailchimpService::signup($email);
} catch (\Exception $e) {
$joinBlockLog->error("Mailchimp error for email $email: " . $e->getMessage());
return new WP_REST_Response(['status' => 'internal server error'], 500);
}

$joinBlockLog->info("Completed Mailchimp signup request for $email");
return new WP_REST_Response(['status' => 'ok'], 200);
}
));
});

// Happens after carbon_fields_register_fields
Expand Down
Loading

0 comments on commit 614e936

Please sign in to comment.