PHP code example of fet / postcard-api

1. Go to this page and download the library: Download fet/postcard-api 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/ */

    

fet / postcard-api example snippets


use Fet\PostcardApi\PostcardCreator;

$postcardCreator = PostcardCreator::factory(
    'POSTCARD_API_URL', // The base URL of the postcard API
    'POSTCARD_API_CAMPAIGN_KEY', // Your postcard API campaign key
    'POSTCARD_API_CLIENT_ID', // Your postcard API client ID
    'POSTCARD_API_CLIENT_SECRET', // Your postcard API client secret
);

$campaign = $postcardCreator->getCampaign();

// get the unique identifier for the campaign
$campaign->getCampaignKey();

// get the total quota of postcards allowed in the campaign
$campaign->getQuota();

// get the number of postcards already created within the campaign
$campaign->getNumberOfCreatedPostcards();

// get the remaining number of postcards that can be created in the campaign
$campaign->getNumberOfAvailablePostcards();

use Fet\PostcardApi\PostcardCreator;

// recipient address details
$recipient = [
    'title' => 'Mr.',
    'firstname' => 'John',
    'lastname' => 'Smith',
    'company' => 'ABC Inc.',
    'street' => '123 Main St.',
    'houseNr' => '456',
    'zip' => '12345',
    'city' => 'Anytown',
    'country' => 'United States',
    'poBox' => 'P.O. Box 789',
    'additionalAdrInfo' => 'Apt. 789',
];

// sender address details
$sender = [
    'firstname' => 'Jane',
    'lastname' => 'Doe',
    'company' => 'XYZ Corp.',
    'street' => '456 Elm St.',
    'houseNr' => '789',
    'zip' => '67890',
    'city' => 'Anyville',
];

// path to the front image
$image = 'path-to-image';

// text to be printed on the postcard
$senderText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';

// create the postcard
$postcard = $postcardCreator->create($recipient, $sender, $image, $senderText);

// approve the postcard
$postcard->approve();

// add a stamp image to the postcard
$postcard->addStampImage('path-to-stamp-image');

// add branding text to the postcard
$postcard->addBrandingText('branding-text');

// add a branding image to the postcard
$postcard->addBrandingImage('path-to-branding-image');

// add a branding QR tag to the postcard, with an optional side text
$postcard->addBrandingQrTag('qr-tag-text', 'qr-tag-side-text');

// get a base64-encoded preview image of the front of the postcard
$postcard->getFrontPreview()->getImageData();

// get a base64-encoded preview image of the back of the postcard
$postcard->getBackPreview()->getImageData();

// returns a multidimensional array with warnings
$warnings = $postcard->getWarnings();

// returns a multidimensional array with errors
$errors = $postcard->getErrors();

return [
    'url' => 'POSTCARD_API_URL',
    'campaign_key' => 'POSTCARD_API_CAMPAIGN_KEY',
    'client_id' => 'POSTCARD_API_CLIENT_ID',
    'client_secret' => 'POSTCARD_API_CLIENT_SECRET',
];