├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── balanced ├── __init__.py ├── config.py ├── exc.py ├── resources.py └── utils.py ├── docs ├── Makefile └── source │ ├── api_reference.rst │ ├── conf.py │ └── index.rst ├── examples ├── __init__.py ├── accounting.py ├── bank_account_debits.py ├── error_handling.py ├── events_and_callbacks.py ├── examples.py ├── helpers │ └── __init__.py └── orders.py ├── render_scenarios.py ├── requirements.txt ├── scenarios ├── _main.mako ├── _mj │ ├── _template │ │ ├── _create │ │ │ ├── definition.mako │ │ │ ├── executable.py │ │ │ ├── python.mako │ │ │ └── request.mako │ │ ├── _delete │ │ │ ├── definition.mako │ │ │ ├── executable.py │ │ │ ├── python.mako │ │ │ └── request.mako │ │ ├── _list │ │ │ ├── definition.mako │ │ │ ├── executable.py │ │ │ ├── python.mako │ │ │ └── request.mako │ │ ├── _retrieve │ │ │ ├── definition.mako │ │ │ ├── executable.py │ │ │ ├── python.mako │ │ │ └── request.mako │ │ └── _update │ │ │ ├── definition.mako │ │ │ ├── executable.py │ │ │ ├── python.mako │ │ │ └── request.mako │ ├── api_key_create │ │ ├── definition.mako │ │ ├── executable.py │ │ ├── python.mako │ │ └── request.mako │ └── manage ├── account_credit │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── account_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── account_list_customer │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── account_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── api_key_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── api_key_delete │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── api_key_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── api_key_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_associate_to_customer │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_credit │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_debit │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_debit_order │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_delete │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_verification_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_verification_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── bank_account_verification_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── callback_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── callback_delete │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── callback_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── callback_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_associate_to_customer │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_create_creditable │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_create_dispute │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_credit │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_credit_order │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_debit │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_debit_dispute │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_delete │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_hold_capture │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_hold_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_hold_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_hold_order │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_hold_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_hold_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_hold_void │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── card_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── credit_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── credit_list_bank_account │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── credit_order │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── credit_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── credit_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── customer_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── customer_delete │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── customer_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── customer_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── customer_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── debit_dispute_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── debit_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── debit_order │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── debit_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── debit_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── dispute_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── dispute_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── event_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── event_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── order_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── order_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── order_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── order_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── refund_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── refund_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── refund_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── refund_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── reversal_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── reversal_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── reversal_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── reversal_update │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── settlement_create │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── settlement_list │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── settlement_list_account │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako └── settlement_show │ ├── definition.mako │ ├── executable.py │ ├── python.mako │ └── request.mako ├── setup.cfg ├── setup.py ├── snippets ├── account-balance.py ├── bank-account-create.py ├── bank-account-debit.py ├── bank-account-verification-confirm.py ├── bank-account-verification-create.py ├── callback-create.py ├── card-associate-to-customer.py ├── card-create-dispute.py ├── card-create.py ├── card-credit.py ├── card-debit.py ├── card-hold-capture.py ├── card-hold-create.py ├── card-hold-void.py ├── create-buyer-and-card.py ├── credit-create.py ├── credit-fetch.py ├── credit-marketplace-escrow.py ├── credit-reverse.py ├── credit-soft-descriptor.py ├── credit-split.py ├── customer-create.py ├── debit-dispute-show.py ├── debit-fetch.py ├── debit-marketplace-escrow.py ├── debit-refund.py ├── dispute-list.py ├── dispute-show.py ├── examine-order-after-refund.py ├── examine-order-after-reversal.py ├── marketplace-in-escrow.py ├── merchant-payable-account-fetch.py ├── order-amount-escrowed.py ├── order-bank-account-create.py ├── order-create.py ├── order-credit-marketplace.py ├── order-credit-merchant-payable-account.py ├── order-credit.py ├── order-credits-fetch.py ├── order-debit.py ├── order-debits-fetch.py ├── order-fetch.py ├── order-update.py ├── refund-create.py ├── reversal-create.py └── settlement-create.py ├── test-requirements.txt └── tests ├── __init__.py ├── acceptance_suite.py ├── fixtures ├── __init__.py └── resources │ ├── api_keys.json │ └── marketplaces.json ├── test_balanced.py ├── test_client.py ├── test_resource.py ├── test_suite.py └── utils.py /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | local 3 | .settings 4 | *.pyc 5 | *.pyo 6 | dumps 7 | review_index 8 | xml_reviews/*.xml 9 | .cache 10 | tmp 11 | apps/neocrawler/bin/crawlc 12 | zillion/apps/cck/templates/layout.py.bak 13 | .project 14 | .pydevproject 15 | \#* 16 | .\#* 17 | .*.swp 18 | *~ 19 | .*.sw* 20 | TAGS 21 | tags 22 | milo/apps/merchant_address/sears/cookies 23 | *.iml 24 | .ropeproject 25 | *_flymake.py 26 | *,cover 27 | .coverage 28 | coverage/ 29 | docs/api-docs/build 30 | sphinx 31 | .~lock.* 32 | .noseids 33 | *.egg-info/ 34 | *.egg/ 35 | build/ 36 | dist/ 37 | *.log 38 | *.log.* 39 | .dir-locals.el 40 | .idea/ 41 | _build/ 42 | coverage.xml 43 | scenario.cache -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - 2.6 4 | - 2.7 5 | install: 6 | - python setup.py develop 7 | - pip install -r requirements.txt 8 | - pip install -r test-requirements.txt 9 | script: 10 | - python setup.py test 11 | deploy: 12 | provider: pypi 13 | user: balanced-butler 14 | password: 15 | secure: jH1XW+hl+KInnde014cvX8mH5ZRiqXsxMRflR2DEs/na5mK/1LFzFt2iwgN9XwkkmXJYLPr6LA3pSLqHTMKXs8RrHaM1uXmEckXL48jcy0YkQ0+2Cl0EKcbmS8OnqIcjY3g5xFBbsFPjuRx6uJYFksJ3QatTuxkDcY/hQOc6IZg= 16 | on: 17 | tags: true 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.2 2 | 3 | * Account and Settlement support 4 | 5 | ## 1.1.1 6 | 7 | * Fix allowing for voiding holds 8 | 9 | ## 1.1.0 10 | 11 | * Push to card support 12 | 13 | ## 1.0.2 14 | 15 | * Return None when there is actually none instead of a page object (#115) 16 | * Fix polymorphic types coming back as resource (#114) 17 | * Fix for query pagination (#109) 18 | * Fix iterator (#21) 19 | 20 | 21 | ## 1.0.1 22 | 23 | * Fix for returned generic Resource instead of expected resource class 24 | 25 | 26 | ## 1.0 27 | 28 | * Requires Balanced API 1.1 29 | * Hypermedia API support 30 | * Debits and credits are now performed directly on funding instruments and not via Customer 31 | * Support for new Order resource -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Balanced 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | include requirements.txt 3 | include test-requirements.txt 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Balanced 2 | 3 | Online Marketplace Payments 4 | 5 | [![Build Status](https://secure.travis-ci.org/balanced/balanced-python.png?branch=master)](http://travis-ci.org/balanced/balanced-python) [![Latest Version](https://pypip.in/version/balanced/badge.svg)](https://pypi.python.org/pypi/balanced/) [![Downloads](https://pypip.in/download/balanced/badge.svg)](https://pypi.python.org/pypi/balanced/) [![Supported Python versions](https://pypip.in/py_versions/balanced/badge.svg)](https://pypi.python.org/pypi/balanced/) [![License](https://pypip.in/license/balanced/badge.svg)](https://pypi.python.org/pypi/balanced/) 6 | 7 | **v1.x requires Balanced API 1.1. Use [v0.x](https://github.com/balanced/balanced-python/tree/rev0) for Balanced API 1.0.** 8 | 9 | ## Installation 10 | 11 | pip install balanced 12 | 13 | ## Usage 14 | 15 | View Balanced's online tutorial and documentation at https://www.balancedpayments.com/docs/overview?language=python 16 | 17 | ## Contributing 18 | 19 | 1. Fork it 20 | 2. Create your feature branch (`git checkout -b my-new-feature`) 21 | 3. Write your code **and unit tests** 22 | 4. Ensure all tests still pass (`nosetests`) 23 | 5. [PEP8](http://pypi.python.org/pypi/pep8) your code 24 | 6. Commit your changes (`git commit -am 'Add some feature'`) 25 | 7. Push to the branch (`git push origin my-new-feature`) 26 | 8. Create new pull request 27 | 28 | 29 | ## Documentation scenarios 30 | 31 | Each scenario lives in the scenarios directory and is comprised of the following: 32 | 33 | - definition.mako - Method definition 34 | - request.mako - Scenario code 35 | - executable.py - Processed request.mako. Can be executed directly in Python. Generated by render_scenarios.py. 36 | - python.mako - Documentation template to be consumed by balanced-docs. Generated by - render_scenarios.py. 37 | -------------------------------------------------------------------------------- /balanced/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | __version__ = '1.2' 4 | 5 | from balanced.config import configure 6 | from balanced import resources 7 | from balanced.resources import ( 8 | Resource, Marketplace, APIKey, 9 | CardHold, Credit, Debit, Refund, Reversal, 10 | Transaction, BankAccount, Card, Dispute, 11 | Callback, Event, EventCallback, EventCallbackLog, 12 | BankAccountVerification, Customer, Order, 13 | ExternalAccount, Account, Settlement 14 | ) 15 | from balanced import exc 16 | 17 | 18 | __all__ = [ 19 | Account.__name__, 20 | APIKey.__name__, 21 | BankAccount.__name__, 22 | BankAccountVerification.__name__, 23 | Callback.__name__, 24 | Card.__name__, 25 | CardHold.__name__, 26 | Credit.__name__, 27 | Customer.__name__, 28 | Debit.__name__, 29 | Dispute.__name__, 30 | Event.__name__, 31 | EventCallback.__name__, 32 | EventCallbackLog.__name__, 33 | Marketplace.__name__, 34 | Order.__name__, 35 | Resource.__name__, 36 | Refund.__name__, 37 | Reversal.__name__, 38 | Settlement.__name__, 39 | Transaction.__name__, 40 | ExternalAccount.__name__, 41 | str(exc.__name__.partition('.')[-1]) 42 | ] 43 | -------------------------------------------------------------------------------- /balanced/config.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from datetime import datetime 3 | 4 | import simplejson as json 5 | from iso8601 import iso8601 6 | import wac 7 | 8 | from balanced import exc 9 | from . import __version__ 10 | 11 | 12 | API_ROOT = 'https://api.balancedpayments.com' 13 | 14 | 15 | # config 16 | def configure( 17 | user=None, 18 | root_url=API_ROOT, 19 | api_revision='1.1', 20 | user_agent='balanced-python/' + __version__, 21 | accept_type='application/vnd.api+json', 22 | **kwargs 23 | ): 24 | kwargs.setdefault('headers', {}) 25 | 26 | for key, value in ( 27 | ('content-type', 'application/json;revision=' + api_revision), 28 | ('accept', '{0};revision={1}'.format(accept_type, api_revision)) 29 | ): 30 | kwargs['headers'].setdefault(key, value) 31 | 32 | if 'error_cls' not in kwargs: 33 | kwargs['error_cls'] = exc.convert_error 34 | 35 | if user: 36 | kwargs['auth'] = (user, None) 37 | 38 | # apply 39 | Client.config = Config(root_url, user_agent=user_agent, **kwargs) 40 | 41 | 42 | class Config(wac.Config): 43 | 44 | api_revision = None 45 | 46 | user_agent = None 47 | 48 | 49 | default_config = Config(API_ROOT) 50 | 51 | 52 | # client 53 | 54 | class Client(wac.Client): 55 | 56 | config = default_config 57 | 58 | @staticmethod 59 | def _default_serialize(o): 60 | if isinstance(o, datetime): 61 | return o.isoformat() + 'Z' 62 | raise TypeError( 63 | 'Object of type {} with value of {} is not ' 64 | 'JSON serializable'.format(type(o), repr(o)) 65 | ) 66 | 67 | def _serialize(self, data): 68 | data = json.dumps(data, default=self._default_serialize) 69 | return 'application/json', data 70 | 71 | @staticmethod 72 | def _parse_deserialized(e): 73 | if isinstance(e, dict): 74 | for k in e.iterkeys(): 75 | if k.endswith('_at') and isinstance(e[k], basestring): 76 | e[k] = iso8601.parse_date(e[k]) 77 | return e 78 | 79 | def _deserialize(self, response): 80 | if response.headers['Content-Type'] != 'application/json': 81 | raise Exception("Unsupported content-type '{}'".format( 82 | response.headers['Content-Type'] 83 | )) 84 | if not response.content: 85 | return None 86 | data = json.loads(response.content) 87 | return self._parse_deserialized(data) 88 | 89 | 90 | configure() 91 | 92 | client = Client() 93 | -------------------------------------------------------------------------------- /balanced/exc.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | import httplib 4 | 5 | import wac 6 | 7 | 8 | class BalancedError(Exception): 9 | 10 | def __str__(self): 11 | attrs = ', '.join([ 12 | '{0}={1}'.format(k, repr(v)) 13 | for k, v in self.__dict__.iteritems() 14 | ]) 15 | return '{0}({1})'.format(self.__class__.__name__, attrs) 16 | 17 | 18 | class ResourceError(BalancedError): 19 | pass 20 | 21 | 22 | class NoResultFound(BalancedError): 23 | pass 24 | 25 | 26 | class MultipleResultsFound(BalancedError): 27 | pass 28 | 29 | 30 | class FundingSourceNotCreditable(Exception): 31 | pass 32 | 33 | 34 | def convert_error(ex): 35 | if not hasattr(ex.response, 'data'): 36 | return ex 37 | return HTTPError.from_response(**ex.response.data)(ex) 38 | 39 | 40 | class HTTPError(BalancedError, wac.Error): 41 | 42 | class __metaclass__(type): 43 | 44 | def __new__(meta_cls, name, bases, dikt): 45 | cls = type.__new__(meta_cls, name, bases, dikt) 46 | cls.types = [ 47 | getattr(cls, k) 48 | for k in dir(cls) 49 | if k.isupper() and isinstance(getattr(cls, k), basestring) 50 | ] 51 | cls.type_to_error.update(zip(cls.types, [cls] * len(cls.types))) 52 | return cls 53 | 54 | def __init__(self, requests_ex): 55 | super(wac.Error, self).__init__(requests_ex) 56 | self.status_code = requests_ex.response.status_code 57 | data = getattr(requests_ex.response, 'data', {}) 58 | for k, v in data.get('errors', [{}])[0].iteritems(): 59 | setattr(self, k, v) 60 | 61 | @classmethod 62 | def format_message(cls, requests_ex): 63 | data = getattr(requests_ex.response, 'data', {}) 64 | status = httplib.responses[requests_ex.response.status_code] 65 | error = data['errors'][0] 66 | status = error.pop('status', status) 67 | status_code = error.pop('status_code', 68 | requests_ex.response.status_code) 69 | desc = error.pop('description', None) 70 | message = ': '.join(str(v) for v in [status, status_code, desc] if v) 71 | return message 72 | 73 | @classmethod 74 | def from_response(cls, **data): 75 | try: 76 | err = data['errors'][0] 77 | exc = cls.type_to_error.get(err['category_code'], HTTPError) 78 | except: 79 | exc = HTTPError 80 | return exc 81 | 82 | type_to_error = {} 83 | 84 | 85 | class FundingInstrumentVerificationFailure(HTTPError): 86 | pass 87 | 88 | 89 | class BankAccountVerificationFailure(FundingInstrumentVerificationFailure): 90 | AUTH_NOT_PENDING = 'bank-account-authentication-not-pending' 91 | AUTH_FAILED = 'bank-account-authentication-failed' 92 | AUTH_DUPLICATED = 'bank-account-authentication-already-exists' 93 | -------------------------------------------------------------------------------- /balanced/utils.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | 4 | class ClassPropertyDescriptor(object): 5 | 6 | def __init__(self, fget, fset=None): 7 | self.fget = fget 8 | self.fset = fset 9 | 10 | def __get__(self, obj, klass=None): 11 | if klass is None: 12 | klass = type(obj) 13 | return self.fget.__get__(obj, klass)() 14 | 15 | def __set__(self, obj, value): 16 | if not self.fset: 17 | raise AttributeError("can't set attribute") 18 | type_ = type(obj) 19 | return self.fset.__get__(obj, type_)(value) 20 | 21 | def setter(self, func): 22 | if not isinstance(func, (classmethod, staticmethod)): 23 | func = classmethod(func) 24 | self.fset = func 25 | return self 26 | 27 | 28 | def classproperty(func): 29 | if not isinstance(func, (classmethod, staticmethod)): 30 | func = classmethod(func) 31 | 32 | return ClassPropertyDescriptor(func) 33 | 34 | 35 | def extract_href_from_object(obj): 36 | if isinstance(obj, basestring): 37 | return obj 38 | if isinstance(obj, dict): 39 | return obj['href'] 40 | return obj.href 41 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/balanced.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/balanced.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/balanced" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/balanced" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /docs/source/api_reference.rst: -------------------------------------------------------------------------------- 1 | .. _api_reference: 2 | 3 | Balanced API Reference 4 | ###################### 5 | 6 | 7 | .. automodule:: resources 8 | :members: 9 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. balanced documentation master file, created by 2 | sphinx-quickstart on Wed Jun 20 15:15:54 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to balanced's documentation! 7 | ==================================== 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | 15 | 16 | Indices and tables 17 | ================== 18 | 19 | * :ref:`genindex` 20 | * :ref:`modindex` 21 | * :ref:`search` 22 | 23 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'marshall' 2 | -------------------------------------------------------------------------------- /examples/accounting.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ''' 3 | Generate a csv report of month end transaction balances; 4 | please ensure your RAM is commensurate with your transaction volume. 5 | 6 | python examples/accounting.py --api_key [Marketplace API Key] > Report.csv 7 | python examples/accounting.py --api_key [Marketplace API Key] --use_cache > gnuplot ... 8 | 9 | ''' 10 | 11 | import argparse 12 | import calendar 13 | import csv 14 | from itertools import groupby 15 | import os 16 | import pickle 17 | import sys 18 | 19 | import balanced 20 | 21 | 22 | def generate_report(args): 23 | balanced.configure(args.api_key) 24 | marketplace = balanced.Marketplace.mine 25 | 26 | if args.use_cache: 27 | credits = pickle.load(open('cache/credits.obj')) 28 | debits = pickle.load(open('cache/debits.obj')) 29 | refunds = pickle.load(open('cache/refunds.obj')) 30 | 31 | else: 32 | if not os.path.exists('./cache'): 33 | os.makedirs('./cache') 34 | 35 | print 'Downloading Debits' 36 | debits = balanced.Debit.query.all() 37 | 38 | print 'Downloading Credits' 39 | credits = balanced.Credit.query.all() 40 | 41 | print 'Downloading Refunds' 42 | refunds = balanced.Refund.query.all() 43 | 44 | print 'Caching Transactions' 45 | with open('cache/debits.obj', 'w') as f: 46 | pickle.dump(debits, f) 47 | 48 | with open('cache/credits.obj', 'w') as f: 49 | pickle.dump(credits, f) 50 | 51 | with open('cache/refunds.obj', 'w') as f: 52 | pickle.dump(refunds, f) 53 | 54 | txns = sorted(credits + debits + refunds, key=lambda x: x.created_at) 55 | 56 | def group(xs, head, tail): 57 | return {key: [tail(x) for x in group] 58 | for key, group in 59 | groupby(sorted(xs, key=head), 60 | head)} 61 | 62 | # (year, month, txn) 63 | txns_by_period = [(t.created_at.year, 64 | t.created_at.month, 65 | t) for t in txns] 66 | 67 | # {year: [(month, txn)]} 68 | txns_by_year = group(txns_by_period, 69 | lambda (y, m, txn): y, 70 | lambda (y, m, txn): (m, txn)) 71 | 72 | group_by_month = lambda xs: group(xs, lambda (a, b): a, lambda (a, b): b) 73 | 74 | # {year: {month: [txn]}} 75 | txns_by_year_by_month = {key: group_by_month(txns_by_year[key]) 76 | for key in txns_by_year} 77 | 78 | headers = ['Year', 'Month', 'Debits', 'Refunds', 'Credits', 79 | 'Credits Pending', 'Escrow Balance'] 80 | writer = csv.DictWriter(sys.stdout, headers) 81 | writer.writeheader() 82 | rolling_balance = 0 83 | 84 | for year in sorted(txns_by_year_by_month): 85 | for month in sorted(txns_by_year_by_month[year]): 86 | txns = txns_by_year_by_month[year][month] 87 | monthly_credits = [txn for txn in txns 88 | if type(txn) == balanced.resources.Credit] 89 | monthly_debits = [txn for txn in txns 90 | if type(txn) == balanced.resources.Debit] 91 | monthly_refunds = [txn for txn in txns 92 | if type(txn) == balanced.resources.Refund] 93 | 94 | credit_amount = sum([c.amount for c in monthly_credits 95 | if c.status == 'paid']) 96 | debit_amount = sum([d.amount for d in monthly_debits 97 | if d.status == 'succeeded']) 98 | refund_amount = sum([r.amount for r in monthly_refunds]) 99 | credits_pending_amount = sum([c.amount for c in monthly_credits 100 | if c.status == 'pending']) 101 | 102 | rolling_balance += debit_amount 103 | rolling_balance -= (refund_amount + credit_amount) 104 | 105 | row = {} 106 | row['Year'] = str(year) 107 | row['Month'] = calendar.month_name[month] 108 | row['Debits'] = debit_amount / 100.0 109 | row['Refunds'] = refund_amount / 100.0 110 | row['Credits'] = credit_amount / 100.0 111 | row['Credits Pending'] = credits_pending_amount / 100.0 112 | row['Escrow Balance'] = (rolling_balance - 113 | credits_pending_amount) / 100.0 114 | writer.writerow(row) 115 | 116 | def main(): 117 | arg_parser = argparse.ArgumentParser() 118 | arg_parser.add_argument('--api_key', action='store', dest='api_key', 119 | required=True) 120 | arg_parser.add_argument('--use_cache', action='store_true') 121 | args = arg_parser.parse_args() 122 | generate_report(args) 123 | 124 | 125 | if __name__ == '__main__': 126 | main() 127 | -------------------------------------------------------------------------------- /examples/bank_account_debits.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Learn how to verify a bank account so you can debit with it. 3 | ''' 4 | from __future__ import unicode_literals 5 | 6 | import balanced 7 | 8 | 9 | def init(): 10 | key = balanced.APIKey().save() 11 | balanced.configure(key.secret) 12 | balanced.Marketplace().save() 13 | 14 | 15 | def main(): 16 | init() 17 | 18 | # create a bank account 19 | bank_account = balanced.BankAccount( 20 | account_number='1234567890', 21 | routing_number='321174851', 22 | name='Jack Q Merchant', 23 | ).save() 24 | customer = balanced.Customer().save() 25 | bank_account.associate_to_customer(customer) 26 | 27 | print 'you can\'t debit until you authenticate' 28 | try: 29 | bank_account.debit(100) 30 | except balanced.exc.HTTPError as ex: 31 | print 'Debit failed, %s' % ex.message 32 | 33 | # verify 34 | verification = bank_account.verify() 35 | 36 | print 'PROTIP: for TEST bank accounts the valid amount is always 1 and 1' 37 | try: 38 | verification.confirm(amount_1=1, amount_2=2) 39 | except balanced.exc.BankAccountVerificationFailure as ex: 40 | print 'Authentication error , %s' % ex.message 41 | 42 | # reload 43 | verification = balanced.BankAccount.fetch( 44 | bank_account.href 45 | ).bank_account_verification 46 | 47 | if verification.confirm(1, 1).verification_status != 'succeeded': 48 | raise Exception('unpossible') 49 | debit = bank_account.debit(100) 50 | 51 | print 'debited the bank account %s for %d cents' % ( 52 | debit.source.href, 53 | debit.amount 54 | ) 55 | print 'and there you have it' 56 | 57 | 58 | if __name__ == '__main__': 59 | main() 60 | -------------------------------------------------------------------------------- /examples/error_handling.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | import balanced 4 | 5 | 6 | api_key = balanced.APIKey().save() 7 | balanced.configure(api_key.secret) 8 | marketplace = balanced.Marketplace().save() 9 | 10 | # https://docs.balancedpayments.com/1.1/overview/resources/#test-credit-card-numbers 11 | 12 | declined_card = balanced.Card( 13 | number='4444444444444448', 14 | expiration_month='12', 15 | expiration_year='2015', 16 | ).save() 17 | 18 | bank_account = balanced.BankAccount( 19 | account_number='1234567890', 20 | routing_number='321174851', 21 | name='Jack Q Merchant', 22 | ).save() 23 | 24 | # see https://github.com/balanced/balanced-api/blob/master/fixtures/_models/error.json for all possible error codes 25 | try: 26 | declined_card.debit(amount=100) 27 | except balanced.exc.BalancedError as ex: 28 | assert ex.category_code == 'card-declined' 29 | 30 | try: 31 | bank_account.credit(amount=1000) 32 | except balanced.exc.HTTPError as ex: 33 | assert ex.category_code == 'insufficient-funds' 34 | 35 | try: 36 | balanced.Card().save() 37 | except balanced.exc.BalancedError as ex: 38 | # generic missing data has a category-code of request 39 | assert ex.category_code == 'request' 40 | # inspect extras to see the exact field that caused the error 41 | print ex.extras 42 | # if you want to talk to a Balanced support person about an error, give 43 | # them the request ID 44 | print ex.request_id 45 | -------------------------------------------------------------------------------- /examples/events_and_callbacks.py: -------------------------------------------------------------------------------- 1 | """ 2 | Welcome weary traveller. Sick of polling for state changes? Well today have I 3 | got good news for you. Run this example below to see how to get yourself some 4 | callback goodness and to understand how events work. 5 | """ 6 | from __future__ import unicode_literals 7 | import time 8 | 9 | import balanced 10 | 11 | from helpers import RequestBinClient 12 | 13 | 14 | def init(): 15 | key = balanced.APIKey().save() 16 | balanced.configure(key.secret) 17 | balanced.Marketplace().save() 18 | 19 | 20 | def main(): 21 | init() 22 | request_bin = RequestBinClient() 23 | 24 | print 'let\'s create a callback' 25 | balanced.Callback( 26 | url=request_bin.callback_url, 27 | ).save() 28 | 29 | print "let's create a customer" 30 | balanced.Customer(name='Bob McTavish').save() 31 | 32 | print 'let\'s create a card and associate it with a new account' 33 | card = balanced.Card( 34 | expiration_month='12', 35 | csc='123', 36 | number='5105105105105100', 37 | expiration_year='2020', 38 | ).save() 39 | 40 | print 'generate a debit (which implicitly creates and captures a hold)' 41 | card.debit(100) 42 | 43 | print 'event creation is an async operation, let\'s wait until we have ' \ 44 | 'some events!' 45 | while not balanced.Event.query.count(): 46 | print 'Zzzz' 47 | time.sleep(0) 48 | 49 | print 'Woop, we got some events, let us see what there is to look at' 50 | for event in balanced.Event.query: 51 | print 'this was a {0} event, it occurred at {1}, the callback has a ' \ 52 | 'status of {2}'.format( 53 | event.type, 54 | event.occurred_at, 55 | event.callback_statuses 56 | ) 57 | 58 | print 'you can inspect each event to see the logs' 59 | event = balanced.Event.query.first() 60 | for callback in event.callbacks: 61 | print 'inspecting callback to {0} for event {1}'.format( 62 | callback.url, 63 | event.type, 64 | ) 65 | for log in callback.logs: 66 | print 'this attempt to the callback has a status "{0}"'.format( 67 | log.status 68 | ) 69 | 70 | print 'ok, let\'s check with requestb.in to see if our callbacks fired' 71 | print 'we received {0} callbacks, you can view them at {1}'.format( 72 | len(request_bin.get_requests()), 73 | request_bin.view_url, 74 | ) 75 | 76 | 77 | if __name__ == '__main__': 78 | main() 79 | -------------------------------------------------------------------------------- /examples/examples.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | import balanced 4 | 5 | 6 | print "create our new api key" 7 | api_key = balanced.APIKey().save() 8 | print "Our secret is: ", api_key.secret 9 | 10 | print "configure with our secret " + api_key.secret 11 | balanced.configure(api_key.secret) 12 | 13 | print "create our marketplace" 14 | marketplace = balanced.Marketplace().save() 15 | 16 | # what's my marketplace? 17 | if not balanced.Marketplace.my_marketplace: 18 | raise Exception("Marketplace.my_marketplace should not be nil") 19 | print "what's my marketplace?, easy: Marketplace.my_marketplace: {0}".format( 20 | balanced.Marketplace.my_marketplace 21 | ) 22 | 23 | print "My marketplace's name is: {0}".format(marketplace.name) 24 | print "Changing it to TestFooey" 25 | marketplace.name = "TestFooey" 26 | marketplace.save() 27 | print "My marketplace name is now: {0}".format(marketplace.name) 28 | if marketplace.name != 'TestFooey': 29 | raise Exception("Marketplace name is NOT TestFooey!") 30 | 31 | print "cool! let's create a new card." 32 | card = balanced.Card( 33 | number="5105105105105100", 34 | expiration_month="12", 35 | expiration_year="2015", 36 | ).save() 37 | 38 | print "Our card href: " + card.href 39 | 40 | print "create our **buyer** account" 41 | buyer = balanced.Customer(email="buyer@example.org", source=card).save() 42 | print "our buyer account: " + buyer.href 43 | 44 | print "hold some amount of funds on the buyer, lets say 15$" 45 | the_hold = card.hold(1500) 46 | 47 | print "ok, no more holds! lets just capture it (for the full amount)" 48 | debit = the_hold.capture() 49 | 50 | print "hmm, how much money do i have in escrow? should equal the debit amount" 51 | marketplace = balanced.Marketplace.my_marketplace 52 | if marketplace.in_escrow != 1500: 53 | raise Exception("1500 is not in escrow! this is wrong") 54 | print "i have {0} in escrow!".format(marketplace.in_escrow) 55 | 56 | print "cool. now let me refund the full amount" 57 | refund = debit.refund() # the full amount! 58 | 59 | print ("ok, we have a merchant that's signing up, let's create an account for " 60 | "them first, lets create their bank account.") 61 | 62 | bank_account = balanced.BankAccount( 63 | account_number="1234567890", 64 | routing_number="321174851", 65 | name="Jack Q Merchant", 66 | ).save() 67 | 68 | merchant = balanced.Customer( 69 | email_address="merchant@example.org", 70 | name="Billy Jones", 71 | address={ 72 | 'street_address': "801 High St.", 73 | 'postal_code': "94301", 74 | 'country': "USA", 75 | }, 76 | dob="1842-01", 77 | phone_number="+16505551234", 78 | destination=bank_account, 79 | ).save() 80 | 81 | print "oh our buyer is interested in buying something for 130.00$" 82 | another_debit = card.debit(13000, appears_on_statement_as="MARKETPLACE.COM") 83 | 84 | print "lets credit our merchant 110.00$" 85 | credit = bank_account.credit( 86 | 11000, description="Buyer purchased something on MARKETPLACE.COM") 87 | 88 | print "lets assume the marketplace charges 15%, so it earned $20" 89 | mp_credit = marketplace.owner_customer.bank_accounts.first().credit( 90 | 2000, description="Our commission from MARKETPLACE.COM") 91 | 92 | print "ok lets invalid a card" 93 | card.delete() 94 | 95 | assert buyer.cards.count() == 0 96 | 97 | print "invalidating a bank account" 98 | bank_account.delete() 99 | 100 | print "associate a card with an exiting customer" 101 | card = balanced.Card( 102 | number="5105105105105100", 103 | expiration_month="12", 104 | expiration_year="2015", 105 | ).save() 106 | 107 | card.associate_to_customer(buyer) 108 | 109 | assert buyer.cards.count() == 1 110 | 111 | print "and there you have it :)" 112 | -------------------------------------------------------------------------------- /examples/helpers/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | import simplejson as json 3 | 4 | import requests 5 | 6 | 7 | class RequestBinClient(object): 8 | base_url = 'http://requestb.in/api/v1' 9 | create_url = base_url + '/bins' 10 | 11 | def __init__(self): 12 | response = requests.post(self.create_url) 13 | self.bin = json.loads(response.text) 14 | 15 | def get_requests(self): 16 | response = requests.get( 17 | self.create_url + '/{}/requests'.format(self.bin['name']) 18 | ) 19 | return json.loads(response.text) 20 | 21 | @property 22 | def callback_url(self): 23 | return 'http://requestb.in/{}'.format(self.bin['name']) 24 | 25 | @property 26 | def view_url(self): 27 | return self.callback_url + '?inspect' 28 | 29 | def __str__(self): 30 | return str(self.bin) 31 | -------------------------------------------------------------------------------- /examples/orders.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | import balanced 4 | 5 | 6 | key = balanced.APIKey().save() 7 | balanced.configure(key.secret) 8 | balanced.Marketplace().save() 9 | 10 | # here's the merchant customer who is going to be the recipient of the order 11 | merchant = balanced.Customer().save() 12 | bank_account = balanced.BankAccount( 13 | account_number="1234567890", 14 | routing_number="321174851", 15 | name="Jack Q Merchant", 16 | ).save() 17 | bank_account.associate_to_customer(merchant) 18 | 19 | order = merchant.create_order(description='foo order') 20 | 21 | card = balanced.Card( 22 | number="5105105105105100", 23 | expiration_month="12", 24 | expiration_year="2015", 25 | ).save() 26 | 27 | # debit the card and associate with the order. 28 | card.debit(amount=100, order=order) 29 | 30 | order = balanced.Order.fetch(order.href) 31 | 32 | # the order captured the amount of the debit 33 | assert order.amount_escrowed == 100 34 | 35 | # pay out half 36 | credit = bank_account.credit(amount=50, order=order) 37 | 38 | order = balanced.Order.fetch(order.href) 39 | 40 | # half the money remains 41 | assert order.amount_escrowed == 50 42 | 43 | # let's try paying out to another funding instrument that is not the recipient 44 | # of the order. 45 | another_bank_account = balanced.BankAccount( 46 | account_number="1234567890", 47 | routing_number="321174851", 48 | name="Jack Q Merchant", 49 | ).save() 50 | 51 | another_merchant = balanced.Customer().save() 52 | another_bank_account.associate_to_customer(another_merchant) 53 | 54 | # cannot credit to a bank account which is not assigned to either the 55 | # marketplace or the merchant associated with the order. 56 | try: 57 | another_credit = another_bank_account.credit(amount=50, order=order) 58 | except balanced.exc.BalancedError as ex: 59 | print ex 60 | 61 | assert ex is not None 62 | 63 | # bring the money back again 64 | reversal = credit.reverse() 65 | 66 | order = balanced.Order.fetch(order.href) 67 | 68 | # order escrow is topped up again 69 | assert order.amount_escrowed == 100 70 | -------------------------------------------------------------------------------- /render_scenarios.py: -------------------------------------------------------------------------------- 1 | import glob2 2 | import os 3 | import json 4 | import balanced 5 | import pprint 6 | import requests 7 | import sys 8 | 9 | from pprint import PrettyPrinter 10 | from mako.template import Template 11 | from mako.lookup import TemplateLookup 12 | 13 | class colors: 14 | GREEN = '\033[92m' 15 | YELLOW = '\033[93m' 16 | RED = '\033[91m' 17 | RESET = '\033[0m' 18 | 19 | SCENARIO_CACHE_URL = 'https://raw.githubusercontent.com/balanced/balanced-docs/master/scenario.cache' 20 | 21 | def construct_response(scenario_name): 22 | # load up response data 23 | data = json.load(open('scenario.cache','r')) 24 | lookup = TemplateLookup(directories=['./scenarios']) 25 | 26 | for path in glob2.glob('./scenarios/**/request.mako'): 27 | if path != scenario_name: 28 | continue 29 | event_name = path.split('/')[-2] 30 | template = Template("${response}") 31 | try: 32 | response = data[event_name].get('response', {}) 33 | text = template.render(response=response).strip() 34 | response = json.loads(text) 35 | del response["links"] 36 | for key, value in response.items(): 37 | response = value[0] 38 | type = key 39 | resource = balanced.Resource() 40 | object_type = resource.registry[type] 41 | object_instance = object_type() 42 | for key, value in response.items(): 43 | setattr(object_instance, key, value) 44 | text = template.render(response=object_instance) 45 | except KeyError: 46 | text = '' 47 | return text 48 | 49 | def render_executables(): 50 | # load up scenario data 51 | data = json.load(open('scenario.cache','r')) 52 | lookup = TemplateLookup(directories=['./scenarios']) 53 | 54 | for path in glob2.glob('./scenarios/**/request.mako'): 55 | event_name = path.split('/')[-2] 56 | template = Template(filename=path, lookup=lookup,) 57 | try: 58 | request = data[event_name].get('request', {}) 59 | payload = request.get('payload') 60 | text = template.render(api_key=data['api_key'], 61 | request=request, payload=payload).strip() 62 | except KeyError: 63 | text = '' 64 | print colors.YELLOW + "WARN: Skipped {} since {} not in scenario.cache".format( 65 | path, event_name) + colors.RESET 66 | with open(os.path.join(os.path.dirname(path), 67 | 'executable.py'), 'w+') as write_to: 68 | write_to.write(text) 69 | 70 | def render_mako(): 71 | for path in glob2.glob('./scenarios/**/request.mako'): 72 | dir = os.path.dirname(path) 73 | with open(os.path.join(dir, 'python.mako'), 'w+b') as wfile: 74 | definition = open(os.path.join(dir, 'definition.mako'),'r').read() 75 | request = open(os.path.join(dir, 'executable.py'),'r').read() 76 | response = construct_response(path) 77 | body = "% if mode == 'definition':\n{}".format(definition) + "\n" \ 78 | "% elif mode == 'request':\n" + request + "\n" \ 79 | "% elif mode == 'response':\n" + response + "\n% endif" 80 | wfile.write(body) 81 | 82 | def fetch_scenario_cache(): 83 | try: 84 | os.remove('scenario.cache') 85 | except OSError: 86 | pass 87 | 88 | with open('scenario.cache', 'wb') as fo: 89 | response = requests.get(SCENARIO_CACHE_URL) 90 | if not response.ok: 91 | sys.exit() 92 | for block in response.iter_content(): 93 | fo.write(block) 94 | 95 | if __name__ == "__main__": 96 | print colors.GREEN + "Obtaining scenario cache..." + colors.RESET 97 | fetch_scenario_cache() 98 | print colors.GREEN + "Making Executables..." + colors.RESET 99 | render_executables() 100 | print colors.GREEN + "Rendering new mako files..." + colors.RESET 101 | render_mako() 102 | 103 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | wac==0.23 2 | iso8601==0.1.4 3 | uritemplate==0.6 4 | -------------------------------------------------------------------------------- /scenarios/_main.mako: -------------------------------------------------------------------------------- 1 | <%! 2 | import string 3 | def reindent(s, numSpaces): 4 | s = string.split(s, '\n') 5 | s = [(numSpaces * ' ') + string.lstrip(line) for line in s] 6 | s = string.join(s, '\n') 7 | return s 8 | %> 9 | 10 | <%def name="recursive_expand(dikt, delimiter='\\')"> 11 | <% 12 | if not dikt: 13 | raise StopIteration 14 | 15 | keys = sorted(dikt.keys(), key=lambda x: isinstance(dikt[x], dict)) 16 | try: 17 | last = keys[-1] 18 | except IndexError: 19 | last = keys[0] 20 | 21 | lines = [] 22 | for k in keys: 23 | if isinstance(dikt[k], dict): 24 | for subk, v, slash in recursive_expand(dikt[k], delimiter): 25 | lines.append(('{0}[{1}]'.format(k, subk), v, slash)) 26 | else: 27 | lines.append((k, dikt[k], '' if k is last else delimiter)) 28 | return lines 29 | %> 30 | 31 | 32 | 33 | <%def name="python_boilerplate()" filter="trim"> 34 | import balanced 35 | 36 | %if api_location: 37 | balanced.configure('${api_key}', root_url='${api_location}') 38 | %else: 39 | balanced.configure('${api_key}') 40 | %endif 41 | 42 | 43 | 44 | 45 | <%def name="payload_expand(payload)" filter="trim"> 46 | <% 47 | formatted_payload = '' 48 | delimiter = ",\n" 49 | keys = payload.keys() 50 | try: 51 | last = keys[-1] 52 | except IndexError: 53 | last = keys[0] 54 | 55 | for k, v, slash in recursive_expand(payload): 56 | if isinstance(v, basestring): 57 | formatted_payload += "{0}='{1}'".format(k,v) 58 | else: 59 | formatted_payload += "{0}={1}".format(k,v) 60 | formatted_payload += '' if k is last else delimiter 61 | %> 62 | ${reindent(formatted_payload, 2)} 63 | 64 | -------------------------------------------------------------------------------- /scenarios/_mj/_template/_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.RESOURCE 2 | -------------------------------------------------------------------------------- /scenarios/_mj/_template/_create/executable.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_create/executable.py -------------------------------------------------------------------------------- /scenarios/_mj/_template/_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.RESOURCE 3 | 4 | % elif mode == 'request': 5 | 6 | % elif mode == 'response': 7 | 8 | % endif -------------------------------------------------------------------------------- /scenarios/_mj/_template/_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | VARIABLE = balanced.RESOURCE() 5 | VARIABLE.save() 6 | -------------------------------------------------------------------------------- /scenarios/_mj/_template/_delete/definition.mako: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_delete/definition.mako -------------------------------------------------------------------------------- /scenarios/_mj/_template/_delete/executable.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_delete/executable.py -------------------------------------------------------------------------------- /scenarios/_mj/_template/_delete/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | 3 | % elif mode == 'request': 4 | 5 | % elif mode == 'response': 6 | 7 | % endif -------------------------------------------------------------------------------- /scenarios/_mj/_template/_delete/request.mako: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_delete/request.mako -------------------------------------------------------------------------------- /scenarios/_mj/_template/_list/definition.mako: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_list/definition.mako -------------------------------------------------------------------------------- /scenarios/_mj/_template/_list/executable.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_list/executable.py -------------------------------------------------------------------------------- /scenarios/_mj/_template/_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | 3 | % elif mode == 'request': 4 | 5 | % elif mode == 'response': 6 | 7 | % endif -------------------------------------------------------------------------------- /scenarios/_mj/_template/_list/request.mako: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_list/request.mako -------------------------------------------------------------------------------- /scenarios/_mj/_template/_retrieve/definition.mako: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_retrieve/definition.mako -------------------------------------------------------------------------------- /scenarios/_mj/_template/_retrieve/executable.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_retrieve/executable.py -------------------------------------------------------------------------------- /scenarios/_mj/_template/_retrieve/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | 3 | % elif mode == 'request': 4 | 5 | % elif mode == 'response': 6 | 7 | % endif -------------------------------------------------------------------------------- /scenarios/_mj/_template/_retrieve/request.mako: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_retrieve/request.mako -------------------------------------------------------------------------------- /scenarios/_mj/_template/_update/definition.mako: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_update/definition.mako -------------------------------------------------------------------------------- /scenarios/_mj/_template/_update/executable.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_update/executable.py -------------------------------------------------------------------------------- /scenarios/_mj/_template/_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | 3 | % elif mode == 'request': 4 | 5 | % elif mode == 'response': 6 | 7 | % endif -------------------------------------------------------------------------------- /scenarios/_mj/_template/_update/request.mako: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/_mj/_template/_update/request.mako -------------------------------------------------------------------------------- /scenarios/_mj/api_key_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.APIKey 2 | -------------------------------------------------------------------------------- /scenarios/_mj/api_key_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | api_key = balanced.APIKey() 6 | api_key.save() -------------------------------------------------------------------------------- /scenarios/_mj/api_key_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.APIKey 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | api_key = balanced.APIKey() 10 | api_key.save() 11 | % elif mode == 'response': 12 | APIKey(links={}, created_at=u'2015-01-09T03:23:00.061959Z', secret=u'ak-test-2i4j501b699lmRiGiCcIg45CM0bBI0JAQ', href=u'/api_keys/AK3DQGzROuoRYulKXMQdHBxX', meta={}, id=u'AK3DQGzROuoRYulKXMQdHBxX') 13 | % endif -------------------------------------------------------------------------------- /scenarios/_mj/api_key_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | api_key = balanced.APIKey() 5 | api_key.save() 6 | -------------------------------------------------------------------------------- /scenarios/_mj/manage: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import unicode_literals 3 | import argparse 4 | import fileinput 5 | import os 6 | import re 7 | import shutil 8 | import sys 9 | 10 | 11 | def convert(name): 12 | s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) 13 | return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() 14 | 15 | 16 | def get_file_paths(directory): 17 | for root, directories, files in os.walk(directory): 18 | 19 | for filename in files: 20 | 21 | # Join the two strings in order to form the full filepath. 22 | filepath = os.path.join(root, filename) 23 | 24 | yield filepath 25 | 26 | 27 | def main(parser): 28 | args = parser.parse_args() 29 | args.command(args) 30 | 31 | 32 | def create(args): 33 | resource = args.resource 34 | try: 35 | exec('from balanced import ' + resource) 36 | except ImportError: 37 | print 'Sorry, we cannot import the resource {} from balanced.'.format( 38 | resource 39 | ) 40 | sys.exit(1) 41 | variable = convert(resource) 42 | print resource, variable 43 | file_root = os.path.dirname(os.path.abspath(__file__)) 44 | for op in ('create', 'delete', 'list', 'retrieve', 'update'): 45 | # copy 46 | 47 | src = os.path.join(file_root, '_template', '_' + op) 48 | dst = os.path.join(file_root, '{}_{}'.format(variable, op)) 49 | try: 50 | shutil.copytree(src, dst) 51 | except OSError: 52 | pass # already exists? 53 | # replace 54 | for file in get_file_paths(dst): 55 | # TODO: write back to file 56 | for line in fileinput.input(file, inplace=True): 57 | line.replace('VARIABLE', variable) 58 | line.replace('RESOURCE', resource) 59 | 60 | 61 | if __name__ == '__main__': 62 | parser = argparse.ArgumentParser(add_help=False) 63 | parents = [parser] 64 | root_parser = argparse.ArgumentParser(parents=parents) 65 | sub_parsers = root_parser.add_subparsers(title='sub-commands') 66 | 67 | sub_parser = sub_parsers.add_parser( 68 | 'create', 69 | description='Create a new set of scenarios', 70 | parents=parents) 71 | sub_parser.add_argument('resource') 72 | sub_parser.set_defaults(command=create) 73 | 74 | main(root_parser) 75 | -------------------------------------------------------------------------------- /scenarios/account_credit/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Account.credit() -------------------------------------------------------------------------------- /scenarios/account_credit/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | payable_account = balanced.Account.fetch('/accounts/AT3ogJE07IErLJYR510QO6sM') 6 | payable_account.credit( 7 | appears_on_statement_as='ThingsCo', 8 | amount=1000, 9 | description='A simple credit', 10 | order='/orders/OR3vURGwVtqDnnkRS9fgH41G', 11 | meta={ 12 | 'rating': '8' 13 | } 14 | ) -------------------------------------------------------------------------------- /scenarios/account_credit/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Account.credit() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | payable_account = balanced.Account.fetch('/accounts/AT3ogJE07IErLJYR510QO6sM') 9 | payable_account.credit( 10 | appears_on_statement_as='ThingsCo', 11 | amount=1000, 12 | description='A simple credit', 13 | order='/orders/OR3vURGwVtqDnnkRS9fgH41G', 14 | meta={ 15 | 'rating': '8' 16 | } 17 | ) 18 | % elif mode == 'response': 19 | Credit(status=u'succeeded', description=u'A simple credit', links={u'customer': u'CU3o1ZAd8Gtxz6ZTIFK9YmsM', u'destination': u'AT3ogJE07IErLJYR510QO6sM', u'order': u'OR3vURGwVtqDnnkRS9fgH41G'}, amount=1000, created_at=u'2015-01-09T03:22:56.285894Z', updated_at=u'2015-01-09T03:22:56.407717Z', failure_reason=None, currency=u'USD', transaction_number=u'CRMJJ-XQI-MUMX', href=u'/credits/CR3zAL8gnvuDGGTqr1UqehlS', meta={u'rating': u'8'}, failure_reason_code=None, appears_on_statement_as=u'ThingsCo', id=u'CR3zAL8gnvuDGGTqr1UqehlS') 20 | % endif -------------------------------------------------------------------------------- /scenarios/account_credit/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | payable_account = balanced.Account.fetch('${request['href']}') 5 | payable_account.credit( 6 | appears_on_statement_as='${request['payload']['appears_on_statement_as']}', 7 | amount=${request['payload']['amount']}, 8 | description='${request['payload']['description']}', 9 | order='${request['payload']['order']}', 10 | meta={ 11 | 'rating': '${request['payload']['meta']['rating']}' 12 | } 13 | ) -------------------------------------------------------------------------------- /scenarios/account_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Account.query 2 | -------------------------------------------------------------------------------- /scenarios/account_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | accounts = balanced.Account.query -------------------------------------------------------------------------------- /scenarios/account_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Account.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | accounts = balanced.Account.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/account_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | accounts = balanced.Account.query -------------------------------------------------------------------------------- /scenarios/account_list_customer/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Account.query 2 | -------------------------------------------------------------------------------- /scenarios/account_list_customer/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | customer = balanced.Customer.fetch('/customers/CU3o1ZAd8Gtxz6ZTIFK9YmsM') 6 | customer.accounts -------------------------------------------------------------------------------- /scenarios/account_list_customer/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Account.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | customer = balanced.Customer.fetch('/customers/CU3o1ZAd8Gtxz6ZTIFK9YmsM') 10 | customer.accounts 11 | % elif mode == 'response': 12 | 13 | % endif -------------------------------------------------------------------------------- /scenarios/account_list_customer/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | customer = balanced.Customer.fetch('${request['customer_href']}') 5 | customer.accounts -------------------------------------------------------------------------------- /scenarios/account_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Account.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/account_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | account = balanced.Account.fetch('/accounts/AT2V7l4MoUJH8xDse641Xqog') -------------------------------------------------------------------------------- /scenarios/account_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Account.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | account = balanced.Account.fetch('/accounts/AT2V7l4MoUJH8xDse641Xqog') 10 | % elif mode == 'response': 11 | Account(links={u'customer': u'CU2V0zJeFwPUCzJsaK48Ly3S'}, can_credit=True, can_debit=True, created_at=u'2015-01-09T03:22:20.308375Z', updated_at=u'2015-01-09T03:22:20.308376Z', currency=u'USD', href=u'/accounts/AT2V7l4MoUJH8xDse641Xqog', meta={}, balance=0, type=u'payable', id=u'AT2V7l4MoUJH8xDse641Xqog') 12 | % endif -------------------------------------------------------------------------------- /scenarios/account_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | account = balanced.Account.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/api_key_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.APIKey() -------------------------------------------------------------------------------- /scenarios/api_key_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | api_key = balanced.APIKey().save() -------------------------------------------------------------------------------- /scenarios/api_key_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.APIKey() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | api_key = balanced.APIKey().save() 9 | % elif mode == 'response': 10 | APIKey(links={}, created_at=u'2015-01-09T03:23:00.061959Z', secret=u'ak-test-2i4j501b699lmRiGiCcIg45CM0bBI0JAQ', href=u'/api_keys/AK3DQGzROuoRYulKXMQdHBxX', meta={}, id=u'AK3DQGzROuoRYulKXMQdHBxX') 11 | % endif -------------------------------------------------------------------------------- /scenarios/api_key_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | api_key = balanced.APIKey().save() -------------------------------------------------------------------------------- /scenarios/api_key_delete/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.APIKey().delete() -------------------------------------------------------------------------------- /scenarios/api_key_delete/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | key = balanced.APIKey.fetch('/api_keys/AK3DQGzROuoRYulKXMQdHBxX') 6 | key.delete() -------------------------------------------------------------------------------- /scenarios/api_key_delete/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.APIKey().delete() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | key = balanced.APIKey.fetch('/api_keys/AK3DQGzROuoRYulKXMQdHBxX') 9 | key.delete() 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/api_key_delete/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | key = balanced.APIKey.fetch('${request['uri']}') 5 | key.delete() -------------------------------------------------------------------------------- /scenarios/api_key_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.APIKey.query 2 | -------------------------------------------------------------------------------- /scenarios/api_key_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | keys = balanced.APIKey.query -------------------------------------------------------------------------------- /scenarios/api_key_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.APIKey.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | keys = balanced.APIKey.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/api_key_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | keys = balanced.APIKey.query -------------------------------------------------------------------------------- /scenarios/api_key_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.APIKey.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/api_key_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | key = balanced.APIKey.fetch('/api_keys/AK3DQGzROuoRYulKXMQdHBxX') -------------------------------------------------------------------------------- /scenarios/api_key_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.APIKey.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | key = balanced.APIKey.fetch('/api_keys/AK3DQGzROuoRYulKXMQdHBxX') 10 | % elif mode == 'response': 11 | APIKey(created_at=u'2015-01-09T03:23:00.061959Z', href=u'/api_keys/AK3DQGzROuoRYulKXMQdHBxX', meta={}, id=u'AK3DQGzROuoRYulKXMQdHBxX', links={}) 12 | % endif -------------------------------------------------------------------------------- /scenarios/api_key_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | key = balanced.APIKey.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/bank_account_associate_to_customer/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccount().associate_to_customer() -------------------------------------------------------------------------------- /scenarios/bank_account_associate_to_customer/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN') 6 | bank_account.associate_to_customer('/customers/CU3o1ZAd8Gtxz6ZTIFK9YmsM') -------------------------------------------------------------------------------- /scenarios/bank_account_associate_to_customer/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccount().associate_to_customer() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN') 9 | bank_account.associate_to_customer('/customers/CU3o1ZAd8Gtxz6ZTIFK9YmsM') 10 | % elif mode == 'response': 11 | BankAccount(routing_number=u'121000358', bank_name=u'BANK OF AMERICA, N.A.', account_type=u'checking', name=u'Johann Bernoulli', links={u'customer': u'CU3o1ZAd8Gtxz6ZTIFK9YmsM', u'bank_account_verification': None}, can_credit=True, created_at=u'2015-01-09T03:23:24.352488Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}, updated_at=u'2015-01-09T03:23:25.100561Z', href=u'/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN', meta={}, account_number=u'xxxxxx0001', fingerprint=u'5f0ba9fa3f1122ef13b944a40abfe44e7eba9e16934e64200913cb4c402ace14', can_debit=False, id=u'BA45anEaEr8g0lOhzhcE9VAN') 12 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_associate_to_customer/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_account = balanced.BankAccount.fetch('${request['uri']}') 5 | bank_account.associate_to_customer('${request['payload']['customer']}') -------------------------------------------------------------------------------- /scenarios/bank_account_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccount().save() -------------------------------------------------------------------------------- /scenarios/bank_account_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | bank_account = balanced.BankAccount( 6 | routing_number='121000358', 7 | account_type='checking', 8 | account_number='9900000001', 9 | name='Johann Bernoulli' 10 | ).save() -------------------------------------------------------------------------------- /scenarios/bank_account_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccount().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | bank_account = balanced.BankAccount( 9 | routing_number='121000358', 10 | account_type='checking', 11 | account_number='9900000001', 12 | name='Johann Bernoulli' 13 | ).save() 14 | % elif mode == 'response': 15 | BankAccount(routing_number=u'121000358', bank_name=u'BANK OF AMERICA, N.A.', account_type=u'checking', name=u'Johann Bernoulli', links={u'customer': None, u'bank_account_verification': None}, can_credit=True, created_at=u'2015-01-09T03:23:24.352488Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}, updated_at=u'2015-01-09T03:23:24.352490Z', href=u'/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN', meta={}, account_number=u'xxxxxx0001', fingerprint=u'5f0ba9fa3f1122ef13b944a40abfe44e7eba9e16934e64200913cb4c402ace14', can_debit=False, id=u'BA45anEaEr8g0lOhzhcE9VAN') 16 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_account = balanced.BankAccount( 5 | <% main.payload_expand(request['payload']) %> 6 | ).save() -------------------------------------------------------------------------------- /scenarios/bank_account_credit/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccount().credit() -------------------------------------------------------------------------------- /scenarios/bank_account_credit/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN') 6 | bank_account.credit( 7 | amount=5000 8 | ) -------------------------------------------------------------------------------- /scenarios/bank_account_credit/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccount().credit() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN') 9 | bank_account.credit( 10 | amount=5000 11 | ) 12 | % elif mode == 'response': 13 | Credit(status=u'pending', description=None, links={u'customer': u'CU3o1ZAd8Gtxz6ZTIFK9YmsM', u'destination': u'BA45anEaEr8g0lOhzhcE9VAN', u'order': None}, amount=5000, created_at=u'2015-01-09T03:25:41.350099Z', updated_at=u'2015-01-09T03:25:41.727056Z', failure_reason=None, currency=u'USD', transaction_number=u'CR6XX-6KR-7GSZ', href=u'/credits/CR6zeufmfv0u1KHrUBCQtAgU', meta={}, failure_reason_code=None, appears_on_statement_as=u'example.com', id=u'CR6zeufmfv0u1KHrUBCQtAgU') 14 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_credit/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_account = balanced.BankAccount.fetch('${request['bank_account_href']}') 5 | bank_account.credit( 6 | <% main.payload_expand(request['payload']) %> 7 | ) -------------------------------------------------------------------------------- /scenarios/bank_account_debit/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccount().debit() -------------------------------------------------------------------------------- /scenarios/bank_account_debit/executable.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/bank_account_debit/executable.py -------------------------------------------------------------------------------- /scenarios/bank_account_debit/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccount().debit() 3 | % elif mode == 'request': 4 | 5 | % elif mode == 'response': 6 | 7 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_debit/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_account = balanced.BankAccount.fetch('${request['bank_account_href']}') 5 | bank_account.debit( 6 | <% main.payload_expand(request['payload']) %> 7 | ) -------------------------------------------------------------------------------- /scenarios/bank_account_debit_order/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Order().debit_from() 2 | -------------------------------------------------------------------------------- /scenarios/bank_account_debit_order/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 6 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3LVXVgJLrzkmB3vUntKJ6t') 7 | order.debit_from( 8 | amount=5000, 9 | source=bank_account, 10 | ) -------------------------------------------------------------------------------- /scenarios/bank_account_debit_order/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Order().debit_from() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 10 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3LVXVgJLrzkmB3vUntKJ6t') 11 | order.debit_from( 12 | amount=5000, 13 | source=bank_account, 14 | ) 15 | % elif mode == 'response': 16 | Debit(status=u'pending', description=u'Order #12341234', links={u'customer': None, u'source': u'BA3LVXVgJLrzkmB3vUntKJ6t', u'dispute': None, u'order': u'OR3vURGwVtqDnnkRS9fgH41G', u'card_hold': None}, amount=5000, created_at=u'2015-01-09T03:23:26.676705Z', updated_at=u'2015-01-09T03:23:26.949357Z', failure_reason=None, currency=u'USD', transaction_number=u'WULC-EFN-JTW0', href=u'/debits/WD47MlpITdspMYF3lZSxmGtT', meta={}, failure_reason_code=None, appears_on_statement_as=u'BAL*example.com', id=u'WD47MlpITdspMYF3lZSxmGtT') 17 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_debit_order/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | order = balanced.Order.fetch('${request['order_href']}') 5 | bank_account = balanced.BankAccount.fetch('${request['bank_account_href']}') 6 | order.debit_from( 7 | amount=${payload['amount']}, 8 | source=bank_account, 9 | ) -------------------------------------------------------------------------------- /scenarios/bank_account_delete/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccount().delete() -------------------------------------------------------------------------------- /scenarios/bank_account_delete/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3Ya2sAlEQE14O1iS17FN0Q') 6 | bank_account.delete() -------------------------------------------------------------------------------- /scenarios/bank_account_delete/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccount().delete() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3Ya2sAlEQE14O1iS17FN0Q') 9 | bank_account.delete() 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_delete/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_account = balanced.BankAccount.fetch('${request['uri']}') 5 | bank_account.delete() -------------------------------------------------------------------------------- /scenarios/bank_account_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccount.query 2 | -------------------------------------------------------------------------------- /scenarios/bank_account_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | bank_accounts = balanced.BankAccount.query -------------------------------------------------------------------------------- /scenarios/bank_account_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccount.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | bank_accounts = balanced.BankAccount.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_accounts = balanced.BankAccount.query -------------------------------------------------------------------------------- /scenarios/bank_account_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccount.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/bank_account_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3Ya2sAlEQE14O1iS17FN0Q') -------------------------------------------------------------------------------- /scenarios/bank_account_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccount.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3Ya2sAlEQE14O1iS17FN0Q') 10 | % elif mode == 'response': 11 | BankAccount(routing_number=u'121000358', bank_name=u'BANK OF AMERICA, N.A.', account_type=u'checking', name=u'Johann Bernoulli', links={u'customer': None, u'bank_account_verification': None}, can_credit=True, created_at=u'2015-01-09T03:23:18.120531Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}, updated_at=u'2015-01-09T03:23:18.120532Z', href=u'/bank_accounts/BA3Ya2sAlEQE14O1iS17FN0Q', meta={}, account_number=u'xxxxxx0001', fingerprint=u'5f0ba9fa3f1122ef13b944a40abfe44e7eba9e16934e64200913cb4c402ace14', can_debit=False, id=u'BA3Ya2sAlEQE14O1iS17FN0Q') 12 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_account = balanced.BankAccount.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/bank_account_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccount().debit() -------------------------------------------------------------------------------- /scenarios/bank_account_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3Ya2sAlEQE14O1iS17FN0Q') 6 | bank_account.meta = { 7 | 'twitter.id'='1234987650', 8 | 'facebook.user_id'='0192837465', 9 | 'my-own-customer-id'='12345' 10 | } 11 | bank_account.save() -------------------------------------------------------------------------------- /scenarios/bank_account_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccount().debit() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3Ya2sAlEQE14O1iS17FN0Q') 9 | bank_account.meta = { 10 | 'twitter.id'='1234987650', 11 | 'facebook.user_id'='0192837465', 12 | 'my-own-customer-id'='12345' 13 | } 14 | bank_account.save() 15 | % elif mode == 'response': 16 | BankAccount(routing_number=u'121000358', bank_name=u'BANK OF AMERICA, N.A.', account_type=u'checking', name=u'Johann Bernoulli', links={u'customer': None, u'bank_account_verification': None}, can_credit=True, created_at=u'2015-01-09T03:23:18.120531Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}, updated_at=u'2015-01-09T03:23:22.310587Z', href=u'/bank_accounts/BA3Ya2sAlEQE14O1iS17FN0Q', meta={u'twitter.id': u'1234987650', u'facebook.user_id': u'0192837465', u'my-own-customer-id': u'12345'}, account_number=u'xxxxxx0001', fingerprint=u'5f0ba9fa3f1122ef13b944a40abfe44e7eba9e16934e64200913cb4c402ace14', can_debit=False, id=u'BA3Ya2sAlEQE14O1iS17FN0Q') 17 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_account = balanced.BankAccount.fetch('${request['uri']}') 5 | bank_account.meta = { 6 | 'twitter.id'='1234987650', 7 | 'facebook.user_id'='0192837465', 8 | 'my-own-customer-id'='12345' 9 | } 10 | bank_account.save() -------------------------------------------------------------------------------- /scenarios/bank_account_verification_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccountVerification().save() -------------------------------------------------------------------------------- /scenarios/bank_account_verification_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3LVXVgJLrzkmB3vUntKJ6t') 6 | verification = bank_account.verify() -------------------------------------------------------------------------------- /scenarios/bank_account_verification_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccountVerification().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA3LVXVgJLrzkmB3vUntKJ6t') 9 | verification = bank_account.verify() 10 | % elif mode == 'response': 11 | BankAccountVerification(verification_status=u'pending', links={u'bank_account': u'BA3LVXVgJLrzkmB3vUntKJ6t'}, created_at=u'2015-01-09T03:23:13.465191Z', attempts_remaining=3, updated_at=u'2015-01-09T03:23:13.465192Z', deposit_status=u'pending', attempts=0, href=u'/verifications/BZ3SVvXTx85CrYo8045tr2cU', meta={}, id=u'BZ3SVvXTx85CrYo8045tr2cU') 12 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_verification_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_account = balanced.BankAccount.fetch('${request['bank_account_uri']}') 5 | verification = bank_account.verify() -------------------------------------------------------------------------------- /scenarios/bank_account_verification_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccountVerification.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/bank_account_verification_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | verification = balanced.BankAccountVerification.fetch('/verifications/BZ3SVvXTx85CrYo8045tr2cU') -------------------------------------------------------------------------------- /scenarios/bank_account_verification_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccountVerification.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | verification = balanced.BankAccountVerification.fetch('/verifications/BZ3SVvXTx85CrYo8045tr2cU') 9 | % elif mode == 'response': 10 | BankAccountVerification(verification_status=u'pending', links={u'bank_account': u'BA3LVXVgJLrzkmB3vUntKJ6t'}, created_at=u'2015-01-09T03:23:13.465191Z', attempts_remaining=3, updated_at=u'2015-01-09T03:23:13.465192Z', deposit_status=u'pending', attempts=0, href=u'/verifications/BZ3SVvXTx85CrYo8045tr2cU', meta={}, id=u'BZ3SVvXTx85CrYo8045tr2cU') 11 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_verification_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | verification = balanced.BankAccountVerification.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/bank_account_verification_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccountVerification().confirm() -------------------------------------------------------------------------------- /scenarios/bank_account_verification_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | verification = balanced.BankAccountVerification.fetch('/verifications/BZ3SVvXTx85CrYo8045tr2cU') 6 | verification.confirm(amount_1=1, amount_2=1) -------------------------------------------------------------------------------- /scenarios/bank_account_verification_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccountVerification().confirm() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | verification = balanced.BankAccountVerification.fetch('/verifications/BZ3SVvXTx85CrYo8045tr2cU') 9 | verification.confirm(amount_1=1, amount_2=1) 10 | % elif mode == 'response': 11 | BankAccountVerification(verification_status=u'succeeded', links={u'bank_account': u'BA3LVXVgJLrzkmB3vUntKJ6t'}, created_at=u'2015-01-09T03:23:13.465191Z', attempts_remaining=2, updated_at=u'2015-01-09T03:23:16.381292Z', deposit_status=u'succeeded', attempts=1, href=u'/verifications/BZ3SVvXTx85CrYo8045tr2cU', meta={}, id=u'BZ3SVvXTx85CrYo8045tr2cU') 12 | % endif -------------------------------------------------------------------------------- /scenarios/bank_account_verification_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | verification = balanced.BankAccountVerification.fetch('${request['uri']}') 5 | verification.confirm(amount_1=1, amount_2=1) 6 | -------------------------------------------------------------------------------- /scenarios/callback_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Callback() -------------------------------------------------------------------------------- /scenarios/callback_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | callback = balanced.Callback( 6 | url='http://www.example.com/callback_test', 7 | method='post' 8 | ).save() -------------------------------------------------------------------------------- /scenarios/callback_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Callback() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | callback = balanced.Callback( 9 | url='http://www.example.com/callback_test', 10 | method='post' 11 | ).save() 12 | % elif mode == 'response': 13 | Callback(links={}, url=u'http://www.example.com/callback_test', id=u'CB4a7Q7HSdJJgMVHwPsarIw8', href=u'/callbacks/CB4a7Q7HSdJJgMVHwPsarIw8', method=u'post', revision=u'1.1') 14 | % endif -------------------------------------------------------------------------------- /scenarios/callback_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | callback = balanced.Callback( 5 | <% main.payload_expand(request['payload']) %> 6 | ).save() -------------------------------------------------------------------------------- /scenarios/callback_delete/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Callback().unstore() -------------------------------------------------------------------------------- /scenarios/callback_delete/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | callback = balanced.Callback.fetch('/callbacks/CB4a7Q7HSdJJgMVHwPsarIw8') 6 | callback.unstore() -------------------------------------------------------------------------------- /scenarios/callback_delete/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Callback().unstore() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | callback = balanced.Callback.fetch('/callbacks/CB4a7Q7HSdJJgMVHwPsarIw8') 9 | callback.unstore() 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/callback_delete/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | callback = balanced.Callback.fetch('${request['uri']}') 5 | callback.unstore() -------------------------------------------------------------------------------- /scenarios/callback_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Callback.query 2 | -------------------------------------------------------------------------------- /scenarios/callback_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | callbacks = balanced.Callback.query -------------------------------------------------------------------------------- /scenarios/callback_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Callback.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | callbacks = balanced.Callback.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/callback_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | callbacks = balanced.Callback.query -------------------------------------------------------------------------------- /scenarios/callback_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Callback.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/callback_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | callback = balanced.Callback.fetch('/callbacks/CB4a7Q7HSdJJgMVHwPsarIw8') -------------------------------------------------------------------------------- /scenarios/callback_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Callback.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | callback = balanced.Callback.fetch('/callbacks/CB4a7Q7HSdJJgMVHwPsarIw8') 10 | % elif mode == 'response': 11 | Callback(links={}, url=u'http://www.example.com/callback_test', id=u'CB4a7Q7HSdJJgMVHwPsarIw8', href=u'/callbacks/CB4a7Q7HSdJJgMVHwPsarIw8', method=u'post', revision=u'1.1') 12 | % endif -------------------------------------------------------------------------------- /scenarios/callback_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | callback = balanced.Callback.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/card_associate_to_customer/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().associate_to_customer() -------------------------------------------------------------------------------- /scenarios/card_associate_to_customer/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card.fetch('/cards/CC4HDcgvzIltvwv6GSjBVbji') 6 | card.associate_to_customer('/customers/CU3o1ZAd8Gtxz6ZTIFK9YmsM') -------------------------------------------------------------------------------- /scenarios/card_associate_to_customer/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().associate_to_customer() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card.fetch('/cards/CC4HDcgvzIltvwv6GSjBVbji') 9 | card.associate_to_customer('/customers/CU3o1ZAd8Gtxz6ZTIFK9YmsM') 10 | % elif mode == 'response': 11 | Card(links={u'customer': u'CU3o1ZAd8Gtxz6ZTIFK9YmsM'}, cvv_result=None, number=u'xxxxxxxxxxxx1118', expiration_month=5, href=u'/cards/CC4HDcgvzIltvwv6GSjBVbji', type=u'debit', id=u'CC4HDcgvzIltvwv6GSjBVbji', category=u'other', is_verified=True, cvv_match=None, bank_name=u'WELLS FARGO BANK, N.A.', avs_street_match=None, brand=u'Visa', updated_at=u'2015-01-09T03:23:59.133903Z', fingerprint=u'7dc93d35b59078a1da8e0ebd2cbec65a6ca205760a1be1b90a143d7f2b00e355', can_debit=True, name=u'Johannes Bach', expiration_year=2020, cvv=None, avs_postal_match=None, avs_result=None, can_credit=True, meta={}, created_at=u'2015-01-09T03:23:58.549644Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}) 12 | % endif -------------------------------------------------------------------------------- /scenarios/card_associate_to_customer/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card.fetch('${request['uri']}') 5 | card.associate_to_customer('${request['payload']['customer']}') -------------------------------------------------------------------------------- /scenarios/card_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().save() -------------------------------------------------------------------------------- /scenarios/card_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card( 6 | cvv='123', 7 | expiration_month='12', 8 | number='5105105105105100', 9 | expiration_year='2020' 10 | ).save() -------------------------------------------------------------------------------- /scenarios/card_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card( 9 | cvv='123', 10 | expiration_month='12', 11 | number='5105105105105100', 12 | expiration_year='2020' 13 | ).save() 14 | % elif mode == 'response': 15 | Card(links={u'customer': None}, cvv_result=u'Match', number=u'xxxxxxxxxxxx5100', expiration_month=12, href=u'/cards/CC4zyuNpxY0A0eAf87SeULCR', type=u'credit', id=u'CC4zyuNpxY0A0eAf87SeULCR', category=u'other', is_verified=True, cvv_match=u'yes', bank_name=u'BANK OF HAWAII', avs_street_match=None, brand=u'MasterCard', updated_at=u'2015-01-09T03:23:51.373359Z', fingerprint=u'fc4ccd5de54f42a5e75f76fbfde60948440c7a382ee7d21b2bc509ab9cfed788', can_debit=True, name=None, expiration_year=2020, cvv=u'xxx', avs_postal_match=None, avs_result=None, can_credit=False, meta={}, created_at=u'2015-01-09T03:23:51.373358Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}) 16 | % endif -------------------------------------------------------------------------------- /scenarios/card_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card( 5 | <% main.payload_expand(request['payload']) %> 6 | ).save() -------------------------------------------------------------------------------- /scenarios/card_create_creditable/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().save() -------------------------------------------------------------------------------- /scenarios/card_create_creditable/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card( 6 | expiration_month='05', 7 | name='Johannes Bach', 8 | expiration_year='2020', 9 | number='4342561111111118' 10 | ).save() -------------------------------------------------------------------------------- /scenarios/card_create_creditable/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card( 9 | expiration_month='05', 10 | name='Johannes Bach', 11 | expiration_year='2020', 12 | number='4342561111111118' 13 | ).save() 14 | % elif mode == 'response': 15 | Card(links={u'customer': None}, cvv_result=None, number=u'xxxxxxxxxxxx1118', expiration_month=5, href=u'/cards/CC4HDcgvzIltvwv6GSjBVbji', type=u'debit', id=u'CC4HDcgvzIltvwv6GSjBVbji', category=u'other', is_verified=True, cvv_match=None, bank_name=u'WELLS FARGO BANK, N.A.', avs_street_match=None, brand=u'Visa', updated_at=u'2015-01-09T03:23:58.549645Z', fingerprint=u'7dc93d35b59078a1da8e0ebd2cbec65a6ca205760a1be1b90a143d7f2b00e355', can_debit=True, name=u'Johannes Bach', expiration_year=2020, cvv=None, avs_postal_match=None, avs_result=None, can_credit=True, meta={}, created_at=u'2015-01-09T03:23:58.549644Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}) 16 | % endif -------------------------------------------------------------------------------- /scenarios/card_create_creditable/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card( 5 | <% main.payload_expand(request['payload']) %> 6 | ).save() -------------------------------------------------------------------------------- /scenarios/card_create_dispute/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().save() -------------------------------------------------------------------------------- /scenarios/card_create_dispute/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card( 6 | cvv='123', 7 | expiration_month='12', 8 | number='6500000000000002', 9 | expiration_year='3000' 10 | ).save() -------------------------------------------------------------------------------- /scenarios/card_create_dispute/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card( 9 | cvv='123', 10 | expiration_month='12', 11 | number='6500000000000002', 12 | expiration_year='3000' 13 | ).save() 14 | % elif mode == 'response': 15 | Card(links={u'customer': None}, cvv_result=u'Match', number=u'xxxxxxxxxxxx0002', expiration_month=12, href=u'/cards/CC5RRvpnZIg0PWdSphR8xxPa', type=u'debit', id=u'CC5RRvpnZIg0PWdSphR8xxPa', category=u'other', is_verified=True, cvv_match=u'yes', bank_name=u'BANK OF AMERICA', avs_street_match=None, brand=u'Discover', updated_at=u'2015-01-09T03:25:02.773172Z', fingerprint=u'3c667a62653e187f29b5781eeb0703f26e99558080de0c0f9490b5f9c4ac2871', can_debit=True, name=None, expiration_year=3000, cvv=u'xxx', avs_postal_match=None, avs_result=None, can_credit=True, meta={}, created_at=u'2015-01-09T03:25:02.773170Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}) 16 | % endif -------------------------------------------------------------------------------- /scenarios/card_create_dispute/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card( 5 | <% main.payload_expand(request['payload']) %> 6 | ).save() -------------------------------------------------------------------------------- /scenarios/card_credit/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().credit() -------------------------------------------------------------------------------- /scenarios/card_credit/executable.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/scenarios/card_credit/executable.py -------------------------------------------------------------------------------- /scenarios/card_credit/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().credit() 3 | % elif mode == 'request': 4 | 5 | % elif mode == 'response': 6 | 7 | % endif -------------------------------------------------------------------------------- /scenarios/card_credit/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card.fetch('${request['card_href']}') 5 | card.credit( 6 | <% main.payload_expand(request['payload']) %> 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /scenarios/card_credit_order/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Order().credit_to() 2 | -------------------------------------------------------------------------------- /scenarios/card_credit_order/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 6 | card = balanced.Card.fetch('/cards/CC4HDcgvzIltvwv6GSjBVbji') 7 | order.credit_to( 8 | amount=5000, 9 | source=card, 10 | ) -------------------------------------------------------------------------------- /scenarios/card_credit_order/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Order().credit_to() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 10 | card = balanced.Card.fetch('/cards/CC4HDcgvzIltvwv6GSjBVbji') 11 | order.credit_to( 12 | amount=5000, 13 | source=card, 14 | ) 15 | % elif mode == 'response': 16 | Credit(status=u'succeeded', description=u'Order #12341234', links={u'customer': u'CU3o1ZAd8Gtxz6ZTIFK9YmsM', u'destination': u'CC4HDcgvzIltvwv6GSjBVbji', u'order': u'OR3vURGwVtqDnnkRS9fgH41G'}, amount=5000, created_at=u'2015-01-09T03:24:02.493888Z', updated_at=u'2015-01-09T03:24:02.893852Z', failure_reason=None, currency=u'USD', transaction_number=u'CROCY-7EY-ZRI2', href=u'/credits/CR4M2HpYdKDcG8nh4d5HrKJL', meta={}, failure_reason_code=None, appears_on_statement_as=u'example.com', id=u'CR4M2HpYdKDcG8nh4d5HrKJL') 17 | % endif -------------------------------------------------------------------------------- /scenarios/card_credit_order/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | order = balanced.Order.fetch('${request['order_href']}') 5 | card = balanced.Card.fetch('${request['card_href']}') 6 | order.credit_to( 7 | amount=${payload['amount']}, 8 | source=card, 9 | ) -------------------------------------------------------------------------------- /scenarios/card_debit/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().debit() -------------------------------------------------------------------------------- /scenarios/card_debit/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') 6 | card.debit( 7 | appears_on_statement_as='Statement text', 8 | amount=5000, 9 | description='Some descriptive text for the debit in the dashboard' 10 | ) -------------------------------------------------------------------------------- /scenarios/card_debit/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().debit() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') 9 | card.debit( 10 | appears_on_statement_as='Statement text', 11 | amount=5000, 12 | description='Some descriptive text for the debit in the dashboard' 13 | ) 14 | % elif mode == 'response': 15 | Debit(status=u'succeeded', description=u'Some descriptive text for the debit in the dashboard', links={u'customer': None, u'source': u'CC4zyuNpxY0A0eAf87SeULCR', u'dispute': None, u'order': None, u'card_hold': u'HL5NbQRZSxbr0o64QWu7szni'}, amount=5000, created_at=u'2015-01-09T03:24:58.643499Z', updated_at=u'2015-01-09T03:24:59.368094Z', failure_reason=None, currency=u'USD', transaction_number=u'WS4G-1FI-AT4Z', href=u'/debits/WD5Nd61WpdlRk6D39YVNFAEo', meta={}, failure_reason_code=None, appears_on_statement_as=u'BAL*Statement text', id=u'WD5Nd61WpdlRk6D39YVNFAEo') 16 | % endif -------------------------------------------------------------------------------- /scenarios/card_debit/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card.fetch('${request['card_href']}') 5 | card.debit( 6 | <% main.payload_expand(request['payload']) %> 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /scenarios/card_debit_dispute/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().debit() -------------------------------------------------------------------------------- /scenarios/card_debit_dispute/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card.fetch('/cards/CC5RRvpnZIg0PWdSphR8xxPa') 6 | card.debit( 7 | appears_on_statement_as='Statement text', 8 | amount=5000, 9 | description='Some descriptive text for the debit in the dashboard' 10 | ) -------------------------------------------------------------------------------- /scenarios/card_debit_dispute/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().debit() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card.fetch('/cards/CC5RRvpnZIg0PWdSphR8xxPa') 9 | card.debit( 10 | appears_on_statement_as='Statement text', 11 | amount=5000, 12 | description='Some descriptive text for the debit in the dashboard' 13 | ) 14 | % elif mode == 'response': 15 | Debit(status=u'succeeded', description=u'Some descriptive text for the debit in the dashboard', links={u'customer': None, u'source': u'CC5RRvpnZIg0PWdSphR8xxPa', u'dispute': None, u'order': None, u'card_hold': u'HL5Svbmw6nDDP5HO2RblsBCJ'}, amount=5000, created_at=u'2015-01-09T03:25:03.383375Z', updated_at=u'2015-01-09T03:25:04.090381Z', failure_reason=None, currency=u'USD', transaction_number=u'WA4K-D44-O5DR', href=u'/debits/WD5SwXr9jcCfCmmjTH5MCMFD', meta={}, failure_reason_code=None, appears_on_statement_as=u'BAL*Statement text', id=u'WD5SwXr9jcCfCmmjTH5MCMFD') 16 | % endif -------------------------------------------------------------------------------- /scenarios/card_debit_dispute/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card.fetch('${request['card_href']}') 5 | card.debit( 6 | <% main.payload_expand(request['payload']) %> 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /scenarios/card_delete/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().unstore() -------------------------------------------------------------------------------- /scenarios/card_delete/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') 6 | card.unstore() -------------------------------------------------------------------------------- /scenarios/card_delete/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().unstore() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') 9 | card.unstore() 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/card_delete/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card.fetch('${request['uri']}') 5 | card.unstore() -------------------------------------------------------------------------------- /scenarios/card_hold_capture/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.CardHold().capture() -------------------------------------------------------------------------------- /scenarios/card_hold_capture/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card_hold = balanced.CardHold.fetch('/card_holds/HL4iHX8OBNW7nVsu6MqyjnQ9') 6 | debit = card_hold.capture( 7 | appears_on_statement_as='ShowsUpOnStmt', 8 | description='Some descriptive text for the debit in the dashboard' 9 | ) -------------------------------------------------------------------------------- /scenarios/card_hold_capture/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.CardHold().capture() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card_hold = balanced.CardHold.fetch('/card_holds/HL4iHX8OBNW7nVsu6MqyjnQ9') 9 | debit = card_hold.capture( 10 | appears_on_statement_as='ShowsUpOnStmt', 11 | description='Some descriptive text for the debit in the dashboard' 12 | ) 13 | % elif mode == 'response': 14 | Debit(status=u'succeeded', description=u'Some descriptive text for the debit in the dashboard', links={u'customer': None, u'source': u'CC3vhL91rWtwtHcOBl0ITshG', u'dispute': None, u'order': None, u'card_hold': u'HL4iHX8OBNW7nVsu6MqyjnQ9'}, amount=5000, created_at=u'2015-01-09T03:23:43.969240Z', updated_at=u'2015-01-09T03:23:44.454341Z', failure_reason=None, currency=u'USD', transaction_number=u'W456-5GN-9ECN', href=u'/debits/WD4relmrBWDQmtlKKKmKLi7z', meta={u'holding.for': u'user1', u'meaningful.key': u'some.value'}, failure_reason_code=None, appears_on_statement_as=u'BAL*ShowsUpOnStmt', id=u'WD4relmrBWDQmtlKKKmKLi7z') 15 | % endif -------------------------------------------------------------------------------- /scenarios/card_hold_capture/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card_hold = balanced.CardHold.fetch('${request['card_hold_href']}') 5 | debit = card_hold.capture( 6 | <% main.payload_expand(request['payload']) %> 7 | ) -------------------------------------------------------------------------------- /scenarios/card_hold_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().hold() -------------------------------------------------------------------------------- /scenarios/card_hold_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card.fetch('/cards/CC3vhL91rWtwtHcOBl0ITshG') 6 | card_hold = card.hold( 7 | amount=5000, 8 | description='Some descriptive text for the debit in the dashboard' 9 | ) -------------------------------------------------------------------------------- /scenarios/card_hold_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().hold() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card.fetch('/cards/CC3vhL91rWtwtHcOBl0ITshG') 9 | card_hold = card.hold( 10 | amount=5000, 11 | description='Some descriptive text for the debit in the dashboard' 12 | ) 13 | % elif mode == 'response': 14 | CardHold(status=u'succeeded', description=u'Some descriptive text for the debit in the dashboard', links={u'order': None, u'card': u'CC3vhL91rWtwtHcOBl0ITshG', u'debit': None}, amount=5000, created_at=u'2015-01-09T03:23:46.500278Z', updated_at=u'2015-01-09T03:23:46.803224Z', expires_at=u'2015-01-16T03:23:46.699907Z', failure_reason=None, currency=u'USD', transaction_number=u'HL07I-F9N-OVPO', href=u'/card_holds/HL4u4T2877PfgYwnbhD2XweV', meta={}, failure_reason_code=None, voided_at=None, id=u'HL4u4T2877PfgYwnbhD2XweV') 15 | % endif -------------------------------------------------------------------------------- /scenarios/card_hold_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card.fetch('${request['card_href']}') 5 | card_hold = card.hold( 6 | <% main.payload_expand(request['payload']) %> 7 | ) -------------------------------------------------------------------------------- /scenarios/card_hold_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.CardHold.query 2 | -------------------------------------------------------------------------------- /scenarios/card_hold_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card_holds = balanced.CardHold.query -------------------------------------------------------------------------------- /scenarios/card_hold_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.CardHold.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | card_holds = balanced.CardHold.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/card_hold_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card_holds = balanced.CardHold.query -------------------------------------------------------------------------------- /scenarios/card_hold_order/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().hold() -------------------------------------------------------------------------------- /scenarios/card_hold_order/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 6 | card = balanced.Card.fetch('/cards/CC3vhL91rWtwtHcOBl0ITshG') 7 | card_hold = card.hold( 8 | amount=5000, 9 | description='Some descriptive text for the debit in the dashboard', 10 | order='/orders/OR3vURGwVtqDnnkRS9fgH41G' 11 | ) -------------------------------------------------------------------------------- /scenarios/card_hold_order/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().hold() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 9 | card = balanced.Card.fetch('/cards/CC3vhL91rWtwtHcOBl0ITshG') 10 | card_hold = card.hold( 11 | amount=5000, 12 | description='Some descriptive text for the debit in the dashboard', 13 | order='/orders/OR3vURGwVtqDnnkRS9fgH41G' 14 | ) 15 | % elif mode == 'response': 16 | CardHold(status=u'succeeded', description=u'Some descriptive text for the debit in the dashboard', links={u'order': u'OR3vURGwVtqDnnkRS9fgH41G', u'card': u'CC3vhL91rWtwtHcOBl0ITshG', u'debit': None}, amount=5000, created_at=u'2015-01-09T03:23:34.413652Z', updated_at=u'2015-01-09T03:23:34.713108Z', expires_at=u'2015-01-16T03:23:34.647009Z', failure_reason=None, currency=u'USD', transaction_number=u'HLVKB-4MF-JL5N', href=u'/card_holds/HL4gu3SX4Z5LEPYtYhg6HOOp', meta={}, failure_reason_code=None, voided_at=None, id=u'HL4gu3SX4Z5LEPYtYhg6HOOp') 17 | % endif -------------------------------------------------------------------------------- /scenarios/card_hold_order/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | order = balanced.Order.fetch('${request['order_href']}') 5 | card = balanced.Card.fetch('${request['card_href']}') 6 | card_hold = card.hold( 7 | <% main.payload_expand(request['payload']) %> 8 | ) -------------------------------------------------------------------------------- /scenarios/card_hold_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.CardHold.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/card_hold_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card_hold = balanced.CardHold.fetch('/card_holds/HL4iHX8OBNW7nVsu6MqyjnQ9') -------------------------------------------------------------------------------- /scenarios/card_hold_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.CardHold.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | card_hold = balanced.CardHold.fetch('/card_holds/HL4iHX8OBNW7nVsu6MqyjnQ9') 10 | % elif mode == 'response': 11 | CardHold(status=u'succeeded', description=u'Some descriptive text for the debit in the dashboard', links={u'order': None, u'card': u'CC3vhL91rWtwtHcOBl0ITshG', u'debit': None}, amount=5000, created_at=u'2015-01-09T03:23:36.391121Z', updated_at=u'2015-01-09T03:23:36.674542Z', expires_at=u'2015-01-16T03:23:36.585031Z', failure_reason=None, currency=u'USD', transaction_number=u'HLI6T-T0A-HGZI', href=u'/card_holds/HL4iHX8OBNW7nVsu6MqyjnQ9', meta={}, failure_reason_code=None, voided_at=None, id=u'HL4iHX8OBNW7nVsu6MqyjnQ9') 12 | % endif -------------------------------------------------------------------------------- /scenarios/card_hold_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card_hold = balanced.CardHold.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/card_hold_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.CardHold().save() -------------------------------------------------------------------------------- /scenarios/card_hold_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card_hold = balanced.CardHold.fetch('/card_holds/HL4iHX8OBNW7nVsu6MqyjnQ9') 6 | card_hold.description = 'update this description' 7 | card_hold.meta = { 8 | 'holding.for': 'user1', 9 | 'meaningful.key': 'some.value', 10 | } 11 | card_hold.save() -------------------------------------------------------------------------------- /scenarios/card_hold_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.CardHold().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card_hold = balanced.CardHold.fetch('/card_holds/HL4iHX8OBNW7nVsu6MqyjnQ9') 9 | card_hold.description = 'update this description' 10 | card_hold.meta = { 11 | 'holding.for': 'user1', 12 | 'meaningful.key': 'some.value', 13 | } 14 | card_hold.save() 15 | % elif mode == 'response': 16 | CardHold(status=u'succeeded', description=u'update this description', links={u'order': None, u'card': u'CC3vhL91rWtwtHcOBl0ITshG', u'debit': None}, amount=5000, created_at=u'2015-01-09T03:23:36.391121Z', updated_at=u'2015-01-09T03:23:42.106452Z', expires_at=u'2015-01-16T03:23:36.585031Z', failure_reason=None, currency=u'USD', transaction_number=u'HLI6T-T0A-HGZI', href=u'/card_holds/HL4iHX8OBNW7nVsu6MqyjnQ9', meta={u'holding.for': u'user1', u'meaningful.key': u'some.value'}, failure_reason_code=None, voided_at=None, id=u'HL4iHX8OBNW7nVsu6MqyjnQ9') 17 | % endif -------------------------------------------------------------------------------- /scenarios/card_hold_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card_hold = balanced.CardHold.fetch('${request['uri']}') 5 | card_hold.description = '${request['payload']['description']}' 6 | card_hold.meta = { 7 | 'holding.for': 'user1', 8 | 'meaningful.key': 'some.value', 9 | } 10 | card_hold.save() -------------------------------------------------------------------------------- /scenarios/card_hold_void/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.CardHold().cancel() -------------------------------------------------------------------------------- /scenarios/card_hold_void/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card_hold = balanced.CardHold.fetch('/card_holds/HL4u4T2877PfgYwnbhD2XweV') 6 | card_hold.cancel() -------------------------------------------------------------------------------- /scenarios/card_hold_void/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.CardHold().cancel() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card_hold = balanced.CardHold.fetch('/card_holds/HL4u4T2877PfgYwnbhD2XweV') 9 | card_hold.cancel() 10 | % elif mode == 'response': 11 | CardHold(status=u'succeeded', description=u'Some descriptive text for the debit in the dashboard', links={u'order': None, u'card': u'CC3vhL91rWtwtHcOBl0ITshG', u'debit': None}, amount=5000, created_at=u'2015-01-09T03:23:46.500278Z', updated_at=u'2015-01-09T03:23:47.578727Z', expires_at=u'2015-01-16T03:23:46.699907Z', failure_reason=None, currency=u'USD', transaction_number=u'HL07I-F9N-OVPO', href=u'/card_holds/HL4u4T2877PfgYwnbhD2XweV', meta={}, failure_reason_code=None, voided_at=u'2015-01-09T03:23:47.257558Z', id=u'HL4u4T2877PfgYwnbhD2XweV') 12 | % endif -------------------------------------------------------------------------------- /scenarios/card_hold_void/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card_hold = balanced.CardHold.fetch('${request['uri']}') 5 | card_hold.cancel() -------------------------------------------------------------------------------- /scenarios/card_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card.query 2 | -------------------------------------------------------------------------------- /scenarios/card_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | cards = balanced.Card.query -------------------------------------------------------------------------------- /scenarios/card_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | cards = balanced.Card.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/card_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | cards = balanced.Card.query -------------------------------------------------------------------------------- /scenarios/card_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card.fetch() -------------------------------------------------------------------------------- /scenarios/card_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') -------------------------------------------------------------------------------- /scenarios/card_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card.fetch() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') 9 | % elif mode == 'response': 10 | Card(links={u'customer': None}, cvv_result=u'Match', number=u'xxxxxxxxxxxx5100', expiration_month=12, href=u'/cards/CC4zyuNpxY0A0eAf87SeULCR', type=u'credit', id=u'CC4zyuNpxY0A0eAf87SeULCR', category=u'other', is_verified=True, cvv_match=u'yes', bank_name=u'BANK OF HAWAII', avs_street_match=None, brand=u'MasterCard', updated_at=u'2015-01-09T03:23:51.373359Z', fingerprint=u'fc4ccd5de54f42a5e75f76fbfde60948440c7a382ee7d21b2bc509ab9cfed788', can_debit=True, name=None, expiration_year=2020, cvv=u'xxx', avs_postal_match=None, avs_result=None, can_credit=False, meta={}, created_at=u'2015-01-09T03:23:51.373358Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}) 11 | % endif -------------------------------------------------------------------------------- /scenarios/card_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card.fetch('${request['uri']}') 5 | -------------------------------------------------------------------------------- /scenarios/card_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Card().save() -------------------------------------------------------------------------------- /scenarios/card_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') 6 | card.meta = { 7 | 'twitter.id': '1234987650', 8 | 'facebook.user_id': '0192837465', 9 | 'my-own-customer-id': '12345' 10 | } 11 | card.save() -------------------------------------------------------------------------------- /scenarios/card_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Card().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') 9 | card.meta = { 10 | 'twitter.id': '1234987650', 11 | 'facebook.user_id': '0192837465', 12 | 'my-own-customer-id': '12345' 13 | } 14 | card.save() 15 | % elif mode == 'response': 16 | Card(links={u'customer': None}, cvv_result=u'Match', number=u'xxxxxxxxxxxx5100', expiration_month=12, href=u'/cards/CC4zyuNpxY0A0eAf87SeULCR', type=u'credit', id=u'CC4zyuNpxY0A0eAf87SeULCR', category=u'other', is_verified=True, cvv_match=u'yes', bank_name=u'BANK OF HAWAII', avs_street_match=None, brand=u'MasterCard', updated_at=u'2015-01-09T03:23:56.070888Z', fingerprint=u'fc4ccd5de54f42a5e75f76fbfde60948440c7a382ee7d21b2bc509ab9cfed788', can_debit=True, name=None, expiration_year=2020, cvv=u'xxx', avs_postal_match=None, avs_result=None, can_credit=False, meta={u'twitter.id': u'1234987650', u'facebook.user_id': u'0192837465', u'my-own-customer-id': u'12345'}, created_at=u'2015-01-09T03:23:51.373358Z', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}) 17 | % endif -------------------------------------------------------------------------------- /scenarios/card_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | card = balanced.Card.fetch('${request['uri']}') 5 | card.meta = { 6 | 'twitter.id': '1234987650', 7 | 'facebook.user_id': '0192837465', 8 | 'my-own-customer-id': '12345' 9 | } 10 | card.save() -------------------------------------------------------------------------------- /scenarios/credit_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Credit.query 2 | -------------------------------------------------------------------------------- /scenarios/credit_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | credits = balanced.Credit.query -------------------------------------------------------------------------------- /scenarios/credit_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Credit.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | credits = balanced.Credit.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/credit_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | credits = balanced.Credit.query -------------------------------------------------------------------------------- /scenarios/credit_list_bank_account/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.BankAccount.credits() -------------------------------------------------------------------------------- /scenarios/credit_list_bank_account/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN') 6 | credits = bank_account.credits -------------------------------------------------------------------------------- /scenarios/credit_list_bank_account/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.BankAccount.credits() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN') 9 | credits = bank_account.credits 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/credit_list_bank_account/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | bank_account = balanced.BankAccount.fetch('${request['bank_account_href']}') 5 | credits = bank_account.credits -------------------------------------------------------------------------------- /scenarios/credit_order/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Order().credit_to() -------------------------------------------------------------------------------- /scenarios/credit_order/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 6 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN/credits') 7 | order.credit_to( 8 | amount=5000, 9 | destination=bank_account 10 | ) -------------------------------------------------------------------------------- /scenarios/credit_order/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Order().credit_to() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 9 | bank_account = balanced.BankAccount.fetch('/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN/credits') 10 | order.credit_to( 11 | amount=5000, 12 | destination=bank_account 13 | ) 14 | % elif mode == 'response': 15 | 16 | % endif -------------------------------------------------------------------------------- /scenarios/credit_order/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | order = balanced.Order.fetch('${request['order_href']}') 5 | bank_account = balanced.BankAccount.fetch('${request['bank_account_href']}') 6 | order.credit_to( 7 | amount=${payload['amount']}, 8 | destination=bank_account 9 | ) -------------------------------------------------------------------------------- /scenarios/credit_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Credit.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/credit_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | credit = balanced.Credit.fetch('/credits/CR4RdgCoOqYhr4sjPdcDjf3T') -------------------------------------------------------------------------------- /scenarios/credit_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Credit.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | credit = balanced.Credit.fetch('/credits/CR4RdgCoOqYhr4sjPdcDjf3T') 10 | % elif mode == 'response': 11 | Credit(status=u'pending', description=None, links={u'customer': u'CU3o1ZAd8Gtxz6ZTIFK9YmsM', u'destination': u'BA45anEaEr8g0lOhzhcE9VAN', u'order': None}, amount=5000, created_at=u'2015-01-09T03:24:07.078171Z', updated_at=u'2015-01-09T03:24:07.425391Z', failure_reason=None, currency=u'USD', transaction_number=u'CRGY7-P5M-OXHO', href=u'/credits/CR4RdgCoOqYhr4sjPdcDjf3T', meta={}, failure_reason_code=None, appears_on_statement_as=u'example.com', id=u'CR4RdgCoOqYhr4sjPdcDjf3T') 12 | % endif -------------------------------------------------------------------------------- /scenarios/credit_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | credit = balanced.Credit.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/credit_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Credit().save() -------------------------------------------------------------------------------- /scenarios/credit_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | credit = balanced.Credit.fetch('/credits/CR4RdgCoOqYhr4sjPdcDjf3T') 6 | credit.meta = { 7 | 'twitter.id': '1234987650', 8 | 'facebook.user_id': '0192837465', 9 | 'my-own-customer-id': '12345' 10 | } 11 | credit.save() -------------------------------------------------------------------------------- /scenarios/credit_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Credit().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | credit = balanced.Credit.fetch('/credits/CR4RdgCoOqYhr4sjPdcDjf3T') 9 | credit.meta = { 10 | 'twitter.id': '1234987650', 11 | 'facebook.user_id': '0192837465', 12 | 'my-own-customer-id': '12345' 13 | } 14 | credit.save() 15 | % elif mode == 'response': 16 | Credit(status=u'pending', description=u'New description for credit', links={u'customer': u'CU3o1ZAd8Gtxz6ZTIFK9YmsM', u'destination': u'BA45anEaEr8g0lOhzhcE9VAN', u'order': None}, amount=5000, created_at=u'2015-01-09T03:24:07.078171Z', updated_at=u'2015-01-09T03:24:15.880088Z', failure_reason=None, currency=u'USD', transaction_number=u'CRGY7-P5M-OXHO', href=u'/credits/CR4RdgCoOqYhr4sjPdcDjf3T', meta={u'facebook.id': u'1234567890', u'anykey': u'valuegoeshere'}, failure_reason_code=None, appears_on_statement_as=u'example.com', id=u'CR4RdgCoOqYhr4sjPdcDjf3T') 17 | % endif -------------------------------------------------------------------------------- /scenarios/credit_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | credit = balanced.Credit.fetch('${request['uri']}') 5 | credit.meta = { 6 | 'twitter.id': '1234987650', 7 | 'facebook.user_id': '0192837465', 8 | 'my-own-customer-id': '12345' 9 | } 10 | credit.save() -------------------------------------------------------------------------------- /scenarios/customer_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Customer().save() -------------------------------------------------------------------------------- /scenarios/customer_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | customer = balanced.Customer( 6 | dob_year=1963, 7 | dob_month=7, 8 | name='Henry Ford', 9 | address={ 10 | 'postal_code': '48120' 11 | } 12 | ).save() -------------------------------------------------------------------------------- /scenarios/customer_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Customer().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | customer = balanced.Customer( 9 | dob_year=1963, 10 | dob_month=7, 11 | name='Henry Ford', 12 | address={ 13 | 'postal_code': '48120' 14 | } 15 | ).save() 16 | % elif mode == 'response': 17 | Customer(name=u'Henry Ford', links={u'source': None, u'destination': None}, created_at=u'2015-01-09T03:24:47.364051Z', dob_month=7, updated_at=u'2015-01-09T03:24:47.598887Z', phone=None, href=u'/customers/CU5AxbQrjAcjsbquafnvwaas', meta={}, dob_year=1963, email=None, address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': u'48120', u'country_code': None}, id=u'CU5AxbQrjAcjsbquafnvwaas', business_name=None, ssn_last4=None, merchant_status=u'underwritten', ein=None) 18 | % endif -------------------------------------------------------------------------------- /scenarios/customer_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | customer = balanced.Customer( 5 | dob_year=1963, 6 | dob_month=7, 7 | name='Henry Ford', 8 | address={ 9 | 'postal_code': '48120' 10 | } 11 | ).save() -------------------------------------------------------------------------------- /scenarios/customer_delete/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Customer().unstore() -------------------------------------------------------------------------------- /scenarios/customer_delete/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | customer = balanced.Customer.fetch('/customers/CU5AxbQrjAcjsbquafnvwaas') 6 | customer.unstore() -------------------------------------------------------------------------------- /scenarios/customer_delete/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Customer().unstore() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | customer = balanced.Customer.fetch('/customers/CU5AxbQrjAcjsbquafnvwaas') 9 | customer.unstore() 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/customer_delete/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | customer = balanced.Customer.fetch('${request['uri']}') 5 | customer.unstore() -------------------------------------------------------------------------------- /scenarios/customer_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Customer.query 2 | -------------------------------------------------------------------------------- /scenarios/customer_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | customers = balanced.Customer.query -------------------------------------------------------------------------------- /scenarios/customer_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Customer.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | customers = balanced.Customer.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/customer_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | customers = balanced.Customer.query -------------------------------------------------------------------------------- /scenarios/customer_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Customer.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/customer_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | customer = balanced.Customer.fetch('/customers/CU5aACCvYYfV6mcWJL4TEcK1') -------------------------------------------------------------------------------- /scenarios/customer_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Customer.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | customer = balanced.Customer.fetch('/customers/CU5aACCvYYfV6mcWJL4TEcK1') 10 | % elif mode == 'response': 11 | Customer(name=u'Henry Ford', links={u'source': None, u'destination': None}, created_at=u'2015-01-09T03:24:24.298841Z', dob_month=7, updated_at=u'2015-01-09T03:24:24.504781Z', phone=None, href=u'/customers/CU5aACCvYYfV6mcWJL4TEcK1', meta={}, dob_year=1963, email=None, address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': u'48120', u'country_code': None}, id=u'CU5aACCvYYfV6mcWJL4TEcK1', business_name=None, ssn_last4=None, merchant_status=u'underwritten', ein=None) 12 | % endif -------------------------------------------------------------------------------- /scenarios/customer_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | customer = balanced.Customer.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/customer_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Customer().save() -------------------------------------------------------------------------------- /scenarios/customer_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | customer = balanced.Debit.fetch('/customers/CU5aACCvYYfV6mcWJL4TEcK1') 6 | customer.email = 'email@newdomain.com' 7 | customer.meta = { 8 | 'shipping-preference': 'ground' 9 | } 10 | customer.save() -------------------------------------------------------------------------------- /scenarios/customer_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Customer().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | customer = balanced.Debit.fetch('/customers/CU5aACCvYYfV6mcWJL4TEcK1') 9 | customer.email = 'email@newdomain.com' 10 | customer.meta = { 11 | 'shipping-preference': 'ground' 12 | } 13 | customer.save() 14 | % elif mode == 'response': 15 | Customer(name=u'Henry Ford', links={u'source': None, u'destination': None}, created_at=u'2015-01-09T03:24:24.298841Z', dob_month=7, updated_at=u'2015-01-09T03:24:42.621096Z', phone=None, href=u'/customers/CU5aACCvYYfV6mcWJL4TEcK1', meta={u'shipping-preference': u'ground'}, dob_year=1963, email=u'email@newdomain.com', address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': u'48120', u'country_code': None}, id=u'CU5aACCvYYfV6mcWJL4TEcK1', business_name=None, ssn_last4=None, merchant_status=u'underwritten', ein=None) 16 | % endif -------------------------------------------------------------------------------- /scenarios/customer_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | customer = balanced.Debit.fetch('${request['uri']}') 5 | customer.email = '${request['payload']['email']}' 6 | customer.meta = { 7 | 'shipping-preference': 'ground' 8 | } 9 | customer.save() -------------------------------------------------------------------------------- /scenarios/debit_dispute_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Debit().dispute 2 | -------------------------------------------------------------------------------- /scenarios/debit_dispute_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | debit = balanced.Debit.fetch('/debits/WD5SwXr9jcCfCmmjTH5MCMFD') 6 | dispute = debit.dispute -------------------------------------------------------------------------------- /scenarios/debit_dispute_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Debit().dispute 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | debit = balanced.Debit.fetch('/debits/WD5SwXr9jcCfCmmjTH5MCMFD') 10 | dispute = debit.dispute 11 | % elif mode == 'response': 12 | Dispute(status=u'pending', links={u'transaction': u'WD5SwXr9jcCfCmmjTH5MCMFD'}, respond_by=u'2015-02-08T03:22:35.440841Z', amount=5000, created_at=u'2015-01-09T03:25:14.170586Z', updated_at=u'2015-01-09T03:25:14.170588Z', initiated_at=u'2015-01-09T03:22:35.440838Z', currency=u'USD', reason=u'fraud', href=u'/disputes/DT64FIXm5agnVqfCMHZVe8dR', meta={}, id=u'DT64FIXm5agnVqfCMHZVe8dR') 13 | % endif -------------------------------------------------------------------------------- /scenarios/debit_dispute_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | debit = balanced.Debit.fetch('${request['debit_href']}') 5 | dispute = debit.dispute -------------------------------------------------------------------------------- /scenarios/debit_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Debit.query 2 | -------------------------------------------------------------------------------- /scenarios/debit_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | debits = balanced.Debit.query -------------------------------------------------------------------------------- /scenarios/debit_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Debit.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | debits = balanced.Debit.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/debit_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | debits = balanced.Debit.query -------------------------------------------------------------------------------- /scenarios/debit_order/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Order().debit_from() 2 | -------------------------------------------------------------------------------- /scenarios/debit_order/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 6 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') 7 | order.debit_from( 8 | amount=5000, 9 | source=card, 10 | ) -------------------------------------------------------------------------------- /scenarios/debit_order/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Order().debit_from() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | order = balanced.Order.fetch('/orders/OR3vURGwVtqDnnkRS9fgH41G') 10 | card = balanced.Card.fetch('/cards/CC4zyuNpxY0A0eAf87SeULCR') 11 | order.debit_from( 12 | amount=5000, 13 | source=card, 14 | ) 15 | % elif mode == 'response': 16 | Debit(status=u'succeeded', description=u'Order #12341234', links={u'customer': None, u'source': u'CC4zyuNpxY0A0eAf87SeULCR', u'dispute': None, u'order': u'OR3vURGwVtqDnnkRS9fgH41G', u'card_hold': u'HL4JLr6FnToEyeoEdOCOTpC5'}, amount=5000, created_at=u'2015-01-09T03:24:00.472796Z', updated_at=u'2015-01-09T03:24:01.120118Z', failure_reason=None, currency=u'USD', transaction_number=u'W2W2-G3K-YCMU', href=u'/debits/WD4JMhEQTuXpqzpBvpgDo633', meta={}, failure_reason_code=None, appears_on_statement_as=u'BAL*example.com', id=u'WD4JMhEQTuXpqzpBvpgDo633') 17 | % endif -------------------------------------------------------------------------------- /scenarios/debit_order/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | order = balanced.Order.fetch('${request['order_href']}') 5 | card = balanced.Card.fetch('${request['card_href']}') 6 | order.debit_from( 7 | amount=${payload['amount']}, 8 | source=card, 9 | ) 10 | -------------------------------------------------------------------------------- /scenarios/debit_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Debit.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/debit_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | debit = balanced.Debit.fetch('/debits/WD5EW7vbyXlTsudIGF5AkrEA') -------------------------------------------------------------------------------- /scenarios/debit_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Debit.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | debit = balanced.Debit.fetch('/debits/WD5EW7vbyXlTsudIGF5AkrEA') 10 | % elif mode == 'response': 11 | Debit(status=u'succeeded', description=u'Some descriptive text for the debit in the dashboard', links={u'customer': None, u'source': u'CC4zyuNpxY0A0eAf87SeULCR', u'dispute': None, u'order': None, u'card_hold': u'HL5EUR5M3MniPMPUQM0hDdeg'}, amount=5000, created_at=u'2015-01-09T03:24:51.290112Z', updated_at=u'2015-01-09T03:24:52.004949Z', failure_reason=None, currency=u'USD', transaction_number=u'WMBW-XBR-0C9N', href=u'/debits/WD5EW7vbyXlTsudIGF5AkrEA', meta={}, failure_reason_code=None, appears_on_statement_as=u'BAL*Statement text', id=u'WD5EW7vbyXlTsudIGF5AkrEA') 12 | % endif -------------------------------------------------------------------------------- /scenarios/debit_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | debit = balanced.Debit.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/debit_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Debit().save() -------------------------------------------------------------------------------- /scenarios/debit_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | debit = balanced.Debit.fetch('/debits/WD5EW7vbyXlTsudIGF5AkrEA') 6 | debit.description = 'New description for debit' 7 | debit.meta = { 8 | 'facebook.id': '1234567890', 9 | 'anykey': 'valuegoeshere', 10 | } 11 | debit.save() -------------------------------------------------------------------------------- /scenarios/debit_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Debit().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | debit = balanced.Debit.fetch('/debits/WD5EW7vbyXlTsudIGF5AkrEA') 9 | debit.description = 'New description for debit' 10 | debit.meta = { 11 | 'facebook.id': '1234567890', 12 | 'anykey': 'valuegoeshere', 13 | } 14 | debit.save() 15 | % elif mode == 'response': 16 | Debit(status=u'succeeded', description=u'New description for debit', links={u'customer': None, u'source': u'CC4zyuNpxY0A0eAf87SeULCR', u'dispute': None, u'order': None, u'card_hold': u'HL5EUR5M3MniPMPUQM0hDdeg'}, amount=5000, created_at=u'2015-01-09T03:24:51.290112Z', updated_at=u'2015-01-09T03:24:56.837641Z', failure_reason=None, currency=u'USD', transaction_number=u'WMBW-XBR-0C9N', href=u'/debits/WD5EW7vbyXlTsudIGF5AkrEA', meta={u'facebook.id': u'1234567890', u'anykey': u'valuegoeshere'}, failure_reason_code=None, appears_on_statement_as=u'BAL*Statement text', id=u'WD5EW7vbyXlTsudIGF5AkrEA') 17 | % endif -------------------------------------------------------------------------------- /scenarios/debit_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | debit = balanced.Debit.fetch('${request['uri']}') 5 | debit.description = '${request['payload']['description']}' 6 | debit.meta = { 7 | 'facebook.id': '1234567890', 8 | 'anykey': 'valuegoeshere', 9 | } 10 | debit.save() -------------------------------------------------------------------------------- /scenarios/dispute_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Dispute.query -------------------------------------------------------------------------------- /scenarios/dispute_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | disputes = balanced.Dispute.query -------------------------------------------------------------------------------- /scenarios/dispute_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Dispute.query 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | disputes = balanced.Dispute.query 9 | % elif mode == 'response': 10 | 11 | % endif -------------------------------------------------------------------------------- /scenarios/dispute_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | disputes = balanced.Dispute.query -------------------------------------------------------------------------------- /scenarios/dispute_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Dispute.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/dispute_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | dispute = balanced.Dispute.fetch('/disputes/DT64FIXm5agnVqfCMHZVe8dR') -------------------------------------------------------------------------------- /scenarios/dispute_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Dispute.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | dispute = balanced.Dispute.fetch('/disputes/DT64FIXm5agnVqfCMHZVe8dR') 10 | % elif mode == 'response': 11 | Dispute(status=u'pending', links={u'transaction': u'WD5SwXr9jcCfCmmjTH5MCMFD'}, respond_by=u'2015-02-08T03:22:35.440841Z', amount=5000, created_at=u'2015-01-09T03:25:14.170586Z', updated_at=u'2015-01-09T03:25:14.170588Z', initiated_at=u'2015-01-09T03:22:35.440838Z', currency=u'USD', reason=u'fraud', href=u'/disputes/DT64FIXm5agnVqfCMHZVe8dR', meta={}, id=u'DT64FIXm5agnVqfCMHZVe8dR') 12 | % endif -------------------------------------------------------------------------------- /scenarios/dispute_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | dispute = balanced.Dispute.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/event_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Event.query 2 | -------------------------------------------------------------------------------- /scenarios/event_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | events = balanced.Event.query -------------------------------------------------------------------------------- /scenarios/event_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Event.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | events = balanced.Event.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/event_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | events = balanced.Event.query -------------------------------------------------------------------------------- /scenarios/event_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Event.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/event_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | event = balanced.Event.fetch('/events/EVc7cbc12497ae11e48e4606debca797bb') -------------------------------------------------------------------------------- /scenarios/event_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Event.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | event = balanced.Event.fetch('/events/EVc7cbc12497ae11e48e4606debca797bb') 10 | % elif mode == 'response': 11 | Event(links={}, occurred_at=u'2015-01-09T03:25:04.090381Z', entity={u'debits': [{u'status': u'succeeded', u'description': u'Some descriptive text for the debit in the dashboard', u'links': {u'customer': None, u'source': u'CC5RRvpnZIg0PWdSphR8xxPa', u'dispute': u'DT64FIXm5agnVqfCMHZVe8dR', u'order': None, u'card_hold': u'HL5Svbmw6nDDP5HO2RblsBCJ'}, u'href': u'/debits/WD5SwXr9jcCfCmmjTH5MCMFD', u'created_at': u'2015-01-09T03:25:03.383375Z', u'transaction_number': u'WA4K-D44-O5DR', u'failure_reason': None, u'updated_at': u'2015-01-09T03:25:04.090381Z', u'currency': u'USD', u'amount': 5000, u'failure_reason_code': None, u'meta': {}, u'appears_on_statement_as': u'BAL*Statement text', u'id': u'WD5SwXr9jcCfCmmjTH5MCMFD'}], u'links': {u'debits.customer': u'/customers/{debits.customer}', u'debits.dispute': u'/disputes/{debits.dispute}', u'debits.card_hold': u'/holds/{debits.card_hold}', u'debits.source': u'/resources/{debits.source}', u'debits.order': u'/orders/{debits.order}', u'debits.refunds': u'/debits/{debits.id}/refunds', u'debits.events': u'/debits/{debits.id}/events'}}, href=u'/events/EVc7cbc12497ae11e48e4606debca797bb', callback_statuses={u'failed': 0, u'retrying': 0, u'succeeded': 0, u'pending': 1}, type=u'debit.succeeded', id=u'EVc7cbc12497ae11e48e4606debca797bb') 12 | % endif -------------------------------------------------------------------------------- /scenarios/event_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | event = balanced.Event.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/order_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Order() -------------------------------------------------------------------------------- /scenarios/order_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | merchant_customer = balanced.Customer.fetch('/customers/CU5AxbQrjAcjsbquafnvwaas') 6 | merchant_customer.create_order( 7 | description='Order #12341234' 8 | ).save() -------------------------------------------------------------------------------- /scenarios/order_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Order() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | merchant_customer = balanced.Customer.fetch('/customers/CU5AxbQrjAcjsbquafnvwaas') 9 | merchant_customer.create_order( 10 | description='Order #12341234' 11 | ).save() 12 | % elif mode == 'response': 13 | Order(delivery_address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}, description=u'Order #12341234', links={u'merchant': u'CU5AxbQrjAcjsbquafnvwaas'}, created_at=u'2015-01-09T03:25:31.087736Z', updated_at=u'2015-01-09T03:25:31.087737Z', currency=u'USD', amount=0, href=u'/orders/OR6nHTLOYehaSU5SoxqQE5WB', meta={}, id=u'OR6nHTLOYehaSU5SoxqQE5WB', amount_escrowed=0) 14 | % endif -------------------------------------------------------------------------------- /scenarios/order_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | merchant_customer = balanced.Customer.fetch('${request['customer_href']}') 5 | merchant_customer.create_order( 6 | <% main.payload_expand(request['payload']) %> 7 | ).save() -------------------------------------------------------------------------------- /scenarios/order_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Order.query 2 | -------------------------------------------------------------------------------- /scenarios/order_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | orders = balanced.Order.query -------------------------------------------------------------------------------- /scenarios/order_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Order.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | orders = balanced.Order.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/order_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | orders = balanced.Order.query -------------------------------------------------------------------------------- /scenarios/order_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Order.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/order_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | order = balanced.Order.fetch('/orders/OR6nHTLOYehaSU5SoxqQE5WB') -------------------------------------------------------------------------------- /scenarios/order_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Order.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | order = balanced.Order.fetch('/orders/OR6nHTLOYehaSU5SoxqQE5WB') 10 | % elif mode == 'response': 11 | Order(delivery_address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}, description=u'Order #12341234', links={u'merchant': u'CU5AxbQrjAcjsbquafnvwaas'}, created_at=u'2015-01-09T03:25:31.087736Z', updated_at=u'2015-01-09T03:25:31.087737Z', currency=u'USD', amount=0, href=u'/orders/OR6nHTLOYehaSU5SoxqQE5WB', meta={}, id=u'OR6nHTLOYehaSU5SoxqQE5WB', amount_escrowed=0) 12 | % endif -------------------------------------------------------------------------------- /scenarios/order_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | order = balanced.Order.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/order_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Order().save() -------------------------------------------------------------------------------- /scenarios/order_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | order = balanced.Order.fetch('/orders/OR6nHTLOYehaSU5SoxqQE5WB') 6 | order.description = 'New description for order' 7 | order.meta = { 8 | 'anykey': 'valuegoeshere', 9 | 'product.id': '1234567890' 10 | } 11 | order.save() -------------------------------------------------------------------------------- /scenarios/order_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Order().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | order = balanced.Order.fetch('/orders/OR6nHTLOYehaSU5SoxqQE5WB') 9 | order.description = 'New description for order' 10 | order.meta = { 11 | 'anykey': 'valuegoeshere', 12 | 'product.id': '1234567890' 13 | } 14 | order.save() 15 | % elif mode == 'response': 16 | Order(delivery_address={u'city': None, u'line2': None, u'line1': None, u'state': None, u'postal_code': None, u'country_code': None}, description=u'New description for order', links={u'merchant': u'CU5AxbQrjAcjsbquafnvwaas'}, created_at=u'2015-01-09T03:25:31.087736Z', updated_at=u'2015-01-09T03:25:34.898356Z', currency=u'USD', amount=0, href=u'/orders/OR6nHTLOYehaSU5SoxqQE5WB', meta={u'product.id': u'1234567890', u'anykey': u'valuegoeshere'}, id=u'OR6nHTLOYehaSU5SoxqQE5WB', amount_escrowed=0) 17 | % endif -------------------------------------------------------------------------------- /scenarios/order_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | order = balanced.Order.fetch('${request['uri']}') 5 | order.description = '${request['payload']['description']}' 6 | order.meta = { 7 | 'anykey': 'valuegoeshere', 8 | 'product.id': '1234567890' 9 | } 10 | order.save() -------------------------------------------------------------------------------- /scenarios/refund_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Debit().refund() -------------------------------------------------------------------------------- /scenarios/refund_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | debit = balanced.Debit.fetch('/debits/WD5Nd61WpdlRk6D39YVNFAEo') 6 | refund = debit.refund( 7 | amount=3000, 8 | description="Refund for Order #1111", 9 | meta={ 10 | "merchant.feedback": "positive", 11 | "user.refund_reason": "not happy with product", 12 | "fulfillment.item.condition": "OK", 13 | } 14 | ) -------------------------------------------------------------------------------- /scenarios/refund_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Debit().refund() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | debit = balanced.Debit.fetch('/debits/WD5Nd61WpdlRk6D39YVNFAEo') 9 | refund = debit.refund( 10 | amount=3000, 11 | description="Refund for Order #1111", 12 | meta={ 13 | "merchant.feedback": "positive", 14 | "user.refund_reason": "not happy with product", 15 | "fulfillment.item.condition": "OK", 16 | } 17 | ) 18 | % elif mode == 'response': 19 | Refund(status=u'succeeded', description=u'Refund for Order #1111', links={u'dispute': None, u'order': None, u'debit': u'WD5Nd61WpdlRk6D39YVNFAEo'}, amount=3000, created_at=u'2015-01-09T03:25:00.202596Z', updated_at=u'2015-01-09T03:25:00.686907Z', currency=u'USD', transaction_number=u'RFN4R-7JB-96UV', href=u'/refunds/RF5OXw4w1a9g2GsPqQ2Hg9hj', meta={u'fulfillment.item.condition': u'OK', u'user.refund_reason': u'not happy with product', u'merchant.feedback': u'positive'}, id=u'RF5OXw4w1a9g2GsPqQ2Hg9hj') 20 | % endif -------------------------------------------------------------------------------- /scenarios/refund_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | debit = balanced.Debit.fetch('${request['debit_href']}') 5 | refund = debit.refund( 6 | amount=3000, 7 | description="Refund for Order #1111", 8 | meta={ 9 | "merchant.feedback": "positive", 10 | "user.refund_reason": "not happy with product", 11 | "fulfillment.item.condition": "OK", 12 | } 13 | ) 14 | -------------------------------------------------------------------------------- /scenarios/refund_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Refund.query 2 | -------------------------------------------------------------------------------- /scenarios/refund_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | refunds = balanced.Refund.query -------------------------------------------------------------------------------- /scenarios/refund_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Refund.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | refunds = balanced.Refund.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/refund_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | refunds = balanced.Refund.query -------------------------------------------------------------------------------- /scenarios/refund_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Refund.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/refund_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | refund = balanced.Refund.fetch('/refunds/RF5OXw4w1a9g2GsPqQ2Hg9hj') -------------------------------------------------------------------------------- /scenarios/refund_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Refund.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | refund = balanced.Refund.fetch('/refunds/RF5OXw4w1a9g2GsPqQ2Hg9hj') 10 | % elif mode == 'response': 11 | Refund(status=u'succeeded', description=u'Refund for Order #1111', links={u'dispute': None, u'order': None, u'debit': u'WD5Nd61WpdlRk6D39YVNFAEo'}, amount=3000, created_at=u'2015-01-09T03:25:00.202596Z', updated_at=u'2015-01-09T03:25:00.686907Z', currency=u'USD', transaction_number=u'RFN4R-7JB-96UV', href=u'/refunds/RF5OXw4w1a9g2GsPqQ2Hg9hj', meta={u'fulfillment.item.condition': u'OK', u'user.refund_reason': u'not happy with product', u'merchant.feedback': u'positive'}, id=u'RF5OXw4w1a9g2GsPqQ2Hg9hj') 12 | % endif -------------------------------------------------------------------------------- /scenarios/refund_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | refund = balanced.Refund.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/refund_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Refund().save() -------------------------------------------------------------------------------- /scenarios/refund_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | refund = balanced.Refund.fetch('/refunds/RF5OXw4w1a9g2GsPqQ2Hg9hj') 6 | refund.description = 'update this description' 7 | refund.meta = { 8 | 'user.refund.count': '3', 9 | 'refund.reason': 'user not happy with product', 10 | 'user.notes': 'very polite on the phone', 11 | } 12 | refund.save() -------------------------------------------------------------------------------- /scenarios/refund_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Refund().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | refund = balanced.Refund.fetch('/refunds/RF5OXw4w1a9g2GsPqQ2Hg9hj') 9 | refund.description = 'update this description' 10 | refund.meta = { 11 | 'user.refund.count': '3', 12 | 'refund.reason': 'user not happy with product', 13 | 'user.notes': 'very polite on the phone', 14 | } 15 | refund.save() 16 | % elif mode == 'response': 17 | Refund(status=u'succeeded', description=u'update this description', links={u'dispute': None, u'order': None, u'debit': u'WD5Nd61WpdlRk6D39YVNFAEo'}, amount=3000, created_at=u'2015-01-09T03:25:00.202596Z', updated_at=u'2015-01-09T03:25:39.570204Z', currency=u'USD', transaction_number=u'RFN4R-7JB-96UV', href=u'/refunds/RF5OXw4w1a9g2GsPqQ2Hg9hj', meta={u'user.refund.count': u'3', u'refund.reason': u'user not happy with product', u'user.notes': u'very polite on the phone'}, id=u'RF5OXw4w1a9g2GsPqQ2Hg9hj') 18 | % endif -------------------------------------------------------------------------------- /scenarios/refund_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | refund = balanced.Refund.fetch('${request['uri']}') 5 | refund.description = '${request['payload']['description']}' 6 | refund.meta = { 7 | 'user.refund.count': '3', 8 | 'refund.reason': 'user not happy with product', 9 | 'user.notes': 'very polite on the phone', 10 | } 11 | refund.save() -------------------------------------------------------------------------------- /scenarios/reversal_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Credit().reverse() -------------------------------------------------------------------------------- /scenarios/reversal_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | credit = balanced.Credit.fetch('/credits/CR6zeufmfv0u1KHrUBCQtAgU') 6 | reversal = credit.reverse( 7 | amount=3000, 8 | description="Reversal for Order #1111", 9 | meta={ 10 | "merchant.feedback": "positive", 11 | "user.refund_reason": "not happy with product", 12 | "fulfillment.item.condition": "OK", 13 | } 14 | ) -------------------------------------------------------------------------------- /scenarios/reversal_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Credit().reverse() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | credit = balanced.Credit.fetch('/credits/CR6zeufmfv0u1KHrUBCQtAgU') 9 | reversal = credit.reverse( 10 | amount=3000, 11 | description="Reversal for Order #1111", 12 | meta={ 13 | "merchant.feedback": "positive", 14 | "user.refund_reason": "not happy with product", 15 | "fulfillment.item.condition": "OK", 16 | } 17 | ) 18 | % elif mode == 'response': 19 | Reversal(status=u'pending', description=u'Reversal for Order #1111', links={u'credit': u'CR6zeufmfv0u1KHrUBCQtAgU', u'order': None}, amount=3000, created_at=u'2015-01-09T03:25:42.331343Z', updated_at=u'2015-01-09T03:25:42.672661Z', failure_reason=None, currency=u'USD', transaction_number=u'RVYWS-BLM-PY8J', href=u'/reversals/RV6AleFrrhNHBDpr9W9ozGmY', meta={u'fulfillment.item.condition': u'OK', u'user.refund_reason': u'not happy with product', u'merchant.feedback': u'positive'}, failure_reason_code=None, id=u'RV6AleFrrhNHBDpr9W9ozGmY') 20 | % endif -------------------------------------------------------------------------------- /scenarios/reversal_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | credit = balanced.Credit.fetch('${request['credit_href']}') 5 | reversal = credit.reverse( 6 | amount=3000, 7 | description="Reversal for Order #1111", 8 | meta={ 9 | "merchant.feedback": "positive", 10 | "user.refund_reason": "not happy with product", 11 | "fulfillment.item.condition": "OK", 12 | } 13 | ) 14 | -------------------------------------------------------------------------------- /scenarios/reversal_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Reversal.query() 2 | -------------------------------------------------------------------------------- /scenarios/reversal_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | reversals = balanced.Reversal.query -------------------------------------------------------------------------------- /scenarios/reversal_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Reversal.query() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | reversals = balanced.Reversal.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/reversal_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | reversals = balanced.Reversal.query -------------------------------------------------------------------------------- /scenarios/reversal_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Reversal.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/reversal_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | refund = balanced.Reversal.fetch('/reversals/RV6AleFrrhNHBDpr9W9ozGmY') -------------------------------------------------------------------------------- /scenarios/reversal_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Reversal.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | refund = balanced.Reversal.fetch('/reversals/RV6AleFrrhNHBDpr9W9ozGmY') 10 | % elif mode == 'response': 11 | Reversal(status=u'pending', description=u'Reversal for Order #1111', links={u'credit': u'CR6zeufmfv0u1KHrUBCQtAgU', u'order': None}, amount=3000, created_at=u'2015-01-09T03:25:42.331343Z', updated_at=u'2015-01-09T03:25:42.672661Z', failure_reason=None, currency=u'USD', transaction_number=u'RVYWS-BLM-PY8J', href=u'/reversals/RV6AleFrrhNHBDpr9W9ozGmY', meta={u'fulfillment.item.condition': u'OK', u'user.refund_reason': u'not happy with product', u'merchant.feedback': u'positive'}, failure_reason_code=None, id=u'RV6AleFrrhNHBDpr9W9ozGmY') 12 | % endif -------------------------------------------------------------------------------- /scenarios/reversal_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | refund = balanced.Reversal.fetch('${request['uri']}') -------------------------------------------------------------------------------- /scenarios/reversal_update/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Reversal().save() -------------------------------------------------------------------------------- /scenarios/reversal_update/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | reversal = balanced.Reversal.fetch('/reversals/RV6AleFrrhNHBDpr9W9ozGmY') 6 | reversal.description = 'update this description' 7 | reversal.meta = { 8 | 'user.refund.count': '3', 9 | 'refund.reason': 'user not happy with product', 10 | 'user.notes': 'very polite on the phone', 11 | } 12 | reversal.save() -------------------------------------------------------------------------------- /scenarios/reversal_update/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Reversal().save() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | reversal = balanced.Reversal.fetch('/reversals/RV6AleFrrhNHBDpr9W9ozGmY') 9 | reversal.description = 'update this description' 10 | reversal.meta = { 11 | 'user.refund.count': '3', 12 | 'refund.reason': 'user not happy with product', 13 | 'user.notes': 'very polite on the phone', 14 | } 15 | reversal.save() 16 | % elif mode == 'response': 17 | Reversal(status=u'pending', description=u'update this description', links={u'credit': u'CR6zeufmfv0u1KHrUBCQtAgU', u'order': None}, amount=3000, created_at=u'2015-01-09T03:25:42.331343Z', updated_at=u'2015-01-09T03:25:46.424201Z', failure_reason=None, currency=u'USD', transaction_number=u'RVYWS-BLM-PY8J', href=u'/reversals/RV6AleFrrhNHBDpr9W9ozGmY', meta={u'user.satisfaction': u'6', u'refund.reason': u'user not happy with product', u'user.notes': u'very polite on the phone'}, failure_reason_code=None, id=u'RV6AleFrrhNHBDpr9W9ozGmY') 18 | % endif -------------------------------------------------------------------------------- /scenarios/reversal_update/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | reversal = balanced.Reversal.fetch('${request['uri']}') 5 | reversal.description = '${request['payload']['description']}' 6 | reversal.meta = { 7 | 'user.refund.count': '3', 8 | 'refund.reason': 'user not happy with product', 9 | 'user.notes': 'very polite on the phone', 10 | } 11 | reversal.save() -------------------------------------------------------------------------------- /scenarios/settlement_create/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Account.settle() -------------------------------------------------------------------------------- /scenarios/settlement_create/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | payable_account = balanced.Account.fetch('/accounts/AT3ogJE07IErLJYR510QO6sM') 6 | payable_account.settle( 7 | appears_on_statement_as='ThingsCo', 8 | funding_instrument='/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN', 9 | description='Payout A', 10 | meta={ 11 | 'group': 'alpha' 12 | } 13 | ) 14 | ) -------------------------------------------------------------------------------- /scenarios/settlement_create/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Account.settle() 3 | % elif mode == 'request': 4 | import balanced 5 | 6 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 7 | 8 | payable_account = balanced.Account.fetch('/accounts/AT3ogJE07IErLJYR510QO6sM') 9 | payable_account.settle( 10 | appears_on_statement_as='ThingsCo', 11 | funding_instrument='/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN', 12 | description='Payout A', 13 | meta={ 14 | 'group': 'alpha' 15 | } 16 | ) 17 | ) 18 | % elif mode == 'response': 19 | Settlement(status=u'pending', description=u'Payout A', links={u'source': u'AT3ogJE07IErLJYR510QO6sM', u'destination': u'BA45anEaEr8g0lOhzhcE9VAN'}, amount=1000, created_at=u'2015-01-09T03:25:48.587751Z', updated_at=u'2015-01-09T03:25:48.946792Z', failure_reason=None, currency=u'USD', transaction_number=u'SCRGN-RWP-FFSL', href=u'/settlements/ST6HmBuLJSEa82oUwId1AShW', meta={u'group': u'alpha'}, failure_reason_code=None, appears_on_statement_as=u'BAL*ThingsCo', id=u'ST6HmBuLJSEa82oUwId1AShW') 20 | % endif -------------------------------------------------------------------------------- /scenarios/settlement_create/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | payable_account = balanced.Account.fetch('${request['href']}') 5 | payable_account.settle( 6 | appears_on_statement_as='${request['payload']['appears_on_statement_as']}', 7 | funding_instrument='${request['payload']['funding_instrument']}', 8 | description='${request['payload']['description']}', 9 | meta={ 10 | 'group': '${request['payload']['meta']['group']}' 11 | } 12 | ) 13 | ) -------------------------------------------------------------------------------- /scenarios/settlement_list/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Settlement.query 2 | -------------------------------------------------------------------------------- /scenarios/settlement_list/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | settlements = balanced.Settlement.query -------------------------------------------------------------------------------- /scenarios/settlement_list/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Settlement.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | settlements = balanced.Settlement.query 10 | % elif mode == 'response': 11 | 12 | % endif -------------------------------------------------------------------------------- /scenarios/settlement_list/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | settlements = balanced.Settlement.query -------------------------------------------------------------------------------- /scenarios/settlement_list_account/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Settlement.query 2 | -------------------------------------------------------------------------------- /scenarios/settlement_list_account/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | account = balanced.Account.fetch('/accounts/AT3ogJE07IErLJYR510QO6sM') 6 | account.settlements -------------------------------------------------------------------------------- /scenarios/settlement_list_account/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Settlement.query 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | account = balanced.Account.fetch('/accounts/AT3ogJE07IErLJYR510QO6sM') 10 | account.settlements 11 | % elif mode == 'response': 12 | 13 | % endif -------------------------------------------------------------------------------- /scenarios/settlement_list_account/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | account = balanced.Account.fetch('${request['href']}') 5 | account.settlements -------------------------------------------------------------------------------- /scenarios/settlement_show/definition.mako: -------------------------------------------------------------------------------- 1 | balanced.Settlement.fetch() 2 | -------------------------------------------------------------------------------- /scenarios/settlement_show/executable.py: -------------------------------------------------------------------------------- 1 | import balanced 2 | 3 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 4 | 5 | settlement = balanced.Settlement.fetch('/settlements/ST6HmBuLJSEa82oUwId1AShW') -------------------------------------------------------------------------------- /scenarios/settlement_show/python.mako: -------------------------------------------------------------------------------- 1 | % if mode == 'definition': 2 | balanced.Settlement.fetch() 3 | 4 | % elif mode == 'request': 5 | import balanced 6 | 7 | balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') 8 | 9 | settlement = balanced.Settlement.fetch('/settlements/ST6HmBuLJSEa82oUwId1AShW') 10 | % elif mode == 'response': 11 | Settlement(status=u'pending', description=u'Payout A', links={u'source': u'AT3ogJE07IErLJYR510QO6sM', u'destination': u'BA45anEaEr8g0lOhzhcE9VAN'}, amount=1000, created_at=u'2015-01-09T03:25:48.587751Z', updated_at=u'2015-01-09T03:25:48.946792Z', failure_reason=None, currency=u'USD', transaction_number=u'SCRGN-RWP-FFSL', href=u'/settlements/ST6HmBuLJSEa82oUwId1AShW', meta={u'group': u'alpha'}, failure_reason_code=None, appears_on_statement_as=u'BAL*ThingsCo', id=u'ST6HmBuLJSEa82oUwId1AShW') 12 | % endif -------------------------------------------------------------------------------- /scenarios/settlement_show/request.mako: -------------------------------------------------------------------------------- 1 | <%namespace file='/_main.mako' name='main'/> 2 | <% main.python_boilerplate() %> 3 | 4 | settlement = balanced.Settlement.fetch('${request['uri']}') -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | Balanced Python client library. 3 | 4 | See ``README.md`` for usage advice. 5 | """ 6 | import os 7 | import re 8 | 9 | try: 10 | import setuptools 11 | except ImportError: 12 | import distutils.core 13 | 14 | setup = distutils.core.setup 15 | else: 16 | setup = setuptools.setup 17 | 18 | 19 | 20 | def _get_version(): 21 | path = os.path.join(PATH_TO_FILE, 'balanced', '__init__.py') 22 | version_re = r".*__version__ = '(.*?)'" 23 | fo = open(path) 24 | try: 25 | return re.compile(version_re, re.S).match(fo.read()).group(1) 26 | finally: 27 | fo.close() 28 | 29 | 30 | def _get_long_description(): 31 | path = os.path.join(PATH_TO_FILE, 'README.md') 32 | fo = open(path) 33 | try: 34 | return fo.read() 35 | finally: 36 | fo.close() 37 | 38 | 39 | def parse_requirements(file_name): 40 | requirements = [] 41 | for line in open(file_name, 'r').read().split('\n'): 42 | if re.match(r'(\s*#)|(\s*$)', line): 43 | continue 44 | if re.match(r'\s*-e\s+', line): 45 | requirements.append(re.sub(r'\s*-e\s+.*#egg=(.*)$', r'\1', line)) 46 | elif re.match(r'\s*-f\s+', line): 47 | pass 48 | else: 49 | requirements.append(line) 50 | 51 | return requirements 52 | 53 | 54 | def parse_dependency_links(file_name): 55 | dependency_links = [] 56 | for line in open(file_name, 'r').read().split('\n'): 57 | if re.match(r'\s*-[ef]\s+', line): 58 | dependency_links.append(re.sub(r'\s*-[ef]\s+', '', line)) 59 | 60 | return dependency_links 61 | 62 | PATH_TO_FILE = os.path.dirname(__file__) 63 | VERSION = _get_version() 64 | LONG_DESCRIPTION = _get_long_description() 65 | 66 | setup( 67 | name='balanced', 68 | version=VERSION, 69 | url='https://balancedpayments.com/', 70 | license='MIT License', 71 | author='Balanced', 72 | author_email='dev@balancedpayments.com', 73 | description='Payments platform for marketplaces', 74 | long_description=LONG_DESCRIPTION, 75 | packages=['balanced'], 76 | test_suite='nose.collector', 77 | install_requires=parse_requirements('requirements.txt'), 78 | dependency_links=parse_dependency_links('requirements.txt'), 79 | classifiers=[ 80 | 'Intended Audience :: Developers', 81 | 'License :: OSI Approved :: MIT License', 82 | 'Programming Language :: Python', 83 | 'Topic :: Software Development :: Libraries :: Python Modules', 84 | ], 85 | ) 86 | -------------------------------------------------------------------------------- /snippets/account-balance.py: -------------------------------------------------------------------------------- 1 | account.balance -------------------------------------------------------------------------------- /snippets/bank-account-create.py: -------------------------------------------------------------------------------- 1 | bank_account = balanced.BankAccount( 2 | routing_number='121000358', 3 | type='checking', 4 | account_number='9900000001', 5 | name='Johann Bernoulli' 6 | ).save() -------------------------------------------------------------------------------- /snippets/bank-account-debit.py: -------------------------------------------------------------------------------- 1 | # bank_account_href is the stored href for the BankAccount 2 | # order_href is the stored href for the Order 3 | bank_account = balanced.BankAccount.fetch(bank_account_href) 4 | bank_account.debit( 5 | appears_on_statement_as='Statement text', 6 | amount=5000, 7 | description='Some descriptive text for the debit in the dashboard', 8 | order=order_href 9 | ) -------------------------------------------------------------------------------- /snippets/bank-account-verification-confirm.py: -------------------------------------------------------------------------------- 1 | # time has elapsed, so find the BankAccountVerification 2 | verification = balanced.BankAccountVerification.find('/verifications/BZ2Sy2Z4Bp2mARnCLztiu2VG') 3 | verification.confirm(amount_1=1, amount_2=1) -------------------------------------------------------------------------------- /snippets/bank-account-verification-create.py: -------------------------------------------------------------------------------- 1 | verification = bank_account.verify -------------------------------------------------------------------------------- /snippets/callback-create.py: -------------------------------------------------------------------------------- 1 | callback = balanced.Callback( 2 | url='http://www.example.com/callback', 3 | method='post' 4 | ).save() -------------------------------------------------------------------------------- /snippets/card-associate-to-customer.py: -------------------------------------------------------------------------------- 1 | card = balanced.Card.fetch(card_href) 2 | card.associate_to_customer(customer_href) -------------------------------------------------------------------------------- /snippets/card-create-dispute.py: -------------------------------------------------------------------------------- 1 | card = balanced.Card( 2 | cvv='123', 3 | expiration_month='12', 4 | number='6500000000000002', 5 | expiration_year='2020' 6 | ).save() -------------------------------------------------------------------------------- /snippets/card-create.py: -------------------------------------------------------------------------------- 1 | card = balanced.Card( 2 | expiration_month='12', 3 | security_code='123', 4 | number='5105105105105100', 5 | expiration_year='2020' 6 | ).save() -------------------------------------------------------------------------------- /snippets/card-credit.py: -------------------------------------------------------------------------------- 1 | # card_href is the stored href for the Card 2 | # order_href is the stored href for the Order 3 | card = balanced.Card.fetch(card_href) 4 | card.credit( 5 | appears_on_statement_as='Some text', 6 | amount=5000, 7 | description='Some descriptive text for the debit in the dashboard', 8 | order=order_href 9 | ) -------------------------------------------------------------------------------- /snippets/card-debit.py: -------------------------------------------------------------------------------- 1 | # card_href is the stored href for the Card 2 | # order_href is the stored href for the Order 3 | card = balanced.Card.fetch(card_href) 4 | card.debit( 5 | appears_on_statement_as='Statement text', 6 | amount=5000, 7 | description='Some descriptive text for the debit in the dashboard', 8 | order=order_href 9 | ) -------------------------------------------------------------------------------- /snippets/card-hold-capture.py: -------------------------------------------------------------------------------- 1 | # card_hold_href is the stored href for the CardHold 2 | card_hold = balanced.CardHold.fetch(card_hold_href) 3 | debit = card_hold.capture( 4 | appears_on_statement_as='ShowsUpOnStmt', 5 | description='Some descriptive text for the debit in the dashboard' 6 | ) -------------------------------------------------------------------------------- /snippets/card-hold-create.py: -------------------------------------------------------------------------------- 1 | # card_href is the stored href for the Card 2 | card = balanced.Card.fetch(card_href) 3 | card_hold = card.hold( 4 | amount=5000, 5 | description='Some descriptive text for the debit in the dashboard' 6 | ) -------------------------------------------------------------------------------- /snippets/card-hold-void.py: -------------------------------------------------------------------------------- 1 | # card_hold_href is the stored href for the CardHold 2 | card_hold = balanced.CardHold.fetch(card_hold_href) 3 | card_hold.cancel() -------------------------------------------------------------------------------- /snippets/create-buyer-and-card.py: -------------------------------------------------------------------------------- 1 | buyer = balanced.Customer( 2 | name='John Buyer' 3 | ).save() 4 | 5 | card = balanced.Card( 6 | expiration_month='12', 7 | security_code='123', 8 | number='5105105105105100', 9 | expiration_year='2020', 10 | name='John Buyer' 11 | ).save() 12 | 13 | card.associate_to(buyer) -------------------------------------------------------------------------------- /snippets/credit-create.py: -------------------------------------------------------------------------------- 1 | # bank_account_href is the stored href for the BankAccount 2 | # order_href is the stored href for the Order 3 | bank_account = balanced.BankAccount.fetch(bank_account_href) 4 | credit = bank_account.credit( 5 | amount=100000, 6 | description='Payout for order #1111', 7 | order=order_href 8 | ) -------------------------------------------------------------------------------- /snippets/credit-fetch.py: -------------------------------------------------------------------------------- 1 | credit = balanced.Credit.fetch(credit_href) -------------------------------------------------------------------------------- /snippets/credit-marketplace-escrow.py: -------------------------------------------------------------------------------- 1 | balanced.Marketplace.mine.owner_customer.bank_accounts[0].credit( 2 | amount=2000000, 3 | description='Credit from Balanced escrow' 4 | ) -------------------------------------------------------------------------------- /snippets/credit-reverse.py: -------------------------------------------------------------------------------- 1 | reversal = credit.reverse() -------------------------------------------------------------------------------- /snippets/credit-soft-descriptor.py: -------------------------------------------------------------------------------- 1 | # bank_account_href is the stored href for the BankAccount 2 | # order_href is the stored href for the Order 3 | bank_account = balanced.BankAccount.fetch(bank_account_href) 4 | credit = bank_account.credit( 5 | amount=100000, 6 | description='Payout for order #1111', 7 | appears_on_statement_as='GoodCo #1111', 8 | order=order_href 9 | ) -------------------------------------------------------------------------------- /snippets/credit-split.py: -------------------------------------------------------------------------------- 1 | # bank_account_href_a is the stored href for the BankAccount for Person A 2 | bank_account_person_a = balanced.BankAccount.fetch(bank_account_href_a) 3 | credit = bank_account_person_a.credit( 4 | amount=50000, 5 | description='Payout for order #1111' 6 | ) 7 | 8 | # bank_account_href_b is the stored href for the BankAccount for Person B 9 | bank_account_person_b = balanced.BankAccount.fetch(bank_account_href_b) 10 | credit = bank_account_person_b.credit( 11 | amount=50000, 12 | description='Payout for order #1111' 13 | ) -------------------------------------------------------------------------------- /snippets/customer-create.py: -------------------------------------------------------------------------------- 1 | merchant = balanced.Customer( 2 | dob_year=1963, 3 | dob_month=7, 4 | name='Henry Ford', 5 | address={ 6 | 'postal_code': '48120' 7 | } 8 | ).save() -------------------------------------------------------------------------------- /snippets/debit-dispute-show.py: -------------------------------------------------------------------------------- 1 | # debit_href is the stored href of the debit 2 | debit = balanced.Debit.fetch(debit_href) 3 | dispute = debit.dispute -------------------------------------------------------------------------------- /snippets/debit-fetch.py: -------------------------------------------------------------------------------- 1 | debit = balanced.Debit.fetch(debit_href) -------------------------------------------------------------------------------- /snippets/debit-marketplace-escrow.py: -------------------------------------------------------------------------------- 1 | balanced.Marketplace.mine.owner_customer.bank_accounts[0].debit( 2 | amount=2000000, 3 | description='Pre-fund Balanced escrow' 4 | ) -------------------------------------------------------------------------------- /snippets/debit-refund.py: -------------------------------------------------------------------------------- 1 | debit.refund() -------------------------------------------------------------------------------- /snippets/dispute-list.py: -------------------------------------------------------------------------------- 1 | disputes = balanced.Dispute.query -------------------------------------------------------------------------------- /snippets/dispute-show.py: -------------------------------------------------------------------------------- 1 | # dispute_href is the stored href of the dispute 2 | dispute = balanced.Dispute.fetch(dispute_href) -------------------------------------------------------------------------------- /snippets/examine-order-after-refund.py: -------------------------------------------------------------------------------- 1 | order = balanced.Order.fetch(order_href) 2 | order.amount # original order amount 3 | order.amount_escrowed # will decrease by amount of reversed credit -------------------------------------------------------------------------------- /snippets/examine-order-after-reversal.py: -------------------------------------------------------------------------------- 1 | order = balanced.Order.fetch(order_href) 2 | order.amount # original order amount 3 | order.amount_escrowed # will increase by amount of reversed credit -------------------------------------------------------------------------------- /snippets/marketplace-in-escrow.py: -------------------------------------------------------------------------------- 1 | balanced.Marketplace.my_marketplace.in_escrow -------------------------------------------------------------------------------- /snippets/merchant-payable-account-fetch.py: -------------------------------------------------------------------------------- 1 | # merchant is a Customer instance 2 | merchant.payable_account -------------------------------------------------------------------------------- /snippets/order-amount-escrowed.py: -------------------------------------------------------------------------------- 1 | order.reload # reload the order to get recent changes 2 | order.amount 3 | order.amount_escrowed -------------------------------------------------------------------------------- /snippets/order-bank-account-create.py: -------------------------------------------------------------------------------- 1 | bank_account = balanced.BankAccount( 2 | routing_number='121000358', 3 | type='checking', 4 | account_number='9900000001', 5 | name='Henry Ford' 6 | ).save() 7 | 8 | bank_account.associate_to(merchant) -------------------------------------------------------------------------------- /snippets/order-create.py: -------------------------------------------------------------------------------- 1 | order = merchant.create_order() -------------------------------------------------------------------------------- /snippets/order-credit-marketplace.py: -------------------------------------------------------------------------------- 1 | marketplace_bank_account = balanced.Marketplace.mine.owner_customer.bank_accounts[0] 2 | order.credit_to( 3 | amount=2000, 4 | description="Credit from order escrow to marketplace bank account", 5 | destination=marketplace_bank_account 6 | ) -------------------------------------------------------------------------------- /snippets/order-credit-merchant-payable-account.py: -------------------------------------------------------------------------------- 1 | order.credit_to( 2 | destination=account_href, 3 | amount=8000 4 | ) -------------------------------------------------------------------------------- /snippets/order-credit.py: -------------------------------------------------------------------------------- 1 | order.credit_to( 2 | destination=bank_account_href, 3 | amount=8000 4 | ) -------------------------------------------------------------------------------- /snippets/order-credits-fetch.py: -------------------------------------------------------------------------------- 1 | order.credits -------------------------------------------------------------------------------- /snippets/order-debit.py: -------------------------------------------------------------------------------- 1 | debit = order.debit_from( 2 | source=card, 3 | amount=10000 4 | ) -------------------------------------------------------------------------------- /snippets/order-debits-fetch.py: -------------------------------------------------------------------------------- 1 | order.debits -------------------------------------------------------------------------------- /snippets/order-fetch.py: -------------------------------------------------------------------------------- 1 | order = balanced.Order.fetch(order_href) -------------------------------------------------------------------------------- /snippets/order-update.py: -------------------------------------------------------------------------------- 1 | order.description = 'Item description' 2 | order.meta = { 3 | 'item_url': 'https://neatitems.com/12342134123' 4 | } 5 | order.save() -------------------------------------------------------------------------------- /snippets/refund-create.py: -------------------------------------------------------------------------------- 1 | # debit_href is the stored href for the Debit 2 | # order_href is the stored href for the Order 3 | debit = balanced.Debit.fetch(debit_href) 4 | refund = debit.refund( 5 | amount=3000, 6 | description="Refund for Order #1111", 7 | meta={ 8 | "merchant.feedback": "positive", 9 | "user.refund_reason": "not happy with product", 10 | "fulfillment.item.condition": "OK", 11 | }, 12 | order=order_href 13 | ) -------------------------------------------------------------------------------- /snippets/reversal-create.py: -------------------------------------------------------------------------------- 1 | # credit_href is the stored href for the Credit 2 | # order_href is the stored href for the Order 3 | credit = balanced.Credit.fetch(credit_href) 4 | reversal = credit.reverse( 5 | amount=100000, 6 | description="Reversal for order #1111", 7 | meta={ 8 | "merchant.feedback": "positive", 9 | "user.refund_reason": "not happy with product", 10 | "fulfillment.item.condition": "OK" 11 | }, 12 | order=order_href 13 | ) -------------------------------------------------------------------------------- /snippets/settlement-create.py: -------------------------------------------------------------------------------- 1 | account.settle( 2 | appears_on_statement_as='ThingsCo', 3 | description='A simple description', 4 | funding_instrument=bank_account_href 5 | ) -------------------------------------------------------------------------------- /test-requirements.txt: -------------------------------------------------------------------------------- 1 | nose 2 | nose-setenv 3 | mock 4 | unittest2 5 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/balanced/balanced-python/1df86b45c36a97ec2e214480c6806c4df3c79860/tests/__init__.py -------------------------------------------------------------------------------- /tests/fixtures/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | import os 3 | 4 | import simplejson as json 5 | 6 | 7 | class ResourceMeta(type): 8 | 9 | def __getattr__(cls, item): 10 | return json.load(open(os.path.join( 11 | os.path.dirname(os.path.abspath(__file__)), 12 | 'resources/{0}.json'.format(item)) 13 | )) 14 | 15 | 16 | class Resources(object): 17 | __metaclass__ = ResourceMeta 18 | -------------------------------------------------------------------------------- /tests/fixtures/resources/api_keys.json: -------------------------------------------------------------------------------- 1 | { 2 | "links": {}, 3 | "api_keys": [ 4 | { 5 | "links": {}, 6 | "created_at": "2013-12-23T19:11:49.250551Z", 7 | "secret": "ak-test-DUiuVXnHrQkxy7VfDv84DhnLHr3uSCR6", 8 | "href": "/api_keys/AKztNL7Ly2W5nhpj53pw3vE", 9 | "meta": {}, 10 | "id": "AKztNL7Ly2W5nhpj53pw3vE" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /tests/fixtures/resources/marketplaces.json: -------------------------------------------------------------------------------- 1 | { 2 | "marketplaces": [ 3 | { 4 | "in_escrow": 0, 5 | "domain_url": "example.com", 6 | "name": "Test Marketplace", 7 | "links": { 8 | "owner_customer": "CUWXtKGXXgqQbJao7PiZ36g" 9 | }, 10 | "href": "/marketplaces/TEST-MPWWcI92W2mLFdLzSrh6cuQ", 11 | "created_at": "2013-12-23T19:12:10.100302Z", 12 | "support_email_address": "support@example.com", 13 | "updated_at": "2013-12-23T19:12:10.620980Z", 14 | "support_phone_number": "+16505551234", 15 | "production": false, 16 | "meta": {}, 17 | "unsettled_fees": 0, 18 | "id": "TEST-MPWWcI92W2mLFdLzSrh6cuQ" 19 | } 20 | ], 21 | "links": { 22 | "marketplaces.debits": "/debits", 23 | "marketplaces.reversals": "/reversals", 24 | "marketplaces.customers": "/customers", 25 | "marketplaces.credits": "/credits", 26 | "marketplaces.cards": "/cards", 27 | "marketplaces.card_holds": "/card_holds", 28 | "marketplaces.refunds": "/refunds", 29 | "marketplaces.owner_customer": "/customers/{marketplaces.owner_customer}", 30 | "marketplaces.transactions": "/transactions", 31 | "marketplaces.bank_accounts": "/bank_accounts", 32 | "marketplaces.callbacks": "/callbacks", 33 | "marketplaces.events": "/events" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/test_balanced.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | from tests.utils import TestCase 4 | 5 | 6 | class TestBalancedImportStar(TestCase): 7 | 8 | def test_import_star(self): 9 | # not sure who uses import * any more, but we should 10 | # test this 11 | try: 12 | # the __import__ doesn't do what I want here. 13 | # and doing a "from balanced import *" generates an 14 | # unsupressable SyntaxWarning. 15 | exec "from balanced import *" # pylint: disable-msg=W0122 16 | except Exception as exc: 17 | raise ImportError("%s" % exc) 18 | -------------------------------------------------------------------------------- /tests/test_client.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | import balanced 4 | 5 | from . import utils 6 | 7 | 8 | class TestClient(utils.TestCase): 9 | 10 | def setUp(self): 11 | super(TestClient, self).setUp() 12 | 13 | def test_configure(self): 14 | expected_headers = { 15 | 'content-type': 'application/json;revision=1.1', 16 | 'accept': 'application/vnd.api+json;revision=1.1', 17 | 'User-Agent': u'balanced-python/' + balanced.__version__, 18 | } 19 | self.assertDictContainsSubset( 20 | expected_headers, balanced.config.client.config.headers 21 | ) 22 | -------------------------------------------------------------------------------- /tests/test_resource.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | import balanced 4 | 5 | from . import fixtures, utils 6 | 7 | 8 | class TestResourceConstruction(utils.TestCase): 9 | 10 | def setUp(self): 11 | super(TestResourceConstruction, self).setUp() 12 | 13 | def test_load_resource(self): 14 | resp = fixtures.Resources.marketplaces 15 | marketplace = balanced.Marketplace(**resp) 16 | self.assertIsNotNone(marketplace.debits) 17 | -------------------------------------------------------------------------------- /tests/utils.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | import contextlib 4 | import multiprocessing 5 | import unittest2 as unittest 6 | 7 | from wsgiref.simple_server import make_server 8 | 9 | 10 | class TestCase(unittest.TestCase): 11 | pass 12 | 13 | 14 | class WSGIServerTest(TestCase): 15 | 16 | def setUp(self): 17 | self.server_process = None 18 | 19 | @contextlib.contextmanager 20 | def start_server(self, app, port=31337): 21 | server = make_server('', port, app) 22 | self.server_process = multiprocessing.Process( 23 | target=server.serve_forever 24 | ) 25 | try: 26 | self.server_process.start() 27 | yield 28 | finally: 29 | self._stop_server() 30 | 31 | def _stop_server(self): 32 | self.server_process.terminate() 33 | self.server_process.join() 34 | del self.server_process 35 | self.server_process = None 36 | --------------------------------------------------------------------------------