Skip to content

Instantly share code, notes, and snippets.

View mjallday's full-sized avatar
🏠
WFH

Marshall Jones mjallday

🏠
WFH
View GitHub Profile
module Balanced
class Invoice
include Balanced::Resource
end
end
@mjallday
mjallday / balanced.rb
Created January 22, 2014 16:25
bank account payment example - ruby
require 'balanced'
# create an api key and marketplace for example purposes only.
# in real-life you only do this once by the dashboard.
api_key = Balanced::ApiKey.new.save
Balanced.configure(api_key.secret)
marketplace = Balanced::Marketplace.new.save
# create a bank account. this is normally done with balanced.js
@mjallday
mjallday / bg_task.py
Created December 4, 2013 19:00 — forked from amjith/bg_task.py
import newrelic.agent
import time
import logging
logging.basicConfig()
logger = logging.getLogger('newrelic')
logger.setLevel(logging.DEBUG)
newrelic.agent.initialize('newrelic.ini', environment='staging')
newrelic.agent.register_application(timeout=10.0)
@mjallday
mjallday / CHANGELOG.md
Created December 3, 2013 19:00
CHANGELOG 1.0 -> 1.1
  • Cards can be charged without being associated to a customer
  • Transactions are now created via the funding instrument, not via the customer. E.g. card.debit(amount), bank_account.credit(amount) is now favoured over customer.debit(card, amount)
  • Failing to create a transaction will result in a transaction being created with a FAILED state. E.g. debiting a card with insufficient funds will result in a transaction with a FAILED state. These are filtered out of the API by default but can be specifically retrieved with a state filter e.g. /credits?state=failed
  • A new resource called "Orders" has been created to allow grouping transactions. An Order can consist of 0:n buyers, 0:n debits and 0:n credits to a single seller. Each debit associated with an Order will result in the Order's escrow balance accruing the value of the debit rather than the marketplace's escrow balance. You cannot pay out more than the total amount escrowed for an Order.
  • Accounts no longer exist, customers and orders are the
@mjallday
mjallday / gist:7590598
Created November 21, 2013 22:04
purge all rabbitmq queues
rabbitmqadmin list queues | cut -d '|' -f 3 | grep -v \+ | xargs -n1 -I@ rabbitmqadmin purge queue name=@
@mjallday
mjallday / EXAMPLE.mkd
Created November 21, 2013 21:07
Failed debit creates transaction

curl https://api.balancedpayments.com/debits -XPOST -u ak-test-2yK59ihwoOOk0S6wsg77iMGzLGnGxiohB: -d "source[number]=4444444444444448" -d "source[expiration_month]=12" -d "source[expiration_year]=2016" -d amount=100

{
  "errors": [
    {
      "status": "Payment Required",
      "category_code": "card-declined",
      "additional": "Account Frozen",
      "status_code": 402,
@mjallday
mjallday / example.mkd
Created November 21, 2013 21:04
Untokenized card debit

curl http://api.balancedpayments.com/debits -XPOST -u ak-test-2DBryLFR3BBam1CipbWEGSO6gqVOBKghP: -d "source[number]=4111111111111111" -d "source[expiration_month]=12" -d "source[expiration_year]=2016" -d amount=100

{
  "debits": [
    {
      "status": "succeeded",
      "description": null,
      "links": {
        "customer": "CU6wJUpqcVWf2JwgyfIsRy1z",
@mjallday
mjallday / README.mkd
Created November 21, 2013 19:28
Implement HTTP Server Problem

Implement a HTTP server which can respond to the following curl command

curl 'http://127.0.0.1:8000/images' -H 'Origin: http://127.0.0.1:8000' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Host: 127.0.0.1:8000' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: http://127.0.0.1:8000/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data-binary '{"name":"Balanced","src":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAAQCAMAAADDNnYVAAAAmVBMVEVXWFpfYGJpaWtycnR7e32EhIaNjY+Wlpefn6CipA+mqB2oqKmxsbKztUS6uru8vV/AwW3Dw8TExXvFxnvJyojMzMzR0qPV1dXW1rHa2r7e3t7e38zj49nmpRLmqR/mrSzmrS3msTnnyonnzpfn1rLn27/n38zn49rn5+fox8Xo0tDqk43qnZjqqKTriIHrk43tU0ntXlTuPzMyENYEAAACeklEQVR42q2VC5PTIBDHIUCghquiRhQ9H3enx/k4td//w7nLApvUpDPO+J+W7oNkfyQLFQ+/T4+56d3Tw9UbMq0mmSn29BH8UO0Z
import balanced
class Invoice(balanced.Resource):
__metaclass__ = balanced.resources.resource_base(collection='invoices')
class Settlement(balanced.Resource):
__metaclass__ = balanced.resources.resource_base(
collection='settlements')
import SimpleHTTPServer
import SocketServer
PORT = 8000
class Server(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
headers = self.headers.dict
# curl http://127.0.0.1:8000 -u username:password