def callbacks_delete(ctx): cb = balanced.Callback( uri=ctx.marketplace.callbacks_uri, url='http://www.example.com/cb/del', method='post', ).save() cb.delete() return ctx.last_req, ctx.last_resp
def callbacks_index(ctx): if ctx.marketplace.callbacks.total < 2: balanced.Callback( uri=ctx.marketplace.callbacks_uri, url='http://www.example.com/cb1', method='post', ).save() balanced.Callback( uri=ctx.marketplace.callbacks_uri, url='http://www.example.com/cb2', method='get', ).save() ctx.marketplace.callbacks_uri += '?limit=2' ctx.marketplace.callbacks[0:2] return ctx.last_req, ctx.last_resp
def callbacks_show(ctx): if ctx.marketplace.callbacks.total == 0: balanced.Callback( uri=ctx.marketplace.callbacks_uri, url='http://www.example.com/cb/fosho', method='post', ).save() balanced.Callback.find(ctx.marketplace.callbacks[0].uri) return ctx.last_req, ctx.last_resp
def callbacks_create(ctx): with balanced.key_switcher(None): secret = balanced.APIKey().save().secret with balanced.key_switcher(secret): mp = balanced.Marketplace().save() balanced.Callback( uri=mp.callbacks_uri, url='http://www.example.com/cb/nu', method='post', ).save() return ctx.last_req, ctx.last_resp
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 customer" balanced.Customer(name='Bob McTavish').save() print 'let\'s create a card and associate it with a new account' card = balanced.Card( expiration_month='12', csc='123', number='5105105105105100', expiration_year='2020', ).save() print 'generate a debit (which implicitly creates and captures a hold)' card.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.first() 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, )
def event_callbacks_show(ctx): raise Exception('does not work') if ctx.marketplace.callbacks.total == 0: balanced.Callback( uri=ctx.marketplace.callbacks_uri, url='http://www.example.com/cb', ).save() total = ctx.marketplace.events.total ctx.buyer.debit(amount=245) while ctx.marketplace.events.total < total + 1: time.sleep(5) event = balanced.Event.find(ctx.marketplace.events[0].uri) balanced.EventCallback.find(event.callbacks[0].uri) return ctx.last_req, ctx.last_resp
import balanced balanced.configure('ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY') callback = balanced.Callback(url='http://www.example.com/callback_test', method='post').save()
import balanced balanced.configure('ak-test-1p1Tsac7gHeMQowL2seB7ieliuAJAufyq') callback = balanced.Callback(url='http://www.example.com/callback').save()