Skip to main content

Credits

2 min read

Credits

Shared across every PremiumPress product. 4 classes in inc/Credits.

Account Account.php​

Members-area "Credits" panel (Ppt\Credits). Shows the buyer's current balance, the credit packs they can buy, and a short transaction statement. Wired into inc/Account/views/account.php as a #credits tab, mirroring the auction Bids and stock-photo Downloads tabs. Shared/theme-agnostic — the same panel serves any profile with the credits feature switched on.

API
visible()balance()renderPanel()
inc/Credits/Account.php

Checkout Checkout.php​

Credit-pack checkout (Ppt\Credits). A member buys a pack of credits from their members area; that routes here as /checkout/?buy_credits=``. This class prices the chosen pack, shows an order summary + gateway choice, takes payment through the shared gateway machinery, and on success tops up the buyer's Wallet. A sibling to the other checkout classes (_sp/_at/_ct/_ph) — it reuses the same ppt_gateway_start / ppt_gateway_verify contracts, the shared ppt_orders CPT, the /checkout/ + /callback/ virtual pages and the receipt emails. Order refs are prefixed CREDITS- so Pages::content() routes callbacks here. Shared and theme-agnostic: the Stock Photo Theme uses it now; the Software Download Theme reuses it unchanged.

API
register()buyUrl()callbackUrl()isCreditsRef()coupon()totals()handlePay()markPaid()orderContext()renderCheckout()renderCallback()
inc/Credits/Checkout.php

Config Config.php​

Credits configuration — a thin reader over the admin "Checkout ▸ Credits" panel (stored in the ppt_checkout option, section credits, edited on the Checkout admin screen next to Coupons/Tax/Shipping). Three things the admin controls: an on/off switch, the monetary value of one credit (so an asset's cash price converts to a credit cost), and the purchasable credit packs (a name, how many credits, for how much money).

API
enabled()pageEnabled()creditValue()packs()pack()find()resolve()label()costInCredits()isPurchasable()
inc/Credits/Config.php

Wallet Wallet.php​

Prepaid credit wallet — a per-user balance plus a small transaction ledger. Shared, theme-agnostic (Ppt\Credits): the Stock Photo Theme lets buyers pay for assets with credits, and the Software Download Theme will reuse the same wallet. A generalisation of Ppt_at\BidCredits (idempotent grant/consume on an order ref) with a history trail so the members area can show statements. Balance is a plain integer counter in user meta; every change also appends a ledger entry {t,d,b,r,ref,note}. grant() and spend() are each idempotent per reference (a duplicate gateway callback or a double-submit never double-counts).

API
balance()canAfford()grant()spend()refund()history()
inc/Credits/Wallet.php