1. Go to this page and download the library: Download quoyer/quoyer-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/ */
use Quoyer\QuoyerClient;
// Just the key: talks to https://quoyer.com.
$quoyer = new QuoyerClient('quoy_live_…');
// Or with options.
$quoyer = new QuoyerClient([
'api_key' => getenv('QUOYER_API_KEY'),
'base_url' => 'https://quoyer.com',
'store_url' => 'https://shop.example.com',
'platform' => 'myshop/2.1.0',
]);
use Quoyer\QuoyerClient;
use Quoyer\Laravel\Facades\Quoyer;
public function __construct(private QuoyerClient $quoyer) {}
Quoyer::customers()->findByEmail('[email protected]');
$me = $quoyer->me(); // call it first: it confirms the key
$me->tenant->name; // "Example Cosmetics"
$me->accountState(); // trial, active, past_due, suspended, cancelled
$me->hasFeature('referrals'); // read entitlements, never plan names
$me->limit('members_active'); // int, or null = unlimited
$customer = $quoyer->customers->upsert([
'external_id' => '1042',
'external_source' => 'myshop',
'email' => '[email protected]',
'first_name' => 'Jane',
'birthday' => '1991-04-29', // Quoyer awards birthday points itself
'locale' => 'ro', // the language of Quoyer's emails to her
'referral_code' => $codeFromLink, // a new customer who arrived by a referral link
]);
$customer->wasCreated(); // true for a new customer (201)
$customer->points(); // spendable balance
$customer->balance->value?->amount; // "3.49", in the programme's default currency
$customer->card_number; // the Quoyer card number
$quoyer->customers->retrieve('cus_…'); // with lifetime totals
$quoyer->customers->findByExternalId('1042', 'myshop');
$quoyer->customers->findByEmail('[email protected]');
$quoyer->customers->findByCardNumber('4821773019');
$quoyer->customers->update('cus_…', ['first_name' => 'Janet']);
$quoyer->customers->transactions('cus_…'); // the ledger, for an activity feed
$quoyer->customers->buckets('cus_…', ['status' => 'active']); // "your points expire on …"
$quoyer->customers->referrals('cus_…');
$quoyer->customers->delete('cus_…'); // permanent erasure (GDPR)
use Quoyer\Enums\RuleType;
// An order.
$result = $quoyer->points->credit([
'customer_external_id' => '1042',
'customer_external_source' => 'myshop',
'rule_type' => RuleType::Purchase,
'source_reference' => 'myshop_order_5531',
'metadata' => [
'amount' => 49.99, // the total paid
'currency' => 'EUR',
'line_items' => [ // lets rules target products, categories, brands
['product_id' => '77', 'category_ids' => ['5', '12'], 'amount' => 40.00, 'quantity' => 2],
['product_id' => '81', 'category_ids' => ['3'], 'amount' => 9.99],
],
],
]);
$result->pointsAwarded(); // across the base rule and any stacking bonuses
$result->wasNew(); // false on a repeat of the same source_reference
$result->note; // set when zero points were awarded, e.g. below the minimum
// The order was refunded: take the points back.
$reversal = $quoyer->points->reverseCredit([
'customer_external_id' => '1042',
'customer_external_source' => 'myshop',
'source_reference' => 'myshop_order_5531',
'reason' => 'refund',
'triggered_by' => ['order_id' => 5531],
]);
$reversal->wasNewlyReversed(); // false if it had been reversed already (still a success)
$redemption = $quoyer->redemptions->create([
'customer_external_id' => '1042',
'customer_external_source' => 'myshop',
'points' => 100,
'generate_coupon_code' => true,
'source_reference' => 'myshop_cart_7_attempt_1',
]);
$redemption->coupon_code; // "QYR-516688D8": create the real coupon on your shop
$redemption->monetary_value; // "1.00" in $redemption->currency
// The order was placed: record it on the redemption.
$quoyer->redemptions->mergeMetadata($redemption->id, ['order_id' => 5532]);
// The coupon was removed or the order refunded: give the points back.
$quoyer->redemptions->reverse($redemption->id, ['reason' => 'coupon removed']);
$quoyer->buckets->list(['customer_id' => 'cus_…', 'status' => 'active']);
$quoyer->earningRules->list(['rue, 'points_multiplier' => 200, 'target_category_ids' => ['5']]);
$quoyer->catalogue->sync($allProductsCategoriesAndBrands); // batches of 1,000 for you
$quoyer->currencies->create(['currency_code' => 'RON', 'currency_units_per_point' => 1000]);
$quoyer->program->retrieve();
$quoyer->tiers->list()->isActive(); // show nothing about tiers when false
$customer->email;
$customer['email'];
$customer->tier?->name;
$customer->toArray(); // exactly what the API sent
json_encode($customer); // the same
use Quoyer\ErrorCode;
use Quoyer\Exceptions\AccountStateException;
use Quoyer\Exceptions\InvalidRequestException;
try {
$quoyer->redemptions->create([...]);
} catch (AccountStateException $e) {
$shopperMessage = $e->getMessage(); // safe to show
$logger->warning($e->getAdminReason()); // never to the shopper
} catch (InvalidRequestException $e) {
match ($e->getErrorCode()) {
ErrorCode::INSUFFICIENT_POINTS => /* offer fewer points */,
ErrorCode::INVALID_REDEEM_REQUEST => /* outside the programme's min/max */,
default => throw $e,
};
}
// One page.
$page = $quoyer->customers->list(['limit' => 100]);
foreach ($page as $customer) { … }
$page->hasMore();
$next = $page->nextPage(); // null on the last page
// Every item, fetching pages only as you reach them.
foreach ($quoyer->customers->all(['external_source' => 'myshop']) as $customer) { … }
use Quoyer\Enums\EventType;
use Quoyer\Exceptions\SignatureVerificationException;
use Quoyer\Webhook;
try {
$event = Webhook::constructEvent(
file_get_contents('php://input'),
$_SERVER['HTTP_X_QUOYER_SIGNATURE'] ?? '',
getenv('QUOYER_WEBHOOK_SECRET'),
);
} catch (SignatureVerificationException) {
http_response_code(400);
exit;
}
match ($event->typeEnum()) {
EventType::RedemptionCreated => handleRedemption($event->data->redemption),
EventType::PointsExpired => notifyExpiry($event->data->customer, $event->data->points_expired),
default => null, // unknown types: ignore, still answer 2xx
};
http_response_code(200);
$response = $customer->getLastResponse();
$response->rateLimit()?->remaining; // calls left this minute
$response->isPaymentPastDue(); // for the merchant's admin, never for shoppers
$response->deprecation(); // fields that will be removed
$response->statusCode;
$response = $quoyer->request('GET', '/new-endpoint', ['limit' => 10]); // any path under /api/v1
$response->json;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
$mock = new MockHandler([new Response(200, [], json_encode(['object' => 'program', 'name' => 'Test']))]);
$quoyer = new QuoyerClient('quoy_sandbox_test', new Client(['handler' => HandlerStack::create($mock)]));
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.