# Catalog & Inventory

PoyntOS supports out-of-the-box catalog and inventory. Poynt Product Service (opens new window) provides a way to access the catalog from the terminal.

TIP

If you would like to learn more about this topic, you can refer to the Catalog Model (opens new window) and Product Model (opens new window).

# Catalog Fetching

Product Service provides multiple ways to access the catalog. Additionally, you can either get all the products alone or get the complete catalog with the categories and metadata.

The following code shows how to fetch the entire catalog from the local content provider or from the cloud.

try {
    productService.getRegisterCatalogWithProducts(catalogWithProductListener);
    // Limit the use of this method since it fetches from the cloud, it is data intensive
    // productService.getRegisterCatalogWithProductsFromCloud(catalogWithProductListener);
} catch (RemoteException e) {
    e.printStackTrace();
}

private IPoyntProductCatalogWithProductListener catalogWithProductListener = new IPoyntProductCatalogWithProductListener.Stub() {
    @Override
    public void onResponse(CatalogWithProduct catalogWithProduct, PoyntError poyntError) throws RemoteException {
        if (poyntError == null) {
            try {
                // CatalogWithProduct has a list of CategoryWithProduct
                // CategoryWithProduct has a list of CatalogItemWithProduct
                // CatalogItemWithProduct has the actual Product
            } catch (Exception e) {
                Log.d(TAG, e.toString());
            }
        } else {
            Log.e(TAG, poyntError.toString())
        }
    });
};

# Product Scanning

You can scan products using the scanner API provided by PoyntOS. The scanner library supports the most commonly used QR and bar codes.

The scanner can be invoked by starting an intent with optional extras:

Intent intent = new Intent("poynt.intent.action.SCANNER");
// "MULTI" or "SINGLE" allows for multiple product scans in a single go
intent.putExtra("MODE", "SINGLE");
// if multi mode - also register the receiver
IntentFilter scannerIntentFilter = new IntentFilter();
startActivityForResult(intent, SCANNER_REQUEST_CODE);

// If multi scan mode is enabled register for a broadcast to receive the codes
scannerIntentFilter.addAction("poynt.intent.action.SCANNER_RESULT");
registerReceiver(scanResultReceiver, scannerIntentFilter);

The result for a scan is obtained in the onActivityResult of the calling activity.

// Check which request we're responding to
if (requestCode == SCANNER_REQUEST_CODE) {
    // Make sure the request was successful
    if (resultCode == RESULT_OK) {
        // get scan results
        String code = data.getStringExtra("CODE");
        String format = data.getStringExtra("FORMAT");
    } else if (resultCode == RESULT_CANCELED) {
        Log.d(TAG, "Result canceled");
    }
    // unregister for the broadcast receiver if you have previously registered for
    unregisterReceiver(scanResultReceiver);
}

# Product Information Update

Updating a product can be done from a smart terminal application. Please follow the three steps outline below to correctly update a product.

  1. Create a .json patch for the fields that need to be updated.

The sample code below shows how to create a patch to changing the price


public static String getProductPatch(Product product) {
        List<JsonPatchElement> patchElements = new ArrayList<JsonPatchElement>();
        JsonArray patchArray = new JsonArray();
        if (product!= null) {
            // price
            if (product.getPrice() != null) {
                // update
                JsonPatchElement<Long> priceElement = new JsonPatchElement<>();
                priceElement.setOp("add");
                priceElement.setPath("/price/amount");
                priceElement.setValue(product.getPrice().getAmount());
                patchElements.add(priceElement);
            } else {
                // remove
                JsonPatchElement<Long> priceElement = new JsonPatchElement<>();
                priceElement.setOp("remove");
                priceElement.setPath("/price/amount");
                patchElements.add(priceElement);
            }
        }
        JsonElement patch = new Gson().toJsonTree(patchElements);
        return patch.toString();
    }
  1. Send the json patch to update the product.
productService.updateProduct(product.getId(), getProductPatch(product), productServiceListener);
  1. Refresh the local catalog by fetching it from the cloud

# Receipt Printing

GoDaddy Poynt provides an easy way to print receipts from your applications for transactions and orders using the IPoyntReceiptPrintingService (opens new window)

Binding to IPoyntReceiptPrintingService

context.bindService(Intents.getComponentIntent(
                Intents.COMPONENT_POYNT_RECEIPT_PRINTING_SERVICE), connection, Context.BIND_AUTO_CREATE);
...
...
private ServiceConnection connection = new ServiceConnection() {
    @Override
    public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        Log.d(TAG, "Receipt printing service connected");
        if (iBinder != null) {
            receiptPrintingService = IPoyntReceiptPrintingService.Stub.asInterface(iBinder);
        }
    }
    @Override
    public void onServiceDisconnected(ComponentName componentName) {
        Log.d(TAG, "Receipt Printing service disconnected");
        receiptPrintingService = null;
    }
};

# Transaction Receipt Printing

To print a transaction receipt, you must pass in the transaction Id and the tip amount to the printTransactionReceipt method of the receiptPrintingService.

String jobId = UUID.randomUUID().toString();
receiptPrintingService.printTransactionReceipt(jobId, transactionId, 0, receiptPrintListener);

Receipt Print listener

    private IPoyntReceiptPrintingServiceListener receiptPrintListener = new IPoyntReceiptPrintingServiceListener.Stub() {
        @Override
        public void printQueued() throws RemoteException {
            Log.d(TAG, "Printing  queued");
        }

        @Override
        public void printFailed(PrinterStatus printerStatus) throws RemoteException {
            Log.d(TAG, "Printing failed with status " + printerStatus.getMessage());
        }
    };

# Order Receipt Printing

Order receipts can be printed by passing in the order Id as shown in the snippet below.

String jobId = UUID.randomUUID().toString();
receiptPrintingService.printOrderReceipt(jobId, orderId, receiptPrintListener);
Last Updated: 6/13/2023, 12:04:00 PM