paymongo.js
A lightweight, fully-featured, modular, typescript-compatible javascript library for PayMongo.
Installation
npm install paymongo.js # or yarn add paymongo.js
Usage
import PaymongoClient from "paymongo.js";
export const client = PaymongoClient("sk_key");
Payment Method
See PaymentMethod Resource reference.
-
const createResponse = await client.method.create({ details: { cardNumber: "4343434343434345", expMonth: 3, expYear: 2023, cvc: "321", }, type: "card", // card | paymaya });
-
const retrieveResponse = await client.method.retrieve("some_method_id");
Payment Intent
See PaymentIntent Resource reference.
-
const createResponse = await client.intent.create({ amount: 10000, metadata: { order_id: "some_order_id", }, });
-
const retrieveResponse = await client.intent.retrieve({ intentId: "some_intent_id", });
-
const attachResponse = await client.intent.attach({ intentId: "some_intent_id", methodId: "some_method_id", });
Sources
See Source Resource reference.
-
const createResponse = await client.source.create({ type: "gcash", // gcash | grab_pay currency: "PHP", amount: 10000, redirect: { success: "https://example.com/payments/success", failed: "https://example.com/payments/error", }, });
-
const retrieveResponse = await client.source.retrieve("some_source_id");
Payments
See Payment Resource reference.
-
const p = await client.payment.create({ amount: 10000, source: { id: "some_source_id" type: "source", }, });
-
const p = await client.payment.list();
-
const p = await client.payment.retrieve("some_payment_id");
Webhooks
See Webhook Resource reference.
-
const webhook = await client.webhook.create({ events: ["payment.failed", "payment.paid", "source.chargeable"], url: "https://example.com/webhook", });
-
const webhook = await client.webhook.update({ webhookId: "some_webhook_id", events: ["payment.failed"], });
-
const webhooks = await client.webhook.list();
-
const webhook = await client.webhook.retrieve("some_webhook_id");
-
const webhook = await client.webhook.enable("some_webhook_id");
-
const webhook = await client.webhook.disable("some_webhook_id");
Contributing
See CONTRIBUTING.md
Like the project? would appreciate a coffee
Contributor list
Running your own instance
Clone the repository:
git clone https://github.com/princejoogie/paymongo.js.git
cd paymongo.js
npm start # or yarn start
This builds to /dist
and runs the project in watch mode so any edits you save inside src
causes a rebuild to /dist
.
To do a one-off build, use npm run build
or yarn build
.
To run tests, use npm test
or yarn test
.
Configuration
Code quality is set up for you with prettier
, husky
, and lint-staged
. Adjust the respective fields in package.json
accordingly.
Jest
Jest tests are set up to run with npm test
or yarn test
.
Bundle Analysis
size-limit
is set up to calculate the real cost of your library with npm run size
and visualize the bundle with npm run analyze
.
Rollup
This library uses Rollup as a bundler and generates multiple rollup configs for various module formats and build settings. See Optimizations for details.
TypeScript
tsconfig.json
is set up to interpret dom
and esnext
types, as well as react
for jsx
. Adjust according to your needs.
Continuous Integration
GitHub Actions
Two actions are added by default:
-
main
which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix -
size
which comments cost comparison of your library on every pull request usingsize-limit
Optimizations
Please see the main tsdx
optimizations docs. In particular, know that you can take advantage of development-only optimizations:
// ./types/index.d.ts
declare var __DEV__: boolean;
// inside your code...
if (__DEV__) {
console.log("foo");
}
You can also choose to install and use invariant and warning functions.
Module Formats
CJS, ESModules, and UMD module formats are supported.
The appropriate paths are configured in package.json
and dist/index.js
accordingly. Please report if any issues are found.
Publishing to NPM
We recommend using np.
Made by Prince Carlo Juguilon together with these awesome Contributors.