Download the PHP package bymayo/craft-points without Composer

On this page you can find all versions of the php package bymayo/craft-points. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package craft-points

Points for Craft CMS

A loyalty, rewards, and gamification system for Craft. Award points for any action - signups, shares, comments, purchases - tier users into levels, and build leaderboards. Add Craft Commerce and customers can redeem their points as store credit at checkout.

Features

Contents

Editions

Lite Pro
Rules, Awards, Levels, Leaderboard
Dashboard widgets
Triggers for Entries, Users, Assets
Formie & Freeform integrations
Twig + GraphQL APIs
Renameable plugin & currency labels
Commerce triggers (orders, subscriptions) -
Percentage-of-order rewards -
Commerce conditions (order total, contains product, …) -
Redeem points as store credit at checkout -

Install

You can also install the plugin via the Plugin Store in the Craft Admin CP by searching for Points.

Requirements

Integrations

Points hooks into other Craft plugins to unlock extra triggers, conditions, and rewards. Integrations activate automatically when the matching plugin is detected - nothing to configure.

Plugin What it adds Edition
Craft Commerce Order triggers (paid · completed · refunded · first ever), Subscription triggers (created · renewed · cancelled · plan changed), Commerce conditions (order total · item count · contains product · has coupon), percentage-of-order rewards, customer redemptions at checkout, money columns on the Users index and Leaderboard Pro
Formie "Form submitted" trigger and the "Form is" condition to scope to specific forms Lite
Freeform "Form submitted" trigger and the "Form is" condition to scope to specific forms Lite

Your Points → Settings → General page shows which integrations are detected on your site, so you can see at a glance what features are available. Third-party developers can plug their own triggers / conditions / limits / rewards into the rule builder via Craft events - see Extending the plugin.

How it works

Three concepts cover everything:

Defaults call everything "Points" - but you can rename. The plugin can show up in the sidebar as "Rewards" or "VIP Club", the unit can be "Coins" or "Stars". Set it all under Points → Settings → General.

Building your first rule

Go to Points → Rules → New rule.

Section What it is
Name What you call this rule
When The trigger - Entry created, Order paid, etc. Or "Manual" if your own code will fire it.
If Optional conditions - e.g. only when the entry is in the "Reviews" section.
Then The reward - flat amount, percentage of order total (Pro), or a deduction.
Limit How often it can fire per user - Once, Max N per day/week/month, optional cooldown.
Active period Optional date range - handy for campaigns.

Triggers that come with the plugin

Subject Triggers Available on
Manual (fired by your own code, see below) Lite
Entry Created · Updated Lite
Asset Created Lite
User Registered · Logged in · Birthday · Anniversary Lite
Formie Form submitted Lite
Freeform Form submitted Lite
Order Paid · Completed · Refunded · First ever Pro
Subscription Created · Renewed · Cancelled · Plan changed Pro

Each non-Manual trigger awards the right person automatically: the entry's author, the order's customer, the asset's uploader, etc. Manual rules don't fire on their own - your code (a form, JS button, or GraphQL mutation) decides when, as explained in Firing a rule from your site.

Birthday trigger: needs a Date field on the user layout. Set its handle in Settings → Triggers. The trigger fires on the user's next login after their birthday - it'll only appear in the rule picker once you've configured it.

Firing a rule from your site

For "Manual" rules (no trigger), pick whichever fits your setup:

1. A regular form - server-rendered pages

Best for claim-style actions where the click itself is the qualifying event - a daily-bonus button, "mark profile complete", "activate promo", etc. Pair with a Once per user or Max 1 / day limit on the rule so the button stays safe to click.

To reverse an award, post to points/awards/remove with the same shape.

For actions that require something else to happen first (a real signup, a real share), don't use the form pattern directly - the user could click it without doing the underlying action. Either fire the rule from your own controller's PHP after the real action completes, or call Points.addAward() from the JS confirmation page.

Forms don't play nicely inside Blitz / {% cache %} blocks - the embedded CSRF token gets stale. Use the JS helper on cached pages.

2. The JS helper - for buttons & cached pages

Drop this once in your layout:

Now you have window.Points everywhere. Cache-safe - works inside Blitz, {% cache %}, anything:

Both methods return a Promise:

Method Args
Points.addAward(handle) rule handle (string)
Points.removeAward(handle) rule handle (string)

Both resolve to an object with these fields:

Field Type When
success bool Always - true on success, false on failure
points int addAward success - number of points awarded
currency string addAward success - the configured plural reward-unit label (e.g. Points, Coins)
awardId int addAward success - id of the new PointAward element
error string On failure - a human-readable reason (rule disabled, limit reached, not logged in, etc.)

Works with React, Vue, Alpine, Stimulus, htmx - anything that can call a global function.

3. A GraphQL mutation - for headless / decoupled apps

For Next.js, Nuxt, native apps, or anything where your frontend lives outside Craft's templates:

Same security rules as the form and JS API - the user must be logged in, the rule must be Manual, and points always go to the authenticated user.

Behind the scenes (the boring but important bit)

All three options share the same safety net: login required, CSRF protected, only Manual rules, current-user-only (no userId ever gets accepted from the client), Limits enforced, and the rule's active dates honoured.

That said, the client is trusted to ask politely. Someone could open devtools and call Points.addAward('shared') without actually sharing. Keep Manual rules low-value, and use trigger-based rules (Order paid, Entry created, …) for anything worth gaming.

Server-side awards

From a module, controller, or console command:

Call Returns
Points::getInstance()->awards->addAward($userId, $handle) PointAward on success, null if the rule isn't found or a limit blocked the award
Points::getInstance()->awards->removeAward($userId, $handle) true if an award was removed, false if there was nothing to remove

This is the only API that can target a user other than the one currently logged in.

Reading points in Twig

Loop through someone's awards:

Levels & leaderboard

Levels are tiers your users earn by accumulating points. Create them in Points → Levels with a threshold, colour, and optional badge icon.

Leaderboard:

There's also a paginated Points → Leaderboard page in the CP and a matching dashboard widget.

Spending points at checkout

Available on Pro + Craft Commerce. Customers apply points against an order - it shows up like a coupon discount, works with any payment gateway.

What happens behind the scenes:

  1. Customer applies points → the plugin validates and records the intent.
  2. Commerce shows it as a discount line on the order.
  3. Customer pays the reduced total via any gateway.
  4. On Order::EVENT_AFTER_ORDER_PAID, the points are taken from their balance (recorded as a negative award for the audit trail).
  5. On refund, points are restored according to your refund-behaviour setting.

Configure conversion rate, minimum redemption, max % of order, and refund behaviour in Settings → Commerce.

Dashboard widgets

Add via the Craft dashboard → + New widget. Both are grouped under your plugin name (e.g. Rewards - Leaderboard):

Widget Shows
Leaderboard Top N users by balance. Columns: Customer · Level · Total.
Latest Awards The N most recent awards across all users. Columns: Customer · {currency} · Date.

Each widget respects your renames - column headers follow whatever you set in Settings.

Examples

A few real-world rule setups to get you started.

General

Welcome bonus on signup

Daily login bonus

Birthday gift

Share button (Manual)

Commented on a post

Commerce (Pro)

1 point per £1 spent

First-order bonus

Big spender bonus (stacks with above)

Subscriber loyalty

Don't reward coupon orders

Settings

Settings can be edited at Points → Settings:

Key Tab Default What it does
pluginName General Points Label shown in the CP sidebar and breadcrumbs
currencyName General Point Reward unit, singular - e.g. Coin, Star
currencyNamePlural General Points Reward unit, plural - e.g. Coins, Stars
conversionPointsCount Commerce (Pro) 100 The points side of the X:Y conversion ratio
conversionCurrencyUnits Commerce (Pro) 1 The currency side - so by default 100 points = 1 unit of store currency
redemptionMinPoints Commerce (Pro) 1 Fewest points a customer can apply in one redemption
redemptionMaxOrderPercent Commerce (Pro) 100 Most of an order's total a customer can pay with points (1-100)
redemptionRefundBehaviour Commerce (Pro) restoreProportional What to do with redeemed points on refund: restoreProportional, restoreFullOnly, or none
birthdayFieldHandle Triggers (empty) Handle of a Date field on the user layout used by the User Birthday trigger

Settings save to the plugin's own DB table - not Project Config. That means admins can rename things on production without the next deploy from staging overwriting their changes. Developers can still pin per-environment values in config/points.php - anything there takes precedence over the DB row:

The store currency itself isn't a setting - it tracks your Craft Commerce primary store automatically. Money helpers (toMoney, spendForUser, the Available Spend / Redeemed columns) only work when Commerce is installed.

Permissions

The plugin ships granular permissions under a Points heading on each user group's permissions page:

A few role recipes:

Frontend endpoints (form, JS, GraphQL) don't use CP permissions. They only check login + the rule is Manual.

GraphQL

Query Args Returns
pointsRules / pointsRule (handle) [PointsRule] / PointsRule
pointsLevels / pointsLevelForUser (userId) [PointsLevel] / PointsLevel
pointsAwards userId, ruleId, limit, offset [PointsAward]
pointsSumForUser / pointsCountForUser userId Int
pointsLeaderboard limit, offset [PointsLeaderboardRow]

Mutation for firing Manual rules from a headless app:

Mutation Args Returns
pointsAddAward ruleHandle: String! PointsAddAwardResult { success, error, points, currency, awardId }

Twig reference

Call Returns
craft.points.sumForUser(id?) int - total points
craft.points.countForUser(id?) int - number of awards
craft.points.awardsByUser(id?) PointAward[]
craft.points.levelForUser(id?) Level or null
craft.points.levelForPoints(n) Level or null
craft.points.leaderboard(limit?, offset?) rows of { user, points, level }
craft.points.toMoney(points?) float - needs Commerce
craft.points.spendForUser(id?) string - their balance as money, e.g. "£2.50" - needs Commerce
craft.points.appliedToOrder(orderId) int - points currently applied to that order
craft.points.script() inline <script> defining window.Points.addAward()
craft.points.pluginName string - configured plugin name (e.g. "VIP Club")
craft.points.currency string - configured reward unit, singular (e.g. "Coin")
craft.points.currencyPlural string - configured reward unit, plural (e.g. "Coins")
craft.points.symbol string - store currency symbol from Commerce (e.g. "£", "$") - empty outside Pro+Commerce
craft.points.currencyCode string or null - 3-letter ISO code from Commerce (e.g. "GBP")
craft.points.rules Rule[] - every rule, in CP-defined order
craft.points.levels Level[] - every level, ordered by threshold
craft.points.awards PointAward[] - every award (use sparingly on large sites)
craft.points.rule(handle) Rule or null - look up a rule by its handle
craft.points.ruleById(id) Rule or null - look up a rule by id
craft.points.awardById(id) PointAward or null - look up a single award
craft.points.levelById(id) Level or null - look up a level by id
craft.points.levelByHandle(handle) Level or null - look up a level by handle
craft.points.user(id) User or null - look up the user behind an award
craft.points.orderRedemption(orderId) OrderRedemption or null - the pending/applied redemption on an order
craft.points.isPro bool - true on Pro

Awards are a first-class element, so you can use element queries too:

Extending the plugin

Custom triggers (and their conditions)

Need points to fire on something Points doesn't ship with - a comment, a forum post, a download, anything? Write one PHP class that wraps the Yii event you care about, return a TriggerContext describing who earned what, and you're in. The trigger then shows up in the rule builder alongside the built-ins.

If your trigger has its own purpose-built conditions (e.g. "only award when the comment is longer than 100 characters"), declare them on the trigger and they're auto-registered. WHEN + IF lives in one file.

Here's a complete example - a "Comment posted" trigger with a "Comment length" condition. Drop it anywhere in your plugin, module, or site code:

Register it in one line from your plugin or module's init():

That's everything. The trigger appears in the rule builder under "Comments", the condition shows when an admin picks it, the Yii listener is attached automatically, and matching events flow through the normal conditions → limits → reward pipeline.

Both classes above are also bundled as a single copy-paste file at examples/CustomTrigger.php - grab it, swap the namespace + Comment element reference, and you're off.

A few details worth knowing:

Award lifecycle events

Need to react to points being awarded, or block one entirely?

Events available:

Event When
Awards::EVENT_BEFORE_ADD_AWARD Before an award is saved (cancellable; can change points)
Awards::EVENT_AFTER_ADD_AWARD After an award is saved
Awards::EVENT_BEFORE_REMOVE_AWARD Before deletion (cancellable)
Awards::EVENT_AFTER_REMOVE_AWARD After deletion
Levels::EVENT_LEVEL_CHANGED When a user crosses a level threshold

Support

If you have any issues (surely not!) then I'll aim to reply to these as soon as possible. If it's a site-breaking-oh-no-what-has-happened moment, then hit me up on the Craft CMS Discord - @bymayo.


All versions of craft-points with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
craftcms/cms Version ^5.6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bymayo/craft-points contains the following files

Loading the files please wait ...