joeymckenzie/givebutter-php

PHP API wrapper for Givebutter's public API.

0.1.0 2025-06-27 06:08 UTC

This package is auto-updated.

Last update: 2025-06-27 06:13:10 UTC


README

logo packgist downloads ci packgist downloads packgist downloads codecov coverage report

🧈 Givebutter PHP

Givebutter PHP is a plug 'n play and easy to use client for Givebutter's public API.

Table of Contents

Getting started

The client is available as a composer packager that can be installed in any project using composer:

composer require joeymckenzie/givebutter-php

Since the client is compatible with any PSR-18 HTTP client, any commonly used HTTP client can be used thanks to our dependency on php-http/discovery. Once both dependencies have been installed, you may start interacting with Givebutter's API:

/** @var string $apiKey */
$apiKey = $_ENV['GIVEBUTTER_API_KEY'];
$client = Givebutter::client($apiKey);

// Create a campaign
$createdCampaign = $client
    ->campaigns()
    ->create([
        'description' => 'This is a test campaign.',
        'end_at' => CarbonImmutable::now()->toIso8601String(),
        'goal' => 1000,
        'subtitle' => 'subtitle',
        'slug' => md5(uniqid('', true)),
        'title' => 'title',
        'type' => 'collect',
    ]);
var_dump($createdCampaign);

// Get a campaign
$campaign = $client
    ->campaigns()
    ->get(441507);
var_dump($campaign);

// Get all campaigns
$campaigns = $client
    ->campaigns()
    ->list();
var_dump($campaigns);

// Update a campaign
$updatedCampaign = $client
    ->campaigns()
    ->update($campaign->id, [
        'description' => 'This is a test campaign.',
        'goal' => 1500,
    ]);
var_dump($updatedCampaign);

// Delete a campaign
$deleteResponse = $client
    ->campaigns()
    ->delete($campaign->id);
var_dump($deleteResponse);

For a comprehensive set of examples, take a look at the examples directory.

Usage

Campaigns

Create a campaign

Creates a campaign from a specified payload.

$response = $client->campaigns()->create([
              'title' => 'Campaign title',
              'description' => 'Campaign description.',
              'end_at' => CarbonImmutable::now()->toIso8601String(),
              'goal' => 10000,
              'subtitle' => 'Campaign subtitle',
              'slug' => 'campaignSlug123',
              'type' => 'collect',
          ]);

echo $response->data(); // GetCampaignResponse::class
echo $response->id; // 42
echo $response->title; // 'Campaign title'
echo $response->goal; // 10000
echo $response->toArray(); // ['id' => 42, ...]

Get all campaigns

Gets a list of available campaigns. Optionally, accepts a scope parameter.

$response = $client->campaigns()->list();

echo $response->data; // array<int, GetCampaignResponse::class>
echo $response->meta; // Meta::class
echo $response->links; // Links::class
echo $response->toArray(); // ['data' => ['id' => 42, ...], 'meta' => [...], 'links' => [...]]

Get a campaign

Gets a single campaign.

$response = $client->campaigns()->get(42);

echo $response->data(); // GetCampaignResponse::class
echo $response->id; // 42
echo $response->title; // 'Campaign title'
echo $response->goal; // 10000
echo $response->toArray(); // ['id' => 42, ...]

Update a campaign

Updates a campaign from a specified payload.

$response = $client->campaigns()->update(42, [
              'description' => 'Updated campaign description.',
              'goal' => 20000,
          ]);

echo $response->data(); // GetCampaignResponse::class
echo $response->id; // 42
echo $response->title; // 'Campaign title'
echo $response->goal; // 20000
echo $response->toArray(); // ['id' => 42, ...]

Delete a campaign

Deletes a campaign.

$response = $client->campaigns()->delete(42);

echo $response->getStatusCode(); // 200