Repository navigation
Take payments through Rotur payment requests - #31
Merged
Merged
Conversation
Buying a project or game product, donating with a comment and refunding a game product now ask Rotur for a payment request with the app's credentials. The person approves it on rotur.dev, Rotur shares the credits between everyone the sale pays, and payment.completed (or the editor's confirm, whichever comes first) delivers the purchase. This replaces checking transfers people made with MistWarp's credits:transfer token, and paying sellers out of MistWarp's own account, so the pending payouts queue and its admin routes go.
…accepts - Starting the same purchase again while its Rotur request is still open hands back that request, so paying twice can't happen. - A refund pays back what the buyer paid, from their purchase record, and a failed revoke keeps the refund key so it can be tried again. - The splits are saved with the purchase and used when it's delivered. - Without the fee account a sale doesn't start, instead of the creator getting MistWarp's share. - The payer is dropped from the splits, with their share going to the next person, since Rotur refuses splits that pay the payer.
Mistium
force-pushed
the
rotur-app-payments-v2
branch
from
October 2, 2026 17:33
8a453a9 to
33d8339
Compare
…e at a time - An open request is reused only while Rotur still has it pending, so a declined one doesn't stop the person trying again until it expires. - Purchase, game product and donation intents answer 409 "MistWarp was updated, reload this page" when the body has no returnUrl, as from an editor tab or packaged game made before payment requests. Those would pay the old way, which nothing delivers any more. - Looking for an open request and making a new one happen under a lock for that purchase, so two clicks can't make two requests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purchases, donations and refunds move to Rotur payment requests (https://docs.rotur.dev/build-an-app/payments). MistWarp no longer needs anyone's
credits:transfer, and no longer pays sellers out of its own account.Before
credits:transfer), then mistwarp-api searched the transfer history for it.MISTWARP_ROTUR_TOKEN. Payouts that failed were queued indata/pending-payouts.json, with admin routes to retry them.Now
referenceis the purchase key (mwbuy_,mwgame_,mwdonate_ormwrefund_). The answer includes Rotur'sapproveUrl.splits, so Rotur pays the creator, collaborators, the remixed project's creator and MistWarp's fee in one go (rotur/api#83). MistWarp's share goes toMISTWARP_ROTUR_USER, or else the app's owner.payment.completedmarks the key paid and delivers projects and game products. The editor's confirm call can do the same before the webhook arrives, by asking Rotur whether the request was paid. Whichever comes second finds the purchase already delivered and answers yes.donation: {key}. A refund has its own intent (POST /projects/:id/products/:product/refund/intent): the creator pays the buyer back, then revokes withrefundKey.Changes to the API
{key, requestId, approveUrl, amount, splits}.{key}./payoutsand the pending-payout admin stats are gone.Depends on
{key}. Merge and deploy the two together. The old editor's transfer-then-confirm flow won't work against this.Rebased on
main, now that #25 is merged.Still on the old keys
COMMERCE_SERVICE_KEY: still needed for bounty awards and the groups integration.MISTWARP_ROTUR_TOKEN: still needed for notifications and/profilelookups.Bounties need a Rotur change before they can move (escrow, or holding a payment request until a winner is picked).
Review fixes
approveUrl, instead of making a second one that could also be paid. It's only reused while Rotur still sayspending, so after declining, the person can try again straight away. The check and the new request happen under a lock for that purchase.client_outdated, "MistWarp was updated, reload this page", when the body has noreturnUrlkey. Editor tabs opened before the deploy, and packaged games exported before scratch-gui#108, would otherwise pay the old way with nothing delivered. The editor and current packaged games always sendreturnUrl, even when it's empty.removeGameProductEntitlementsucceeds, so the revoke can be retried.mistwarpFeeAccount()can't be found (Rotur unreachable andMISTWARP_ROTUR_USERunset), the intent answers 503 "MistWarp can't take payments right now" instead of the creator getting MistWarp's share.Before deploying
data/pending-payouts.jsonis empty, or has nothing still owed. This PR removes the payouts queue and its retry, so anything left in it would never be paid.Testing
Unit tests:
rotur-payments.test.oslis new and covers:invalid_return_urlretry;rotur-webhooks.test.oslcoverspayment.completed. All 29 OSL test files pass, including new cases for reusing an open request, a request about to expire, and payers in the splits.End to end: run against real Rotur (
clawbuilt from rotur/api#83) and this build, in a private network namespace, twice in a row. 29 of 29 checks pass:payment.completedwith no confirm. A forged signature is refused, and confirming afterwards answers yes.Claw only delivers webhooks to public https addresses, so the e2e signs
payment.completeditself, in claw's exact format and with a real request ID. Rotur's own delivery to api.mistwarp.org wasn't tested.No visible surface in this repo; the editor's payments PR carries the screenshots.