Integrate invoice-authorized payments
The contract settles cumulative authority; your service owns purchase identity, acceptance, allocation and delivery. Begin with the balance and voucher model. This guide follows source 04a18763, not every historical deployment.
1. Identify the actual payment contract
Read camManifest() and contractAddress("PayToPlay") from the trusted CAM host. Check the selected chain, exact resource bytes and bound payment address. The EIP-712 verifying contract is PayToPlay, not the CAM host.
Compare that address with the signing projection's domain and the transaction-review target. Reload an open viewer after publication/binding changes; a read refresh alone can retain cached resources. The projection rejects a host whose payment binding differs from its immutable backing, but that does not prove every cached viewer address agrees. Adding a projection moves no funds and revokes no voucher.
2. Reserve one durable authorization interval
Serialize reservations per (chain, paymentContract, customer, channelId). Persist the purchase ID and its interval before a retry can create another increase. Use the previous authorized total, not merely the latest on-chain paid total. Two concurrent purchases cannot both reserve the same interval and then count as independent revenue.
Agree on an invoice codec before signing. The supplied invoice/voucher helper reference owns its normalized PayToPlayInvoice/1 encoding, SHA-256 preimage, fixed vector and acceptance API. Its separately documented peer exact-byte vector is a different codec. Do not hash arbitrary pretty-printed JSON or substitute one codec's hash for the other.
Keep immutable invoice/terms documents separate from mutable acceptance, fulfillment, cancellation and refund records. The helper validates structure and caller-supplied context; it does not authenticate an invoice issuer, reserve backing, lock a database row or deliver a service.
3. Sign with the confirmed permanent key
Read the position's confirmed nonzero voucherKey. That key signs; customer remains the balance owner even when the addresses differ.
text
Domain:
name: "PayToPlay"
version: "2"
chainId: the deployment chain
verifyingContract: the bound PayToPlay address
Voucher(address customer,uint256 channelId,
uint256 cumulativeTotal,bytes32 invoiceHash)Use canonical 65-byte r,s,v ECDSA with low s and v equal to 27 or 28. Compare the typed-data digest with voucherDigest(customer, channelId, cumulativeTotal, invoiceHash). Do not personal-message-sign that digest or substitute the owner's current ERC-1271 approval. The signing-details screen supplies comparison data, not a signature or commercial acceptance.
Preserve every disclosed signature as potential exposure, including signatures attached to rejected or expired invoices. Acceptance expiry, cancellation, failed delivery and a commercial refund do not revoke the voucher or rewind its cumulative stream. A refunded open position can later be funded again; its old unpaid authority remains relevant.
4. Decide whether to accept work
Verify the signature and confirmed key, then check current balance, pending ordinary withdrawal, outstanding authorizations/reservations and recovery cutoff. With balance B, request R, paid total P and greatest outstanding signed/reserved total A, one conservative admission policy for new work x is:
max(A - P, 0) + x <= max(B - R, 0)This is service policy, not an on-chain reservation. Collection can consume funds under a withdrawal request and race another collection or withdrawal. Stop new work when settling and allow time for inclusion, confirmations and transfer failure before the cutoff.
The updated source restarts the ordinary wait after a positive credit when a request is pending. That changes readyAt, not admissible backing: if B = R = 100, the right-hand side remains zero even immediately after replenishment. A later invoice or voucher does not restart this clock. Work accepted near readiness can still lose to withdrawal; check the deployed runtime version and enforce confirmation, inclusion and delivery timing separately. Zero-period channels provide no positive exit window.
5. Collect, then allocate the observed payment
collect(customer, channelId, cumulativeTotal,
invoiceHash, maxAmount, signature)Only the configured nonzero collector may submit. The admin can change that address or set zero to pause collection. maxAmount caps this call; it is not signed and does not prevent later partial collection. Payment goes to the channel's current payee, which the admin can change within the contract's rules.
Example: invoice A reserves 0→30 and B reserves 30→70. With nothing paid and balance 50, B's voucher can collect 50 and emit B's hash. Allocating in authorization order pays 30 toward A and 20 toward B—not 50 for B alone. Another 20 of backing permits the remainder. Different hashes at total 70 do not create more than 70 of cumulative authority.
VoucherCollected(customer, channelId, payee, amount, voucherPaid, invoiceHash) records actual settlement, not invoice allocation. Customer, channel and payee are indexed; the hash is not. A valid zero collection emits no collection event, so a successful receipt alone proves no payment. Reconcile transaction/log identity and your reorganization policy, retaining earlier invoices separately.
Use the deployed ABI and authored route
Use the exact ABI and route arguments. Quantities/IDs are uint256, periods uint64 seconds, invoice references bytes32 and signatures bytes. The immutable asset() is the native-asset sentinel 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; it supplies no display symbol or decimals and does not enable ERC-20 deposits.
CAM continuation inputs are not necessarily Solidity arguments: closeChannel carries a customer for the next read; move maps its channel to the source; fund uses the amount as both argument and native value. Recovery events complement payment events, but time-only phase changes emit nothing. Monitor deadlines as well as logs.
Replace deployments explicitly
Changing a manifest does not upgrade an older contract, tuple layout or selector. Use matching v2 resources and update signers, event consumers and refund-worker runtime-code pins together. New addresses have independent balances and permanent keys; old authorizations remain with the original deployment. No automatic voucher, key or balance migration exists.
Exercise the integration with the isolated fixture handoff and app checks. Contract authority: PayToPlay.sol.