You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 💸 TL;DR
<!-- What's the three sentence summary of purpose of the PR -->
This updates payments docs referencing Devvit Singleton
<!-- Add additional details required for the PR: breaking changes,
screenshots, external dependency changes -->
This PR used cursor pretty heavily I read through the changes but
@RarerAirError just a heads up.
## 🧪 Testing Steps / Validation
<!-- add details on how this PR has been tested, include reproductions
and screenshots where applicable -->
## ✅ Checks
<!-- Make sure your pr passes the CI checks and do check the following
fields as needed - -->
- [ ] CI tests (if present) are passing
- [ ] Adheres to code style for repo
- [ ] Contributor License Agreement (CLA) completed if not a Reddit
employee
Copy file name to clipboardExpand all lines: docs/earn-money/payments/payments_add.mdx
+49-90Lines changed: 49 additions & 90 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -255,31 +255,13 @@ If you don’t provide an image, the default Reddit product image is used.
255
255
256
256
### Purchase buttons (required)
257
257
258
-
#### Blocks
258
+
#### Devvit Web
259
259
260
-
The `ProductButton` is a Devvit blocks component designed to render a product with a purchase button. It can be customized to match your app's look and feel.
260
+
In Devvit Web, use your own UI (e.g. a button or product card) and call `purchase(sku)` from `@devvit/web/client` when the user chooses a product. Follow the [design guidelines](#design-guidelines) (e.g. gold icon, clear labeling).
If your app still uses Devvit Blocks, you can use the `ProductButton` component and [migrate to Devvit Web](./payments_migrate.mdx) when ready. The `ProductButton` renders a product with a purchase button; use `payments.purchase(p.sku)` in the `onPress` callback (from `@devvit/payments`).
283
265
284
266
#### Webviews
285
267
@@ -297,36 +279,30 @@ Use a consistent and clear product component to display paid goods or services t
297
279
298
280
## Complete the payment flow
299
281
300
-
Use `addPaymentHandler` to specify the function that is called during the order flow. This customizes how your app fulfills product orders and provides the ability for you to reject an order.
282
+
Your **fulfill** endpoint (configured in `devvit.json` and implemented in the server) is called during the order flow. It customizes how your app fulfills product orders and lets you reject an order.
301
283
302
-
Errors thrown within the payment handler automatically reject the order. To provide a custom error message to the frontend of your application, you can return `{success: false, reason: <string>}`with a reason for the order rejection.
284
+
Return `{ success: true }` to accept the order, or `{ success: false, reason: "<string>" }`to reject it and send a message to the client. Throwing an error in the handler also rejects the order.
303
285
304
-
This example shows how to issue an "extra life" to a user when they purchase the "extra_life" product.
286
+
This example shows how to grant an "extra life" in your fulfill endpoint when the user purchases the "god_mode" product (using Redis from `@devvit/web/server`):
To launch the payment flow, create a hook with `usePayments()`followed by `hook.purchase()` to initiate the purchase from the frontend.
315
+
To launch the payment flow, call `purchase(sku)`from `@devvit/web/client`. That triggers the native payment flow on all platforms (web, iOS, Android); Reddit then calls your server's **fulfill** endpoint. Your app can acknowledge or reject the order (for example, reject once a limited product is sold out).
340
316
341
-
This triggers a native payment flow on all platforms (web, iOS, Android) that works with the Reddit backend to process the order. The `fulfillOrder()` hook calls your app during this process.
317
+
### Get your product details
342
318
343
-
Your app can acknowledge or reject the order. For example, for goods with limited quantities, your app may reject an order once the product is sold out.
319
+
**Server:** Use `payments.getProducts()` in your server (see [Server: Fetch products](#server-fetch-products)) and expose products via your own `/api/products` (or similar) endpoint if the client needs them.
344
320
345
-
### Get your product details
321
+
**Client:** Fetch product metadata from your API and use it to display products and call `purchase(sku)`:
346
322
347
-
Use the `useProducts` hook or `getProducts` function to fetch details about products.
You can also fetch all products using custom-defined metadata or by an array of skus. Only one is required; if you provide both then they will be AND’d.
Copy file name to clipboardExpand all lines: docs/earn-money/payments/payments_manage.md
+28-37Lines changed: 28 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,30 +4,23 @@ Once your app and products have been approved, you’re ready to use Reddit’s
4
4
5
5
## Check orders
6
6
7
-
Reddit keeps track of historical purchases and lets you query user purchases.
7
+
Reddit keeps track of historical purchases and lets you query orders.
8
8
9
-
Orders are returned in reverse chronological order and can be filtered based on user, product, success state, or other attributes.
9
+
In Devvit Web, use **server-side**`payments.getOrders()` from `@devvit/web/server`. Orders are returned in reverse chronological order and can be filtered by user, product, success state, or other attributes. Expose the data to your client via your own API (e.g. `/api/orders`) if the client needs it.
10
10
11
-
**Example**
11
+
**Example (server):** expose orders for the current user so the client can show "Purchased!" or a purchase button.
**Client:** call your `/api/orders` endpoint; if the user has already bought the product, show "Purchased!"; otherwise show a button that calls `purchase("cosmic_sword")` from `@devvit/web/client`.
23
+
31
24
## Update products
32
25
33
26
Once your app is in production, existing installations will need to be manually updated via the admin tool if you release a new version. Contact the Developer Platform team if you need to update your app installation versions.
@@ -38,25 +31,23 @@ Automatic updates will be supported in a future release.
38
31
39
32
Reddit may reverse transactions under certain circumstances, such as card disputes, policy violations, or technical issues. If there’s a problem with a digital good, a user can submit a request for a refund via [Reddit Help](https://support.reddithelp.com/hc/en-us/requests/new?ticket_form_id=29770197409428).
40
33
41
-
When a transaction is reversed for any reason, you may optionally revoke product functionality from the user by adding a `refundOrder` handler.
if (order.products.some(({ sku }) =>sku===GOD_MODE_SKU)) {
53
-
// redis key for storing number of lives user has left
54
-
const livesKey =`${ctx.userId}:lives`;
55
-
56
-
// if so, decrement the number of lives
57
-
awaitctx.redis.incrBy(livesKey, -1);
58
-
}
59
-
},
34
+
When a transaction is reversed for any reason, you may optionally revoke product functionality from the user by implementing the **refund** endpoint (configured in `devvit.json` under `payments.endpoints.refundOrder`).
35
+
36
+
**Example (Devvit Web):** in your server’s refund endpoint, revoke the entitlement (e.g. decrement lives in Redis).
37
+
38
+
```tsx title="server/index.ts"
39
+
importtype { PaymentHandlerResponse, Order } from"@devvit/web/server";
The [payment handler](./payments_add.mdx#complete-the-payment-flow) is where you award the promised incentive to your supporters. For example, this is how you can award custom user flair:
22
+
In Devvit Web, the [payment handler](./payments_add.mdx#complete-the-payment-flow) is your server’s **fulfill** endpoint. That’s where you award the promised incentive (e.g. custom user flair). Implement it in your server and reference it in `devvit.json` under `payments.endpoints.fulfillOrder`.
Next you need to provide a way for users to support your app:
53
+
Provide a way for users to support your app from your client:
48
54
49
-
-If you use Devvit blocks, you can use the ProductButton helper to render a purchase button.
50
-
-If you use webviews, make sure that your design follows the [design guidelines](./payments_add.mdx#design-guidelines)to [initiate purchases](./payments_add.mdx#initiate-orders).
55
+
-**Devvit Web:** Add a button or link that calls `purchase("support-app")` from `@devvit/web/client`. Handle the result (e.g. show a toast on success). Optionally fetch product info from your `/api/products` endpoint to display the support option.
56
+
-Follow the [design guidelines](./payments_add.mdx#design-guidelines)when [initiating purchases](./payments_add.mdx#initiate-orders).
0 commit comments