npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cortex-atm

v1.0.7

Published

The library is the Angular module which provides access to the Cortex Platform API from application written with the Angular web framework 7 version

Downloads

64

Readme

Cortex ATM Library

The library is the Angular module which provides access to the Cortex Platform API from application written with the Angular web framework 7 version. The library contains methods to initialize the application, interacts with peripherals devices such as cash dispenser and bill acceptor, listeners for outside events.

Installation

You can install this package either with npm or with bower.

npm

npm install cortex-atm

bower

bower install cortex-atm

Requirements

angular-core 7
angular-common 7
rxjs ^5
node v10.13.0
npm 6.9.0

Usage

Create angular application

ng new cortex-test-app
cd cortex-test-app

Add the cortex library to the application

npm install cortex-atm

Adding the cortex atm module to the application

Edit the app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import {CortexAtmModule} from 'cortex-atm/modules/CortexAtmModule' // Import module from node modules

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    CortexAtmModule // Imports into the application
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Inject cortex atm service into application component

Edit the app.component.ts file:

import { Component } from '@angular/core';
import { CortexAtmPeripheralsService } from 'cortex-atm/modules/CortexAtmModule'; // Import the service from node modules

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'cortex-test-app';
  constructor(public cortexAtm: CortexAtmPeripheralsService) {} // Inject cortex atm service
}

Open bill acceptor

To open bill acceptor need to use openBillAcceptor method with two parameters

  • amount - Amount of money you expect to get from bill acceptor.
  • accountNumber - Identificator of user, it may be phone number or any other kind of identificator, the identificator will be printed on the check from fiscal printer.

This method is listener and will be notified with every puted banknotes, notification has BillAcceptor class instance and provide access to the next fields:

  • body.amount - amount of money you expect to get from bill acceptor
  • body.total - how much money is puted to bill acceptor since to call the method
  • body.lastAmount - latest denomination of banknote or coin.

For example need to get 10 from bill acceptor let's assume that user has puted 2 banknotes of 1 USD, so second notification you will get into openBillAcceptor method will be like:

  • body.amount - 10
  • body.total - 2
  • body.lastAmount - 1
import { Component } from '@angular/core';
import { CortexAtmPeripheralsService, BillAcceptor } from 'cortex-atm/modules/CortexAtmModule';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'cortex-test-app';
  constructor(public cortexAtm: CortexAtmPeripheralsService) {} // Inject cortex atm service

  public openBillAcceptorExample(): void {
    let amount = 10;
    this.cortexAtm.openBillAcceptor(amount, "clientid").onmessage = (message) => {
      let response: BillAcceptor = <BillAcceptor>JSON.parse(message.data);
      if (response.body.total == amount) { //we retrieved full amount of money
        // User puted all amount of many do something with it.
      }
    }
  }
}

Close bill acceptor

When the application retrieved full amount of money from bill acceptor it must be closed. To close bill acceptor method closeBillAcceptor must be used, this method has no parameters and doesn't return any result.

import { Component } from '@angular/core';
import { CortexAtmPeripheralsService, BillAcceptor } from 'cortex-atm/modules/CortexAtmModule';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'cortex-test-app';
  constructor(public cortexAtm: CortexAtmPeripheralsService) {} // Inject cortex atm service

  public openBillAcceptorExample(): void {
    let amount = 10;
    this.cortexAtm.openBillAcceptor(amount, "clientid").onmessage = (message) => {
      let response: BillAcceptor = <BillAcceptor>JSON.parse(message.data);
      if (response.body.total == amount) { // we got full amount of money
        this.cortexAtm.closeBillAcceptor(); // close bill acceptor
        // do something with it.
      }
    }
  }
}

Dispense money to user

In case you need ATM machine gives money to user you can use dispence method, it has one parameter with amount to be send and doesn't return any responses.

  • amount - amount of money should be send out to user, amount should be integer type.

Let's assume after you got money from user you will want to give it back to user:

import { Component } from '@angular/core';
import { CortexAtmPeripheralsService, BillAcceptor } from 'cortex-atm/modules/CortexAtmModule';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'cortex-test-app';
  constructor(public cortexAtm: CortexAtmPeripheralsService) {} // Inject cortex atm service

  public openBillAcceptorExample(): void {
    let amount = 10;
    this.cortexAtm.openBillAcceptor(amount, "clientid").onmessage = (message) => {
      let response: BillAcceptor = <BillAcceptor>JSON.parse(message.data);
      if (response.body.total == amount) {
        this.cortexAtm.closeBillAcceptor(); // close bill acceptor
        this.cortexAtm.dispense(amount); // get back money to user
      }
    }
  }
}

Listen button click events

The cortex platform provides back and ok buttons, ones will displayed under launched application so you don't need to inculde/implement these two buttons in the your application, but you can use method atmButtons() to listen events from these buttons, this method has no parameters and returns listener so the application can be notified for every tap by any of these two buttons. Event has String class instance with next values:

  • OK_BUTTON - Tap by ok button
  • BACK_BUTTON - Tap by back button

Let's add code which implements navigation, if user presses ok button application will open component with next-app-page path and back button opens previus page by previous-app-page path, you can add code like that to the constructor:

import { Component } from '@angular/core';
import { CortexAtmPeripheralsService, BillAcceptor } from 'cortex-atm/modules/CortexAtmModule';
import { Router } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'cortex-test-app';
  constructor(public cortexAtm: CortexAtmPeripheralsService, public router: Router) { // Inject cortex atm service
    cortexAtm.atmButtons().onmessage = (message) => { // button listener
      let data = JSON.parse(message.data); // parses data 
      switch(data.type) {
        case "OK_BUTTON": { // if ok button was taped
          router.navigate(['next-app-page']);
          break;
        }

        case "BACK_BUTTON": { // if back button was taped
          router.navigate(['previous-app-page']);
          break;
        }
        
        default: {
          break;
        }

      }
    }
  }

  public openBillAcceptorExample(): void {
    let amount = 10.50;
    this.cortexAtm.openBillAcceptor(amount, "clientid").onmessage = (message) => {
      let response: BillAcceptor = <BillAcceptor>JSON.parse(message.data);
      if (response.body.total == amount) {
        this.cortexAtm.closeBillAcceptor();
        // User puted all amount of many do something with it.
        this.cortexAtm.dispense(amount); // get back money to user
      }
    }
  }
}