Git Product home page Git Product logo

typescript-sdk's Introduction

wallee TypeScript Library

The wallee TypeScript library wraps around the wallee API. This library facilitates your interaction with various services such as transactions, accounts, and subscriptions.

Documentation

wallee Web Service API

Requirements

  • npm 6+

Installation

NOTE: Highly recommended to use TypeScript SDK in server-side applications.
Use front-end frameworks such as Angular at your own risk, as the application might be incompatible or cause a potential threat that the application user information (such as secret keys) might be revealed publicly in the browser.

NPM install (recommended)

npm install wallee

Usage

The library needs to be configured with your account's space id, user id, and secret key which are available in your wallee account dashboard. Set space_id, user_id, and api_secret to their values. You can also add custom default headers to the configuration.

Configuring a Service

'use strict';
import { Wallee } from 'wallee';

let spaceId: number = 405;
let userId: number = 512;
let apiSecret: string = 'FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=';

let config = {
    space_id: spaceId,
    user_id: userId,
    api_secret: apiSecret
    default_headers: {
        'x-meta-header-name-1': 'header-value-1',
        'x-meta-header-name-2': 'header-value-2'
    }
}

// Transaction Service
let transactionService: Wallee.api.TransactionService = new Wallee.api.TransactionService(config);

To get started with sending transactions, please review the example below:

'use strict';
import { Wallee } from 'wallee';

let spaceId: number = 405;
let userId: number = 512;
let apiSecret: string = 'FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=';

let config = {
    space_id: spaceId,
    user_id: userId,
    api_secret: apiSecret
}

// Transaction Service
let transactionService: Wallee.api.TransactionService = new Wallee.api.TransactionService(config);

// TransactionPaymentPage Service
let transactionPaymentPageService: Wallee.api.TransactionPaymentPageService = new Wallee.api.TransactionPaymentPageService(config);

// LineItem of type PRODUCT
let lineItem: Wallee.model.LineItemCreate = new Wallee.model.LineItemCreate();
lineItem.name='Red T-Shirt';
lineItem.uniqueId='5412';
lineItem.sku='red-t-shirt-123';
lineItem.quantity=1;
lineItem.amountIncludingTax=3.50;
lineItem.type=Wallee.model.LineItemType.PRODUCT;

// Transaction
let transaction: Wallee.model.TransactionCreate = new Wallee.model.TransactionCreate();
transaction.lineItems=[lineItem];
transaction.autoConfirmationEnabled=true;
transaction.currency='EUR';

transactionService.create(spaceId, transaction).then((response) => {
    let transactionCreate: Wallee.model.Transaction = response.body;
    transactionPaymentPageService.paymentPageUrl(spaceId, <number> transactionCreate.id).then(function (response) {
        let pageUrl: string = response.body;
        // window.location.href = pageUrl;
    });
});

Configure connection timeout

Connection timeout determines how long the request can take, before cutting off the connection. Same value applies both to inner 'Read timeout' and 'Connection timeout' of a NPM request module.

Default connection timeout is 25s.

Connection timeout can be set 2 ways:

  1. Via configuration property 'timeout' providing value in seconds.
let config = {
    ... other properties ...
    timeout: 15
}
let transactionService: Wallee.api.TransactionService = new Wallee.api.TransactionService(config);
  1. Via service property 'timeout' providing value in seconds
let config = {
    ... properties ...
}
let transactionService: Wallee.api.TransactionService = new Wallee.api.TransactionService(config);
transactionService.timeout = 15;

Integrating Webhook Payload Signing Mechanism into webhook callback handler

The HTTP request which is sent for a state change of an entity now includes an additional field state, which provides information about the update of the monitored entity's state. This enhancement is a result of the implementation of our webhook encryption mechanism.

Payload field state provides direct information about the state update of the entity, making additional API calls to retrieve the entity state redundant.

⚠️ Warning: Generic Pseudocode

The provided pseudocode is intentionally generic and serves to illustrate the process of enhancing your API to leverage webhook payload signing. It is not a complete implementation.

Please ensure that you adapt and extend this code to meet the specific needs of your application, including appropriate security measures and error handling. For a detailed webhook payload signing mechanism understanding we highly recommend referring to our comprehensive Webhook Payload Signing Documentation.

app.post('/webhook/callback', (req: Request, res: Response) => {
    const requestPayload: string = req.body;
    const signature: string | undefined = req.headers['x-signature'] as string;

    if (!signature) {
        // Make additional API call to retrieve the entity state
        // ...
    } else {
        if (webhookEncryptionService().isContentValid(signature, requestPayload)) {
            // Parse requestPayload to extract 'state' value
            // Process entity's state change
            // ...
        }
    }

    // Process the received webhook data
    // ...

});

License

Please see the license file for more information.

typescript-sdk's People

Contributors

wallee-deployment-user avatar vttn avatar andrewrowanwallee avatar edgaraswallee avatar

Stargazers

Buğra Bilgin avatar Tim Izzo avatar Lukas Lewandowski avatar  avatar  avatar  avatar Kazoo avatar  avatar Steffen Wirth avatar

Watchers

James Cloos avatar  avatar  avatar  avatar  avatar thibault-mambour avatar

typescript-sdk's Issues

Support option to use native node modules for crypto-js, bluebird (and request)

"dependencies": {
        "bluebird": "^3.5.0",
        "crypto-js": "^3.1.8",
        "request": "^2.81.0",
}

While I understand that all node versions should be supported it would be convenient to have them somehow optional. The main reason is to reduce the overall size of a code bundle that uses the sdk. While a smaller bundle size is generally a good thing there's also an economic aspect to it in environments such as AWS Lambda. Smaller bundles = less parsing=execution time + less reserved memory needed.

  • bluebird: Native promises are supported since node 0.12
  • crypto-js: the biggest dependency of all. In case the node runtime is compiled with the openssl crypto module (e.g. the AWS lambda node versions are) not necessary.

Optional

  • request: while native http or https could be used instead I understand the inconvenience of using those low-level apis

Do you see any possibility?

Open PR

I opened pull request #6 a while ago which hasn't had any comments / activity. Is the library maintained and are you accepting contributions?

Double declaration of spaceId

The question is whether spaceId can be omitted from the config object.
It seems that it's being sent later, when using the service methods transactionService.create(spaceId, transaction).

In this case api_secret belongs to user_id and the SDK could send requests to different spaces the user belongs to, by choosing the spaceId on every method.

Promise rejection warning

eg. on successful transactionService.read() the following warning appears in the console.
(node:41972) Warning: a promise was rejected with a non-error: [object Object]

The error can be found in a few places when doing..

if (response.statusCode){
  if (response.statusCode >= 200 && response.statusCode <= 299) {
     resolve()
  } else {
     reject()
  }
}
reject()

=> The last reject() is being called always. Either do return resolve/reject() or wrap the last reject() with an else.

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.