diff --git a/CONTIBUTING.md b/CONTIBUTING.md index b66edce..c856904 100644 --- a/CONTIBUTING.md +++ b/CONTIBUTING.md @@ -1,3 +1,7 @@ # Contributing to Daraja Kit Welcome to Daraja Kit! We're excited that you're interested in contributing. Before you start, please follow the guidelines below. + +## Directory structure + +The code for the library itself is under packages/main-lib. If that is the part you are interested in thats where you should make your changes. For the docs the code lives inside packages/docs. The docs are in mdx so if you know markdown you are good to go. diff --git a/README.md b/README.md index 450a857..9d0e144 100644 --- a/README.md +++ b/README.md @@ -2,60 +2,45 @@ Improving the Developer Experience of using the Safaricom daraja API. -![image info](./public/full-logo.png) +Read the docs at https://daraja-kit.amosmachora.com/ # About Daraja Kit is a typesafe Javascript library designed to simplify interactions with the Safaricom Daraja API. This library is suitable for both Node.js and React environments, allowing developers to seamlessly integrate M-Pesa payments into their applications. -## Installation +# Benefits -To install Daraja Kit, run the following command in your project's terminal: - -```bash - npm install daraja-kit -``` - -## Getting Started - -Copy over the `.env.local` file into a `.env` file using the following command. - -``` -cp .env.local .env -``` - -Before using the library, make sure to set up the required environment variables in the .env file. These variables include: - -- **ENVIRONMENT**: Set the environment to either "production" or "development." +- Cached access tokens to minimize network requests and improve performance. +- Way simpler API over using daraja on your own. +- Open source! +- Slow integration. You don`t have to hot swap this library. You can easily integrate it to your app. +- More Util Functions. If you need to generate passwords if you have decided to slowly integrate the app offers helper functions to help you move along nicely. e.g generateTimestamp and generatePassword. -- **MPESA_CONSUMER_KEY**: Consumer Key obtained from Safaricom Daraja. +# Compatibility -- **MPESA_CONSUMER_SECRET**: Consumer Secret obtained from Safaricom Daraja. +Daraja Kit is compatible with Node.js and React environments. It provides a simple interface for initiating M-Pesa transactions using the Safaricom Daraja API. -- **MPESA_BUSINESS_SHORT_CODE**: Your M-Pesa business short code. For Sandbox use the code **174379** +Some APIs are exclusively for Node Environments and some are just React Components so are only used in react. -- **MPESA_TILL_OR_PAYBILL_NO**: Your M-Pesa till or paybill number. For Sandbox use 174379. Sometimes you can use your shortcode in prod but if you run into errors find the correct one in your portal. +# Stack -- **MPESA_TRANSACTION_TYPE**: Set the transaction type, either "CustomerPayBillOnline" or "CustomerBuyGoodsOnline." +## docs -- **MPESA_API_PASS_KEY**: Your M-Pesa API pass key. For sandbox use **bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919** +[Nextra](https://github.com/shuding/nextra) -The library throws errors if any of this values are missing from your .env file. +## Main library -## Benefits +[typescript](https://www.typescriptlang.org/) +[react](https://react.dev/) -- Cached access tokens to minimize network requests and improve performance. -- Way simpler API over using daraja on your own. -- Open source! -- Slow integration. You don`t have to hot swap this library. You can easily integrate it to your app. -- More Util Functions. If you need to generate passwords if you have decided to slowly integrate the app offers helper functions to help you move along nicely. e.g generateTimestamp and generatePassword. +## Package manager -## Compatibility +[pnpm](https://pnpm.io/) -Daraja Kit is compatible with Node.js and React environments. It provides a simple interface for initiating M-Pesa transactions using the Safaricom Daraja API. +## Versioning -Some APIs are exclusively for Node Environments and some are just React Components so are only used in react. +[Changesets](https://github.com/changesets/changesets) -## License +# License This library is licensed under the MIT License. Feel free to contribute or open issues on the GitHub repository. More APIs and components coming. Watch this repo for alerts. diff --git a/packages/docs/.eslintrc.json b/packages/docs/.eslintrc.json deleted file mode 100644 index bffb357..0000000 --- a/packages/docs/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "next/core-web-vitals" -} diff --git a/packages/docs/.github/screenshot.png b/packages/docs/.github/screenshot.png new file mode 100644 index 0000000..1e4a0f3 Binary files /dev/null and b/packages/docs/.github/screenshot.png differ diff --git a/packages/docs/.gitignore b/packages/docs/.gitignore index b9f8d23..f74c781 100644 --- a/packages/docs/.gitignore +++ b/packages/docs/.gitignore @@ -1,38 +1,2 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dependencies -/node_modules -/.pnp -.pnp.js -.yarn/install-state.gz - -# testing -/coverage - -# next.js -/.next/ -/out/ - -# production -/build - -# misc -.DS_Store -*.pem - -# debug -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# local env files -.env*.local - -# vercel -.vercel - -# typescript -*.tsbuildinfo -next-env.d.ts - -.env \ No newline at end of file +.next +node_modules diff --git a/packages/docs/LICENSE b/packages/docs/LICENSE new file mode 100644 index 0000000..490da1f --- /dev/null +++ b/packages/docs/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Shu Ding + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/docs/README.md b/packages/docs/README.md index 02a8d96..7b33473 100644 --- a/packages/docs/README.md +++ b/packages/docs/README.md @@ -1,13 +1,23 @@ -# Daraja Kit Docs +# Nextra Docs Template -The official documentation website of the [Daraja Kit library](https://github.com/amosmachora/daraja-kit). +This is a template for creating documentation with [Nextra](https://nextra.site). -![image info](./public/full-logo.png) +[**Live Demo →**](https://nextra-docs-template.vercel.app) -# About +[![](.github/screenshot.png)](https://nextra-docs-template.vercel.app) -Daraja Kit is a typesafe Javascript library designed to simplify interactions with the Safaricom Daraja API. This library is suitable for both Node.js and React environments, allowing developers to seamlessly integrate M-Pesa payments into their applications. +## Quick Start -This repo is a NextJS project that defines the usage , guides amd overall API of the Daraja Kit repo. +Click the button to clone this repository and deploy it on Vercel: -To contribute just fork your copy of this repo and submit a PR. +[![](https://vercel.com/button)](https://vercel.com/new/clone?s=https%3A%2F%2Fgithub.com%2Fshuding%2Fnextra-docs-template&showOptionalTeamCreation=false) + +## Local Development + +First, run `pnpm i` to install the dependencies. + +Then, run `pnpm dev` to start the development server and visit localhost:3000. + +## License + +This project is licensed under the MIT License. diff --git a/packages/docs/app/api/page.tsx b/packages/docs/app/api/page.tsx deleted file mode 100644 index b919784..0000000 --- a/packages/docs/app/api/page.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import { AccountBalance } from "@/components/AccountBalance"; -import { B2CPaymentRequest } from "@/components/B2CPaymentRequest"; -import { B2BPaymentRequest } from "@/components/B2BPaymentRequest"; -import { B2BExpressCheckout } from "@/components/B2BExpressCheckout"; -import { NextPage } from "@/components/NextPage"; -import { PageNavSmall } from "@/components/PageNavSmall"; -import { QrCode } from "@/components/QrCode"; -import { RegisterC2BUrl } from "@/components/RegisterC2BUrl"; -import { ReverseC2BTransaction } from "@/components/ReverseC2BTransaction"; -import { STKPush } from "@/components/STKPush"; -import { StateOfALNMOnlinePayment } from "@/components/StateOfALNMOnlinePayment"; -import { TaxRemittance } from "@/components/TaxRemittance"; -import { TransactionStatus } from "@/components/TransactionStatus"; -import React from "react"; -import SmoothScroll from "@/components/SmoothScroll"; -import { ScrollArea } from "@/components/ui/scroll-area"; -import { Metadata } from "next"; - -export const metadata: Metadata = { - title: "Api", -}; - -const links = [ - "STKPush", - "QRCode", - "StateOfALipaNaMpesaOnlinePayment", - "RegisterURLS", - "B2CPaymentRequest", - "TransactionStatus", - "Accountbalance", - "ReverseC2BTransaction", - "TaxRemittance", - "B2BPaymentRequest", - "B2BExpressCheckout", -]; - -const Page = () => { - return ( - <> - - -

API

-

The documentation of all available functions and types.

- - - - - - - - - - - - -
- - - - ); -}; - -export default Page; diff --git a/packages/docs/app/favicon.ico b/packages/docs/app/favicon.ico deleted file mode 100644 index 43806bb..0000000 Binary files a/packages/docs/app/favicon.ico and /dev/null differ diff --git a/packages/docs/app/globals.css b/packages/docs/app/globals.css deleted file mode 100644 index 6843197..0000000 --- a/packages/docs/app/globals.css +++ /dev/null @@ -1,104 +0,0 @@ -@tailwind base; -@tailwind components; -@tailwind utilities; - -@layer base { - :root { - --background: 0 0% 100%; - --foreground: 222.2 84% 4.9%; - - --card: 0 0% 100%; - --card-foreground: 222.2 84% 4.9%; - - --popover: 0 0% 100%; - --popover-foreground: 222.2 84% 4.9%; - - --primary: 222.2 47.4% 11.2%; - --primary-foreground: 210 40% 98%; - - --secondary: 210 40% 96.1%; - --secondary-foreground: 222.2 47.4% 11.2%; - - --muted: 210 40% 96.1%; - --muted-foreground: 215.4 16.3% 46.9%; - - --accent: 210 40% 96.1%; - --accent-foreground: 222.2 47.4% 11.2%; - - --destructive: 0 84.2% 60.2%; - --destructive-foreground: 210 40% 98%; - - --border: 214.3 31.8% 91.4%; - --input: 214.3 31.8% 91.4%; - --ring: 222.2 84% 4.9%; - - --radius: 0.5rem; - } - - .dark { - --background: 222.2 84% 4.9%; - --foreground: 210 40% 98%; - - --card: 222.2 84% 4.9%; - --card-foreground: 210 40% 98%; - - --popover: 222.2 84% 4.9%; - --popover-foreground: 210 40% 98%; - - --primary: 210 40% 98%; - --primary-foreground: 222.2 47.4% 11.2%; - - --secondary: 217.2 32.6% 17.5%; - --secondary-foreground: 210 40% 98%; - - --muted: 217.2 32.6% 17.5%; - --muted-foreground: 215 20.2% 65.1%; - - --accent: 217.2 32.6% 17.5%; - --accent-foreground: 210 40% 98%; - - --destructive: 0 62.8% 30.6%; - --destructive-foreground: 210 40% 98%; - - --border: 217.2 32.6% 17.5%; - --input: 217.2 32.6% 17.5%; - --ring: 212.7 26.8% 83.9%; - } -} - -@layer base { - * { - @apply border-border; - } - body { - @apply bg-background text-foreground; - } -} - -.show { - @apply outline outline-1 outline-red-500; -} - -h1 { - @apply font-semibold text-4xl mt-2; -} - -h2 { - @apply font-semibold text-3xl mt-2; -} - -h3 { - @apply font-semibold text-2xl mt-2; -} - -h4 { - @apply font-semibold text-xl mt-8; -} - -section { - @apply mt-10; -} - -.center-absolutely { - @apply absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2; -} diff --git a/packages/docs/app/installation/page.tsx b/packages/docs/app/installation/page.tsx deleted file mode 100644 index 3d734c8..0000000 --- a/packages/docs/app/installation/page.tsx +++ /dev/null @@ -1,110 +0,0 @@ -import { CopyPastableSpan } from "@/components/CopyPastableSpan"; -import { InstallCommands } from "@/components/InstallCommands"; -import { NextPage } from "@/components/NextPage"; -import { PageNavSmall } from "@/components/PageNavSmall"; -import { ScrollArea } from "@/components/ui/scroll-area"; -import { faCircleInfo } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { Metadata } from "next"; -import React from "react"; - -export const metadata: Metadata = { - title: "Installation", -}; - -const links = ["installation", "basic-usage"]; - -const Page = () => { - return ( - <> - - -

Installation

-

- In the directory containing package.json, run your package manager`s - install command: -

- -

- Before using the library, make sure to set up the required environment - variables in the .env file. These variables include: -

-
-

- : Set the environment to - either or - -

-

- : Consumer Key - obtained from Safaricom Daraja. -

-

- : Consumer Secret - obtained from Safaricom Daraja. -

-

- : Your M-Pesa - business short code. For Sandbox use the code{" "} - -

-

- : Your M-Pesa - business short code. For Sandbox use the code{" "} - . Sometimes in prod it can be your - business short code. Just be sure to check your mpesa portal in prod -

-

- : Set the - transaction type, either{" "} - or - -

-

- : Your M-Pesa API pass - key. For sandbox use - -

-
-

- The library throws errors if any of this values are missing from your - .env file. -

-
-
-
-
- -

INFO

-
- Daraja Kit has a peer dependency on React 18. If you use the node - apis you don`t need to have react installed. -
-
-

- Basic usage -

-

- The library consists of a collection of typescript functions, types - and some react components. To use them just import the function you - want from the library and use it in your app. -

- - - - - ); -}; - -export default Page; diff --git a/packages/docs/app/layout.tsx b/packages/docs/app/layout.tsx deleted file mode 100644 index cfb9058..0000000 --- a/packages/docs/app/layout.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import type { Metadata } from "next"; -import { Poppins } from "next/font/google"; -import "./globals.css"; -import { Nav } from "@/components/Nav"; -import { Aside } from "@/components/Aside"; - -const poppins = Poppins({ - subsets: ["latin"], - weight: ["100", "200", "300", "400", "500", "600", "700", "800", "900"], -}); - -export const metadata: Metadata = { - title: { template: "%s | Daraja Kit Docs", default: "Daraja Kit Docs" }, - description: - "Daraja Kit is a typesafe Javascript library designed to simplify interactions with the Safaricom Daraja API, specifically for STK push requests. This library is suitable for both Node.js and React environments, allowing developers to seamlessly integrate M-Pesa payments into their applications.", - twitter: { - images: ["https://daraja-kit.vercel.app/ross.jpeg"], - }, - openGraph: { - images: ["https://daraja-kit.vercel.app/ross.jpeg"], - }, - metadataBase: new URL("https://daraja-kit.vercel.app"), -}; - -export default function RootLayout({ - children, -}: { - children: React.ReactNode; -}) { - return ( - - -