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',
]);
// Get a campaign
$campaign = $client
->campaigns()
->get(441507);
// Get all campaigns
$campaigns = $client
->campaigns()
->list();
// Update a campaign
$updatedCampaign = $client
->campaigns()
->update($campaign->id, [
'description' => 'This is a test campaign.',
'goal' => 1500,
]);
// Delete a campaign
$deleteResponse = $client
->campaigns()
->delete($campaign->id);
$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',
]);
if ($createdCampaign->hasErrors()) {
// Do some error handling...
} else {
// Safely dereference response properties
assert($campaign->id !== null);
// Update a campaign
$updatedCampaign = $client
->campaigns()
->update($createdCampaign->id, [
'description' => 'This is another test campaign.',
'goal' => 1500,
]);
}
use Givebutter\Testing\ClientFake;
use Givebutter\Responses\Campaigns\GetCampaignResponse;
$fake = new ClientFake([
GetCampaignResponse::fake(GetCampaignFixture::class),
]);
$campaign = $fake
->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',
]);
expect($campaign->description)->toBe('This is a test campaign.');
// Assert completion create request was sent
$fake->assertSent(CampaignsResource::class, function (string $method, array $parameters): bool {
return $method === 'create' &&
$parameters[0]['title'] === 'title' &&
$parameters[0]['description'] === 'This is a test campaign.';
});
// Assert 2 completion create requests were sent
$fake->assertSent(CampaignsResource::class, 2);
// Assert no completion create requests were sent
$fake->assertNotSent(CampaignsResource::class);
// Assert no requests were sent
$fake->assertNothingSent();
$fake = new ClientFake([
new Exception('Oops, something bad happened!')
]);
// the `Exception` will be thrown
$campaign = $fake
->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',
]);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.