PHP code example of joeymckenzie / givebutter-php

1. Go to this page and download the library: Download joeymckenzie/givebutter-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

joeymckenzie / givebutter-php example snippets


/** @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);


$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, ...]

$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' => [...]]

$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, ...]

$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, ...]

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

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