项目作者: saudslm

项目描述 :
Recharge API bindings for Node.js
高级语言: JavaScript
项目地址: git://github.com/saudslm/recharge-api-node.git
创建时间: 2019-10-10T09:43:16Z
项目社区:https://github.com/saudslm/recharge-api-node

开源协议:

下载


Recharge API Node.js

Recharge API bindings for Node.js

Installation:

  1. $ npm install --save recharge-api-node

API

This module exports a constructor function which takes an options object.

Recharge(options)

Creates a new Recharge instance.

Arguments

  • options - Required - A plain JavaScript object that contains the
    configuration options.

Options

  • apiKey - Required - A
    string that specifies the API key of the app.
  • secrete - A string that specifies the secrete of the app.
  • autoLimit - Optional - This option allows you to regulate the request rate
    in order to avoid hitting the [rate limit][api-call-limit]. Requests are
    limited using the token bucket algorithm. Accepted values are a boolean or a
    plain JavaScript object. When using an object, the calls property and the
    interval property specify the refill rate and the bucketSize property the
    bucket size. For example { calls: 2, interval: 1000, bucketSize: 35 }
    specifies a limit of 2 requests per second with a burst of 35 requests. When
    set to true requests are limited as specified in the above example. Defaults
    to false.
    presentment prices for products. Defaults to false.
  • timeout - Optional - The number of milliseconds before the request times
    out. If the request takes longer than timeout, it will be aborted. Defaults
    to 60000, or 1 minute.

Return value

A Recharge instance.

Exceptions

Throws an Error exception if the required options are missing.

Example

  1. const Recharge = require('recharge-api-node');
  2. const recharge = new Recharge({
  3. apiKey: 'your-api-key',
  4. secrete: 'your-app-secrete'
  5. });

Resources

Every resource is accessed via your recharge instance:

  1. const recharge = new Recharge({
  2. apiKey: 'your-api-key',
  3. secrete: 'your-app-secrete'
  4. });
  5. // recharge.<resource_name>.<method_name>

Each method returns a Promise that resolves with the result:

  1. recharge.subscription
  2. .list({ limit: 5 })
  3. .then((subscriptions) => console.log(subscriptions))
  4. .catch((err) => console.error(err));

Available resources and methods

  • address
    • count()
    • list([params])
    • get(id[, params])
    • update(id, params)
    • delete(id)
    • validate(params)
    • addDiscount(id, params)
    • removeDiscount(id, params)
    • addOneTimeProduct(id, params)
  • asyncBatch
    • list([params])
    • get(id[, params])
    • create(params)
    • addTasks(batch_id, params)
    • tasks(batch_id)
    • process(batch_id)
  • charge
    • count()
    • list([params])
    • get(id[, params])
    • create(params)
    • update(id, params)
    • delete(id)
    • changeNextChargeDate(id, params)
    • skip(id, params)
    • unskip(id, params)
    • refund(id, params)
    • addDiscount(id, params)
    • removeDiscount(id, params)
  • checkout - BETA - **query_params object can be used in case of partial_shipping ex: {partial_shipping: 1}
    • get(checkout_token[, params])
    • create(params[, query_params])
    • update(checkout_token, params[, query_params])
    • getShippingRates(checkout_token)
    • process(checkout_token, params)
  • collection
    • count()
    • list([params])
    • get(id[, params])
  • customerAddress
    • list(customer_id[, params])
    • create(customer_id, params)
  • customer
    • count()
    • list([params])
    • get(id[, params])
    • create(params)
    • update(id, params)
    • delete(id)
    • getPaymentSources(id)
  • discount
    • count()
    • list([params])
    • get(id[, params])
    • create(params)
    • update(id, params)
    • delete(id)
    • addToAddress(address_id[, params])
    • removeFromAddress(address_id[, params])
    • addToCharge(charge_id[, params])
    • removeFromCharge(charge_id[, params])
  • metafield
    • count()
    • list([params])
    • get(id[, params])
    • create(params)
    • update(id, params)
    • delete(id)
  • oneTime
    • list([params])
    • get(id[, params])
    • create(address_id, params)
    • update(id, params)
    • delete(id)
  • order
    • count()
    • list([params])
    • get(id[, params])
    • create(params)
    • update(id, params)
    • delete(id)
    • changeShippingDate(id, params)
    • changeOrderVariant(id, shopify_variant_id, params)
    • clone(id, charge_id, params)
  • product
    • count()
    • list([params])
    • get(id[, params])
  • shop
    • get()
    • getShippingCountries()
  • subscription
    • count()
    • list([params])
    • get(id[, params])
    • create(params)
    • update(id, params)
    • delete(id)
    • changeNextChargeDate(id, params)
    • changeAddress(id, params)
    • cancel(id, params)
    • activate(id)
    • ** 'swap product' end point can be triggered using 'update()' function
  • webhook
    • count()
    • list([params])
    • get(id[, params])
    • create(params)
    • update(id, params)
    • delete(id)
    • validate(request_body, secrete)

where params is a plain JavaScript object. See
https://developer.rechargepayments.com/#webhooks for parameters details.