Skip to content

Instantly share code, notes, and snippets.

@mjallday
Created September 17, 2012 18:20
Show Gist options
  • Save mjallday/3738885 to your computer and use it in GitHub Desktop.
Save mjallday/3738885 to your computer and use it in GitHub Desktop.
Balanced - Filtering Cards and Bank Accounts Example
import balanced
key = balanced.APIKey().save()
balanced.configure(key.secret)
balanced.Marketplace().save()
buyer = balanced.Account(email_address='buyer@example.org').save()
# add a new card
card = balanced.Marketplace.my_marketplace.create_card(
name='First card',
card_number='5105105105105100',
expiration_month='12',
expiration_year='2020',
security_code='123',
)
buyer.add_card(card.uri)
# add another valid card
card = balanced.Marketplace.my_marketplace.create_card(
name='Second card',
card_number='5105105105105100',
expiration_month='12',
expiration_year='2020',
security_code='123',
)
buyer.add_card(card.uri)
# this card is not active
card = balanced.Marketplace.my_marketplace.create_card(
name='Inactive card',
card_number='5105105105105100',
expiration_month='12',
expiration_year='2020',
security_code='123',
)
buyer.add_card(card.uri)
# invalidate
card.is_valid = False
card.save()
# let's find the most recent, active card
card = [c for c in buyer.cards.filter(is_valid=True, sort='created_at,desc')][0]
# this is the most recent active one
print card
# create a merchant account
merchant_data = {
'type': "person",
'name': "Billy Jones",
'street_address': "801 High St.",
'postal_code': "94301",
'country': "USA",
'dob': "1842-01",
'phone_number': "+16505551234",
}
bank_account = balanced.BankAccount(
account_number="1234567890",
bank_code="321174851",
name="Jack Q Merchant",
).save()
# notice we always use the uri of an object (bank account here) to refer to something
seller = balanced.Marketplace.my_marketplace.create_merchant('seller@example.com',
merchant_data, bank_account_uri=bank_account.uri)
bank_account = balanced.BankAccount(
account_number="1234567890",
bank_code="321174851",
name="Invalid Bank Account",
).save()
valid_bank_account = seller.bank_accounts.filter(is_valid=True)[0]
print valid_bank_account.name, ' is valid'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment