-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #552 from gurch101/add-cash-payments
Add cash payment method (SHUUP-2723)
- Loading branch information
Showing
12 changed files
with
291 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# This file is part of Shoop. | ||
# | ||
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved. | ||
# | ||
# This source code is licensed under the AGPLv3 license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
from django.utils.timezone import now | ||
|
||
from shoop.core.models import CustomPaymentProcessor | ||
|
||
|
||
# TEMPORARY until we get admin orders also calling service methods | ||
|
||
|
||
def _create_cash_payment_for_order(order): | ||
if not order.is_paid(): | ||
order.create_payment( | ||
order.taxful_total_price, | ||
payment_identifier="Cash-%s" % now().isoformat(), | ||
description="Cash Payment" | ||
) | ||
|
||
|
||
def handle_custom_payment_return_requests(sender, order, *args, **kwargs): | ||
payment_processor = order.payment_method.payment_processor if order.payment_method else None | ||
if isinstance(payment_processor, CustomPaymentProcessor): | ||
service = order.payment_method.choice_identifier | ||
if service == "cash": | ||
_create_cash_payment_for_order(order) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
from decimal import Decimal | ||
import shoop.core.models | ||
import enumfields.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('shoop', '0027_contact_group_behavior'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='RoundingBehaviorComponent', | ||
fields=[ | ||
('servicebehaviorcomponent_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='shoop.ServiceBehaviorComponent')), | ||
('quant', models.DecimalField(default=Decimal('0.05'), verbose_name='rounding quant', max_digits=36, decimal_places=9)), | ||
('mode', enumfields.fields.EnumField(default=b'ROUND_HALF_UP', max_length=10, verbose_name='rounding mode', enum=shoop.core.models.RoundingMode)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('shoop.servicebehaviorcomponent',), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
# This file is part of Shoop. | ||
# | ||
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved. | ||
# | ||
# This source code is licensed under the AGPLv3 license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from decimal import Decimal | ||
|
||
import pytest | ||
|
||
from shoop.core.models import ( | ||
CustomPaymentProcessor, PaymentMethod, PaymentStatus, PaymentUrls | ||
) | ||
from shoop.core.pricing import TaxfulPrice | ||
from shoop.testing.factories import ( | ||
create_order_with_product, get_default_product, get_default_shop, | ||
get_default_supplier, get_default_tax_class | ||
) | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize('choice_identifier, expected_payment_status', [ | ||
('cash', PaymentStatus.FULLY_PAID), | ||
('manual', PaymentStatus.DEFERRED) | ||
]) | ||
def test_custom_payment_processor_cash_service(choice_identifier, expected_payment_status): | ||
shop = get_default_shop() | ||
product = get_default_product() | ||
supplier = get_default_supplier() | ||
processor = CustomPaymentProcessor.objects.create() | ||
payment_method = PaymentMethod.objects.create( | ||
shop=shop, | ||
payment_processor=processor, | ||
choice_identifier=choice_identifier, | ||
tax_class=get_default_tax_class()) | ||
order = create_order_with_product( | ||
product=product, | ||
supplier=supplier, | ||
quantity=1, | ||
taxless_base_unit_price=Decimal('5.55'), | ||
shop=shop) | ||
order.taxful_total_price = TaxfulPrice(Decimal('5.55'), u'EUR') | ||
order.payment_method = payment_method | ||
order.save() | ||
|
||
assert order.payment_status == PaymentStatus.NOT_PAID | ||
processor.process_payment_return_request(choice_identifier, order, None) | ||
assert order.payment_status == expected_payment_status | ||
processor.process_payment_return_request(choice_identifier, order, None) | ||
assert order.payment_status == expected_payment_status |
Oops, something went wrong.