0.5.3 • Published 5 years ago

xsolla v0.5.3

Weekly downloads
14
License
ISC
Repository
github
Last release
5 years ago

Xsolla Node Client

A Node.js client for the Xsolla API. Written in TypeScript to provide you with all the type checking and auto-completion convenience supported by most modern JS IDEs. 👌

Installation

Pull in the package with npm:

npm install xsolla

Usage

Initialize Xsolla:

const Xsolla = require('xsolla').default;

const client = new Xsolla({
    merchantId: 123456,
    apiKey: 'abc123',
})

Projects

The Xsolla client exposes a projects property that can be used to create, update and read projects attached to your merchant account.

Create a project

client.projects.create({
    name: ["My brand new Xsolla project"],
    url: 'https://example.com',
}).then((project) => console.log('Created new project', project));

Returns a promise for a Project model.

Get a project:

const project = await client.projects.get({ project_id: 123456 })

Returns a promise for a Project model.

Fetch all projects

const projects = client.projects.all();

Returns a promise for an array of Project models.

The Project Model

The Project model is an instance of a project that you've either created or fetched

Create a payment token

You can create payment tokens directly from a Project model. (Obtained by either Xsolla.projects.get() or Xsolla.projects.create())

const { token } = await project.createPaymentToken({
    user: {
        id: {
            value: '47',
        }
    },
    
    settings: {
        mode: 'sandbox',
    },
   
    purchase: {
        checkout: {
            amount: 13.37,
            currency: 'USD',
        }
    }
});

Create a payment link

const url = await project.createPaymentUrl({
    user: {
         id: {
             value: '47',
         }
     },
     
     settings: {
         mode: 'sandbox',
     },
    
     purchase: {
         checkout: {
             amount: 13.37,
             currency: 'USD',
         }
     }
});

Update a project

const updatedProject = await project.update({
    name: ["Some other Xsolla project name"],
});

Returns a promise for an updated Project model.

Validate an incoming webhook

app.post('/webhooks/xsolla', (req, res) => {
    try {
        project.validateWebhookRequest(req.getHeader('authorization'), req.rawBody);   
    } catch (xsollaException) {
        res.send(xsollaException.jsonResponse());
        res.status(xsollaException.httpResponseCode).end();
    }
});

Project's validateWebhookRequest() method throws an XsollaException for unauthorized requests.

License

This repository is licensed under the ISC license.

Copyright (c) 2019, Jørgen Vatle.

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago