mirror of
https://github.com/pretix/pretix.git
synced 2026-03-02 10:42:26 +00:00
Compare commits
2 Commits
master
...
api-add-pa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50a3d4e855 | ||
|
|
8f6ee7ae3e |
@@ -19,6 +19,7 @@
|
||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from collections import Counter, defaultdict
|
||||
@@ -1215,6 +1216,18 @@ class OrderCreateSerializer(I18nAwareModelSerializer):
|
||||
raise ValidationError('The given payment provider is not known.')
|
||||
return pp
|
||||
|
||||
def validate_payment_info(self, info):
|
||||
if info:
|
||||
try:
|
||||
obj = json.loads(info)
|
||||
except ValueError:
|
||||
raise ValidationError('Payment info must be valid JSON.')
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
# only objects are allowed
|
||||
raise ValidationError('Payment info must be a JSON-object.')
|
||||
return info
|
||||
|
||||
def validate_expires(self, expires):
|
||||
if expires < now():
|
||||
raise ValidationError('Expiration date must be in the future.')
|
||||
|
||||
@@ -895,6 +895,41 @@ def test_order_create_payment_info_optional(token_client, organizer, event, item
|
||||
assert json.loads(p.info) == res['payment_info']
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_order_create_payment_info_valid_object(token_client, organizer, event, item, quota, question):
|
||||
res = copy.deepcopy(ORDER_CREATE_PAYLOAD)
|
||||
res['positions'][0]['item'] = item.pk
|
||||
res['positions'][0]['answers'][0]['question'] = question.pk
|
||||
|
||||
res["payment_info"] = [{"should": "fail"}]
|
||||
resp = token_client.post(
|
||||
'/api/v1/organizers/{}/events/{}/orders/'.format(
|
||||
organizer.slug, event.slug
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
|
||||
res['payment_info'] = {
|
||||
'foo': {
|
||||
'bar': [1, 2],
|
||||
'test': False
|
||||
}
|
||||
}
|
||||
resp = token_client.post(
|
||||
'/api/v1/organizers/{}/events/{}/orders/'.format(
|
||||
organizer.slug, event.slug
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
with scopes_disabled():
|
||||
o = Order.objects.get(code=resp.data['code'])
|
||||
|
||||
p = o.payments.first()
|
||||
assert p.provider == "banktransfer"
|
||||
assert p.amount == o.total
|
||||
assert json.loads(p.info) == res['payment_info']
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_order_create_position_secret_optional(token_client, organizer, event, item, quota, question):
|
||||
res = copy.deepcopy(ORDER_CREATE_PAYLOAD)
|
||||
|
||||
Reference in New Issue
Block a user