|
| 1 | +import { Callout, Tab, Tabs } from 'nextra-theme-docs'; |
| 2 | + |
| 3 | +# Purchase Webhooks |
| 4 | + |
| 5 | +Purchase webhooks allow you to receive real-time notifications when players purchase any of your cobranded products available on the Lunar Client store. |
| 6 | +These notifications can be used to give the player an extra in-server item, thank them publicly in server chat, or just for your records. |
| 7 | + |
| 8 | +<Callout type="warning" emoji="⚠️"> |
| 9 | + This feature is only available to server partners who sell cobranded packages on [our store](https://store.lunarclient.com/category/servers). |
| 10 | +</Callout> |
| 11 | + |
| 12 | +## Configuring a Webhook |
| 13 | + |
| 14 | +There is currently no automatic process to configure a new webhook endpoint. Please reach out to your contact on the Lunar Client team to configure a webhook. |
| 15 | + |
| 16 | +## Webhook Signatures |
| 17 | + |
| 18 | +It's important to verify the webhooks you're receiving are actually from Lunar Client. All webhooks will be sent with a `X-Signature` header, whose |
| 19 | +value should be checked prior to accepting the webhook. |
| 20 | + |
| 21 | +This value is generated by computing a SHA256 HMAC hash of the body of the webhook. The secret to verify with will be provided to you as part |
| 22 | +of the setup process. |
| 23 | + |
| 24 | +<Tabs items={['Node.js']}> |
| 25 | + <Tab> |
| 26 | + ```javascript |
| 27 | + const signatureSecret = process.env.LUNAR_CLIENT_WEBHOOK_SECRET; |
| 28 | + const body = ...; // This must be the raw body of the webhook. Parsing as JSON and re-serializing can create differences in whitespace. |
| 29 | + |
| 30 | + const expectedSignature = crypto |
| 31 | + .createHmac("sha256", signatureSecret) |
| 32 | + .update(body) |
| 33 | + .digest("hex"); |
| 34 | + ``` |
| 35 | + </Tab> |
| 36 | +</Tabs> |
| 37 | + |
| 38 | +## Webhook Types |
| 39 | + |
| 40 | +`store.purchase.completed` - A purchase has been completed, and a player has received your partnered product. |
| 41 | +`store.purchase.refunded` - A previously-completed purchase has been refunded by Lunar Client, and any partnered products have been removed. |
| 42 | +`store.purchase.disputed` - A previously-completed purchase has been disputed by the purchaser, and any partnered products have been removed. |
| 43 | + |
| 44 | +## Webhook Format |
| 45 | + |
| 46 | +```JSON |
| 47 | +{ |
| 48 | + "id": "0a838fbe-b3be-4ebf-ba0c-1ee55caf5c68", // Unique ID assigned to this webhook invoke |
| 49 | + "date": "2024-07-04T16:54:16.515Z", // Date this webhook was created, in ISO format |
| 50 | + "type": "store.purchase.completed", // Type of this webhook. See Webhook Types section above. |
| 51 | + "subject": { |
| 52 | + "packages": [ |
| 53 | + { |
| 54 | + "id": 5362597, // Internal ID of the package purchased. This should be a stable identifier. |
| 55 | + "name": "Purple Prison (Hearts)", // Name of the package purchased. |
| 56 | + "quantity": 1, // Quantity purchased |
| 57 | + }, |
| 58 | + { |
| 59 | + "id": 5362600, |
| 60 | + "name": "Purple Prison Necklace", |
| 61 | + "quantity": 1, |
| 62 | + } |
| 63 | + ], |
| 64 | + "customer": { |
| 65 | + "username": "macguy", // Minecraft username |
| 66 | + "uuid": "7471b8e8-27c2-4354-a7d2-bd6a82dc00a0", // Minecraft uuid, with dashes |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +Please note that webhooks will only be sent for purchases that are relevant to you. That is, you'll only receive webhooks for purchases |
| 73 | +of your partnered packages, and not other unrelated purchases. |
| 74 | + |
| 75 | +Additionally, webhooks will be filtered to only include relevant packages. If a player makes a single purchase for one partnered package |
| 76 | +and one Lunar Client owned package, the webhook body will only contain details about the partnered package. |
0 commit comments