Skip to content

voucherifyio/voucherify-python-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Official Voucherify SDK for Python

Setup | Contributing | Changelog

API: Vouchers | Distributions | Redemptions | Customers | Utils


Setup

pip install 'Voucherify'

Log-in to Voucherify web interface and obtain your Application Keys from Configuration:

from voucherify import Client as voucherifyClient

client = voucherifyClient(
    application_id='YOUR-APPLICATION-ID',
    client_secret_key='YOUR-CLIENT-SECRET-KEY'
)

API Endpoint

Optionally, you can add api_endpoint to the client options if you want to use Voucherify running in a specific region. Optionally, you can add timeout to specify request's timeout in seconds. Default value is set to 3 minutes.

from voucherify import Client as voucherifyClient

client = voucherifyClient(
    application_id='YOUR-APPLICATION-ID',
    client_secret_key='YOUR-CLIENT-SECRET-KEY',
    api_endpoint='https://<region>.api.voucherify.io',
    timeout=180
)

API

This SDK is consistent with restful API Voucherify provides. Not all API methods are currently supported in this SDK, but they are coming soon.

You will find detailed description and example responses at official docs. Method headers point to more detailed descriptions of params you can use.

Vouchers API

Methods are provided within client.vouchers.* namespace.

client.vouchers.create(voucher)

Check voucher object.

client.vouchers.get(code)
client.vouchers.update(voucher)
client.vouchers.list(params)
client.vouchers.enable(code)
client.vouchers.disable(code)
client.vouchers.releaseValidationSession(code, sessionKey)

Distributions API

Methods are provided within client.distributions.* namespace.

client.distributions.publish(params)

Validations API

Methods are provided within client.validations.* namespace.

client.validations.validateVoucher(code, params)
client.validations.validateStackable(params)

Redemptions API

Methods are provided within client.redemptions.* namespace.

client.redemptions.redeem(code, tracking_id)
client.redemptions.redeemStackable(params)
client.redemptions.list(params)
client.redemptions.getForVoucher(code)
client.redemptions.rollback(redemptionId)
client.redemptions.rollback(redemptionId, reason)

Check redemption rollback object.


Customers API

Methods are provided within client.customers.* namespace.

client.customers.create(customer)

Check customer object.

client.customers.get(customerId)

customer object must contain id or source_id.

client.customers.update(customer)
client.customers.delete(customerId)

Utils

from voucherify import utils

Available methods

  • utils.calculate_price(base_price, voucher, unit_price)
  • utils.calculate_discount(base_price, voucher, unit_price)

Contributing

Bug reports and pull requests are welcome through GitHub Issues.

Changelog

  • 2022-04-06 - 2.2.2
    • Added client.vouchers.releaseValidationSession method
    • Added client.redemptions.redeemStackable method
    • Added client.validations.validateStackable method
  • 2021-05-26 - 2.2.1
    • Upload new version to pypi.org. No changes compared to 2.2.0
  • 2021-05-20 - 2.2.0
    • Added client.validations* member
    • Added method validateVoucher to client.validations
    • Changed default timeout from 500 minutes to 3 minutes. Made timeout configurable
    • Bugfix: Fixed raising exception when response json contains property "error"
  • 2019-06-19 - 2.1.0 Added support for custom API endpoint, that allows to connect to projects created in specific Voucherify region.
  • 2018-01-20 - 2.0.0
    • Moved vouchers related methods to client.vouchers.* namespace
    • Moved redemptions related methods to client.redemptions.* namespace
    • Moved distributions related methods to client.distributions.* namespace
    • Renamed client.customer.* to client.customers.*
    • Removed outdated client.distributions.publish(campaignName) method interface
    • Fixed utils methods to accept vouchers with None gift
  • 2016-12-02 - 1.4.2 - Support gift vouchers in utils
  • 2016-10-04 - 1.4.1 - Publish update
  • 2016-07-18 - 1.4.0 - Voucher code pattern
  • 2016-07-18 - 1.3.0 - Update voucher
  • 2016-06-23 - 1.2.1 - Gift vouchers
  • 2016-06-16 - 1.2.0 - Unified naming convention
  • 2016-06-16 - 1.1.0 - Added customer methods
  • 2016-06-08 - 1.0.0 - Release version
  • 2016-05-31 - 0.1.0 - First version:
    • Authentication
    • Voucher informations: get, usage
    • Voucher operations: use
    • Utils