@alliedpayment/alliedjs
v11.3.0
Published
Facade used to send HTTP/s request to Allied's API
Downloads
54
Keywords
Readme
Alliedjs
Facade for Allied REST api.
This project is built in Typescript.
Getting Started
- Set Environment vars
ALLIED_API_URL (default prod=https://api.alliedpayment.com)
ALLIED_PUBLIC_KEY (required)
ALLIED_PRIVATE_KEY (required)
- Install
npm install @alliedpayment/alliedjs
- Import package
- Javascript
const allied = require("@alliedpayment/alliedjs");
- Typescript
import allied from "@alliedpayment/alliedjs";
For example, if you'd like to get a customer.
allied.customer.getCustomer(customerId: string)
Allied API Auth
For basic one user scripts you can persist auth by setting
allied.setPersistantAuthHeaders({username:'nate.ross'});
OR
For mutliple user sessions some parts of the API will require a user auth context.
allied.getCustomer(customerId: string, authContext?: AuthContext): Promise<ApiCustomer>
Advanced Debugging
Environment Variables
PROXY_PROTOCOL (default='http')
PROXY_PORT (example 3000)
PROXY_HOST (example localhost)
HTTP_CLIENT_LOGGING (default false)
HTTP_CLIENT_TIMEOUT (default 1000000)
Examples
import log from '@alliedpayment/logger';
const main = async () => {
try {
const res = await allied.getVersion();
log.info(`response status code ${res.status}`);
log.info('version: ', res.data);
/***
* logged to console
Current Version {
data: .....,
version: '1.109.9',
build: 'v21590'
}
*/
} catch (error) {
log.error('failed to get version', error);
}
};
const main = async () => {
const username = 'USERNAME';
const password = 'PASSWORD';
const domain = 'DOMAIN';
const multiFactorPin = '123951';
try {
const response = await allied.auth.login(username, password, domain);
if (response.authenticationResult === 'RequiresMultiFactor') {
const success = await (
await allied.auth.multiFactorAuth(
multiFactorPin,
response.user.UserName
)
).success;
if (success) {
console.log('logged in!');
} else {
console.log('Invalid multifactor code!');
}
} else if (response.authenticationResult === 'Authorized') {
console.log('logged in!');
}
} catch (error) {
console.log('Failed to login', error);
}
};
main();