sokolnikov911/laravel-sendy

Service provider for Sendy API in PHP Laravel 5+

dev-master 2021-02-08 16:57 UTC

This package is auto-updated.

Last update: 2024-10-09 00:49:54 UTC


README

Github Packagist Packagist downloads

Package description: Laravel simple integration with Sendy API to subscribe/unsubscribe users to list.

Installation

Install via composer

composer require sokolnikov911/laravel-sendy

Register Service Provider

Note! This step is optional if you use laravel >= 5.5 with package auto discovery feature.

Add service provider to config/app.php in providers section

sokolnikov911\LaravelSendy\ServiceProvider::class,

Register Facade

Register package facade in config/app.php in aliases section

'LaravelSendy' => sokolnikov911\LaravelSendy\Facades\LaravelSendy::class,

Add env variables

SENDY_API_KEY=your-api-key
SENDY_URL=your-sendy-url
SENDY_LIST_ID=your-list-id

LIST ID can be found encrypted & hashed in View all lists section under the column named ID

Customizing or extending

Publish configuration file

You can publish configuration file to edit the variables, in case you don't want to use ENV. File will pe published in /config/larave-sendy.php

php artisan vendor:publish --provider="sokolnikov911\LaravelSendy\ServiceProvider" --tag="config"

Publish translations

You can publish translations to edit them. Files will be published in /resources/lang/vendor/laravel-sendy.

Note: You can extend translations by creating a new file in /resources/lang/vendor/laravel-sendy/{lang}/messages.php using the format from en language file.

Usage examples

Before any usage add Namespace to file.

use sokolnikov911\LaravelSendy\LaravelSendy;

Subscribe

Subscribes a new email to list. This can be used to edit already subscribed users. (eg. change name)

// initialize LaravelSendy
$sendy = new LaravelSendy();

// Simple email subscribe
$subscribe = $sendy->subscribe('email@example.com');

// Add subscriber with email and name
$subscribe = $sendy->subscribe('email@example.com', 'John Doe');

// Full subscribe method
$subscribe = $sendy->subscribe($email, $name = null, $listId = null, $json = false, $customFields = []);

// Response example
$subscribe = [
  "success" => true
  "message" => "You have been subscribed."
]

Unsubscribe Examples

Marks email as unsubscribed from the list.

// initialize LaravelSendy
$sendy = new LaravelSendy();

// Simple unsubscribe
$unsubscribe = $sendy->unsubscribe('email@example.com');

// Full unsubscribe method
$unsubscribe = $sendy->unsubscribe($email, $listId = null, $json = false);

// Response example
$unsubscribe = [
  "success" => true
  "message" => "You have been unsubscribed."
]

Delete Example

Deletes email from list. Action is definitive.

// initialize LaravelSendy
$sendy = new LaravelSendy();

// Simple delete
$delete = $sendy->delete('email@example.com');

// Full unsubscribe method
$delete = $sendy->delete($email, $listId = null, $json = false);

// Response example
$delete = [
  "success" => true
  "message" => "You have been deleted from the list."
]

Security

If you discover any security related issues, please email instead of using the issue tracker.

Contribute

If you wish to contribute to translations for the package in your language you can submit a PR request with the lang files copied from en resources/lang/en/messages.php.