Git Product home page Git Product logo

gocardless-nodejs's Introduction

Node.js client for the GoCardless API

GoCardless npm version

A Node.js client for the GoCardless API. For full details of the GoCardless API, see the API docs.

Installation

$ npm i gocardless-nodejs

Usage

Initialising the client

To initialise the client, you must provide:

  • An access token.
  • The environment that this token is for (see here for a list of available environments).
  • Any additional options (see here for a list of supported options).
const gocardless = require('gocardless-nodejs');
const constants = require('gocardless-nodejs/constants');


// Initialise the client.
const client = gocardless(
  process.env.GC_ACCESS_TOKEN,
  constants.Environments.Sandbox,
  { raiseOnIdempotencyConflict: true },
);

The Basics

We'll illustrate the basic library usage by demonstrating on the payment resource.

For a full list of available resources, visit the GoCardless API reference.

const uuidv4 = require('uuid/v4');

// Create a new payment.
const payment = await client.payments.create(
  {
    amount: 100,
    currency: "GBP",
    links: { mandate: "MD123" },
  },
  { uuidv4() },
);

// List the first three payments past a certain date.
const payments = await client.payments.list({
  limit: 3,
  created_at: {
    gt: '2020-01-01T17:01:06.000Z',
  },
});

// Get a payment.
const payment = await client.payments.find('PM123');

// Update a payment.
await client.payments.update('PM123', { amount: '22' });

// Cancel a payment.
await client.payments.cancel('PM123');

The all method

All resources with a list method will also have an additional *all method. This method acts like the regular list method and accepts the same parameters, but instead returns an async generator.

for await (const payment of client.payments.all()) {
  console.log(payment.id);
}

Available client options

  • raiseOnIdempotencyConflict: set to true to raise exceptions on idempotency conflicts. Defaults to false.

gocardless-nodejs's People

Contributors

amaraliou avatar appetiser-robot avatar barrucadu avatar bekundayo avatar brettwillis avatar cafetiere avatar danwakefield avatar gocardless-robot avatar hjheath avatar jasonlafferty avatar jessezach avatar jjholmes927 avatar karmanleung avatar loreenwong avatar martin-nef avatar matthieuprat avatar opsz2 avatar prolific117 avatar saurav1991 avatar steveofficerseccl avatar szastupov avatar tallosan avatar vdandugc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gocardless-nodejs's Issues

Use GitHub release and changelog

Hello,

It is sometimes hard to know what was shipped during the previous releases and I think it would be great if you could put a changelog in GitHub releases.

For example, I had to find the related PR for the 1.1.2 version to know what it was about.

Rate limit headers

Is there any way to access ratelimit-remaining and ratelimit-reset headers when api call throws a rate_limit_exceeded error?

Update crypto-js dependency

Hi, can you upgrade your version of crypto-js to 4.0.0? Snyk is reporting a vulnerability when I include gocardless-nodejs in my project. I believe the only change to crypto-js is to use native randomness generators that won't work in IE 10 or React Native, so it should be fine for a NodeJS library.

All fields on GoCardlessException are private

Using typescript, when GoCardlessException is raised, how does one figure out what is the cause of this exception as all fields on GoCardlessException are private? Also GoCardlessException does not seem to have toString or toJson implemented, while JSON.stringify(exception) fails with

    "errorType": "TypeError",
    "errorMessage": "Converting circular structure to JSON\n    --> starting at object with constructor 'TLSSocket'\n    |     property '_httpMessage' -> object with constructor 'ClientRequest'\n    --- property 'socket' closes the circle",
    "stack": [
        "TypeError: Converting circular structure to JSON",
        "    --> starting at object with constructor 'TLSSocket'",
        "    |     property '_httpMessage' -> object with constructor 'ClientRequest'",
        "    --- property 'socket' closes the circle",
        "    at JSON.stringify (<anonymous>)",
        "    at GoCardlessException.gocardless_nodejs_GoCardlessException__WEBPACK_IMPORTED_MODULE_5__.GoCardlessException.toString (/var/task/dist/lambda.js:3041:17)",
        "    at new Error (<anonymous>)",
        "    at _homogeneousError (/var/runtime/CallbackContext.js:12:12)",
        "    at postError (/var/runtime/CallbackContext.js:29:54)",
        "    at done (/var/runtime/CallbackContext.js:56:7)",
        "    at fail (/var/runtime/CallbackContext.js:68:7)",
        "    at /var/runtime/CallbackContext.js:104:16"
    ]
}

Seeing ```connect ECONNREFUSED 127.0.0.1:443``` coming from got libary

Full error output is below. This comes from any call that I've tried, e.g. await client.customers.find('CUXXXXX')

GotError: connect ECONNREFUSED 127.0.0.1:443
    at onError (/Users/laurie/wrisk/runbook/.yarn/cache/got-npm-10.7.0-9215e39e3e-e233703fcf.zip/node_modules/got/dist/source/request-as-event-emitter.js:140:29)
    at handleRequest (/Users/laurie/wrisk/runbook/.yarn/cache/got-npm-10.7.0-9215e39e3e-e233703fcf.zip/node_modules/got/dist/source/request-as-event-emitter.js:173:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
  name: 'RequestError',
  code: 'ECONNREFUSED'
}

Someone else reported a similar issue coming from this repo at the beginning of the year here: #88. I've asked if they ever found a solution.

Could this be caused by using got version ^10.2.2 (10.7.0 being used)? Latest version of got is 11.8.2: https://www.npmjs.com/package/got.

ES modules syntax support?

Hello ๐Ÿ‘‹ We use TypeScript throughout our projects. Typically we use ES modules syntax (import/export) to load our modules, this then gets boiled down to CommonJS style (require) after the compiler has run.

It seems this module does not support use of the import/export syntax, is it suppose to?

For example we encounter these sorts of errors:

Working example:

const webhooks = require("gocardless-nodejs/webhooks");

webhooks.parse(...); // ok

Broken example:

import webhooks from "gocardless-nodejs/webhooks";

webhooks.parse(...); // => Runtime TypeError: Cannot read properties of undefined (reading 'parse')

What is the rational for making every field optional

Since release 3.0.0 all fields on Payment became optional. What is the rational for this? How are these types should now be used? Should we be using not-null assertion?

According to the api reference fields like amount cannot be undefined. Also it is very strange now that some fields can be both undefined and null.

Make prefilled_customer properties optional

Hi! We're using your library and would like to use the prefilled_customer property when creating a redirectFlows (using client.redirectFlows.create).

We are using TypeScript and we can't use prefilled_customer without putting all the property with empty string for the one we don't want to fill.

For example if we omit region:

Property 'region' is missing in type '{ 
  address_line2: string; 
  address_line3: string; 
  ... 10 more ... ; 
  country_code: string; 
}'
but required in type 'RedirectFlowPrefilledCustomer'.

'description' attribute in redirectFlows.create() is ignored

Hello,
When I fill the description attribute of the create method of redirectFlows, it is ignored.

It used to worked well before, but recently this field has stopped to be taking into account and instead there is a paragraph named mandate-description where the custom description field used to lay.

'invalid_api_usage' error attempting to list subscriptions filtered by type

Attempting to set the status parameter on a SubscriptionListRequest results in an API error.

Steps:

import { GoCardlessClient } from 'gocardless-nodejs/client';
import { SubscriptionStatus } from 'gocardless-nodejs/types/Types';

const gocardless = new GoCardlessClient(gocardlessKey, gocardlessEnv)
await gocardless.subscriptions.list({
  status: [SubscriptionStatus.Active],
});

Result:

{
  "message": "One of your parameters was incorrectly typed",
  "errors": [
    {
      "field": "status",
      "message": "{\"0\"=>\"active\"} is not an array or string.",
      "request_pointer": "/subscriptions/status"
    }
  ],
  "documentationUrl": "https://developer.gocardless.com/api-reference#invalid_type",
  "type": "invalid_api_usage",
  "requestId": "<omitted>",
  "code": 422
}

I've also attempted to import SubscriptionStatus from gocardless-nodejs instead of gocardless-nodejs/types/Types, but SubscriptionStatus is undefined at run time when importing this way.

As a workaround when filtering by a single status, an @ts-ignore flag can be added to allow passing in a single string.

await gocardless.subscriptions.list({
  //@ts-ignore
  status: SubscriptionStatus.Active,
});

Everything is now optional by default in v3.0.0

Moving to V3, everything is optional by default: v2.4.0...v3.0.0#files_bucket

Is there a reason for that? I feel like status , amount, currency perhaps? Can a big rework of typing be done so it 100% represents your documentation? For typescript developers, this is unfortunately hardly usable.

It's also gonna take me a long time to fix those in small bunch of PR like those : #114 and you guys probably have the best knowledge to know what is required or not ๐Ÿ’ช

Thank you!

Typescript definitions for core client?

Hello ๐Ÿ‘‹ When using this module as per the readme instructions, we don't get type definitions for the core client object. It comes back as any type. This then has repercussions for the rest of its usage throughout an app. For example:

const gocardless = require('gocardless-nodejs');

const client = gocardless(...); // ==> client is of type 'any'

const mandate = await client.mandates.find(mandateId); // ==> mandate is of type 'any'

etc etc

Perhaps I've missed something blatantly obvious...?

[BUG] BillingRequestMandateRequest defined twice

Hi!
BillingRequestMandateRequest interface is defined twice in the file, and this leads to exporting only the second.

The implementations are the following:

// first

/** Type for a billingrequestmandaterequest resource. */
export interface BillingRequestMandateRequest {
    currency: string;
    scheme?: string;
}


// second

/** Type for a billingrequestmandaterequest resource. */
export interface BillingRequestMandateRequest {
    currency: string;
    links: BillingRequestMandateRequestLinks;
    scheme?: string;
    verify: BillingRequestMandateRequestVerify;
}

The difference between them is that the second has links and verify property, which I have looked for in the API Reference in the docs, and regarding to the links property, I haven't found any mandate_request[links], and regarding to the verify property, it appears in the introduction of the Billing Requests Section.

The first definition appears in the create billing request endpoint section.

Thanks!

Repository Creation Checklist

Hey, if you're seeing this issue, it's good news: Appetiser has completed setting up your repository!

The following integrations are expected to be working:

  • CircleCI: check that initial commits made by Appetiser have a Passing build status
  • Dependabot: check that your repository has a base .dependabot/config.yml file

If the above items have not happened within 15 minutes since you requested a repository, please let Developer Enablement know via a ticket.


The following tasks are just reminders for you to complete, so that your repository is consistent with other GoCardless repositories. We are aware that all of these might not apply to your project - please ignore such tasks.

Dockerfile / Service

Ruby

Go

If you have any feedback about the automated repository setup, do not hesitate to reach out to Developer Enablement on our Slack channel #developer-enablement, or create a ticket for us to investigate.

Unprocessable Entity

Hello,

Since 20.01.2022 I started getting 'Error: Unprocessable Entity' when calling client.redirectFlows.create:

    const redirectFlow = await client.redirectFlows.create({
      description: description,
      session_token: session_token,
      success_redirect_url: success_redirect_url,
      prefilled_customer: prefilled_customer,
    });

I didn't change anything in the code and it used to work before.

Apparently it is the line const response = await this.api.request(requestParams); in redirectFlowService that creates the issue.

Any ideas?

Types don't match reality

Hey team,

I have noticed that a payout's amount using cURL is of type integer (in line with your Java SDK), yet for some reason Node version of the SDK has it as string

    "payouts": {
        "amount": 50000,
        "deducted_fees": 0,
        "currency": "GBP",
        .....
    }
    ```

[bug ?] broken types for gocardless-nodejs/webhooks

Hi there. I'm trying to build integration with gocardless and validate a webhook signature with parse function form the import { parse } from 'gocardless-nodejs/webhooks'. But my linter doesn't see webhook.d.ts and fails with error File '/...path/node_modules/gocardless-nodejs/webhooks.d.ts' is not a module.

How can I include types from the webhook.d.ts ?

Stack:

  • serverless
  • typescript

Tsconfig

{
  "compilerOptions": {
    "sourceMap": true,
    "target": "es2020",
    "lib": ["es2020"],
    "strict": true,
    "noUnusedLocals": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "typeRoots": ["./node_modules/@types", "./src/types"],
    "outDir": "dist"
  }
}

RequestError with ERR_INVALID_ARG_TYPE

Hello,

I have (in a production environment only) this kind of error that happens randomly when I try call some methods of the library (using the 1.1.2 version) like the following:

      const mandate = await client.mandates.find(mandateId);

      const { account_number_ending: bankAccountNumberEnding } = await client.customerBankAccounts.find(
        mandate.links.customer_bank_account,
      );

OR

      const { url } = await client.mandatePdfs.create(
        {
          links: {
            mandate: mandateId,
          },
        },
        '',
        {
          'Accept-Language': language || 'en',
        },
      );

The error:

"extensions": {
  "name": "RequestError",
  "code": "GOCARDLESS_ERROR",
  "exception": {
    "name": "RequestError",
    "code": "ERR_INVALID_ARG_TYPE"
  }
}

GOCARDLESS_ERROR is an internal error name, but RequestError and ERR_INVALID_ARG_TYPE are returned by GoCardless.

Do you know where this could come from? It sometimes works like a charm, but then I will have this error.

'links' property is not optional in RedirectFlowCreateRequest

According to the API reference the links property is optional, and is only needed when an account has multiple creditors. The REST API appears to work fine when this parameter is omitted.

In the RedirectFlowCreateRequest interface below, this property is not marked as optional.

links: Types.RedirectFlowCreateRequestLinks;

It looks like the code here might be generated / imported from elsewhere, so I'm assuming I shouldn't open a pull request?

Angular 12 error: gocardless is not a function

Trying to use this API on an Angular 12 app, following the instructions.

Importing the module as follows:

const gocardless = require('gocardless-nodejs');
const constants = require("gocardless-nodejs/constants");

Then trying to create the client:

const client = gocardless(
    [gcAccessToken],
    // Change this to constants.Environments.Live when you're ready to go live
    constants.Environments.Sandbox
);

but keeps showing this error:
ERROR TypeError: gocardless is not a function

Here are the dependencies of my app:

"dependencies": {
        "@angular-material-components/file-input": "^6.0.0",
        "@angular/animations": "12.2.3",
        "@angular/cdk": "12.2.3",
        "@angular/cli": "12.2.3",
        "@angular/common": "12.2.3",
        "@angular/compiler": "12.2.3",
        "@angular/compiler-cli": "12.2.3",
        "@angular/core": "12.2.3",
        "@angular/forms": "12.2.3",
        "@angular/material": "12.2.3",
        "@angular/material-moment-adapter": "12.2.3",
        "@angular/platform-browser": "12.2.3",
        "@angular/platform-browser-dynamic": "12.2.3",
        "@angular/router": "12.2.3",
        "@capacitor/android": "^3.3.3",
        "@capacitor/core": "^3.3.3",
        "@capacitor/ios": "^3.3.3",
        "@capacitor/push-notifications": "^1.0.9",
        "@fullcalendar/angular": "4.4.5-beta",
        "@fullcalendar/core": "^4.4.2",
        "@fullcalendar/daygrid": "4.4.2",
        "@fullcalendar/interaction": "4.4.2",
        "@fullcalendar/list": "4.4.2",
        "@fullcalendar/moment": "4.4.2",
        "@fullcalendar/resource-timegrid": "4.4.2",
        "@fullcalendar/resource-timeline": "4.4.2",
        "@fullcalendar/rrule": "4.4.2",
        "@fullcalendar/timegrid": "4.4.2",
        "@ngneat/transloco": "2.22.0",
        "apexcharts": "3.28.1",
        "assert": "^2.0.0",
        "aws-sdk": "^2.1060.0",
        "crypto-browserify": "^3.12.0",
        "crypto-js": "3.3.0",
        "express": "^4.17.1",
        "gocardless-nodejs": "^2.3.0",
        "highlight.js": "11.2.0",
        "https-browserify": "^1.0.0",
        "lodash-es": "4.17.21",
        "moment": "2.29.1",
        "ng-apexcharts": "1.5.12",
        "ngx-color-picker": "^11.0.0",
        "ngx-markdown": "12.0.1",
        "ngx-quill": "14.3.0",
        "os-browserify": "^0.3.0",
        "perfect-scrollbar": "1.5.2",
        "quill": "1.3.7",
        "rrule": "2.6.8",
        "rxjs": "6.6.7",
        "stream": "0.0.2",
        "stream-browserify": "^3.0.0",
        "stream-http": "^3.2.0",
        "tslib": "2.3.1",
        "util": "^0.12.4",
        "web-animations-js": "2.3.2",
        "zone.js": "0.11.4"
    },
    "devDependencies": {
        "@angular-builders/custom-webpack": "^12.0.0",
        "@angular-devkit/build-angular": "12.2.3",
        "@angular-eslint/builder": "12.3.1",
        "@angular-eslint/eslint-plugin": "12.3.1",
        "@angular-eslint/eslint-plugin-template": "12.3.1",
        "@angular-eslint/schematics": "12.3.1",
        "@angular-eslint/template-parser": "12.3.1",
        "@angular/cli": "12.2.3",
        "@angular/compiler-cli": "12.2.3",
        "@capacitor/cli": "^3.3.3",
        "@tailwindcss/aspect-ratio": "0.2.1",
        "@tailwindcss/line-clamp": "0.2.1",
        "@tailwindcss/typography": "0.4.1",
        "@types/chroma-js": "2.1.3",
        "@types/crypto-js": "3.1.47",
        "@types/highlight.js": "10.1.0",
        "@types/jasmine": "3.8.2",
        "@types/lodash": "4.14.172",
        "@types/lodash-es": "4.17.4",
        "@types/node": "^12.20.21",
        "@typescript-eslint/eslint-plugin": "4.30.0",
        "@typescript-eslint/parser": "4.30.0",
        "autoprefixer": "10.3.3",
        "chroma-js": "2.1.2",
        "eslint": "7.32.0",
        "eslint-plugin-import": "2.24.2",
        "eslint-plugin-jsdoc": "36.0.8",
        "eslint-plugin-prefer-arrow": "1.2.3",
        "jasmine-core": "3.8.0",
        "karma": "6.3.4",
        "karma-chrome-launcher": "3.1.0",
        "karma-coverage": "2.0.3",
        "karma-jasmine": "4.0.1",
        "karma-jasmine-html-reporter": "1.7.0",
        "lodash": "4.17.21",
        "postcss": "8.3.6",
        "tailwindcss": "2.2.9",
        "typescript": "4.3.5"
    }

Billing request types doesn't match documentation

Both BillingRequestMandateRequest and BillingRequestPaymentRequest are declared twice, and TypeScript merges the declarations. The second declaration includes non-optional fields which seem optional based on the documentation for example:

BillingRequestMandateRequest

The second declaration includes required fields links and verify fields, where as per the API documentation, only curreny is required:

{
 "billing_requests": {
   "mandate_request": {
     "currency": "GBP"
   }
 }
}

/** Type for a billingrequestmandaterequest resource. */
export interface BillingRequestMandateRequest {
// [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency
// code.
currency: string;
// A Direct Debit scheme. Currently "ach", "bacs", "becs", "becs_nz",
// "betalingsservice", "pad" and "sepa_core" are supported.
scheme?: string;
}

/** Type for a billingrequestmandaterequest resource. */
export interface BillingRequestMandateRequest {
// [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency
// code.
currency: string;
// Resources linked to this BillingRequestMandateRequest.
links: BillingRequestMandateRequestLinks;
// A Direct Debit scheme. Currently "ach", "bacs", "becs", "becs_nz",
// "betalingsservice", "pad" and "sepa_core" are supported.
scheme?: string;
// Verification preference for the mandate. One of:
// <ul>
// <li>`minimum`: only verify if absolutely required, such as when part of
// scheme rules</li>
// <li>`recommended`: in addition to minimum, use the GoCardless risk engine
// to decide an appropriate level of verification</li>
// <li>`when_available`: if verification mechanisms are available, use
// them</li>
// <li>`always`: as `when_available`, but fail to create the Billing Request
// if a mechanism isn't available</li>
// </ul>
//
// If not provided, the `recommended` level is chosen.
verify: BillingRequestMandateRequestVerify;
}

BillingRequestPaymentRequest

It's a similar story for BillingRequestPaymentRequest, declared twice with the second declaration requiring fields that should be optional, please check.

Dependabot couldn't find a Dockerfile for this project

Dependabot couldn't find a Dockerfile for this project.

Dependabot requires a Dockerfile to evaluate your project's current Docker dependencies. It had expected to find one at the path: /Dockerfile.

If this isn't a Docker project, or if it is a library, you may wish to disable updates for it in the .dependabot/config.yml file in this repo.

View the update logs.

Api.isIdempotencyConflict error when hosting package in Firebase Cloud Function

Hi! I'm using firebase cloud functions to host the client and I have this simple boilerplate code set up to add a customer:

import * as functions from 'firebase-functions';
const gocardless = require('gocardless-nodejs');
const constants = require('gocardless-nodejs/constants');
import { config } from '../goCardless/config';

const goCardless = gocardless(config.token, constants.Environments.Sandbox);

export const getPaymentUrl = functions.https.onCall(
  async (session_token, success_redirect_url) => {
    try {
      const redirectFlow = await goCardless.redirectFlows.create({
        description: 'Collective',
        session_token,
        success_redirect_url
      });
      return redirectFlow;
    } catch (error) {
      console.log(error);
    }
  }
);

When I call getPaymentUrl in a local shell of firebase functions, it all works. And when I run it in a simple node/express server it also works.

However when I deploy the function to firebase I get this error:

TypeError: Cannot read property 'statusCode' of undefined     
at Api.isIdempotencyConflict (/workspace/node_modules/gocardless-nodejs/api/api.js:126:26)     at Api.request (/workspace/node_modules/gocardless-nodejs/api/api.js:58:22)    
at process._tickCallback (internal/process/next_tick.js:68:7) | more_vert

I think the error being displayed is likely hiding the actual error?

Versions:
firebase-functions: 3.6.0
gocardless-nodejs: 1.1.1
node: 10

Thanks, and let me know if you need any more info!

Internal error in error handling logic

Got a TypeError inside internal error handling code of the library today.

webpack://handler/node_modules/gocardless-nodejs/errors.js:29
const { statusCode, body: { error: { type, errors }, }, } = response;
^
TypeError: Cannot read property 'type' of undefined
at Function.buildFromResponse (/var/task/dist/lambda.js:11700:46)
-> webpack://handler/node_modules/gocardless-nodejs/errors.js:29:45
at Api.request (/var/task/dist/lambda.js:3748:55)
-> webpack://handler/node_modules/gocardless-nodejs/api/api.js:79:1
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async PaymentService.create (/var/task/dist/lambda.js:13225:26)
-> webpack://handler/node_modules/gocardless-nodejs/services/paymentService.js:21:1

list_for_billing_request doesn't take in a billing request ID

I'm trying to use list_for_billing_request as documented here in step 5 https://developer.gocardless.com/billing-requests/billing-request-actions:

const constants = require('gocardless-nodejs/constants');
const gocardless = require('gocardless-nodejs');
const client = gocardless('your_access_token_here', constants.Environments.Sandbox);

// List of billing request institutions for a country code.
const institutions = await client.institutions.list_for_billing_request("BR123", { countryCode: 'GB'});

I switched to using Typescript after that code didn't work, and it seems there just isn't a first argument for the billing request ID.

It's defined like so, ids in InstitutionListForBillingRequestRequest is for ids of the institutions. Also you can see it's country_code not countryCode as in the documentation.

interface InstitutionListForBillingRequestRequest {
    country_code: string;
    ids?: string[];
    search?: string;
}
export declare class InstitutionService {
    private api;
    constructor(api: any);
    list(requestParameters: InstitutionListRequest): Promise<InstitutionListResponse>;
    list_for_billing_request(requestParameters: InstitutionListForBillingRequestRequest): Promise<InstitutionListResponse>;
}

No matter how I try to call it, I get an error saying resource not found and you can see the path the request is made to is:

/billing_requests/:identity/institutions?country_code=gb

I can't see anyway to get the ID of the billing request in place of the :identity

Typescript experience is not great

Hi

I guess you guys have put a lot of efforts in adding typescript support for a lib that wasn't originally designed for it - and thank you for that.

But it seems the typescript support is incomplete and not conveinient - which in the end gives more difficulties than help. I think it could be improved by changing a few things I listed there and that I (and probably others) have found confusing.

Expected

As the library provides Typescript definitions, I'd like to rely on them to speed up the developments and learn the API faster through autocompletion - so that I get more time for my core business.

Actual

Through a very simple use case (listing clients), I experienced 3 issues with the provided typings:

Issue 1: Importing the index is not enough

Expectation:

As 99% of the libs on npm, I expect to import the lib name and use it

import GC from "gocardless-nodejs"

const client = new GC(...);
// or
const client = new GC.Client(...);

// and for other exports from the lib
const res = await client.customers.list({ sort_field: GC.constants.CustomerSortField.CreatedAt });

Actual:

import GC from "gocardless-nodejs"
import { GoCardlessClient } from "gocardless-nodejs/client";
import { CustomerSortField } from "gocardless-nodejs/constants";

const client = new GC(...); // does not work
const client = new GC.GoCardlessClient(...); // does not work
const client = new GC.Client(...); // does not work

const client = new GoCardlessClient(); // works from a second import

// and a third import for the consts
const res = await gc.customers.list({ sort_field: CustomerSortField.CreatedAt });

Issue 2: The typescript structure do not match the NodeJS doc of the lib

Expectation:

The README.md of the lib gives the following Getting Started

// Initialise the client.
const client = gocardless(
  process.env.GC_ACCESS_TOKEN,
  constants.Environments.Sandbox,
  { raiseOnIdempotencyConflict: true },
);

Therefore, I expect to use the example - with the power of typescript

Actual:

This does not work

// Initialise the client.
const client = gocardless(
  process.env.GC_ACCESS_TOKEN,
  constants.Environments.Sandbox,
  { raiseOnIdempotencyConflict: true },
);

I had to dig into the lib and to find the issue #125 to find out that Typescript has a totally different contract

import { Environments } from "gocardless-nodejs/constants";
import { GoCardlessClient } from "gocardless-nodejs/client";
const client = new GoCardlessClient("your_access_token_here", Environments.Sandbox);

Issue 3: I get unexpected typing behaviors with documentation

Expectation:

I could pass an optional "after" parameter to gc.customers.list in order to paginate

const clients = await gc.customers.list({ limit: "10", sort_field: CustomerSortField.CreatedAt, sort_direction: CustomerSortDirection.Desc, ...(lastCursor != null ? { after: lastCursor } : {})  });

Actual:

This conditional spread causes a type error causing an implicit any of the return of the function.

Dependabot couldn't find a Dockerfile for this project

Dependabot couldn't find a Dockerfile for this project.

Dependabot requires a Dockerfile to evaluate your project's current Docker dependencies. It had expected to find one at the path: /Dockerfile.

If this isn't a Docker project, or if it is a library, you may wish to disable updates for it in the .dependabot/config.yml file in this repo.

View the update logs.

Error with node modules

Hi there,

I'm getting a bunch of package errors once I install gocardless-nodejs and then import into my project. I've tried installing and updating the packages, but the errors still persist. Is there something else I can do to resolve the issue?

The only relevant code added to my project after importing is const gocardless = require('gocardless-nodejs');

These are the errors I'm getting

`ERROR in ./node_modules/dns/node_modules/native-dns/lib/server.js
Module not found: Error: Can't resolve 'dgram' in '/Users/benwozak/Documents/Workspace/CaaS-Integrator-Portal/node_modules/dns/node_modules/native-dns/lib'
@ ./node_modules/dns/node_modules/native-dns/lib/server.js 23:12-28
@ ./node_modules/dns/node_modules/native-dns/dns.js
@ ./node_modules/dns/lib/dns.js
@ ./node_modules/gocardless-nodejs/node_modules/cacheable-lookup/index.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/normalize-arguments.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/create.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/index.js
@ ./node_modules/gocardless-nodejs/api/api.js
@ ./node_modules/gocardless-nodejs/client.js
@ ./node_modules/gocardless-nodejs/index.js
@ ./src/components/billing/goCardless/CardlessInputs.jsx
@ ./src/components/billing/CreateBillingUser.jsx
@ ./src/components/billing/SetupBillingStepper.jsx
@ ./src/views/BillingView.jsx
@ ./src/App.js
@ ./src/index.js
@ multi react-hot-loader/patch ./src/index.js webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr

ERROR in ./node_modules/dns/node_modules/native-dns/lib/utils.js
Module not found: Error: Can't resolve 'dgram' in '/Users/benwozak/Documents/Workspace/CaaS-Integrator-Portal/node_modules/dns/node_modules/native-dns/lib'
@ ./node_modules/dns/node_modules/native-dns/lib/utils.js 21:12-28
@ ./node_modules/dns/node_modules/native-dns/lib/platform.js
@ ./node_modules/dns/node_modules/native-dns/dns.js
@ ./node_modules/dns/lib/dns.js
@ ./node_modules/gocardless-nodejs/node_modules/cacheable-lookup/index.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/normalize-arguments.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/create.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/index.js
@ ./node_modules/gocardless-nodejs/api/api.js
@ ./node_modules/gocardless-nodejs/client.js
@ ./node_modules/gocardless-nodejs/index.js
@ ./src/components/billing/goCardless/CardlessInputs.jsx
@ ./src/components/billing/CreateBillingUser.jsx
@ ./src/components/billing/SetupBillingStepper.jsx
@ ./src/views/BillingView.jsx
@ ./src/App.js
@ ./src/index.js
@ multi react-hot-loader/patch ./src/index.js webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr

ERROR in ./node_modules/native-dns-cache/lookup.js
Module not found: Error: Can't resolve 'dgram' in '/Users/benwozak/Documents/Workspace/CaaS-Integrator-Portal/node_modules/native-dns-cache'
@ ./node_modules/native-dns-cache/lookup.js 21:12-28
@ ./node_modules/native-dns-cache/index.js
@ ./node_modules/dns/node_modules/native-dns/lib/platform.js
@ ./node_modules/dns/node_modules/native-dns/dns.js
@ ./node_modules/dns/lib/dns.js
@ ./node_modules/gocardless-nodejs/node_modules/cacheable-lookup/index.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/normalize-arguments.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/create.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/index.js
@ ./node_modules/gocardless-nodejs/api/api.js
@ ./node_modules/gocardless-nodejs/client.js
@ ./node_modules/gocardless-nodejs/index.js
@ ./src/components/billing/goCardless/CardlessInputs.jsx
@ ./src/components/billing/CreateBillingUser.jsx
@ ./src/components/billing/SetupBillingStepper.jsx
@ ./src/views/BillingView.jsx
@ ./src/App.js
@ ./src/index.js
@ multi react-hot-loader/patch ./src/index.js webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr

ERROR in ./node_modules/dns/node_modules/native-dns/lib/platform.js
Module not found: Error: Can't resolve 'fs' in '/Users/benwozak/Documents/Workspace/CaaS-Integrator-Portal/node_modules/dns/node_modules/native-dns/lib'
@ ./node_modules/dns/node_modules/native-dns/lib/platform.js 23:9-22
@ ./node_modules/dns/node_modules/native-dns/dns.js
@ ./node_modules/dns/lib/dns.js
@ ./node_modules/gocardless-nodejs/node_modules/cacheable-lookup/index.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/normalize-arguments.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/create.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/index.js
@ ./node_modules/gocardless-nodejs/api/api.js
@ ./node_modules/gocardless-nodejs/client.js
@ ./node_modules/gocardless-nodejs/index.js
@ ./src/components/billing/goCardless/CardlessInputs.jsx
@ ./src/components/billing/CreateBillingUser.jsx
@ ./src/components/billing/SetupBillingStepper.jsx
@ ./src/views/BillingView.jsx
@ ./src/App.js
@ ./src/index.js
@ multi react-hot-loader/patch ./src/index.js webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr

ERROR in ./node_modules/gocardless-nodejs/node_modules/got/dist/source/request-as-event-emitter.js
Module not found: Error: Can't resolve 'fs' in '/Users/benwozak/Documents/Workspace/CaaS-Integrator-Portal/node_modules/gocardless-nodejs/node_modules/got/dist/source'
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/request-as-event-emitter.js 3:13-26
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/as-stream.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/index.js
@ ./node_modules/gocardless-nodejs/api/api.js
@ ./node_modules/gocardless-nodejs/client.js
@ ./node_modules/gocardless-nodejs/index.js
@ ./src/components/billing/goCardless/CardlessInputs.jsx
@ ./src/components/billing/CreateBillingUser.jsx
@ ./src/components/billing/SetupBillingStepper.jsx
@ ./src/views/BillingView.jsx
@ ./src/App.js
@ ./src/index.js
@ multi react-hot-loader/patch ./src/index.js webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr

ERROR in ./node_modules/gocardless-nodejs/node_modules/got/dist/source/utils/get-body-size.js
Module not found: Error: Can't resolve 'fs' in '/Users/benwozak/Documents/Workspace/CaaS-Integrator-Portal/node_modules/gocardless-nodejs/node_modules/got/dist/source/utils'
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/utils/get-body-size.js 3:13-26
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/normalize-arguments.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/create.js
@ ./node_modules/gocardless-nodejs/node_modules/got/dist/source/index.js
@ ./node_modules/gocardless-nodejs/api/api.js
@ ./node_modules/gocardless-nodejs/client.js
@ ./node_modules/gocardless-nodejs/index.js
@ ./src/components/billing/goCardless/CardlessInputs.jsx
@ ./src/components/billing/CreateBillingUser.jsx
@ ./src/components/billing/SetupBillingStepper.jsx
@ ./src/views/BillingView.jsx
@ ./src/App.js
@ ./src/index.js
@ multi react-hot-loader/patch ./src/index.js webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr`

Cannot deploy on Firebase Cloud Functions

Hello! I am using Firebase Cloud Functions and I want to integrate it with the API, but when I try to deploy my functions, I get an error.

The only thing I've added was the

const gocardless = require("gocardless-nodejs");

and it returns an error

`Detailed stack trace: /srv/node_modules/got/dist/source/create.js:101
got.paginate = async function* (url, options) {
^

SyntaxError: Unexpected token *
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object. (/srv/node_modules/got/dist/source/index.js:7:18)`

I am using:

Firebase Functions: 3.6.1
GoCardless: 1.1.2
Node: 12.13.0

Cloud functions GotError

Hi,

while using the gocardless nodejs api in a firebase cloud functions, i have this specific error while creating a paymentFlow

{"severity":"ERROR","message":"Unhandled error GotError: connect ECONNREFUSED 127.0.0.1:443\n    at onError (/Users/herve/dev/xxxxxxx/functions/node_modules/got/dist/source/request-as-event-emitter.js:140:29)\n    at handleRequest (/Users/herve/dev/xxxxxxxx/functions/node_modules/got/dist/source/request-as-event-emitter.js:173:17)\n    at processTicksAndRejections (internal/process/task_queues.js:93:5)\n    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1145:16) {\n  name: 'RequestError',\n  code: 'ECONNREFUSED'\n}"}

Do you have any ideas on what could cause this ?
It seem to be related to got

Edit: The error seem to be coming from the mailjet library. There must be some conflic with the http-proxy-agent dependency

isIdempotencyConflict: error combining mailgun-js and gocardless-nodejs

I ran into a bug when I import mailgun-js and gocardless-nodejs libs in the same project.

Here is the error message I got:

(node:62883) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'statusCode' of undefined
    at Api.isIdempotencyConflict (/Users/johndoe/Github/johndoe-admin/node_modules/gocardless-nodejs/api/api.js:125:26)
    at Api.request (/Users/johndoe/Github/johndoe-admin/node_modules/gocardless-nodejs/api/api.js:58:22)
(node:62883) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:62883) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

You need to install 3 libs to reproduce the problem:

npm i mailgun-js gocardless-nodejs cuid

Here is the full code you can use (don't forget to add your GoCardless PRIVATE_API_KEY):

const mailgun = require("mailgun-js");
const constants = require("gocardless-nodejs/constants");
const gocardless = require("gocardless-nodejs");

const cuid = require("cuid");

(async function () {
  const client = gocardless(
    "XXXXXX_PRIVATE_API_KEY_XXXXXX",
    constants.Environments.Sandbox
  );

  const session_token = cuid();
  const redirectFlow = await client.redirectFlows.create({
    description: "my product",
    session_token,
    success_redirect_url:
      "https://anyredirecturl.com`,
    prefilled_customer: {
      given_name: "john",
      family_name: "doe",
      email: "[email protected]",
      company_name: "JD Company",
      address_line1: "Hi",
      postal_code: "12334",
    },
  });
})();

It might be an error with the got lib GoCardless uses.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.