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

Upgrade SDK v.2.0 [BC BREAK] #27

Merged
merged 23 commits into from
Jul 16, 2024
Merged

Upgrade SDK v.2.0 [BC BREAK] #27

merged 23 commits into from
Jul 16, 2024

Conversation

gaalferov
Copy link
Collaborator

@gaalferov gaalferov commented May 17, 2024

Motivation

Make a similar architecture with other libraries.
Add a layer for quick creation of email client depending on parameters
Add native support for adding a template and its variables

Changes

  • [BC BREAK] PHP 7.4 will no longer be supported (PHP 8.0+) (only 2% of customers are using this version)
    • They can still use the previous version 1.*, which supports PHP 7.4.
  • improve codebase to support PHP 8.0 features
  • Rebuild Bridge (Laravel&Symfony) to support new architecture + more tests
  • Added a short method to get the Email layer depending on config params MailtrapClient::initSendingEmails()
  • Added MailtrapEmail wrapper (MIME) for easy add category, custom variables, template uuid, etc + tests
  • [BC BREAK] Rebuild ALL Emails layers to use the inbox ID at the client level + tests
  • [BC BREAK] Rebuild SANDBOX Projects & Messages & Attachments & Inboxes layers + tests
  • [BC BREAK] Rebuild GENERAL Accounts & Permissions & Users layers + tests

How to test

composer test

OR install and run some examples from the new version of library

composer require railsware/mailtrap-php:dev-feature/v.2.0.0 symfony/http-client nyholm/psr7
<?php

use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapClient;
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Header\UnstructuredHeader;

require __DIR__ . '/vendor/autoload.php';

// Mailtrap SENDING client (real)
$mailtrap = MailtrapClient::initSendingEmails(
    apiKey: getenv('MAILTRAP_API_KEY') # your API token from here https://mailtrap.io/api-tokens
);

$email = (new MailtrapEmail())
    ->from(new Address('[email protected]', 'Mailtrap Test'))
    ->to(new Address('[email protected]', 'Jon'))
    ->category('Integration Test')
    ->customVariables([
        'user_id' => '45982',
        'batch_id' => 'PSJ-12'
    ])
;

try {
    $response = $mailtrap->send($email);

    var_dump(ResponseHelper::toArray($response)); // body (array)
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

// OR -> Mailtrap BULK SENDING client (real)
try {
    $mailtrapBulkSending = MailtrapClient::initSendingEmails(
        apiKey: getenv('MAILTRAP_API_KEY'), # your API token from here https://mailtrap.io/api-tokens
        isBulk: true # Bulk sending (@see https://help.mailtrap.io/article/113-sending-streams)
    );

    $response = $mailtrapBulkSending->send($email);

    var_dump(ResponseHelper::toArray($response)); // body (array)
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

// OR -> Mailtrap Testing client (sandbox)
try {
    $mailtrapTesting = MailtrapClient::initSendingEmails(
        apiKey: getenv('MAILTRAP_API_KEY'), # your API token from here https://mailtrap.io/api-tokens
        isSandbox: true, # Sandbox sending (@see https://help.mailtrap.io/article/109-getting-started-with-mailtrap-email-testing)
        inboxId: getenv('MAILTRAP_INBOX_ID') # required param for sandbox sending
    );

    $response = $mailtrapTesting->send($email);

    var_dump(ResponseHelper::toArray($response)); // body (array)
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

@gaalferov gaalferov marked this pull request as draft May 17, 2024 11:00
@gaalferov gaalferov changed the title Upgrade SDK v.2.0 Upgrade SDK v.2.0 [BC BREAK] May 23, 2024
@gaalferov gaalferov marked this pull request as ready for review June 6, 2024 10:09
@gaalferov gaalferov requested a review from IgorDobryn June 6, 2024 10:12
Copy link
Contributor

@VladimirTaytor VladimirTaytor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

Integration between products is seamless right now 🎖️

UPGRADE-2.0.md Show resolved Hide resolved
src/Bridge/Symfony/README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
examples/testing/messages.php Outdated Show resolved Hide resolved
gaalferov and others added 2 commits July 5, 2024 09:52
Co-authored-by: Ihor Dobryn <[email protected]>
@VladimirTaytor VladimirTaytor merged commit 8021b0b into main Jul 16, 2024
13 checks passed
@VladimirTaytor VladimirTaytor deleted the feature/v.2.0.0 branch July 16, 2024 08:48
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

Successfully merging this pull request may close these issues.

4 participants