# Purchase Flow

URL: https://zerodev.ca/docs/store/purchase-flow

> What happens from a click to a delivered reward, the commands and troubleshooting.



## Posting a Panel

Run `/store panel` and pick:

| Option    | What to enter                   |
| --------- | ------------------------------- |
| `panel`   | The panel ID. It autocompletes. |
| `channel` | Where to post it.               |

Panels keep working after restarts. If you change a panel's products, post it again.

## What the Buyer Sees

1. **They pick a product.** If they already have its role reward, or have bought it `max_purchases` times, they are told they already own it.
2. **They pick how to pay.** Only when the product has more than one provider.
3. **They get a checkout link.** A private message with a button to the provider's checkout page.
4. **They pay.** On Stripe, PayPal, Razorpay, Polar or NOWPayments. After paying they are sent back to your server's invite link.
5. **The message changes to Paid.** As soon as the provider's webhook arrives.
6. **They get their rewards and a receipt by DM.**

| Provider | Checkout              |
| -------- | --------------------- |
| Stripe   | Stripe Checkout page  |
| PayPal   | PayPal approval page  |
| Razorpay | Razorpay payment link |
| Polar    | Polar checkout page   |
| Crypto   | NOWPayments invoice   |

## When a Payment Completes

When the provider's webhook arrives, Store:

1. Finds the product from the details saved with the checkout.
2. Runs each reward.
3. Saves the purchase.
4. Updates the buyer's checkout message to **Paid**.
5. DMs the buyer a receipt.
6. Posts a log in `store-logs`.

If a reward fails, such as a role that no longer exists, the purchase is still saved as **completed with errors** and the log shows what went wrong. The provider still gets a success reply, so it does not keep retrying. Fix the problem and give the reward by hand.

## Looking Up Purchases

`/store lookup` searches saved purchases. Use any of these together:

| Option          | Filters by                     |
| --------------- | ------------------------------ |
| `user`          | The buyer.                     |
| `transactionid` | The provider's transaction ID. |
| `email`         | The email the buyer paid with. |
| `date`          | A day, as `YYYY-MM-DD`.        |

## Commands

| Command         | What it does      |
| --------------- | ----------------- |
| `/store panel`  | Post a panel.     |
| `/store lookup` | Search purchases. |

Both need the `store_command` permission level.

## Troubleshooting

| Problem                              | Fix                                                                                                                                                                |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| The checkout link never appears      | Check the console. The provider's keys are probably wrong or missing.                                                                                              |
| "Payment provider is not configured" | The product uses a provider that is not in `providers`.                                                                                                            |
| Paid but nothing happened            | The webhook did not reach AthenaBot. Check the provider's webhook log for errors, that the URL uses your domain, and that the reverse proxy points at port `3111`. |
| Webhook returns 400 or 403           | The webhook secret does not match. Copy it again from the provider.                                                                                                |
| Webhook returns 500                  | That provider's keys or webhook secret are missing from `store.json5`.                                                                                             |
| Role not given                       | AthenaBot's role must be above the reward role. The error is in `store-logs`.                                                                                      |
| No receipt DM                        | The buyer has DMs from server members turned off.                                                                                                                  |
