dealt / dealt-sdk
Dealt API SDK
Installs: 3 681
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: >=7.0 || ^8.0
- symfony70/polyfill-php80: <=1.18.1
Requires (Dev)
README
Dealt PHP SDK
Installation ⚙️
Requirements
PHP 7+ - library tested on php 7.0, 7.1, 7.2, 7.3, 7.4 & 8.1
Composer
composer require dealt/dealt-sdk
Usage ✨
Dealt Client initialization
Initalize the Dealt client with your api key.
You can specify the API environment you want to target using the DealtEnvironment
constants. Use DealtEnvironment.TEST
for development purposes.
use Dealt\DealtSDK\DealtClient; use Dealt\DealtSDK\DealtEnvironment; $client = new DealtClient([ "api_key" => "secret_dealt_api_key", "env" => DealtEnvironment::$PRODUCTION ]);
Checking offer availability
Check if an offer is available for a given country / zipCode :
/** @var Dealt\DealtSDK\GraphQL\Types\Object\OfferAvailabilityQuerySuccess */ $offer = $client->offers->availability([ 'offer_id' => 'your-offer-uuid', 'address' => [ 'country' => 'France', 'zip_code' => '75016', ] ]); $available = $offer->available; /** @var Dealt\DealtSDK\GraphQL\Types\Object\Money */ $net_price = $offer->net_price; /** @var Dealt\DealtSDK\GraphQL\Types\Object\Money */ $gross_price = $offer->gross_price; /** @var Dealt\DealtSDK\GraphQL\Types\Object\Money */ $vat_price = $offer->vat_price;
Getting a mission by id
/** @var Dealt\DealtSDK\GraphQL\Types\Object\MissionQuerySuccess */ $result = $client->missions->get("your-mission-id"); /** @var Dealt\DealtSDK\GraphQL\Types\Object\Mission */ $mission = $result->mission; /** @var Dealt\DealtSDK\GraphQL\Types\Object\Offer */ $offer = $mission->offer;
Getting all missions
/** @var Dealt\DealtSDK\GraphQL\Types\Object\MissionsQuerySuccess */ $result = $client->missions->all(); /** @var Dealt\DealtSDK\GraphQL\Types\Object\Mission[] */ $missions = $result->missions;
Submitting a mission
/** @var Dealt\DealtSDK\GraphQL\Types\Object\SubmitMissionMutationSuccess */ $result = $client->missions->submit([ "offer_id" => "your-offer-id", "address" => [ "country" => "France", "zip_code" => "92190", "city" => "Antony", "street1" => "XX Rue de la Paix" ], "customer" => [ "first_name" => "John", "last_name" => "Doe", "email_address" => "xxx@yyy.zzz", "phone_number" => "+33700000000" ], "webHookUrl" => "https://optional.webhook.url", "extraDetails" => "https://test-shop.com/optional/product.html" ]); /** @var Dealt\DealtSDK\GraphQL\Types\Object\Mission */ $mission = $result->mission;
Canceling a mission
/** @var Dealt\DealtSDK\GraphQL\Types\Object\CancelMissionMutationSuccess */ $result = $client->missions->cancel("your-mission-id"); /** @var Dealt\DealtSDK\GraphQL\Types\Object\Mission */ $mission = $result->mission;
Return types
Common return types you will encounter while interacting with the Dealt PHP SDK :
Dealt\DealtSDK\GraphQL\Types\Object\Mission
Dealt\DealtSDK\GraphQL\Types\Object\Offer
Dealt\DealtSDK\GraphQL\Types\Object\Money
Development 👨🏼💻
In order to run the E2E tests you will need to export the following environment variables in your current session (or automatically source them in your .zshrc or .bashrc)
DEALT_TEST_API_KEY=your-secret-api-key DEALT_TEST_OFFER_ID=your-offer-id
composer lint # lint source files composer test:lint # ensure valid codestyle composer test:types # phpstan reporting composer test:unit # phpunit tests