@re-up/paymongo-fn
TypeScript icon, indicating that this package has built-in type declarations

0.0.17 • Public • Published

Paymongo Fn

Paymongo SDK - All Functions Everything

features

  • Built primarily for tRPC
  • Zod validated schemas and resource, all Typescript inferred.
  • Axios handled API calls
  • All server side requests
  • Also works on NextJS

install

bun i @re-up/paymongo-fn

usage

import { Paymongo } from "@re-up/paymongo-fn";

const p = Paymongo(process.env.PAYMONGO_SK);

const onCheckout = async (params) => await p.checkout.create(params);

tRPC

// trpc/router.ts

const paymongo = createRouter({
    checkout: checkoutProcedure.mutation(async({input}) => await p.checkout.create(input)
})

// trpc/caller.ts

const checkout = async (params) => await api.paymongo.checkout(params)

async helpers

interface Input<T> {
  input: T;
}

const asyncR =
  <TParams, TReturn>(fn: (params: TParams) => Promise<TReturn>) =>
  async ({ input }: Input<TParams>) =>
    await fn(input);

This helper is for mutations and expects input as key. It makes your code a bit concise and readable.

const paymongo = createRouter({
  // checkout params is inferred by what paymongo.checkout.create accepts
  checkout: checkoutProcedure.mutation(asyncR(p.checkout.create)),
  // retrieve params is inferred by what paymongo.checkout.retrieve accepts
  retrieve: retrieveProcedure.mutation(asyncR(p.checkout.retrieve)),
});
const asyncFn =
  <TParams, TReturn>(fn: (params: TParams) => Promise<TReturn>) =>
  async (params: TParams) =>
    await fn(params);

This one is a plane async/await wrapper, also type inferred based on the callers params.

const checkout = asyncFn(api.paymongo.checkout);

re-up.ph

Readme

Keywords

Package Sidebar

Install

npm i @re-up/paymongo-fn

Weekly Downloads

2

Version

0.0.17

License

MIT

Unpacked Size

239 kB

Total Files

39

Last publish

Collaborators

  • re-up