gifty/gifty-php

PHP library for interacting with the Gifty API.

V1.8.0 2024-05-01 12:34 UTC

This package is auto-updated.

Last update: 2024-05-01 12:35:28 UTC


README

Latest Stable Version CI License

PHP library for interacting with the Gifty API. This SDK is using the public Gifty API and enables you to:

  • Accept gift cards in your webshop
  • Redeem and issue gift cards in your POS-system
  • Retrieve gift card packages
  • Retrieve store locations

Requirements

  • PHP 8.0 and later
  • A valid API Key, that can be generated in your Gifty dashboard

Installation

The SDK is published on Packagist and can be installed using Composer.

composer require gifty/gifty-php

Getting Started

Before starting, it is recommended to read the documentation of the underlying Gifty API where all possible options to include are described.

Initializing the client and performing an API call is done as follows.

$gifty = new \Gifty\Client\GiftyClient('eyJ0eXAi....');
$giftCard = $gifty->giftCards->get('ABCDABCDABCDABCD');

You can also pass additional headers to the client.

$gifty = new \Gifty\Client\GiftyClient('eyJ0eXAi....', ['api_headers' => [
  'Accept-Language' => 'en',
  'X-Gifty-Location' => 'lc_123456789'
]]);
$giftCard = $gifty->giftCards->get('ABCDABCDABCDABCD');

Retrieve Locations

$locations = $gifty->locations->all();

Retrieve Packages

$packages = $gifty->packages->all();

Retrieve a Package

$package = $gifty->packages->get('gp_ABCDABCD');

Retrieve a Gift Card

$giftCard = $gifty->giftCards->get('ABCDABCDABCDABCD');

Issue a Gift Card

$transaction = $gifty->giftCards->issue(
  'ABCDABCDABCDABCD',
  [
    "amount" => 1250,
    "currency" => "EUR",
    "promotional" => false
  ]
);

Redeem a Gift Card

$transaction = $gifty->giftCards->redeem(
  'ABCDABCDABCDABCD',
  [
    "amount" => 1250,
    "currency" => "EUR",
    "capture" => false
  ]
);

Extend a Gift Card

$transaction = $gifty->giftCards->extend(
  'ABCDABCDABCDABCD',
  [
    "expires_at" => "2027-09-15T12:42:42+00:00"
  ]
);

Retrieve all Transactions

$transactions = $gifty->transactions->all(['limit' => 5]);

Retrieve all Transactions filtered by gift card ID

$transactions = $gifty->transactions->all(['giftcard' => 'gc_123456789']);

Retrieve a Transaction

$transaction = $gifty->transactions->get('tr_BV94pGgqRvgobxvrLX28jEl0');

Capture a Transaction

$transaction = $gifty->transactions->capture('tr_BV94pGgqRvgobxvrLX28jEl0');

Release a Transaction

$transaction = $gifty->transactions->release('tr_BV94pGgqRvgobxvrLX28jEl0');

Development

Clone the Git repository, so you have a local working copy.

git clone https://github.com/giftyhq/gifty-php

Install required (developing) dependencies using Composer.

composer install

Run and create PHPUnit tests for your modifications.

composer test

Make sure you follow the PSR12 coding standards.

composer phpstan & composer phpcs