@passninja/passninja-js
v0.6.0
Published
PassNinja pass creation helper library.
Downloads
80
Readme
Contents
Installation
Use npm
or yarn
to install the passninja-js module:
npm install @passninja/passninja-js
Usage
PassNinjaClient
This function returns a newly created PassNinjaClient
object. Make sure to
pass your user credentials to make any authenticated requests.
const {PassNinjaClient} = require('@passninja/passninja-js');
const accountId = '**your-account-id**';
const apiKey = '**your-api-key**';
const passNinjaClient = new PassNinjaClient(accountId, apiKey);
We’ve placed our demo user API credentials in this example. Replace it with your actual API credentials to test this code through your PassNinja account and don't hesitate to contact PassNinja with our built in chat system if you'd like to subscribe and create your own custom pass type(s).
For more information on how to use passninja-js
once it loads, please refer to
the PassNinja JS API reference
PassNinjaClientMethods
This library currently supports methods for creating, getting, updating, and deleting passes via the PassNinja api. The methods are outlined below. Note that each method returns a promise.
Create
const simplePassObject = await passNinjaClient.pass.create(
'ptk_0x14', // passType
{discount: '50%', memberName: 'John'} // passData
);
console.log(simplePassObject.url);
console.log(simplePassObject.passType);
console.log(simplePassObject.serialNumber);
Find
Finds issued passes for a given pass template key
const passObjects = await passNinjaClient.pass.find(
'ptk_0x14' // passType or pass template key
);
Decrypt
Decrypts issued passes payload for a given pass template key
const decryptedPass = await passNinjaClient.pass.decrypt(
'ptk_0x14', // passType or pass template key
'55166a9700250a8c51382dd16822b0c763136090b91099c16385f2961b7d9392d31b386cae133dca1b2faf10e93a1f8f26343ef56c4b35d5bf6cb8cd9ff45177e1ea070f0d4fe88887' // payload
);
Get
const detailedPassObject = await passNinjaClient.pass.get(
'ptk_0x14', // passType
'840a0562-f22d-4ecf-a2d7-9ac785bed8e4' // serialNumber
);
Get Pass Template Details
const passTemplate = await passNinjaClient.passTemplates.find(
'ptk_0x14', // passTemplate key
);
console.log(passTemplate.pass_type_id);
Update
const simplePassObject = await passNinjaClient.pass.put(
'ptk_0x14', // passType
'840a0562-f22d-4ecf-a2d7-9ac785bed8e4', // serialNumber
{discount: '100%', memberName: 'Ted'} // passData
);
Delete
const deletedPassSerialNumber = await passninja.pass.delete(
'ptk_0x14', // passType,
'840a0562-f22d-4ecf-a2d7-9ac785bed8e4' // serialNumber
);
console.log(`Pass deleted. serial_number: ${deletedPassSerialNumber})); })();
Script Tag
Manually add the passninja-js script tag to the <head>
of each page on your
site in order to use PassNinjaClient
.
<!-- Somewhere in your site's <head> -->
<script src="https://js.passninja.com/v1" async></script>
Examples
Feel free to browse the Examples Folder for implementations
TypeScript support
This package includes TypeScript declarations for passninja-js. We support projects using TypeScript versions >= 3.1.