npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gpayments

v0.1.3

Published

Simple 4Geeks Payments API wrapper for NodeJS.

Downloads

11

Readme

gpayments

Build Status NPM version

Simple 4Geeks Payments API Client for NodeJS.

Installation

$ npm install gpayments

Usage

const gpayments = require('gpayments')

const gpApi = gpayments({
  clientId: '4geeks-payment-client-id',
  clientSecret: '4geeks-payment-client-secret'
})
gpApi.plans.create({
  id_name: 'plan-1',
  name: 'Test Plan',
  amount: 300000,
  currency: 'crc',
  trial_period_days: 0,
  interval: 'month',
  interval_count: 1,
  credit_card_description: 'Test Credit Card'
}).then((plan) => {
  console.log(plan)
}).catch((error) => {
  console.log('error', error.response)
})

// or with async/await

const plan = await gpApi.plans.create({
  id_name: 'plan-1',
  name: 'Test Plan',
  amount: 300000,
  currency: 'crc',
  trial_period_days: 0,
  interval: 'month',
  interval_count: 1,
  credit_card_description: 'Test Credit Card'
})

API

You will need your 4Geeks Payment Client ID and a Client Secret in order to use this library.

For additional information on all supported parameters of each method you can visit the official 4Geeks Payment API Documentation.

gpayments(options)

Create a new instance of gpayment api by passing the required clientId and clientSecret properties.

const api = gpayments({
  clientId: '4geeks-payment-client-id',
  clientSecret: '4geeks-payment-client-secret'
})

You can also set the GPAYMENTS_CLIENT_ID and GPAYMENTS_SECRET_ID environment variables instead of passing clientId and clientSecret properties directly.

For example, lets say somewhere in your app you have:

const api = gpayments()

You can startup your node application like this:

GPAYMENTS_CLIENT_ID=abc123 GPAYMENTS_SECRET_ID=123abcsecret node app.js

api.me.fetch()

Fetch my account information.

const account = await api.me.fetch()

console.log(account)

api.me.update(data)

Update my account information.

const account = await api.me.update({ bank_name: 'Bac', test: false })

console.log(account)

api.customers.fetch([key])

Fetch customers. You can also pass a customer key to fetch an specific customer.

const customers = await api.customers.fetch()

console.log(customers)

Or to fetch a single customer.

const customer = await api.customers.fetch('GfGsOKTZVlTKyn7khcihXYuEUx0nBxb')

console.log(customer)

api.customers.create(data)

Create a new customer.

const customer = await api.customers.create({
  name: 'Bruce Banner',
  email: '[email protected]',
  currency: 'usd',
  credit_card_number: 4242424242424242,
  credit_card_security_code_number: 123,
  exp_month: 12,
  exp_year: 2035
})

console.log(customer)

api.customers.update(key, data)

Update a customer.

const data = { email: '[email protected]' }
const customer = await api.customers.update('GfGsOKTZVlTKyn7khcihXYuEUx0nBxb', data)

console.log(customer)

api.customers.remove(key)

Delete a customer.

await api.customers.remove('GfGsOKTZVlTKyn7khcihXYuEUx0nBxb')

api.plans.fetch([key])

Fetch all plans. You can also pass a plan key to fetch an specific plan.

const plans = await api.plans.fetch()

console.log(plans)

Or to fetch a single plan.

const plan = await api.plans.fetch('ftmDCyPmun7QiKah5PrP2f')

console.log(plan)

api.plans.create(data)

Create a new plan.

const plan = await api.plans.create({
  id_name: 'plan-1',
  name: 'Test Plan',
  amount: 300000,
  currency: 'crc',
  trial_period_days: 0,
  interval: 'month',
  interval_count: 1,
  credit_card_description: 'Test Credit Card'
})

console.log(plan)

api.plans.remove(key)

Delete a plan.

await api.plans.remove('ftmDCyPmun7QiKah5PrP2f')

api.subscriptions.fetch([id])

Fetch all subscriptions. You can also pass a subscription id to fetch an specific subscription.

const subscriptions = await api.subscriptions.fetch()

console.log(subscriptions)

Or to fetch a single subscription.

const subscription = await api.subscriptions.fetch('BtZ3TxvsEvFh2x')

console.log(subscription)

api.subscriptions.subscribe(data)

Create a subscription.

await api.subscriptions.subscribe({
  plan_id_name: 'plan-1',
  customer_key: 'GfGsOKTZVlTKyn7khcihXYuEUx0nBxb',
})

api.subscriptions.unsubscribe(id)

Delete a subscription.

await api.subscriptions.unsubscribe('sub_B6Vje4CBVugWea')

api.charges.create(data)

Create a new charge.

await api.charges.create({
  amount: 90.32,
  customer_key: 'GfGsOKTZVlTKyn7khcihXYuEUx0nBxb',
  description: 'Plan 1 service charge',
  entity_description: 'Plan 1',
  currency: 'usd',
})

You can also just simple charge a credit card by omitting a customer_key and adding just the credit card information:

// Simple charge the credit card provided.
await api.charges.create({
  amount: 90.32,
  description: 'Plan 1 service charge',
  entity_description: 'Plan 1',
  currency: 'usd',
  credit_card_number: 4242424242424242,
  credit_card_security_code_number: 123,
  exp_month: 11,
  exp_year: 2020
})

api.charges.logs([id])

List all charges logs. You can also pass a charge id to fetch an specific charge log.

const logs = await api.charges.logs()

console.log(logs)

Or to fetch a single charge log.

const log = await api.charges.logs('1BTvroCqnAM123fqhvZw4dlkHk')

console.log(log)

Run tests

$ npm install
$ npm run test

License

Under The MIT License