store library, powered by stripe

master
Steve Nyemba 9 months ago
commit 023eefe9e1

@ -0,0 +1,8 @@
import stripe
import get
import set
def init(key:str):
"""
Initializing stripe store with a key
"""
stripe.api_key = key

@ -0,0 +1,33 @@
def customer(email:str) :
"""
This function returns a customer given an email
"""
return stripe.Customer.search(query=f"email:'{email}'").data
def customers():
"""
This function returns a list of customers (all customers)
"""
_data = []
customers = stripe.Customer.list(limit=100)
for _customer in customers.auto_paging_iter() :
_data.append(_customer)
return _data
def product (_name):
"""
returns a product given it's name
"""
return stripe.Product.search(query=f"name:'{_name}'").data
def products():
"""
return a list of products
"""
_products = stripe.Product.list(limit=100)
return _products.auto_paging_iter()
def plans(_name:str):
"""retrieves plans for a given producti
:_name name of the product
"""
_prod = product(_name)
_id = _prod[0]['id']
return stripe.Price.search(query=f"product:'{_id}'").data

@ -0,0 +1,23 @@
def customer(email:str,name:str):
"""
:email customer's email
:name customer's name
"""
return stripe.Customer.create(name=name,email=email)
def subscribe(_id,_price):
"""
:_id customer identifier
:_price price object associated with product/plan
"""
return stripe.Subscription.create(customer=_id,
items=[{"price":_price}]
)
def unsubscribe(_id:str):
"""
Cancelling a given subscription for a given user
_id: subscription identifier
"""
return stripe.Subscription.cancel(_id)
Loading…
Cancel
Save