Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/setup-page-paystack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@dashcommerce/registry-setup": patch
---

The DashCommerce Setup page now covers Paystack: card and M-Pesa payments with `@dashcommerce/paystack`, and its install steps. Step 6 asks for the chosen provider's keys instead of Stripe's.
58 changes: 55 additions & 3 deletions packages/registry-setup/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const LINKS = {
patches:
"https://github.com/emdashCommerce/dashcommerce/blob/main/packages/core/patches/README.md",
npm: "https://www.npmjs.com/package/@dashcommerce/core",
paystack: "https://github.com/emdashCommerce/dashcommerce/blob/main/packages/paystack/README.md",
} as const;

const ASTRO_CONFIG = `// astro.config.mjs
Expand All @@ -30,6 +31,19 @@ export default defineConfig({
],
});`;

const PAYSTACK_INSTALL = "npm install @dashcommerce/paystack";

const PAYSTACK_MIDDLEWARE = `// src/middleware.ts
import "@dashcommerce/paystack"; // registers the "paystack" provider
import { defineMiddleware } from "astro:middleware";

export const onRequest = defineMiddleware((_context, next) => next());`;

const PAYSTACK_CONFIG = `plugins: [dashcommerce({ allowedHosts: ["api.paystack.co"] })],`;

const PAYSTACK_WEBHOOK =
"https://<your-site>/_emdash/api/plugins/dashcommerce/checkout/webhook?provider=paystack";

const BUN_PATCH = `// package.json (Bun). Keep only the line for your installed EmDash version.
{
"patchedDependencies": {
Expand Down Expand Up @@ -78,15 +92,18 @@ export function renderSetupPage(): BlockResponse {
},
{
type: "section",
text: "DashCommerce is an MIT licensed commerce plugin for EmDash. It adds products (simple, variable, subscription and digital), a cart, Stripe checkout, orders with refunds, coupons, shipping zones, tax, inventory, reviews, subscriptions, and multi-vendor payouts through Stripe Connect. It runs on Cloudflare Workers or Node.js and adds its own pages to the EmDash admin.",
text: "DashCommerce is an MIT licensed commerce plugin for EmDash. It adds products (simple, variable, subscription and digital), a cart, checkout through Stripe or Paystack, orders with refunds, coupons, shipping zones, tax, inventory, reviews, subscriptions, and multi-vendor payouts through Stripe Connect. It runs on Cloudflare Workers or Node.js and adds its own pages to the EmDash admin.",
},
{
type: "fields",
fields: [
{ label: "npm package", value: "@dashcommerce/core" },
{ label: "EmDash versions DashCommerce supports", value: "0.37.x, or 1.1.0 to 1.6.x" },
{ label: "Hosting", value: "Cloudflare Workers or Node.js" },
{ label: "Payments", value: "Stripe (test mode works out of the box)" },
{
label: "Payments",
value: "Stripe (test mode works out of the box), or Paystack for card and M-Pesa",
},
],
},
{
Expand Down Expand Up @@ -165,7 +182,7 @@ export function renderSetupPage(): BlockResponse {
{ type: "code", language: "bash", code: SEED },
{
type: "section",
text: "6. Restart or redeploy the site. Open the DashCommerce settings page in the admin and paste your Stripe test keys.",
text: "6. Restart or redeploy the site. Open the DashCommerce settings page in the admin, choose your payment provider and paste its test keys.",
},
{
type: "actions",
Expand All @@ -185,6 +202,41 @@ export function renderSetupPage(): BlockResponse {
],
},
{ type: "divider" },
{ type: "header", text: "Taking payments with Paystack" },
{
type: "section",
text: "Paystack takes card and M-Pesa payments in KES, NGN, GHS, ZAR and USD. It needs @dashcommerce/core 0.4.0 or later.",
},
{ type: "section", text: "1. Install the Paystack package." },
{ type: "code", language: "bash", code: PAYSTACK_INSTALL },
{
type: "section",
text: "2. Import it in a module the server loads before any request, such as src/middleware.ts. Importing it in astro.config.mjs is not enough, because that file only runs at build time.",
},
{ type: "code", language: "ts", code: PAYSTACK_MIDDLEWARE },
{ type: "section", text: "3. Let DashCommerce call Paystack's API." },
{ type: "code", language: "ts", code: PAYSTACK_CONFIG },
{
type: "section",
text: "4. In the DashCommerce settings, choose Paystack, paste your secret key and webhook signing secret, and press Test Paystack connection.",
},
{
type: "section",
text: "5. In the Paystack dashboard, set the webhook URL. Keep ?provider=paystack on the end.",
},
{ type: "code", language: "bash", code: PAYSTACK_WEBHOOK },
{
type: "actions",
elements: [
{
type: "link",
label: "Paystack setup",
target: { kind: "external", url: LINKS.paystack },
appearance: "secondary",
},
],
},
{ type: "divider" },
{
type: "section",
text: "A sandboxed option with no npm step, DashCommerce Lite, is available in the EmDash plugin registry (slug dashcommerce-lite). Full DashCommerce stays on npm as @dashcommerce/core. Don't install Lite alongside core.",
Expand Down
4 changes: 4 additions & 0 deletions packages/registry-setup/tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ describe("setup page", () => {
expect(text).toContain("DashCommerce Lite");
expect(text).toContain("dashcommerce-lite");
expect(text).toContain("Don't install Lite alongside core.");
expect(text).toContain("npm install @dashcommerce/paystack");
expect(text).toContain('import "@dashcommerce/paystack"');
expect(text).toContain('allowedHosts: ["api.paystack.co"]');
expect(text).toContain("checkout/webhook?provider=paystack");
expect(text).not.toMatch(/in progress/i);
});

Expand Down
Loading