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
import datetime
from decimal import Decimal
import logging
from urlparse import urljoin
import uuid
from django.conf import settings
......@@ -302,11 +303,14 @@ class Paypal(BasePaymentProcessor):
Raises:
KeyError: If a required setting is not configured for this payment processor
AttributeError: If ECOMMERCE_URL_ROOT setting is not set.
"""
configuration = self.configuration
self.receipt_url = configuration['receipt_url']
self.cancel_url = configuration['cancel_url']
self.ecommerce_url_root = settings.ECOMMERCE_URL_ROOT
def get_transaction_parameters(self, basket, request=None):
"""
Create a new PayPal payment.
......@@ -325,7 +329,7 @@ class Paypal(BasePaymentProcessor):
GatewayError: Indicates a general error or unexpected behavior on the part of PayPal which prevented
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 = {
'intent': 'sale',
'redirect_urls': {
......
# -*- coding: utf-8 -*-
"""Unit tests of payment processor implementations."""
from uuid import UUID
import datetime
import json
from urlparse import urljoin
from uuid import UUID
import ddt
from django.conf import settings
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import RequestFactory
import httpretty
......@@ -280,6 +283,10 @@ class PaypalTests(PaypalMixin, PaymentProcessorTestCaseMixin, TestCase):
self._assert_transaction_parameters()
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
@mock.patch.object(processors.Paypal, '_get_error', mock.Mock(return_value=ERROR))
def test_unexpected_payment_creation_state(self):
......
......@@ -204,6 +204,9 @@ MIDDLEWARE_CLASSES = (
# See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
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.
LMS_URL_ROOT = None
......
......@@ -68,6 +68,8 @@ INTERNAL_IPS = ('127.0.0.1',)
# URL CONFIGURATION
ECOMMERCE_URL_ROOT = 'http://localhost:8002'
LMS_URL_ROOT = 'http://127.0.0.1:8000'
# The location of the LMS heartbeat page
......
......@@ -56,6 +56,8 @@ DATABASES = {
# URL CONFIGURATION
ECOMMERCE_URL_ROOT = 'http://localhost:8002'
LMS_URL_ROOT = 'http://127.0.0.1:8000'
# 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