DotShare 3.8.1: Charging for X posts like a card payment
DotShare 3.8.1 and dotshare-cli 3.2.1 were released to address overcharging for X posts and a critical database bug that prevented publishing. The previous DotShare 3.8 version's billing rule, designed to prevent DotSuite from under-charging, resulted in users paying up to five times the actual cost X billed, prompting a new payment-like 'Hold, Pending, Settle' system.
DotSuite's DotShare 3.8 initially introduced charges for posts made to X, with each user plan allocated a monthly X budget. The billing logic aimed to prevent DotSuite from losing money, charging the greater of X's list price or the actual credit balance drop. However, this approach led to users being overcharged; for instance, a developer discovered a four-part thread was billed five times its actual cost, as X often charged significantly less for replies within a thread than its list price for a link post.
This issue prompted an overhaul of the billing mechanism in DotShare 3.8.1, adopting a three-step 'Hold, Pending, Settle' process inspired by how card payments manage variable costs. When a user initiates an X post, DotSuite first places a 'Hold' on the estimated maximum cost against the user's monthly budget, daily post limit, and an app-wide daily spend cap. This step ensures that requests exceeding the available budget are refused before reaching X.
Next, each part of the post enters a 'Pending' state as it is published under a global lock. DotSuite then monitors its X credit balance before and after each post. If the deduction from X's balance is not immediately visible, the part remains pending, with the balance checked up to three more times, two seconds apart. Once the exact deduction appears, the transaction moves to 'Settle,' charging the user precisely what X took and releasing any excess from the initial hold back to the budget. This system ensures users are charged only the actual amount X bills, even if X charges more than the initial hold.
Concurrently, DotSuite addressed a critical database bug that initially prevented X publishing from being activated. The issue stemmed from three database migrations, including those for X billing tables, failing with 'permission denied for schema public' errors during DotSuite Core's startup. Core and the web app were designed to share one PostgreSQL database under separate roles, and neither role owned the schema, which prevented table creation during migrations.
The fix involved ensuring migrations are applied as the database owner, and updating the role script to match production. Additionally, a bug where a failed migration left its connection in an aborted transaction state within the connection pool was resolved. Now, failed migrations run on their own dedicated connection, which is subsequently closed instead of being returned to the pool, preventing subsequent queries from failing due to an aborted transaction. An interesting edge case remains: what happens if X's deduction never shows up, leaving a transaction permanently pending?
Share this article
Related reading
6 stories
Ant International and BNY Eye Real-Time Treasury, Global Payments
Ant International and BNY are also exploring real-time global payments, a similar innovation to DotShare's card-like X post charges.

Digital Wallets Could Double as Bank Accounts, Says MAS Tokenisation Guide
MAS's tokenisation guide suggests digital wallets could function as bank accounts, echoing the article's theme of new payment methods.

Builder.ai Raised $450M to Build Apps With AI. Then It Collapsed — A Developer's Post-Mortem

Leapmotor DX filed in China – five-seat SUV on D19 wheelbase, EREV or EV, up to 734 PS

Zeekr 8X EV filed in China – pure electric version of PHEV SUV gets 925 PS, 260 km/h top speed

