Access Codes
A plan's access codes as a connector's creator surface prices, generates, lists and revokes them — a batch priced before it is queued, delivered to the creator on their account, and never handed back in full.
Subscriby\Connector\Core\AccessCodes. An access code is one code for one person that grants the plan outright, the way Storefront::redeemAccessCode() completes it on a member's surface. A batch is generated on the queue and delivered to the creator as a file or one message per code, through the connector their account is on, so the call answers a receipt rather than the codes. Every call takes the CreatorRef of the account talking and runs as that creator, and every refusal reaches you as AccessCodesRefused with a stable reason.
previewCost()
$cost = $this->codes->previewCost($creator, $planId, 50);
$cost->freeRemaining; // the codes still included this month
$cost->chargeableQuantity; // how many of the batch are billed
$cost->cost; // the charge in words, "0" when nothing is billed
$cost->exceedsThreshold; // whether the core asks for an explicit confirmationWhat a batch would cost before it is queued. The creator's plan includes some codes a month; a batch beyond them is billed, so a surface shows the cost and asks before queueing, because the charge cannot be undone once the codes exist.
generate()
$receipt = $this->codes->generate($creator, new AccessCodeBatch(
planId: $planId,
quantity: 50,
exportType: AccessCodeBatch::EXPORT_FILE,
expiryPreset: AccessCodeBatch::EXPIRY_ONE_MONTH,
));Queues the batch and answers an AccessCodeReceipt: the key the core generates it under and the cost as previewed at that moment. The codes reach the creator on their account once generated, so a surface tells them to watch for the file or the messages. EXPORT_MESSAGES sends one message per code and takes batches of 25 at most; a custom expiry names customExpiryAmount and customExpiryUnit (days, weeks, months, years).
list() and revoke()
foreach ($this->codes->list($creator, $planId, AccessCodeState::Unredeemed) as $code) {
// $code->id, ->maskedCode, ->redeemed, ->redeemedAt, ->expiresAt
}
$this->codes->revoke($creator, $planId, $code->id);The plan's codes, masked (the first and last characters, enough to match a member's ticket), filtered by an AccessCodeState (All, Unredeemed, Redeemed or Expired), newest first. A revoke takes an unredeemed code out of circulation.
Refusals
AccessCodesRefused carries a stable reason: creator_unknown, plan_unknown (no plan the creator may manage has the id), code_unknown (no unredeemed code of the plan has the id), invalid (a quantity outside 1 to 1000, a messages export over 25, a custom expiry without its parts), batch_in_flight (a batch for the plan is still being generated) and not_permitted.
The full code leaves the core once, in the file or the messages the batch delivers; every later read is masked.
How is this guide?
Last updated on
Coupons
A project's coupons as a connector's creator surface lists, creates, pauses and deletes them — one code any number of members redeem for money off, checked the way the dashboard checks it.
Broadcasts
A project's broadcasts as a connector's creator surface sizes and sends them — the audiences with their sizes, a draft previewed before it is sent, and the send that posts once where a connector announces and per member everywhere else.