Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split logic from Model, split address into billing, shipping, use functions instead prefixed fields #149

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
18 changes: 9 additions & 9 deletions payments/authorizenet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ def __init__(self, login_id, transaction_key,
'Authorize.Net does not support pre-authorization.')

def get_transactions_data(self, payment):
data = {
billing = payment.get_billing_address()
return {
'x_amount': payment.total,
'x_currency_code': payment.currency,
'x_description': payment.description,
'x_first_name': payment.billing_first_name,
'x_last_name': payment.billing_last_name,
'x_address': "%s, %s" % (payment.billing_address_1,
payment.billing_address_2),
'x_city': payment.billing_city,
'x_zip': payment.billing_postcode,
'x_country': payment.billing_country_area
'x_first_name': billing["first_name"],
'x_last_name': billing["last_name"],
'x_address': "%s, %s" % (billing["address_1"],
billing["address_2"]),
'x_city': billing["city"],
'x_zip': billing["postcode"],
'x_country': billing["country_area"]
}
return data

def get_product_data(self, payment, extra_data=None):
data = self.get_transactions_data(payment)
Expand Down
27 changes: 6 additions & 21 deletions payments/authorizenet/test_authorizenet.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import unicode_literals
from unittest import TestCase
from mock import patch, MagicMock, Mock
try:
from unittest.mock import patch, MagicMock
except ImportError:
from mock import patch, MagicMock

from . import AuthorizeNetProvider
from .. import PaymentStatus, RedirectNeeded
from ..testcommon import create_test_payment


LOGIN_ID = 'abcd1234'
Expand All @@ -18,26 +22,7 @@
STATUS_CONFIRMED = '1'


class Payment(Mock):
id = 1
variant = 'authorizenet'
currency = 'USD'
total = 100
status = PaymentStatus.WAITING
transaction_id = None
captured_amount = 0

def get_process_url(self):
return 'http://example.com'

def get_failure_url(self):
return 'http://cancel.com'

def get_success_url(self):
return 'http://success.com'

def change_status(self, status):
self.status = status
Payment = create_test_payment()



Expand Down
22 changes: 12 additions & 10 deletions payments/braintree/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ def get_credit_card_clean_data(self):
'expiration_year': self.cleaned_data.get('expiration').year}

def get_billing_data(self):
billing = self.payment.get_billing_address()
return {
'first_name': self.payment.billing_first_name,
'last_name': self.payment.billing_last_name,
'street_address': self.payment.billing_address_1,
'extended_address': self.payment.billing_address_2,
'locality': self.payment.billing_city,
'region': self.payment.billing_country_area,
'postal_code': self.payment.billing_postcode,
'country_code_alpha2': self.payment.billing_country_code}
'first_name': billing["first_name"],
'last_name': billing["last_name"],
'street_address': billing["address_1"],
'extended_address': billing["address_2"],
'locality': billing["city"],
'region': billing["country_area"],
'postal_code': billing["postcode"],
'country_code_alpha2': billing["country_code"]}

def get_customer_data(self):
billing = self.payment.get_billing_address()
return {
'first_name': self.payment.billing_first_name,
'last_name': self.payment.billing_last_name}
'first_name': billing["first_name"],
'last_name': billing["last_name"]}

def save(self):
braintree.Transaction.submit_for_settlement(self.transaction_id)
Expand Down
27 changes: 6 additions & 21 deletions payments/braintree/test_braintree.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import unicode_literals
from unittest import TestCase
from mock import patch, MagicMock, Mock
try:
from unittest.mock import patch, MagicMock
except ImportError:
from mock import patch, MagicMock

from . import BraintreeProvider
from .. import PaymentStatus, RedirectNeeded
from ..testcommon import create_test_payment


MERCHANT_ID = 'test11'
Expand All @@ -18,26 +22,7 @@
'cvv2': '1234'}


class Payment(Mock):
id = 1
variant = 'braintree'
currency = 'USD'
total = 100
status = PaymentStatus.WAITING
transaction_id = None
captured_amount = 0

def get_process_url(self):
return 'http://example.com'

def get_failure_url(self):
return 'http://cancel.com'

def get_success_url(self):
return 'http://success.com'

def change_status(self, status):
self.status = status
Payment = create_test_payment()


class TestBraintreeProvider(TestCase):
Expand Down
35 changes: 6 additions & 29 deletions payments/coinbase/test_coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import json
from decimal import Decimal
from unittest import TestCase
try:
from unittest.mock import patch, MagicMock
except ImportError:
from mock import patch, MagicMock

from django.http import HttpResponse, HttpResponseForbidden
from mock import MagicMock, patch

from .. import PaymentStatus
from . import CoinbaseProvider
from ..testcommon import create_test_payment

PAYMENT_TOKEN = '5a4dae68-2715-4b1e-8bb2-2c2dbe9255f6'
KEY = 'abc123'
Expand All @@ -23,34 +27,7 @@
PAYMENT_TOKEN, KEY)).encode('utf-8')).hexdigest()}}


class Payment(object):

id = 1
description = 'payment'
currency = 'BTC'
total = Decimal(100)
status = PaymentStatus.WAITING
token = PAYMENT_TOKEN
variant = VARIANT

def change_status(self, status):
self.status = status

def get_failure_url(self):
return 'http://cancel.com'

def get_process_url(self):
return 'http://example.com'

def get_purchased_items(self):
return []

def save(self):
return self

def get_success_url(self):
return 'http://success.com'

Payment = create_test_payment(variant=VARIANT, token=PAYMENT_TOKEN, description='payment', currency='BTC', total=Decimal(100))

class TestCoinbaseProvider(TestCase):

Expand Down
17 changes: 9 additions & 8 deletions payments/cybersource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,16 @@ def _prepare_card_data(self, data):
return card

def _prepare_billing_data(self, payment):
_billing_address = payment.get_billing_address()
billing = self.client.factory.create('data:BillTo')
billing.firstName = payment.billing_first_name
billing.lastName = payment.billing_last_name
billing.street1 = payment.billing_address_1
billing.street2 = payment.billing_address_2
billing.city = payment.billing_city
billing.postalCode = payment.billing_postcode
billing.country = payment.billing_country_code
billing.state = payment.billing_country_area
billing.firstName = _billing_address["first_name"]
billing.lastName = _billing_address["last_name"]
billing.street1 = _billing_address["address_1"]
billing.street2 = _billing_address["address_2"]
billing.city = _billing_address["city"]
billing.postalCode = _billing_address["postcode"]
billing.country = _billing_address["country_code"]
billing.state = _billing_address["country_area"]
billing.email = payment.billing_email
billing.ipAddress = payment.customer_ip_address
return billing
Expand Down
42 changes: 10 additions & 32 deletions payments/cybersource/test_cybersource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
from decimal import Decimal
from unittest import TestCase
from django.core import signing
from mock import patch, MagicMock, Mock
try:
from unittest.mock import patch, MagicMock
except ImportError:
from mock import patch, MagicMock

from . import CyberSourceProvider, AUTHENTICATE_REQUIRED, ACCEPTED, \
TRANSACTION_SETTLED
from .. import PaymentStatus, PurchasedItem, RedirectNeeded

from ..testcommon import create_test_payment

MERCHANT_ID = 'abcd1234'
PASSWORD = '1234abdd1234abcd'
ORG_ID = 'abc'
Expand All @@ -20,40 +25,13 @@
'cvv2': '1234',
'fingerprint': 'abcd1234'}


class Payment(Mock):
id = 1
variant = 'cybersource'
currency = 'USD'
total = 100
status = PaymentStatus.WAITING
transaction_id = None
captured_amount = 0
message = ''

_Payment = create_test_payment()
class Payment(_Payment):
# MagicMock is not serializable so overwrite attrs Proxy
class attrs(object):
fingerprint_session_id = 'fake'
merchant_defined_data = {}

def get_process_url(self):
return 'http://example.com'

def get_failure_url(self):
return 'http://cancel.com'

def get_success_url(self):
return 'http://success.com'

def change_status(self, status, message=''):
self.status = status
self.message = message

def get_purchased_items(self):
return [
PurchasedItem(
name='foo', quantity=Decimal('10'), price=Decimal('20'),
currency='USD', sku='bar')]

capture = {}

class TestCybersourceProvider(TestCase):

Expand Down
25 changes: 6 additions & 19 deletions payments/dotpay/test_dotpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
from unittest import TestCase

from django.http import HttpResponse, HttpResponseForbidden
from mock import MagicMock, Mock
try:
from unittest.mock import MagicMock
except ImportError:
from mock import MagicMock

from .. import PaymentStatus
from .forms import ACCEPTED, REJECTED
from . import DotpayProvider
from ..testcommon import create_test_payment

VARIANT = 'dotpay'
PIN = '123'
Expand Down Expand Up @@ -45,24 +49,7 @@ def get_post_with_md5(post):
return post


class Payment(Mock):
id = 1
variant = VARIANT
currency = 'USD'
total = 100
status = PaymentStatus.WAITING

def get_process_url(self):
return 'http://example.com'

def get_failure_url(self):
return 'http://cancel.com'

def get_success_url(self):
return 'http://success.com'

def change_status(self, status):
self.status = status
Payment = create_test_payment(variant=VARIANT, id=1, currency='USD')


class TestDotpayProvider(TestCase):
Expand Down
24 changes: 2 additions & 22 deletions payments/dummy/test_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,12 @@

from . import DummyProvider
from .. import FraudStatus, PaymentError, PaymentStatus, RedirectNeeded
from ..testcommon import create_test_payment

VARIANT = 'dummy-3ds'


class Payment(object):
id = 1
variant = VARIANT
currency = 'USD'
total = 100
status = PaymentStatus.WAITING
fraud_status = ''

def get_process_url(self):
return 'http://example.com'

def get_failure_url(self):
return 'http://cancel.com'

def get_success_url(self):
return 'http://success.com'

def change_status(self, new_status):
self.status = new_status

def change_fraud_status(self, fraud_status):
self.fraud_status = fraud_status
Payment = create_test_payment(variant=VARIANT)


class TestDummy3DSProvider(TestCase):
Expand Down
Loading