Esempio n. 1
0
def get_balanced_account(participant_id, balanced_account_uri):
    """Find or create a balanced.Account.
    """
    typecheck(participant_id, unicode, balanced_account_uri, (unicode, None))

    # XXX Balanced requires an email address
    # https://github.com/balanced/balanced-api/issues/20

    email_address = '{}@gittip.com'.format(participant_id)

    if balanced_account_uri is None:
        try:
            account = \
               balanced.Account.query.filter(email_address=email_address).one()
        except balanced.exc.NoResultFound:
            account = balanced.Account(email_address=email_address).save()
        BALANCED_ACCOUNT = """\

                UPDATE participants
                   SET balanced_account_uri=%s
                 WHERE id=%s

        """
        gittip.db.execute(BALANCED_ACCOUNT, (account.uri, participant_id))
        account.meta['participant_id'] = participant_id
        account.save()  # HTTP call under here
    else:
        account = balanced.Account.find(balanced_account_uri)
    return account
Esempio n. 2
0
def get_balanced_account(username, balanced_account_uri):
    """Find or create a balanced.Account.
    """
    typecheck(username, unicode, balanced_account_uri, (unicode, None))

    # XXX Balanced requires an email address
    # https://github.com/balanced/balanced-api/issues/20
    # quote to work around https://github.com/gittip/www.gittip.com/issues/781
    email_address = '{}@gittip.com'.format(quote(username))

    if balanced_account_uri is None:
        try:
            account = \
               balanced.Account.query.filter(email_address=email_address).one()
        except balanced.exc.NoResultFound:
            account = balanced.Account(email_address=email_address).save()
        BALANCED_ACCOUNT = """\

                UPDATE participants
                   SET balanced_account_uri=%s
                 WHERE username=%s

        """
        gittip.db.run(BALANCED_ACCOUNT, (account.uri, username))
        account.meta['username'] = username
        account.save()  # HTTP call under here
    else:
        account = balanced.Account.find(balanced_account_uri)
    return account
Esempio n. 3
0
    def test_does_not_parse_meta(self):
        payload = {
            'uri': '/v1/yo-momma',
            'meta': {
                'uri': 'None',
            }
        }

        balanced.Account(**payload)
Esempio n. 4
0
    def save(self, **kwargs):
        if not self.uri:
            ac = balanced.Account(name=self.user.username, )
            try:
                ac.save()
            except balanced.exc.HTTPError as ex:
                raise ex
            self._sync(ac)

        super(Account, self).save(**kwargs)
def main():
    init()
    request_bin = RequestBinClient()

    print 'let\'s create a callback'
    balanced.Callback(url=request_bin.callback_url, ).save()

    print 'let\'s create a card and associate it with a new account'
    card = balanced.Card(
        expiration_month='12',
        security_code='123',
        card_number='5105105105105100',
        expiration_year='2020',
    ).save()
    buyer = balanced.Account(card_uri=card.uri, ).save()

    print 'generate a debit (which implicitly creates and captures a hold)'
    buyer.debit(100)

    print 'event creation is an async operation, let\'s wait until we have ' \
          'some events!'
    while not balanced.Event.query.count():
        print 'Zzzz'
        time.sleep(0)

    print 'Woop, we got some events, let us see what there is to look at'
    for event in balanced.Event.query:
        print 'this was a {0} event, it occurred at {1}, the callback has a ' \
              'status of {2}'.format(
            event.type,
            event.occurred_at,
            event.callback_statuses
        )

    print 'you can inspect each event to see the logs'
    event = balanced.Event.query[0]
    for callback in event.callbacks:
        print 'inspecting callback to {0} for event {1}'.format(
            callback.url,
            event.type,
        )
        for log in callback.logs:
            print 'this attempt to the callback has a status "{0}"'.format(
                log.status)

    print 'ok, let\'s check with requestb.in to see if our callbacks fired'
    print 'we received {0} callbacks, you can view them at {1}'.format(
        len(request_bin.get_requests()),
        request_bin.view_url,
    )
Esempio n. 6
0
 def test_34_create_merchant_with_attributes(self):
     marketplace = self._create_marketplace()
     merchant_attributes = {
         'type': 'person',
         'name': 'Billy Jones',
         'street_address': '801 High St.',
         'postal_code': '94301',
         'country': 'USA',
         'dob': '1842-01',
         'phone_number': '+16505551234'
     }
     bank_account = marketplace.create_bank_account(**BANK_ACCOUNT)
     merchant = balanced.Account(uri=marketplace.accounts_uri,
                                 email_address='*****@*****.**',
                                 merchant=merchant_attributes,
                                 bank_account_uri=bank_account.uri,
                                 name='Jack Q Merchant').save()
     self.assertEqual(merchant.email_address, '*****@*****.**')
     self.assertIn('merchant', merchant.roles)
     self.assertEqual(merchant.name, 'Jack Q Merchant')
Esempio n. 7
0
 def test_14_appends_marketplace_for_creating_account(self):
     with self.assertRaises(requests.HTTPError) as exc:
         balanced.Account().save()
     the_exception = exc.exception
     self.assertEqual(the_exception.status_code, 400)
     print the_exception
Esempio n. 8
0
import balanced

balanced.configure("46c08048cd8811e2acae026ba7c1aba6")


account = balanced.Account().save()