Code Monkey home page Code Monkey logo

checkout-sdk-node's Introduction

build-status CI Tests CodeQL codecov

build-status GitHub release

zip badge

npm start

🚀 Install

npm install checkout-sdk-node

💻 Import

// ES6:
import { Checkout } from 'checkout-sdk-node';
// Common JS:
const { Checkout } = require('checkout-sdk-node');

If you don't have your API keys, you can sign up for a test account here.

🎬 Initialize SDK

With api keys or access credentials

Based on how your account was set up, you will either have a pair or API key or a set of access credentials. Here is how you can use the SDK in both scenarios:

// API Keys
const cko = new Checkout('sk_XXXXXXXXX', {
    pk: 'pk_XXXXXXX'
});

// Access credentials
const cko = new Checkout('your api secret here', {
    client: 'ack_XXXXXXXX',
    scope: ['gateway'], // or whatever scope required
    environment: 'sandbox', // or 'production'
});

With environment variables

If your account uses API Keys (pk_XXX + sk_XXX), you can set the following environment variables, and the SK will pick them up:

  • CKO_SECRET_KEY (with a value like sk_XXX)
  • CKO_PUBLIC_KEY (with a value like pk_XXX)

If you use access credentials (ack_XXXX), you can set the following environment variables, and the SK will pick them up:

  • CKO_SECRET
  • CKO_CLIENT (with a value like ack_XXXX)
  • CKO_SCOPE (with a value of the scope or semicolon separated scopes in case you use multiple)
  • CKO_ENVIRONMENT (with a value like sandbox or production)

Set custom config

Basides the authentication, you also have the option to configure some extra elements about the SDK

const cko = new Checkout('...', {
    ..., //other authentication config
    host: "https://myProxyExample.com", // in case you need to use a custom host for tests
    timeout: 60000,   // HTTP request timout in ms
    agent: new http.Agent({ keepAlive: true }), // custom HTTP agent
    httpClient: 'axios' // specify axios httpClient, by default fetch. Optional
});

🔧 SDK Environment (Sandbox/Production)

When using API Keys (pk_XXX + sk_XXX) the SDK will automatically figure out what environment you are using however, if you use access credentials (ack_XXXX), make sure you set the "environment" in the config, as shown above in the initialization.

⁉️ Error handling

The SDK is using promises, and you can handle errors similar to any other HTTP call.

try {
    // some async request made with the SDK
    const action = await cko.payments.request({...});
    ...
} catch (error) {
    console.log(error.name, error.http_code, error.body)
    switch (error.name) {
        ...
    }
}

Here you have all the possible SDK specific errors:

error.name error.http_code error.body
AuthenticationError 401 undefined
ActionNotAllowed 403 undefined
UrlAlreadyRegistered 409 undefined
NotFoundError 404 undefined
BadGateway 502 undefined
ValidationError 422 object
TooManyRequestsError 429 object/undefined
ValueError 429 string describing error

📖 Examples of usage

You can see examples of how to use the SDK for every endpoint documented in our API Reference. All you have to do is to navigate to the endpoint you want to use, and select "Node" for the example on the right side.

NOTE: If you use access credentials (ack_XXXX) the link to the API reference relevant to you will be shared by your Solutions Engineers.

👓 Try it on RunKit

You can try the SDK here.

checkout-sdk-node's People

Contributors

6aka avatar a-ibarra avatar armando-rodriguez-cko avatar armandojaleo avatar cko-developer-portal[bot] avatar cko-ibrahim-mahmood avatar dependabot-preview[bot] avatar dependabot[bot] avatar ioan-ghisoi avatar ioan-ghisoi-cko avatar martinseco avatar mitja-kramberger-cko avatar nazwa avatar srcarlos avatar ziyadf296 avatar

Stargazers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

checkout-sdk-node's Issues

response.header.raw not a function (Vuejs. Webpack issue)

I've tried running the basic request:

const cko = new Checkout('sk_test...');
const payment = await cko.payments.get("pay_w6ktefehnck2zlguyvocdvuhry");

But this gave me:

API Error: API Error
    at eval (webpack-internal:///./node_modules/checkout-sdk-node/dist/services/errors.js:289:18)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (webpack-internal:///./node_modules/checkout-sdk-node/dist/services/errors.js:8:103)
    at _next (webpack-internal:///./node_modules/checkout-sdk-node/dist/services/errors.js:10:194)

with an error body of: "response.header.raw not a function"

My current setup

Quasar + Vuejs
I also tried this on Nuxt.js. Got the same issue.


I also tried running it plainly as a simple nodejs script. That worked.
But as soon as it runs in a vuejs framework it seems to break. And I suspect it might be some webpack nonsense with node-fetch perhaps.

Thanks!

Sandbox testing for Giropay

I am trying to simulate payment using Giropay in my sandbox env but I keep getting "business_not_onboarded" error. Not sure what I am missing anything, here is my code.

const { Checkout } = require('checkout-sdk-node');

// Creating an environment
let secretKey = "SECRET_KEY_FROM_CHANNEL";
const cko = new Checkout(secretKey);

const createOrder = async () => {
const response = await cko.payments.request({
"source": {
"type": "giropay",
"purpose":"Mens black t-shirt L"
},
"amount": 5,
"currency": "EUR",
"success_url": "https://example.com/pay/giropay/return",
"failure_url": "https://example.com/pay/giropay/cancel",
});
console.log(Response: ${JSON.stringify(response)});
return response;
}

Here is the error I got
"body": {
"request_id": "7e12e59f-a2c6-4b88-9a82-56f6b3113b4e",
"error_type": "request_invalid",
"error_codes": [
"business_not_onboarded"
]
},

Not sure if the error is within SDK or I am missing some setting here. Please Help. Thanks

Incremental authorisation method Payments.increment doesn't expose idempotencyKey

Unlike
Payments.request (body, idempotencyKey)
and
Payments.capture(paymentId, body, idempotencyKey)
the
Payments.increment(paymentId, body)
method doesn't allow specification of an idempotency key. Since the body contains an incremental authorisation amount, the effect of a replayed transaction is to double-increment.

Additionally, and differently from the documentation, the returned payment object doesn't contain reference, metadata or a status field (example attached)

increment.txt

Testing

Environment

  • Checkout SDK version:
  • Platform and version:
  • Operating System and version:

Description

Proposed Solution

  • I may be able to implement this feature

'uploadAFile' in platforms.d.ts is not exposed for accessibility

Environment

  • Checkout SDK version: 2.3.2
  • node version: v16.15.0 (npm v8.5.5)

Description

The current codebase lacks the necessary exposure of the 'uploadAFile' functionality within the 'platforms.d.ts' declaration file. This omission is hindering accessibility and seamless integration with other components. To enhance the overall usability and maintain consistency, it's essential to expose 'uploadAFile' in 'platforms.d.ts'. This adjustment will contribute to a more cohesive and developer-friendly environment.

Major version bump 1 > 2 breaking changes?

I've tried to find the changelog as I'm wanting to know what, if any, breaking changes were include in the v2 major bump?

We're planning on bumping shortly and want to know if I can expect any breaking changes or changes to how we use the package in production.

@ioan-ghisoi-cko I saw you performed the bump, do you know?

Thanks.

Missing types in Payment Type. Payment Request

Environment

  • Checkout SDK version: 2.2.2
  • Platform and version: N/A
  • Operating System and version: N/A

Description

Missing payment types in payment request:

  • Installment
  • Unscheduled

Expected behavior

Payment request accept these payment types

Current behavior

Payment request don't accept these payment types and return an exception: The payment type is not valid

Steps to reproduce

Make a payment request using these types

Possible solution

Add these payment types.

  • I may be able to implement this bug fix

Additional information

Audit runtime dependency

codecov is defined as runtime dependency even though is a development utility (for uploading code coverage reports). Also, the currently used version has a security vulnerability. I would encourage us to also remove / audit babel as runtime dependency as it most probably only used during build time.

Ship more detailed types? Codegen from OpenAPI-spec?

Hey gang!

Looking at the typedefs of this SDK, I see a big void of actual type-safety:

Screenshot 2022-09-12 at 16 23 05

Even looking at the docs I still don't know what different endpoints are supposed to return without actually invoking the call. The problem with that is that we won't have any reconciliation reports in our sandbox environment.

This example above is just in order to showcase and issue and grokking that is a separate issue.

Suggestion: You shouldn't need to manually write the implementation of every endpoint and instead be able to automatically generate a typesafe SDK based on your OpenAPI-schema using something like the openapi-generator.

Automating this would likely:

  • Greatly reduce the amount of effort needed to put into this SDK
  • Improve your quality of life maintaining it
  • Remove inconsistencies between the actual API & this SDK
  • Improve the experience for your customers

error TS2300: Duplicate identifier 'addPaymentInstrument'.

Hello, I am using the latest version of checkout-sdk-node (2.1.0) and at the time of build. I have the following error:

Checkout SDK Error

Looking at the build source code, I see that the function is duplicated addPaymentInstrument

CHECKOUT SDK

I sent a PR to fix this error but I'm not sure if it fixes it at all.

PR

Missing Checkout features compared to Checkout SDKs in other languages

Hello,

I'm currently planning on implementing Checkout in my Node app.
After having a look at the documentation, I have seen that some actions are missing in the Node SDK compared to the Java or C# one (for instance).
Example : Standalone Authentication

I have some questions :

  • Are you planning on implementing the same features as other languages ?
    • If so, do you have a public roadmap ?
  • Do you accept pull requests ?

Thanks !

Request header field pragma is not allowed by Access-Control-Allow-Headers in preflight response

Hi Team,

I have been helping a merchant with their integration and they've been facing CROS issue.

According to the developer, they’re facing this error on local and on server

The following are the errors in local development:

"Access to fetch at ‘https://api.sandbox.checkout.com/tokens’ from origin ‘http://localhost:4200’ has been blocked by CORS policy: Request header field pragma is not allowed by Access-Control-Allow-Headers in preflight response."

The following are the error in server:
"Access to fetch at ‘https://api.sandbox.checkout.com/tokens’ from origin ‘https://prologix-test.web.app’ has been blocked by CORS policy: Request header field pragma is not allowed by Access-Control-Allow-Headers in preflight response.”

This is what they’re using:

  • Node : 14.17.6
  • Angular CLI: 12.2.5
  • Checkout sdk node: 1.0.37

I have also asked for the HAR file for the requests, look here.

I can see that in our sdk, we’re adding the pragma parameter in file /src/services/http.js line 43

Re-validating an event respond with not found error

I am having a very weird issue here. I have implemented few Bank Transfer payments such as Giropay, Sofort. They all work fine. I have added a webhook to receive all notifications which are working great. The error appears when I try to re-validate the event I received. I always get the following error

image
I have no idea why this is happening. Here is the code I am trying

const { Checkout } = require('checkout-sdk-node');
let cko = new Checkout("sk_test_xxxx");
let response = await cko.events.retrieveEvent('evt_xxxx')

Here I get the NotFound Error.

I also tried to retrieve all events for a payment id using the following code but that tells me that there are no events for the payment

const { Checkout } = require('checkout-sdk-node');
let cko = new Checkout("sk_test_xxxx");
let response = await cko.events.retrieveEvents({payment_id:'pay_xxxxx'})

So I have no clue what's happening under the hood. I received the event fine but I am not able to verify it. Could someone please shed some light on this?

Add types property to package.json

If the package has types property in package.json pointing to d.ts file it will have ts icon on npm page indicating it has build in typescript types.

For example here is the chalk package

Screenshot 2023-08-08 at 19 34 48

And here is how their package.json looks like:

Screenshot 2023-08-08 at 19 36 47

So for this package to have the same icon on npm types property should be added to package.json with the value of ./types/dist/index.d.ts.

This should be really easy to do.

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.