stripe.charge(token=...)

This commit is contained in:
mdipierro
2013-05-16 22:03:20 -05:00
parent 65e9cc2127
commit 579f0d752f
2 changed files with 28 additions and 15 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.4.6-stable+timestamp.2013.05.15.21.34.19
Version 2.4.6-stable+timestamp.2013.05.16.22.02.34
+27 -14
View File
@@ -23,6 +23,10 @@ class Stripe:
if paid is True than transaction was processed
"""
URL_CHARGE = 'https://%s:@api.stripe.com/v1/charges'
URL_CHECK = 'https://%s:@api.stripe.com/v1/charges/%s'
URL_REFUND = 'https://%s:@api.stripe.com/v1/charges/%s/refund'
def __init__(self, key):
self.key = key
@@ -33,27 +37,36 @@ class Stripe:
card_exp_month='5',
card_exp_year='2012',
card_cvc_check='123',
description='test charge'):
params = urllib.urlencode({'amount': amount,
'currency': currency,
'card[number]': card_number,
'card[exp_month]': card_exp_month,
'card[exp_year]': card_exp_year,
'card[cvc_check]': card_cvc_check,
'description': description})
u = urllib.urlopen('https://%s:@api.stripe.com/v1/charges' %
self.key, params)
token=None,
description='test charge',
more=None):
if token:
d = {'amount': amount,
'currency': currency,
'card': token,
'description': description}
else:
d = {'amount': amount,
'currency': currency,
'card[number]': card_number,
'card[exp_month]': card_exp_month,
'card[exp_year]': card_exp_year,
'card[cvc_check]': card_cvc_check,
'description': description}
if more:
d.update(mode)
params = urllib.urlencode(d)
u = urllib.urlopen(self.URL_CHARGE % self.key, params)
return simplejson.loads(u.read())
def check(self, charge_id):
u = urllib.urlopen('https://%s:@api.stripe.com/v1/charges/%s' %
(self.key, charge_id))
u = urllib.urlopen(self.URL_CHECK % (self.key, charge_id))
return simplejson.loads(u.read())
def refund(self, charge_id):
params = urllib.urlencode({})
u = urllib.urlopen('https://%s:@api.stripe.com/v1/charges/%s/refund' %
(self.key, charge_id), params)
u = urllib.urlopen(self.URL_REFUND % (self.key, charge_id),
params)
return simplejson.loads(u.read())
if __name__ == '__main__':