|
|
Line 1: |
Line 1: |
| == API Overview ==
| | {{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/other-development/customize-pinpad-gui}} |
| === <big>setupCallbackHandler</big>===
| |
| <syntaxhighlight lang="java">boolean setupCallbackHandler(PinPadCallbackHandler handler)</syntaxhighlight>
| |
| This API allows you to set a custom callback handler for PINPAD inputs in your POS application. When a PIN is inputted on the PINPAD, the specified callback handler is triggered.
| |
| | |
| {|class="wizarpostable" | |
| |-
| |
| ! scope="row" colspan="2" | Parameters
| |
| |-
| |
| | handler|| '''PinPadCallbackHandler :''' Not null.
| |
| |-
| |
| ! scope="row" colspan="2" | Returns
| |
| |-
| |
| | boolean|| true: success.
| |
| |}
| |
| | |
| === <big>processCallback of PinPadCallbackHandler </big>===
| |
| <syntaxhighlight lang="java">void processCallback(byte[] data);</syntaxhighlight>
| |
| The API provides a method to set this callback handler.
| |
| | |
| {|class="wizarpostable"
| |
| |-
| |
| ! scope="row" colspan="2" | Parameters
| |
| |-
| |
| | data|| '''byte[] :''' date[0] is the count of input pin.
| |
| |}
| |
| {|
| |
| |-
| |
| |
| |
| |}
| |
| | |
| == Implementation Steps ==
| |
| # '''Initialize the PINPAD:'''
| |
| #* Before setting up the callback handler, ensure to call the ''''open'''' method to initialize the PINPAD.
| |
| # '''Setting the Callback Handler:'''
| |
| #* Use the ''''setupcallbackhandler'''' method to assign your custom callback handler.
| |
| #* Once this handler is set, the default PINPAD user interface (UI) will not appear.
| |
| # '''Handling PIN Input:'''
| |
| #* The driver will send the count of the inputted PIN to the callback handler.
| |
| #* Your application (referred to as the third-app) can then process this inputted PIN count as needed.
| |
| | |
| '''Snippet code:'''
| |
| <syntaxhighlight lang="java">
| |
| | |
| PINPadDevice device = (PINPadDevice) POSTerminal.getInstance(mContext)
| |
| .getDevice("cloudpos.device.pinpad");
| |
| | |
| device.open();
| |
| | |
| device.setupCallbackHandler(new PinPadCallbackHandler() {
| |
| @Override
| |
| public void processCallback(byte[] data) {
| |
| Log.e(TAG, "processCallback ");
| |
| | |
| mHandler.obtainMessage(PIN_KEY_CALLBACK, data[0]).sendToTarget();
| |
| }
| |
| @Override
| |
| public void processCallback(int nCount, int nExtra){
| |
| // don't need implement.
| |
| }
| |
| });
| |
| | |
| KeyInfo keyInfo = new KeyInfo(PINPadDevice.KEY_TYPE_MK_SK, 0, 0, 4);
| |
| String pan = "0123456789012345678";
| |
| OperationResult operationResult = device.waitForPinBlock(keyInfo, pan, false,
| |
| TimeConstants.FOREVER);
| |
| if (operationResult.getResultCode() == OperationResult.SUCCESS) {
| |
| byte[] pinBlock = ((PINPadOperationResult) operationResult).getEncryptedPINBlock();
| |
| sendSuccessLog2("PINBlock = " + StringUtility.byteArray2String(pinBlock));
| |
| } else {
| |
| sendFailedLog2(mContext.getString(R.string.operation_failed));
| |
| }
| |
| | |
| | |
| device.close();
| |
| </syntaxhighlight>
| |