ocrl-mock 0.1.0

Mock C ABI library for OCRL (Octopus Card Reader Library) - provides test implementations for payment terminal integration
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented0 out of 3 items with examples
  • Size
  • Source code size: 46.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 412.31 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • caiguanhao/ocrl-mock
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • caiguanhao

OCRL Mock Library

A mock implementation of the OCRL (Octopus Card Reader Library) C ABI for testing purposes. This library provides a test-friendly simulation of payment terminal operations including card enquiry, deduction, and settlement functions.

Installation

From Crates.io

cargo add ocrl-mock

From Source

git clone https://github.com/caiguanhao/ocrl-mock.git
cd ocrl-mock
cargo build --release

Usage

As a Dependency

Add this to your Cargo.toml:

[dependencies]
ocrl-mock = "0.1.0"

If you have the actual OCRL library (libocrl.a) for Linux x86_64 but need to develop and test on macOS or other systems:

[target.'cfg(not(all(target_os = "linux", target_arch = "x86_64")))'.dependencies]
ocrl-mock = "0.1.0"

build.rs file in your project root:

fn main() {
    if cfg!(all(target_os = "linux", target_arch = "x86_64")) {
        // Link against libocrl.a placed in the lib/ directory
        println!("cargo:rerun-if-changed=lib");
        println!("cargo:rustc-link-search=native=lib");
        println!("cargo:rustc-link-lib=static=ocrl");
    }
}

Supported Commands

  • config.get - Get device configuration
  • display.img - Display image (resId 1-8)
  • scheme.enquiry - Get available promotion schemes
  • trans.request - Request transaction (card.enquiry, deduct, settle)
  • trans.perform - Perform requested transaction
  • trans.cancel - Cancel transaction

Environment Variables

You can control the mock behavior using environment variables:

  • CARD=1 - Simulates invalid card error
  • CARD=2 - Simulates card with transaction history
  • Default - Normal card with balance

Error Codes

Code Description
0 Success (communication succeeded)
-1 COM not opened
-2 Communication error with R/W
-3 responseJSON buffer size not enough
-6 Link busy

License

MIT

Disclaimer

This is a mock library for testing purposes only. It does not connect to real hardware and should not be used in production environments where actual payment processing is required.