Add crate to your Cargo.toml
[dependencies]
voucherify_rs = "1.0.0"
Import voucherify-rs crate
extern crate voucherify_rs;
Create voucherify api object
let voucherify = Voucherify::new("<YOUR_APP_ID_GOES_HERE>",
"<YOUR_SECRET_KEY_GOES_HERE>");
Optionally, you can specify API Endpoint if you want to use Voucherify running in a specific region.
let voucherify: &mut Voucherify = &mut Voucherify::new("<YOUR_APP_ID_GOES_HERE>",
"<YOUR_SECRET_KEY_GOES_HERE>");
voucherify.set_endpoint("https://<region>.api.voucherify.io");
Provided methods:
- Create Voucher
- Get Voucher
- Update Voucher
- Delete Voucher
- List Vouchers
- Enable Voucher
- Disable Voucher
let new_voucher = Voucher::new()
.voucher_type(VoucherType::DISCOUNT_VOUCHER)
.discount(DiscountType::AMOUNT, 20)
.build();
let created_voucher = voucherify.voucher_create(new_voucher).send().unwrap();
let single_voucher: Voucher = voucherify.voucher_get("D1dsWQVE").send().unwrap();
let updated_metadata = Metadata::new()
.number("number", 32)
.string("is", "working")
.boolean("is_amazing", true)
.build();
let updated_voucher = voucherify.voucher_update("D1dsWQVE")
.category("hello_world")
.active(true)
.metadata(updated_metadata)
// .gift_amount(1234)
.send().unwrap();
let was_voucher_deleted: bool = voucherify.voucher_delete(created_voucher_code.as_str()).send().unwrap();
let voucher_list: Vec<Voucher> = voucherify.voucher_list().limit(19).page(1).send().unwrap();
let was_voucher_enabled: bool = voucherify.voucher_enable("D1dsWQVE").send().unwrap();
let was_voucher_disabled: bool = voucherify.voucher_disable("D1dsWQVE").send().unwrap();
Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)
- 2019-06-19 -
1.0.0
- Added support for custom API endpoint, that allows to connect to projects created in specific Voucherify region. Additionally, updated the model here and there (more Option-al variables + added simple VouchersList).