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.
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]
})
exportclassAppModule{}
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']
})
exportclassAppComponent{
title='cortex-test-app';
constructor(publiccortexAtm: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:
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.
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:
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: