forked from getyouridx/pychargify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
84 lines (66 loc) · 2.32 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
''' Test the Pychargify Library.
Edit my chargify = line with API key, then run me.
'''
import sys
import api
def print_spacer(repeat=70):
''' Print a spacer line, 70 chars across '''
print "\n" + "#" * repeat + "\n"
def print_product(item):
''' Print out a little formatted product info item. '''
product_info = '''#########################################
''' + item.name + ''' Product
#########################################
Id: ''' + item.id + '''
Price in Cents: ''' + item.price_in_cents + '''
Name: ''' + item.name + '''
Handle: ''' + item.handle + '''
Accounting Code: ''' + item.accounting_code + '''
Interval Unit: ''' + item.interval_unit + '''
Interval: ''' + item.interval + '''
'''
print product_info
def run_test(credentials):
''' Init the API, and run some sample queries. '''
# Initialize the API with the API Key and the sub domain
chargify = api.Chargify(cred_file=credentials)
# Get All Products
print "Get All Products: \n"
for item in chargify.Product().getAll():
print_product(item)
print_spacer()
# Get a Single Product by its ID
#print "Get a Product By its ID: "
#print ""
#print_product(chargify.Product().getById(161))
#print_spacer()
# Get a Single Product by its Handle
#print "Get a Product By its Handle: "
#print ""
#print_product(chargify.Product().getByHandle('plus'))
#print_spacer()
# Get a Single Product by its Handle
print "Save a Subscription: \n"
customer = chargify.Customer('customer_attributes')
customer.first_name = 'Paul'
customer.last_name = 'Trippett'
customer.email = '[email protected]'
creditcard = chargify.CreditCard('credit_card_attributes')
creditcard.full_number = 1
creditcard.expiration_month = 10
creditcard.expiration_year = 2020
subscription = chargify.Subscription()
subscription.product_handle = 'fhaar-mini'
subscription.customer = customer
subscription.credit_card = creditcard
if subscription.save():
print "Subscription Created Successfully"
else:
print "Subscription Creation Failed"
if __name__ == "__main__":
if len(sys.argv) > 1:
credentials = sys.argv[1]
else:
credentials = "credentials.json"
run_test(credentials)