| Crates.io | ocrl-mock |
| lib.rs | ocrl-mock |
| version | 0.1.0 |
| created_at | 2025-09-04 02:08:08.016244+00 |
| updated_at | 2025-09-04 02:08:08.016244+00 |
| description | Mock C ABI library for OCRL (Octopus Card Reader Library) - provides test implementations for payment terminal integration |
| homepage | |
| repository | https://github.com/caiguanhao/ocrl-mock |
| max_upload_size | |
| id | 1823531 |
| size | 46,504 |
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.
cargo add ocrl-mock
git clone https://github.com/caiguanhao/ocrl-mock.git
cd ocrl-mock
cargo build --release
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");
}
}
config.get - Get device configurationdisplay.img - Display image (resId 1-8)scheme.enquiry - Get available promotion schemestrans.request - Request transaction (card.enquiry, deduct, settle)trans.perform - Perform requested transactiontrans.cancel - Cancel transactionYou can control the mock behavior using environment variables:
CARD=1 - Simulates invalid card errorCARD=2 - Simulates card with transaction history| 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 |
MIT
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.