ocrl-mock

Crates.ioocrl-mock
lib.rsocrl-mock
version0.1.0
created_at2025-09-04 02:08:08.016244+00
updated_at2025-09-04 02:08:08.016244+00
descriptionMock C ABI library for OCRL (Octopus Card Reader Library) - provides test implementations for payment terminal integration
homepage
repositoryhttps://github.com/caiguanhao/ocrl-mock
max_upload_size
id1823531
size46,504
CGH (caiguanhao)

documentation

README

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.

Commit count: 1

cargo fmt