buchin/sendfox-integration
SendFox Integration Package
This package provides a simple integration with the SendFox API for Laravel applications. It allows you to create contacts using the SendFox API.
Installation
-
Add the package to your Laravel project:
composer require buchin/sendfox-integration -
Publish the configuration file:
php artisan vendor:publish --tag=config -
Add the required environment variables to your
.envfile:SENDFOX_TOKEN=your_sendfox_api_token SENDFOX_URL=https://api.sendfox.com/contacts SENDFOX_LIST_ID=your_list_id
Usage
Creating a Contact
You can use the SendFoxService to create a contact:
use Buchin\SendFoxIntegration\SendFoxService;
$service = new SendFoxService();
$user = (object) [
'email' => 'test@example.com',
'first_name' => 'Test',
'last_name' => 'User',
];
$response = $service->createContact($user);
if ($response->successful()) {
echo "Contact created successfully!";
} else {
echo "Failed to create contact.";
}
Automatically Sending User to SendFox on Creation
You can use Laravel's model events to automatically send a user to SendFox when a user is created. For example, in your User model:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Buchin\SendFoxIntegration\SendFoxService;
class User extends Model
{
protected static function booted()
{
static::created(function ($user) {
$service = new SendFoxService();
$nameParts = explode(' ', $user->name, 2);
$firstName = $nameParts[0] ?? '';
$lastName = $nameParts[1] ?? '';
$response = $service->createContact((object) [
'email' => $user->email,
'first_name' => $firstName,
'last_name' => $lastName,
]);
if ($response->successful()) {
Log::info('Contact created successfully in SendFox.');
} else {
Log::error('Failed to create contact in SendFox.', $response->json());
}
});
}
}
Testing
The package includes its own tests. To run the tests, navigate to the package directory and run:
php artisan test packages/SendFoxIntegration/tests
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.
License
This package is open-sourced software licensed under the MIT license.
Related Packages
laravel-paypalpayment is simple package help you process direct credit card paym...
Powerful PHP database abstraction layer (DBAL) with many features for database s...