paymongo.js
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

paymongo.js

CI CJS ESM License Version

A lightweight, fully-featured, modular, typescript-compatible javascript library for PayMongo.

Installation

NPM

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.

  • Create a Method

    const createResponse = await client.method.create({
      details: {
        cardNumber: "4343434343434345",
        expMonth: 3,
        expYear: 2023,
        cvc: "321",
      },
      type: "card", // card | paymaya
    });
  • Retrieve a Method

    const retrieveResponse = await client.method.retrieve("some_method_id");

Payment Intent

See PaymentIntent Resource reference.

  • Create a Intent

    const createResponse = await client.intent.create({
      amount: 10000,
      metadata: {
        order_id: "some_order_id",
      },
    });
  • Retrieve a PaymentIntent

    const retrieveResponse = await client.intent.retrieve({
      intentId: "some_intent_id",
    });
  • Attach to PaymentIntent

    const attachResponse = await client.intent.attach({
      intentId: "some_intent_id",
      methodId: "some_method_id",
    });

Sources

See Source Resource reference.

  • Create a Source

    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",
      },
    });
  • Retrieve a Source

    const retrieveResponse = await client.source.retrieve("some_source_id");

Payments

See Payment Resource reference.

  • Create a Payment

    const p = await client.payment.create({
      amount: 10000,
      source: {
        id: "some_source_id"
        type: "source",
      },
    });
  • List all Payments

    const p = await client.payment.list();
  • Retrieve a Payment

    const p = await client.payment.retrieve("some_payment_id");

Webhooks

See Webhook Resource reference.

  • Create a Webhook

    const webhook = await client.webhook.create({
      events: ["payment.failed", "payment.paid", "source.chargeable"],
      url: "https://example.com/webhook",
    });
  • Update a Webhook

    const webhook = await client.webhook.update({
      webhookId: "some_webhook_id",
      events: ["payment.failed"],
    });
  • List all Webhooks

    const webhooks = await client.webhook.list();
  • Retrieve a Webhook

    const webhook = await client.webhook.retrieve("some_webhook_id");
  • Enable a Webhook

    const webhook = await client.webhook.enable("some_webhook_id");
  • Disable a Webhook

    const webhook = await client.webhook.disable("some_webhook_id");

Contributing

See CONTRIBUTING.md

Like the project? would appreciate a coffee

Buy Me A Coffee

Contributor list

Contributors


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 using size-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.

Readme

Keywords

none

Package Sidebar

Install

npm i paymongo.js

Weekly Downloads

22

Version

1.1.2

License

MIT

Unpacked Size

417 kB

Total Files

87

Last publish

Collaborators

  • princejoogie