Skip to content

Commit

Permalink
refs agiliq#71: updated stripe integration
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Jun 4, 2013
1 parent 20f1009 commit 634f19b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
24 changes: 10 additions & 14 deletions merchant/contrib/django/billing/gateways/stripe_gateway.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from merchant import GatewayNotConfigured
from merchant.gateways.stripe_gateway import StripeGateway as Gateway
from billing.signals import transaction_was_successful, transaction_was_unsuccessful
from billing.utils.credit_card import InvalidCard, Visa, MasterCard, \
AmericanExpress, Discover, CreditCard
import stripe

from django.conf import settings

from merchant import GatewayNotConfigured
from merchant.gateways.stripe_gateway import StripeGateway as Gateway
from merchant.contrib.django.billing.signals import (
transaction_was_successful,
transaction_was_unsuccessful
)
from merchant.utils.credit_card import (InvalidCard, Visa, MasterCard,
AmericanExpress, Discover, CreditCard)


class StripeGateway(Gateway):
supported_cardtypes = [Visa, MasterCard, AmericanExpress, Discover]
Expand All @@ -14,15 +19,6 @@ class StripeGateway(Gateway):
homepage_url = "https://stripe.com/"
display_name = "Stripe"

def __init__(self):
merchant_settings = getattr(settings, "MERCHANT_SETTINGS")
if not merchant_settings or not merchant_settings.get("stripe"):
raise GatewayNotConfigured("The '%s' gateway is not correctly "
"configured." % self.display_name)
stripe_settings = merchant_settings["stripe"]
stripe.api_key = stripe_settings['API_KEY']
self.stripe = stripe

def purchase(self, amount, credit_card, options=None):
response = super(StripeGateway, self).purchase(amount,
credit_card,
Expand Down
4 changes: 2 additions & 2 deletions merchant/contrib/django/billing/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
integration_cache = {}


def get_integration(integration, *args, **kwargs):
def get_integration(integration, module_path="merchant.contrib.django.billing.integrations", *args, **kwargs):
"""Return a integration instance specified by `integration` name"""

klass = integration_cache.get(integration, None)

if not klass:
integration_filename = "%s_integration" % integration
integration_module = import_module("merchant.contrib.django.billing.integrations.%s" % integration_filename)
integration_module = import_module("%s.%s" % (module_path, integration_filename))
if not integration_module:
raise IntegrationModuleNotFound("Missing integration: %s" % (integration))
integration_class_name = "".join(integration_filename.title().split("_"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

from merchant.integrations.stripe_integration import StripeIntegration as Integration
from merchant.contrib.django.billing.forms.stripe_forms import StripeForm
from merchant.contrib.django.billing.gateway import get_gateway


class StripeIntegration(Integration):
display_name = "Stripe"
template = "billing/stripe.html"

def __init__(self, settings):
self.gateway = get_gateway("stripe")
self.publishable_key = settings['PUBLISHABLE_KEY']

def form_class(self):
Expand All @@ -26,7 +28,7 @@ def transaction(self, request):

def get_urls(self):
urlpatterns = patterns('',
url('^stripe_token/$', self.transaction, name="stripe_transaction")
url('^merchant/stripe/$', self.transaction, name="stripe_transaction")
)
return urlpatterns

Expand Down

0 comments on commit 634f19b

Please sign in to comment.