Balanced API library in python.

Overview

Balanced

Online Marketplace Payments

Build Status Latest Version Downloads Supported Python versions License

v1.x requires Balanced API 1.1. Use v0.x for Balanced API 1.0.

Installation

pip install balanced

Usage

View Balanced's online tutorial and documentation at https://www.balancedpayments.com/docs/overview?language=python

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write your code and unit tests
  4. Ensure all tests still pass (nosetests)
  5. PEP8 your code
  6. Commit your changes (git commit -am 'Add some feature')
  7. Push to the branch (git push origin my-new-feature)
  8. Create new pull request

Documentation scenarios

Each scenario lives in the scenarios directory and is comprised of the following:

  • definition.mako - Method definition
  • request.mako - Scenario code
  • executable.py - Processed request.mako. Can be executed directly in Python. Generated by render_scenarios.py.
  • python.mako - Documentation template to be consumed by balanced-docs. Generated by - render_scenarios.py.
Comments
  • Failed to handle doesn't exist resource correctly

    Failed to handle doesn't exist resource correctly

    Install 1.1.0dev

    pip install balanced==1.1.0dev
    

    and run following script

    import balanced
    from wac import NoResultFound
    
    api_key = balanced.APIKey().save()
    balanced.config.Client.config.auth = (api_key.secret, '')
    try:
        mp = balanced.Marketplace.my_marketplace
    except (NoResultFound, balanced.exc.NoResultFound):
        mp = balanced.Marketplace().save()
    print mp
    

    and here is the error

    Traceback (most recent call last):
      File "tests/rev1/test_client.py", line 5, in <module>
        mp = balanced.Marketplace.my_marketplace
      File "/srv/acceptance/.tox/rev1/local/lib/python2.7/site-packages/balanced/utils.py", line 13, in __get__
        return self.fget.__get__(obj, klass)()
      File "/srv/acceptance/.tox/rev1/local/lib/python2.7/site-packages/balanced/resources.py", line 225, in mine
        return cls.query.one()
      File "/srv/acceptance/.tox/rev1/local/lib/python2.7/site-packages/wac.py", line 783, in one
        items = self.pagination._page(0, 2).items
      File "/srv/acceptance/.tox/rev1/local/lib/python2.7/site-packages/balanced/resources.py", line 128, in items
        return self.event_callbacks
    AttributeError: 'JSONSchemaPage' object has no attribute 'event_callbacks'
    

    It should raise NoResultFound, but somehow, something is broken

    bug 1.1 
    opened by fangpenlin 11
  • TypeError at /rider/edit/2/ the_new() keywords must be strings (line 317, branch: requests 1.1.0)

    TypeError at /rider/edit/2/ the_new() keywords must be strings (line 317, branch: requests 1.1.0)

    Able to create bank account (i can see it in my account online), but it throws this error before i am able to parse a response.

    Exception Location: Bustr/bustr/ENV/lib/python2.6/site-packages/balanced/resources.py in save, line 317

    Traceback: http://dpaste.com/hold/1022301/

    opened by cinquemb 11
  • Debit class has no `self.refunds_uri`

    Debit class has no `self.refunds_uri`

    Been looking at this class:

    class Debit(Resource):
        """
        A Debit represents a transfer of funds from a buyer's Account to your
        Marketplace's escrow account.
    
        A Debit may be created directly, or it will be created as a side-effect
        of capturing a Hold. If you create a Debit directly it will implicitly
        create the associated Hold if the funding source supports this.
    
        If no Hold is specified, the Debit will by default be created using the
        most recently added funding source associated with the Account. You
        cannot change the funding source between creating a Hold and capturing
        it.
        """
        __metaclass__ = resource_base(collection='debits')
    
        def refund(self, amount=None, description=None, meta=None):
            """
            Refunds this Debit. If no amount is specified it will refund the entire
            amount of the Debit, you may create many Refunds up to the sum total
            of the original Debit's amount.
    
            :rtype: Refund
            """
            meta = meta or {}
            return Refund(
                uri=self.refunds_uri,
                debit_uri=self.uri,
                amount=amount,
                description=description,
                meta=meta,
            ).save()
    

    But when you try to use this, you get AttributeError: 'Debit' object has no attribute 'refunds_uri'

    I tried changing self.refunds_uri to self.uri but then I got: HTTPError: Method Not Allowed: 405: Your request id is OHM2f81d254500c11e...redacted....

    opened by peterbe 9
  • Card.associate_to_customer(customer) fails

    Card.associate_to_customer(customer) fails

    When I call: MYCARD.associate_to_customer(customer) It fails to save when adding new attribute 'links' to Card object as indicated in resources.py:

    class FundingInstrument(Resource):
    ...
        def associate_to_customer(self, customer):
            try:
                self.links
            except AttributeError:
                self.links = {}
            self.links['customer'] = utils.extract_href_from_object(customer)
            self.save()
    

    In fact, at the end of saving process, MYCARD got a new attribute called 'customer_href' instead of 'links' that I expected. Next, I fetch MYCARD again to see its response, but neither 'links' nor 'customer_href' is on MYCARD. However, the number of cards associated with the customer increases by one.

    I'd appreciate any help. Thanks!

    opened by quangkcao 8
  • Implement the Customers resource

    Implement the Customers resource

    We have a new Customer resource.

    With a customer you should be able to debit, credit, as well as add_card and add_bank_account. A customer should be able to tell you their active_card and active_bank_account.

    opened by mjallday 8
  • Does not work with python <= 2.6

    Does not work with python <= 2.6

    >>> balanced.Card(card_number='4111111111111111', expiration_month=12, expiration_year=2020).save()
    Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
       File "/usr/local/lib/python2.6/dist-packages/balanced/resources.py", line 356, in the_init
         self.uri = uri_discovery(self)
       File "/usr/local/lib/python2.6/dist-packages/balanced/resources.py", line 265, in uri_discovery
         resource.RESOURCE['collection']
     ValueError: zero length field name in format
    
    opened by mjallday 7
  • Upgrade Requests to 1.2.3; #43

    Upgrade Requests to 1.2.3; #43

    This repins requests in requirements.txt. The change is so minor that I can't imagine Requests 1.1.0 wouldn't still work, but it seemed better to stick with pinning and let advanced users manually use an older Requests version as necessary.

    opened by chadwhitacre 6
  • Unable to add buyer w/o card URI

    Unable to add buyer w/o card URI

    I was trying to add a buyer without a card URI as I was wanting to write my program in steps instead of doing 2 things at once.

    client = balanced.Marketplace.my_marketplace.create_buyer(email, None)
    

    This returns an issue saying that None is not a valid card URI.

    client = balanced.Marketplace.my_marketplace.create_buyer(email, {})
    

    This returns saying that "{}" needs to be a URI

    client = balanced.Marketplace.my_marketplace.create_buyer(email, "")
    

    Same as using None.

    The fix for this is to do the following:

    client = balanced.Account(uri=balanced.Marketplace.my_marketplace.accounts_uri,email_address=email).save()
    

    Perhaps there can be an easier fix for this, though?

    opened by SecurityForUs 5
  • Edit cancel function to void holds

    Edit cancel function to void holds

    https://docs.balancedpayments.com/1.1/api/card-holds/#void-a-card-hold wasn't actually working for the python library. The holds object voided_at would just return as null when you called cancel.

    opened by rserna2010 4
  • Is our version schema correct (for pip)?

    Is our version schema correct (for pip)?

    I just tried to install it with

    pip install "balanced<1.0"
    

    But what I got looks like this

    Downloading/unpacking balanced<1.0
      Downloading balanced-1.beta3.tar.gz
      Running setup.py egg_info for package balanced
    

    I am pretty familiar with how pip handles version number, maybe we can figure it out, see is this our problem or that's a bug of pip or something else.

    An article to reference to: http://guide.python-distribute.org/specification.html

    opened by fangpenlin 4
  • update to newest version of requests

    update to newest version of requests

    The requests library has gone through big changes since the April 2012 version the balanced python client requires: http://pypi.python.org/pypi/requests#history

    It had some backwards incompatible changes w/ the big refactor/rewrite 1.0 release, but that's now 2 months ago, so it might be stable enough to rely on by now. Might take a bit of reworking of our code, I don’t know how hard it would be.

    Also worth investigating is version 0.14.2 of Requests from the end of October, the last version before the big refactor.

    When trying to run on google app engine, the python client currently fails, because requests can't find a list of certificate authority keys, and therefore raises an exception. It’s possible to work around this by leaving the same requests version and modifying the balanced python client. But it also might fix things to just use a newer version of the library. I haven’t done much testing of it.

    opened by jrus 4
  • docs: fix simple typo, resouce -> resource

    docs: fix simple typo, resouce -> resource

    There is a small typo in tests/test_suite.py.

    Should read resource rather than resouce.

    Semi-automated pull request generated by https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

    opened by timgates42 1
  • Exception Type for NoResultFound is incorrect

    Exception Type for NoResultFound is incorrect

    For instance when running a simple query that returns no results:

    customer = balanced.Customer.query.filter(email=self.email).one()
    

    the error type should be balanced.exc.NoResultFound, instead it's wac.NoResultFound.

    opened by rserna2010 0
  • The NoResultFound should be the one in balanced rather than wac

    The NoResultFound should be the one in balanced rather than wac

    I noticed that the NoResultFound raised was the one from balanced in revision 1.0 client. However, it appears that becomes the one from wac in revision 1.1.

    2014-04-21 11:31:52,489 ERROR [billy.models.base][Dummy-3] Failed to process transaction TX7SpmonpnuYoDt4JF1Yetsq, failure_count=1
    Traceback (most recent call last):
      File "/Users/VictorLin/Documents/workspace/billy/billy/models/transaction.py", line 316, in process_one
        result = method(transaction)
      File "/Users/VictorLin/Documents/workspace/billy/billy/models/processors/balanced_payments.py", line 49, in callee
        return func(self, *args, **kwargs)
      File "/Users/VictorLin/Documents/workspace/billy/billy/models/processors/balanced_payments.py", line 333, in debit
        extra_kwargs=extra_kwargs,
      File "/Users/VictorLin/Documents/workspace/billy/billy/models/processors/balanced_payments.py", line 286, in _do_transaction
        record = self._get_resource_by_tx_guid(resource_cls, transaction.guid)
      File "/Users/VictorLin/Documents/workspace/billy/billy/models/processors/balanced_payments.py", line 254, in _get_resource_by_tx_guid
        .filter(**{'meta.billy.transaction_guid': guid})
      File "/Users/VictorLin/Documents/workspace/billy/env/lib/python2.7/site-packages/wac.py", line 788, in one
        raise NoResultFound()
    NoResultFound
    

    IMHO, that should be the one from balanced.

    opened by fangpenlin 0
  • Python3 support

    Python3 support

    Implemented python3 support (HOWEVER: at the cost of python2 support). Currently, requires wac to be installed from my fork, since I had to port that to python3 as well. However, I will be submitting a pull request to wac's author as well. Passed all test cases of nosetests.

    opened by zmike808 6
  • Write a test for sideloading

    Write a test for sideloading

    Given the payload

    {
        "debits": [
            {
                "amount": 5000, 
                "appears_on_statement_as": "BAL*Statement text", 
                "created_at": "2014-02-27T20:03:06.176697Z", 
                "currency": "USD", 
                "description": "Some descriptive text for the debit in the dashboard", 
                "failure_reason": null, 
                "failure_reason_code": null, 
                "href": "/debits/WD1l5vYA21ZP24LMQMqHizea", 
                "id": "WD1l5vYA21ZP24LMQMqHizea", 
                "links": {
                    "customer": null, 
                    "dispute": null, 
                    "order": null, 
                    "source": "CC1diaA1Lunr4RlelwKQ8C4v"
                }, 
                "meta": {}, 
                "status": "succeeded", 
                "transaction_number": "W347-910-8642", 
                "updated_at": "2014-02-27T20:03:07.629780Z"
            }
        ], 
        "foos": [
            {
            }
        ], 
        "links": {
            "debits.customer": "/customers/{debits.customer}", 
            "debits.dispute": "/disputes/{debits.dispute}", 
            "debits.events": "/debits/{debits.id}/events", 
            "debits.order": "/orders/{debits.order}", 
            "debits.refunds": "/debits/{debits.id}/refunds", 
            "debits.source": "/resources/{debits.source}"
        }
    }
    
    

    Make sure that this client library does not choke and return the wrong object.

    opened by mjallday 0
Owner
Balanced
Balanced
Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Harun Mbaabu Mwenda 46 Sep 1, 2022
Python API wrapper library for Convex Value API

convex-value-python Python API wrapper library for Convex Value API. Further Links: Convex Value homepage @ConvexValue on Twitter JB on Twitter Authen

Aaron DeVera 2 May 11, 2022
This an API wrapper library for the OpenSea API written in Python 3.

OpenSea NFT API Python 3 wrapper This an API wrapper library for the OpenSea API written in Python 3. The library provides a simplified interface to f

Attila Tóth 159 Dec 26, 2022
Aio-binance-library - Async library for connecting to the Binance API on Python

aio-binance-library Async library for connecting to the Binance API on Python Th

GRinvest 10 Nov 21, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
WhatsApp Api Python - This documentation aims to exemplify the use of Moorse Whatsapp API in Python

WhatsApp API Python ChatBot Este repositório contém uma aplicação que se utiliza

Moorse.io 3 Jan 8, 2022
Official python API for Phish.AI public and private API to detect zero-day phishing websites

phish-ai-api Summary Official python API for Phish.AI public and private API to detect zero-day phishing websites How it Works (TLDR) Essentially we h

Phish.AI 168 May 17, 2022
Python API wrapper around Trello's API

A wrapper around the Trello API written in Python. Each Trello object is represented by a corresponding Python object. The attributes of these objects

Richard Kolkovich 904 Jan 2, 2023
A python to scratch API connector. Can fetch data from the API and send it back in cloud variables.

Scratch2py Scratch2py or S2py is a easy to use, versatile tool to communicate with the Scratch API Based of scratchclient by Raihan142857 Installation

null 20 Jun 18, 2022
Async ready API wrapper for Revolt API written in Python.

Mutiny Async ready API wrapper for Revolt API written in Python. Installation Python 3.9 or higher is required To install the library, you can just ru

null 16 Mar 29, 2022
🚀 An asynchronous python API wrapper meant to replace discord.py - Snappy discord api wrapper written with aiohttp & websockets

Pincer An asynchronous python API wrapper meant to replace discord.py ❗ The package is currently within the planning phase ?? Links |Join the discord

Pincer 125 Dec 26, 2022
wyscoutapi is an extremely basic API client for the Wyscout API (v2 & v3) for Python

wyscoutapi wyscoutapi is an extremely basic API client for the Wyscout API (v2 & v3). Usage Install with pip install wyscoutapi. To connect to the Wys

Ben Torvaney 11 Nov 22, 2022
A Python API wrapper for the Twitter API!

PyTweet PyTweet is an api wrapper made for twitter using twitter's api version 2! Installation Windows py3 -m pip install PyTweet Linux python -m pip

TheFarGG 1 Nov 19, 2022
A new coin listing alert bot using Python, Flask, MongoDB, Telegram API and Binance API

Bzzmans New Coin Listing Detection Bot Architecture About Project Work in progress. This bot basically gets new coin listings from Binance using Binan

Eyüp Barlas 21 May 31, 2022
YARSAW is an Async Python API Wrapper for the Random Stuff API.

Yet Another Random Stuff API Wrapper - YARSAW YARSAW is an Async Python API Wrapper for the Random Stuff API. This module makes it simpler for you to

Bruce 6 Mar 27, 2022
Python API Client for Twitter API v2

?? Python Client For Twitter API v2 ?? Why Twitter Stream ? Twitter-Stream.py a python API client for Twitter API v2 now supports FilteredStream, Samp

Twitivity 31 Nov 19, 2022
EpikCord.py - This is an API Wrapper for Discord's API for Python

EpikCord.py - This is an API Wrapper for Discord's API for Python! We've decided not to fork discord.py and start completely from scratch for a new, better structuring system!

EpikHost 28 Oct 10, 2022
A simple Python API wrapper for Cloudflare Stream's API.

python-cloudflare-stream A basic Python API wrapper for working with Cloudflare Stream. Arbington.com started off using Cloudflare Stream. We used the

Arbington 3 Sep 8, 2022