paymongo.js
An end-to-end typesafe library for PayMongo
Installation
npm install paymongo.js
Usage
import { createPaymongoClient } from "paymongo.js";
const client = createPaymongoClient("sk_key");
Payment Intent
See PaymentIntent Resource reference.
-
const res = await client.intent.create({ amount: 10000, payment_method_allowed: ["card", "gcash"], currency: "PHP", });
-
const res = client.intent.retrieve({ intentId: "some_intent_id", });
-
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.
-
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, }, });
-
const retrieveResponse = await client.method.retrieve({ methodId: "some_method_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");
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.
-
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");
Contributing
See CONTRIBUTING.md
Like the project? would appreciate a coffee ☕
Contributor list
Made by Prince Carlo Juguilon together with these awesome Contributors.