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 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): def __init__(self, key):
self.key = key self.key = key
@@ -33,27 +37,36 @@ class Stripe:
card_exp_month='5', card_exp_month='5',
card_exp_year='2012', card_exp_year='2012',
card_cvc_check='123', card_cvc_check='123',
description='test charge'): token=None,
params = urllib.urlencode({'amount': amount, description='test charge',
'currency': currency, more=None):
'card[number]': card_number, if token:
'card[exp_month]': card_exp_month, d = {'amount': amount,
'card[exp_year]': card_exp_year, 'currency': currency,
'card[cvc_check]': card_cvc_check, 'card': token,
'description': description}) 'description': description}
u = urllib.urlopen('https://%s:@api.stripe.com/v1/charges' % else:
self.key, params) 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()) return simplejson.loads(u.read())
def check(self, charge_id): def check(self, charge_id):
u = urllib.urlopen('https://%s:@api.stripe.com/v1/charges/%s' % u = urllib.urlopen(self.URL_CHECK % (self.key, charge_id))
(self.key, charge_id))
return simplejson.loads(u.read()) return simplejson.loads(u.read())
def refund(self, charge_id): def refund(self, charge_id):
params = urllib.urlencode({}) params = urllib.urlencode({})
u = urllib.urlopen('https://%s:@api.stripe.com/v1/charges/%s/refund' % u = urllib.urlopen(self.URL_REFUND % (self.key, charge_id),
(self.key, charge_id), params) params)
return simplejson.loads(u.read()) return simplejson.loads(u.read())
if __name__ == '__main__': if __name__ == '__main__':