Coder Social home page Coder Social logo

omise-python's Introduction

Omise Python Client

Build Status Python Versions PyPi Version

Please raise an issue or contact [email protected] if you have any question regarding this library and the functionality it provides.

Installation

If you simply want to use Omise Python client in your application, you can install it using pip:

pip install omise

Or easy_install in case your system do not have pip installed:

easy_install omise

The Omise Python client officially supports the following Python versions:

  • Python 2.7
  • Python 3.6
  • Python 3.7
  • Python 3.8
  • Python 3.9

Any versions not listed here may work but they are not automatically tested.

Usage

Please refer to examples in our API documentation. For basic usage, you can use the package in your application by importing omise and setting the secret key:

import omise
omise.api_secret = 'skey_test_4xsjvwfnvb2g0l81sjz'

After the secret key is set, you can use all APIs which use secret key authentication.

To create a new credit card charge, use Omise.js to create a new token and run the following:

token_id = "tokn_test_no1t4tnemucod0e51mo" # see https://www.omise.co/tokens-api#create
charge = omise.Charge.create(
    amount=100000,
    currency="THB",
    card=token_id,
    return_uri="https://www.omise.co/example_return_uri",
)
# <Charge id='chrg_test_5ktrim62oiosnrc1r41' at 0x105d6bf28>
charge.status
# 'successful'

To create a new customer without any cards associated to the customer, run the following:

customer = omise.Customer.create(
   description='John Doe',
   email='[email protected]'
)
# <Customer id='cust_test_4xtrb759599jsxlhkrb' at 0x7ffab7136910>

Then to retrieve, update, and destroy that customer, run the following:

customer = omise.Customer.retrieve('cust_test_4xtrb759599jsxlhkrb')
customer.description = 'John W. Doe'
customer.update()
# <Customer id='cust_test_4xtrb759599jsxlhkrb' at 0x7ffab7136910>
customer.destroy()
customer.destroyed
# True

In case of error (such as authentication failure, invalid card and others as listed in errors section in the documentation), the error of a subclass omise.errors.BaseError will be raised. Your application code should handle these errors appropriately.

API version

In case you want to enforce API version the application use, you can specify it by setting api_version. The version specified by this setting will override the version setting in your account. This is useful if you have multiple environments with different API versions (e.g. development on the latest but production on the older version).

import omise
omise.api_version = '2019-05-29'

It is highly recommended to set this version to the current version you're using.

Contributing

The Omise Python client uses tox and Docker for testing. All changes must be tested against all supported Python versions. You can run tests using the following instructions:

  1. Install Docker
  2. Run docker run -it -v $(pwd):/app --rm $(docker build -q .)

This command builds a Docker image using the Dockerfile, mounts the current directory to the container's /app directory, and runs the default entrypoint for the image: /app/run-tox.sh.

After you've made your changes and run the tests, please open a Pull Request.

License

See LICENSE.txt

omise-python's People

Contributors

jakyns avatar mazon avatar phanpak avatar pistachiology avatar sirn avatar som-m avatar spacebra avatar zentetsukenz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.