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

@lucadiba/satispay-client

v1.0.0

Published

<h1 align="center">Satispay Node.js client</h1>

Downloads

53

Readme

A JavaScript Node.js client for Satispay APIs with built-in TypeScript types. This package supports both ESM and CommonJS.


Installation

Install the package using your preferred package manager:

npm install @lucadiba/satispay-client

Usage

Import the package in your Node.js application:

import Satispay from "@lucadiba/satispay-client";

Initialize the client

Initialize the client with your keyId and privateKey. You can get both using this package. See the Authentication section for more details.

const satispay = new Satispay.Client({
  keyId: "ldg9sbq283og7ua1abpj989kbbm2g60us6f18c1sciq...",
  privateKey: "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBg...",
  environment: "sandbox", // optional, defaults to "production"
});

Create a payment

const payment = await satispay.payments.create({
  flow: "MATCH_CODE",
  amountUnit: 100,
  currency: "EUR",
});

// Save the payment id
const paymentId = payment.id;

// Redirect the user to the redirectUrl
const redirectUrl = payment.redirect_url;

Get a payment

satispay.payments.get({
  id: "payment_id",
});

Get all payments

satispay.payments.getAll();

Update a payment

satispay.payments.update({
  id: "payment_id",
  action: "CANCEL",
});

Authentication

The Satispay API uses an authentication method based on a RSA key pair. You can generate a new key pair using the generateKeyPair method:

import Satispay from "@lucadiba/satispay-client";

const { publicKey, privateKey } =
  await Satispay.Authentication.generateKeyPair();

Then, you can use the authenticateWithToken method to get the keyId needed to initialize the client. The token is a 6 characters string that you can find in the Satispay Business Dashboard. It can only be used once, so you need to save the keyId, which can be reused and does not expire.

const { keyId } = await Satispay.Authentication.authenticateWithToken({
  token: "623ECX",
  publicKey,
});

Finally, you can initialize the client:

const satispay = new Satispay.Client({
  keyId,
  privateKey,
});

Errors

Handling errors

This package throws an error when the Satispay API returns an error. You can catch the error and handle it as you prefer.

If the errors comes from the Satispay API, the error will be an instance of SatispayError. There is a utility method to check if an error is a SatispayError.

import { SatispayError } from "@lucadiba/satispay-client";

try {
  await satispay.payments.create({
    flow: "MATCH_CODE",
    amountUnit: -100,
    currency: "EUR",
  });
} catch (error) {
  if (SatispayError.isSatispayError(error)) {
    // The SatispayError type is automatically inferred
    console.error({
      message: error.message,
      data: error.data,
      code: error.code,
      status: error.status,
    });
  } else {
    // The type of error is unknown
    console.error(error);
  }
}

Contributing

Contributions, issues and feature requests are welcome!

License

Copyright © 2022 Luca Dibattista. This project is MIT licensed.