Last active
November 3, 2021 17:37
-
-
Save alvinslee/09a9357cd159bca8b152ff1322ee3479 to your computer and use it in GitHub Desktop.
Demonstration of Marqeta Core API Python SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# USAGE: APPLICATION_TOKEN=<insert app token> ADMIN_ACCESS_TOKEN=<insert admin token> python3 marqeta-core-api-demo.py | |
# | |
import os | |
from marqeta import Client | |
application_token = os.environ.get('APPLICATION_TOKEN') | |
admin_access_token = os.environ.get('ADMIN_ACCESS_TOKEN') | |
base_url = "https://sandbox-api.marqeta.com/v3/" | |
timeout = 60 # seconds | |
client = Client(base_url, application_token, admin_access_token, timeout) | |
data = { | |
'first_name': 'Ada' | |
} | |
user = client.users.create(data) | |
print(f"USER\n{user}\n") | |
data = { | |
'user_token': user.token, | |
'first_name': 'Computing', | |
'last_name': 'Company', | |
'address_1': '555 Microchip Way', | |
'city': 'San Francisco', | |
'state': 'CA', | |
'postal_code': '94112', | |
'country': 'USA' | |
} | |
fs_address = client.funding_sources.addresses.create(data) | |
print(f"FUNDING SOURCE ADDRESS\n{fs_address}\n") | |
data = { | |
'name': 'My Card Product', | |
'start_date': '2021-10-13' | |
} | |
card_product = client.card_products.create(data) | |
print(f"CARD PRODUCT\n{card_product}\n") | |
updated_data = { | |
'address1': fs_address.address_1, | |
'city': fs_address.city, | |
'state': fs_address.state, | |
'postal_code': fs_address.postal_code, | |
'country': fs_address.country | |
} | |
updated_user = client.users.save(user.token, updated_data) | |
print(f"UPDATED USER\n{updated_user}\n") | |
data = { | |
'user_token': user.token, | |
'card_product_token': card_product.token | |
} | |
card = client.cards.create(data) | |
print(f"CARD\n{card}\n") | |
updated_data = { | |
'name': 'Cool Card' | |
} | |
updated_card_product = client.card_products.save(card_product.token, updated_data) | |
print(f"UPDATED CARD PRODUCT\n{updated_card_product}\n") | |
balance = client.balances.find_for_user_or_business(user.token) | |
print(f"BALANCE\n{balance}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment