Back

January 30, 2022

paymongo.js

CI License Size Version

An end-to-end typesafe library for PayMongo

Installation

NPM

npm install paymongo.js

Usage

import { createPaymongoClient } from "paymongo.js";
const client = createPaymongoClient("sk_key");

Payment Intent

See PaymentIntent Resource reference.

  • Create a Intent

    const res = await client.intent.create({
      amount: 10000,
      payment_method_allowed: ["card", "gcash"],
      currency: "PHP",
    });
  • Retrieve a PaymentIntent

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

    const res = await client.intent.attach({
      intentId: "some_intent_id",
      intentId: "some_method_id",
      return_url: "https://example.com/success",
    });

Payment Method

See PaymentMethod Resource reference.

  • Create a Method

    const res = await client.method.create({
      type: "gcash",
      billing: {
        name: "John Doe",
        email: "john@email.com",
        phone: "+639999999999",
        address: {
          city: "Manila",
          line1: "line 1",
          line2: "line 2",
          state: "Metro Manila",
          country: "PH",
          postal_code: "1000",
        },
      },
    });
    const res = await client.method.create({
      type: "card",
      details: {
        card_number: "4242424242424242",
        exp_month: 12,
        exp_year: 2025,
      },
    });
  • Retrieve a Method

    const retrieveResponse = await client.method.retrieve({
      methodId: "some_method_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");

Older APIs

The following API's are for older workflows, it is recommended that you use the Payment Intent workflow

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");

Contributing

See CONTRIBUTING.md

Like the project? would appreciate a coffee ☕

Buy Me A Coffee

Contributor list

Contributors


Made by Prince Carlo Juguilon together with these awesome Contributors.


About

Projects

Blogs

Prince Carlo Juguilon © 2023 All Right Reserved