Options
All
  • Public
  • Public/Protected
  • All
Menu

Squish Node.js Library

The Squish Node library provides convenient access to Squish API from server-side applications.

Documentation

Installation

Install the package with:

npm install squish --save

Usage

The package needs to be configured with your account's secret key.

import Squish from "squish"

const squish = new Squish({
  token: "<secret_key>",
  swish: {
    vendor: "1231181189",
    callbackUrl: "https://www.example.com/hooks/payments",
    cert: {
      pfx: __dirname + "/ssl/1231181189.p12",
      passphrase: "swish"
    }
  }
})


// Create new invoice
const invoice = await squish.create(
  { amount: '100.00', customer: "46700123456" }
);

Example

// Setup Swish payment request webook
app.post("/paymentrequests", squish.paymentHook)

// Create invoice
squish.create({ amount: "100.00", customer: "46700123456" }).then(invoice => {
  console.log("invoice created: ", invoice)
  /*
  { id: 'M.kkF6;se;4ssHN19,P:',
    customer: 'foo',
    vendor: 'vendor_id',
    status: 'unpaid',
    amount_due: '100.00',
    currency: 'SEK',
    created_at: '2018-02-09T17:44:59.355Z',
    expires_at: '2018-02-10T17:44:59.355Z',
    paid_at: null,
    meta: null,
    payment: null,
    __typename: 'Invoice' }
  */

  // Request payment token to be consumed by client to initiate Swish payment
  squish.paymentRequest(invoice).then(
    token => console.log("payment request token to be sent to client :", token)
    // 900D843722644C149995AC246E14D8C6
  )

  // Subscribe to changes to an invoice
  squish.subscribe(
    invoice.id,
    update => console.log("payment update for invoice: ", update),
    console.error
  )

  // Simulate payment
  squish
    .simulate({
      id: invoice.id,
      amount: invoice.amount_due,
      customer: "46700123457"
    })
    .then(paid => {
      console.log("simulated payment: ", paid)
    })
})

Index

Type aliases

InvoiceInputType

InvoiceInputType: object

Type declaration

  • amount: string
  • customer: string
  • Optional id?: undefined | string

InvoiceType

InvoiceType: object

Type declaration

  • amount: string
  • amount_due: string
  • created_at: string
  • currency: string
  • customer: string
  • expires_at: string
  • Optional id?: undefined | string
  • meta: string
  • paid_at: string
  • payment: any
  • status: string
  • vendor: string

SquishOptions

SquishOptions: object

Type declaration

  • swish: object
    • callbackUrl: string
    • cert: object
      • passphrase: string
      • pfx: string
    • vendor: string
  • token: string

Variables

Const CreateInvoiceMutation

CreateInvoiceMutation: any = gql`mutation createInvoice($data: InvoiceInput!) {createInvoice(data: $data) {${INVOICE}}}`

Const INVOICE

INVOICE: "idcustomervendorstatusamount_duecurrencycreated_atexpires_atpaid_atmetapayment {amountpayerAliasdateCreateddatePaidstatussimulated}" = `idcustomervendorstatusamount_duecurrencycreated_atexpires_atpaid_atmetapayment {amountpayerAliasdateCreateddatePaidstatussimulated}`

Const InvoiceSubscription

InvoiceSubscription: any = gql`subscription invoice($id: ID!) {invoice(id: $id) {${INVOICE}}}`

Const PayInvoiceMutation

PayInvoiceMutation: any = gql`mutation payInvoice($data: PaymentInput!) {payInvoice(data: $data) {${INVOICE}}}`

Const SimulatePaymentMutation

SimulatePaymentMutation: any = gql`mutation simulate($data: InvoiceInput!) {simulate(data: $data) {${INVOICE}}}`

Functions

createClient

  • createClient(__namedParameters: object): ApolloClient<any>
  • Parameters

    • __namedParameters: object
      • token: string
      • uri: string

    Returns ApolloClient<any>

handleResponse

  • handleResponse(res: FetchResult): any

splitOnOperation

  • splitOnOperation(ws: WebSocketLink, http: HttpLink): ApolloLink
  • Parameters

    • ws: WebSocketLink
    • http: HttpLink

    Returns ApolloLink

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc