Skip to content

Commit

Permalink
docs: update README example to unavailable reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
Mollemoll committed May 16, 2024
1 parent 450c2f8 commit e79a0dd
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ tax_ids = { version = "0.1.0", features = ["eu_vat", "gb_vat"] }

```rust
use tax_ids::TaxId;
use tax_ids::VerificationStatus::{Verified, Unverified, Unavailable};
use tax_ids::UnavailableReason::{ServiceUnavailable, Timeout, Block, RateLimit};

fn main () {
fn main() {
// Instantiate a new TaxId object. This can raise a ValidationError.
let tax_id = match TaxId::new("SE556703748501") {
Ok(tax_id) => tax_id,
Expand Down Expand Up @@ -73,27 +75,37 @@ fn main () {
Err(e) => {
println!("VerificationError: {}", e);
return;
},
}
};
assert_eq!(verification.status(), &tax_ids::VerificationStatus::Verified);

assert_eq!(verification.status(), &Verified);

// VerificationStatus can take one out of three different statuses:
// - Verified - The tax ID is legitimate.
// - Unverified - The tax ID is not legitimate.
// - Unavailable - The verification couldn't be performed (due to rate limit, database unavailability, etc.).
// - Unavailable(UnavailableReason) - The verification couldn't be performed due to some reason.

// These statuses are what you want to act upon.
match verification.status() {
tax_ids::VerificationStatus::Verified => {
Verified => {
// Proceed with payment
},
tax_ids::VerificationStatus::Unverified => {
}
Unverified => {
// Ask the customer to provide a proper tax ID
},
tax_ids::VerificationStatus::Unavailable => {
}
Unavailable(reason) => {
// Process payment and verify the tax ID later?
},

match reason {
ServiceUnavailable | Timeout => {},
Block => {
// Adapt to your IP / VAT being blocked
}
RateLimit => {
// Consider how to avoid rate limiting
}
}
}
}

// The full verification object:
Expand Down

0 comments on commit e79a0dd

Please sign in to comment.