Commit 457b415d by Renzo Lucioni

Merge pull request #92 from edx/renzo/url-root

Add URL root setting used to construct URLs pointing back to the service.
parents f3b8c35c fda48a9e
...@@ -3,6 +3,7 @@ import abc ...@@ -3,6 +3,7 @@ import abc
import datetime import datetime
from decimal import Decimal from decimal import Decimal
import logging import logging
from urlparse import urljoin
import uuid import uuid
from django.conf import settings from django.conf import settings
...@@ -302,11 +303,14 @@ class Paypal(BasePaymentProcessor): ...@@ -302,11 +303,14 @@ class Paypal(BasePaymentProcessor):
Raises: Raises:
KeyError: If a required setting is not configured for this payment processor KeyError: If a required setting is not configured for this payment processor
AttributeError: If ECOMMERCE_URL_ROOT setting is not set.
""" """
configuration = self.configuration configuration = self.configuration
self.receipt_url = configuration['receipt_url'] self.receipt_url = configuration['receipt_url']
self.cancel_url = configuration['cancel_url'] self.cancel_url = configuration['cancel_url']
self.ecommerce_url_root = settings.ECOMMERCE_URL_ROOT
def get_transaction_parameters(self, basket, request=None): def get_transaction_parameters(self, basket, request=None):
""" """
Create a new PayPal payment. Create a new PayPal payment.
...@@ -325,7 +329,7 @@ class Paypal(BasePaymentProcessor): ...@@ -325,7 +329,7 @@ class Paypal(BasePaymentProcessor):
GatewayError: Indicates a general error or unexpected behavior on the part of PayPal which prevented GatewayError: Indicates a general error or unexpected behavior on the part of PayPal which prevented
a payment from being created. a payment from being created.
""" """
return_url = request.build_absolute_uri(reverse('paypal_execute')) return_url = urljoin(self.ecommerce_url_root, reverse('paypal_execute'))
data = { data = {
'intent': 'sale', 'intent': 'sale',
'redirect_urls': { 'redirect_urls': {
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Unit tests of payment processor implementations.""" """Unit tests of payment processor implementations."""
from uuid import UUID
import datetime import datetime
import json
from urlparse import urljoin
from uuid import UUID
import ddt import ddt
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse
from django.test import TestCase from django.test import TestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
import httpretty import httpretty
...@@ -280,6 +283,10 @@ class PaypalTests(PaypalMixin, PaymentProcessorTestCaseMixin, TestCase): ...@@ -280,6 +283,10 @@ class PaypalTests(PaypalMixin, PaymentProcessorTestCaseMixin, TestCase):
self._assert_transaction_parameters() self._assert_transaction_parameters()
self.assert_processor_response_recorded(self.processor.NAME, self.PAYMENT_ID, response, basket=self.basket) self.assert_processor_response_recorded(self.processor.NAME, self.PAYMENT_ID, response, basket=self.basket)
last_request_body = json.loads(httpretty.last_request().body)
expected = urljoin(settings.ECOMMERCE_URL_ROOT, reverse('paypal_execute'))
self.assertEqual(last_request_body['redirect_urls']['return_url'], expected)
@httpretty.activate @httpretty.activate
@mock.patch.object(processors.Paypal, '_get_error', mock.Mock(return_value=ERROR)) @mock.patch.object(processors.Paypal, '_get_error', mock.Mock(return_value=ERROR))
def test_unexpected_payment_creation_state(self): def test_unexpected_payment_creation_state(self):
......
...@@ -204,6 +204,9 @@ MIDDLEWARE_CLASSES = ( ...@@ -204,6 +204,9 @@ MIDDLEWARE_CLASSES = (
# See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf # See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
ROOT_URLCONF = '{}.urls'.format(SITE_NAME) ROOT_URLCONF = '{}.urls'.format(SITE_NAME)
# Absolute URL used to construct URLs pointing back to the ecommerce service.
ECOMMERCE_URL_ROOT = None
# Absolute URL used to construct LMS URLs. # Absolute URL used to construct LMS URLs.
LMS_URL_ROOT = None LMS_URL_ROOT = None
......
...@@ -68,6 +68,8 @@ INTERNAL_IPS = ('127.0.0.1',) ...@@ -68,6 +68,8 @@ INTERNAL_IPS = ('127.0.0.1',)
# URL CONFIGURATION # URL CONFIGURATION
ECOMMERCE_URL_ROOT = 'http://localhost:8002'
LMS_URL_ROOT = 'http://127.0.0.1:8000' LMS_URL_ROOT = 'http://127.0.0.1:8000'
# The location of the LMS heartbeat page # The location of the LMS heartbeat page
......
...@@ -56,6 +56,8 @@ DATABASES = { ...@@ -56,6 +56,8 @@ DATABASES = {
# URL CONFIGURATION # URL CONFIGURATION
ECOMMERCE_URL_ROOT = 'http://localhost:8002'
LMS_URL_ROOT = 'http://127.0.0.1:8000' LMS_URL_ROOT = 'http://127.0.0.1:8000'
# The location of the LMS heartbeat page # The location of the LMS heartbeat page
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment