Skip to content

Commit

Permalink
new source value
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Mar 21, 2017
1 parent 83b95a2 commit d7f7492
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 3 deletions.
54 changes: 51 additions & 3 deletions src/examples/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def new_charge(self):
exp_month = self.field("exp_month", 1, cast = int)
exp_year = self.field("exp_year", 2020, cast = int)
number = self.field("number", 4242424242424242, cast = int)
cvc = self.field("cvc", None)
cvc = self.field("cvc", 123, cast = int)
name = self.field("name", None)
api = self.get_api()
balance = api.create_charge(
Expand Down Expand Up @@ -118,7 +118,7 @@ def new_token(self):
exp_month = self.field("exp_month", 1, cast = int)
exp_year = self.field("exp_year", 2020, cast = int)
number = self.field("number", 4242424242424242, cast = int)
cvc = self.field("cvc", None)
cvc = self.field("cvc", 123, cast = int)
name = self.field("name", None)
api = self.get_api()
token = api.create_token(
Expand All @@ -134,7 +134,7 @@ def new_3d_secure(self):
exp_month = self.field("exp_month", 1, cast = int)
exp_year = self.field("exp_year", 2020, cast = int)
number = self.field("number", 4242424242424242, cast = int)
cvc = self.field("cvc", None)
cvc = self.field("cvc", 123, cast = int)
name = self.field("name", None)
api = self.get_api()
return_url = return_url or self.url_for(
Expand Down Expand Up @@ -174,6 +174,54 @@ def return_3d_secure(self):
error_code = error_code
)

@appier.route("/source/new", "GET")
def new_source(self):
amount = self.field("amount", 100, cast = int)
currency = self.field("currency", "EUR")
return_url = self.field("return_url", None)
exp_month = self.field("exp_month", 1, cast = int)
exp_year = self.field("exp_year", 2020, cast = int)
number = self.field("number", 4242424242424242, cast = int)
cvc = self.field("cvc", 123, cast = int)
name = self.field("name", None)
api = self.get_api()
return_url = return_url or self.url_for(
"stripe.return_source",
absolute = True
)
token = api.create_token(
exp_month, exp_year, number, cvc = cvc, name = name
)
secure = api.create_3d_secure(
amount,
currency,
return_url,
card = token["id"]
)
return secure

@appier.route("/source/redirect", "GET")
def redirect_source(self):
redirect_url = self.field("redirect_url", None)
return self.html(
"<html>" +\
"<body onload=\"document.autoRedirect.submit();\">" +\
"<form name=\"autoRedirect\" method=\"POST\" action=\"%s\">" % redirect_url +\
"</form>" +\
"</body>" +\
"</html>"
)

@appier.route("/source/return", "GET")
def return_source(self):
id = self.field("id", None)
status = self.field("status", None)
error_code = self.field("error_code", None)
return dict(
status = status,
error_code = error_code
)

def get_api(self):
return base.get_api()

Expand Down
2 changes: 2 additions & 0 deletions src/stripe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
from . import charge
from . import customer
from . import secure
from . import source
from . import token

from .balance import BalanceApi
from .base import BASE_URL, Api
from .charge import ChargeApi
from .customer import CustomerApi
from .secure import SecureApi
from .source import SourceApi
from .token import TokenApi
61 changes: 61 additions & 0 deletions src/stripe/source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Hive Stripe API
# Copyright (c) 2008-2017 Hive Solutions Lda.
#
# This file is part of Hive Stripe API.
#
# Hive Stripe API is free software: you can redistribute it and/or modify
# it under the terms of the Apache License as published by the Apache
# Foundation, either version 2.0 of the License, or (at your option) any
# later version.
#
# Hive Stripe API is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Apache License for more details.
#
# You should have received a copy of the Apache License along with
# Hive Stripe API. If not, see <http://www.apache.org/licenses/>.

__author__ = "João Magalhães <joamag@hive.pt>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2017 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
""" The license for the module """

class SourceApi(object):

def create_source(
self,
amount,
currency,
return_url,
type = "three_d_secure",
card = None,
customer = None
):
url = self.base_url + "sources"
params = {
"amount" : amount,
"currency" : currency,
"type" : type,
"redirect[return_url]" : return_url
}
if card: params["three_d_secure[card]"] = card
if customer: params["three_d_secure[customer]"] = customer
contents = self.post(url, params = params)
return contents

0 comments on commit d7f7492

Please sign in to comment.