vemcogroup / laravel-sparkpost-driver

SparkPost driver to use with Laravel
MIT License
40 stars 16 forks source link

Options as shown in README don't work #8

Closed MeesterDev closed 4 years ago

MeesterDev commented 4 years ago

Some of the options shown in the README don't work.

The README shows:

'options' => [
    'endpoint' => env('SPARKPOST_ENDPOINT'),
    'open_tracking' => false,
    'click_tracking' => false,
    'transactional' => true,
],

What actually works is:

'options' => [
    'endpoint' => env('SPARKPOST_ENDPOINT'),
    'options' => [
        'open_tracking'  => false,
        'click_tracking' => false,
        'transactional'  => true,
    ],
],

In both cases, the "endpoint" is also added to the actual request payload.

(I can make a PR later today)

eldor commented 4 years ago

Hi @MeesterDev,

Thanks for you comments, the options are working as intended, we have the running in large systems without issues:

Are you sure you are using it to describe your sparpost settings in services.php ?

'sparkpost' => [
    'secret' => env('SPARKPOST_SECRET'),
    'guzzle' => [
        'verify' => true,
        'decode_content' => true,
        ...
    ],
    'options' => [
        'endpoint' => env('SPARKPOST_ENDPOINT'),
        'open_tracking' => false,
        'click_tracking' => false,
        'transactional' => true,
    ],
],

Which errors are you getting of you use the options as described in README?

MeesterDev commented 4 years ago

Yes, I've put them in services.php.

If I use what the readme says

    'sparkpost' => [
        'secret'  => env('SPARKPOST_SECRET'),
        'options' => [
            'open_tracking'  => false,
            'click_tracking' => false,
            'transactional'  => true,
        ],
    ],

The resulting e-mail contains the links with tracking: image (the mentioned time in the e-mail is hardcoded as it is a test, I did make a new screenshot just now)

However, if I use

    'sparkpost' => [
        'secret'  => env('SPARKPOST_SECRET'),
        'options' => [
            'options' => [
                'open_tracking'  => false,
                'click_tracking' => false,
                'transactional'  => true,
            ],
        ],
    ],

The resulting mail has the direct links: image

If I dump the actual request payload of what happens when using the readme example (with some things redacted), it is:

array:2 [
  "headers" => array:1 [
    "Authorization" => "(nopenopenopenopenope)"
  ]
  "json" => array:5 [
    "recipients" => array:1 [
      0 => array:1 [
        "address" => array:2 [
          "name" => null
          "email" => "..."
        ]
      ]
    ]
    "content" => array:1 [
      "email_rfc822" => """
        Return-Path: <...>\r\n
        Message-ID: <...>\r\n
        Date: Mon, 22 Jun 2020 13:54:34 +0200\r\n
        Subject: Test e-mail\r\n
        From: ... <...>\r\n
        To: ...\r\n
        MIME-Version: 1.0\r\n
        Content-Type: text/html; charset=utf-8\r\n
        Content-Transfer-Encoding: quoted-printable\r\n
        \r\n
        DUMMY\r\n
        """
    ]
    "open_tracking" => false
    "click_tracking" => false
    "transactional" => true
  ]
]

Whereas the API doc (https://developers.sparkpost.com/api/transmissions/#header-request-body) says they should be in an 'options' array.

The options contain

array:3 [
  "open_tracking" => false
  "click_tracking" => false
  "transactional" => true
]

and are directly merged into the payload (https://github.com/vemcogroup/laravel-sparkpost-driver/blob/master/src/Transport/SparkPostTransport.php#L67).

I'm using version 3.0.2 with Laravel 7.13.0.

eldor commented 4 years ago

You are actually right, my mistake, was looking the wrong place. I have updated the README, thank you for your contribution.