Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Support partially refunded in dummy gateway

Unknown1b608a9c6808
diff --git a/saleor/payment/gateways/dummy/__init__.py b/saleor/payment/gateways/dummy/__init__.py
index f11ceb9557..46aad9cc3b 100644
--- a/saleor/payment/gateways/dummy/__init__.py
+++ b/saleor/payment/gateways/dummy/__init__.py
@@ -106,6 +106,10 @@ def process_payment(payment_information: Dict, connection_params) -> Dict:
if charge_status == ChargeStatus.NOT_CHARGED:
return responses
responses.append(capture(payment_information, connection_params))
- if charge_status == ChargeStatus.FULLY_REFUNDED:
+ if charge_status == ChargeStatus.PARTIALLY_REFUNDED:
+ payment_information['amount'] = (
+ payment_information['amount'] / Decimal(2))
+ responses.append(refund(payment_information, connection_params))
+ elif charge_status == ChargeStatus.FULLY_REFUNDED:
responses.append(refund(payment_information, connection_params))
return responses
diff --git a/saleor/payment/gateways/dummy/forms.py b/saleor/payment/gateways/dummy/forms.py
index 339df63e2c..9ed72713d9 100644
--- a/saleor/payment/gateways/dummy/forms.py
+++ b/saleor/payment/gateways/dummy/forms.py
@@ -1,5 +1,6 @@
from django import forms
from django.utils.translation import pgettext_lazy
+from django.utils.translation import ugettext_lazy as _
from ... import ChargeStatus
@@ -10,6 +11,17 @@ class DummyPaymentForm(forms.Form):
choices=ChargeStatus.CHOICES, initial=ChargeStatus.NOT_CHARGED,
widget=forms.RadioSelect)
+ def clean(self):
+ cleaned_data = super(DummyPaymentForm, self).clean()
+
+ charge_status = cleaned_data['charge_status']
+ if charge_status == ChargeStatus.PARTIALLY_REFUNDED:
+ raise forms.ValidationError(
+ _('Setting charge status to partially refunded directly '
+ 'is not supported.'), code='invalid_charge_status')
+
+ return cleaned_data
+
def get_payment_token(self):
"""Return selected charge status instead of token for testing only.
Gateways used for production should return an actual token instead."""
diff --git a/templates/order/payment/dummy.html b/templates/order/payment/dummy.html
index 8846ec4bf3..f3575d26de 100644
--- a/templates/order/payment/dummy.html
+++ b/templates/order/payment/dummy.html
@@ -6,6 +6,13 @@
<div class="checkout__payment-form">
<form method="POST" id="payment-form" class="form-horizontal"{% if form.action %} action="{{ form.action }}"{% endif %} novalidate>
{% csrf_token %}
+ {% if form.errors or form.non_field_errors %}
+ <blockquote>
+ {% for non_field_error in form.non_field_errors %}
+ {{ non_field_error }}
+ {% endfor %}
+ </blockquote>
+ {% endif %}
{{ form.media }}
{% for choice in form.charge_status %}
<div class="radio">