REST API: Order creation: Allow to set payment_date

This commit is contained in:
Raphael Michel
2019-04-05 08:55:57 +02:00
parent 19a2f4163a
commit db0c13a3c2
3 changed files with 11 additions and 2 deletions
+1
View File
@@ -750,6 +750,7 @@ Creating orders
should only use this if you know the specific payment provider in detail. Please keep in mind that the payment
provider will not be called to do anything about this (i.e. if you pass a bank account to a debit provider, *no*
charge will be created), this is just informative in case you *handled the payment already*.
* ``payment_date`` (optional) Date and time of the completion of the payment.
* ``comment`` (optional)
* ``checkin_attention`` (optional)
* ``invoice_address`` (optional)
+4 -2
View File
@@ -458,11 +458,12 @@ class OrderCreateSerializer(I18nAwareModelSerializer):
payment_info = CompatibleJSONField(required=False)
consume_carts = serializers.ListField(child=serializers.CharField(), required=False)
force = serializers.BooleanField(default=False, required=False)
payment_date = serializers.DateTimeField(required=False, allow_null=True)
class Meta:
model = Order
fields = ('code', 'status', 'testmode', 'email', 'locale', 'payment_provider', 'fees', 'comment', 'sales_channel',
'invoice_address', 'positions', 'checkin_attention', 'payment_info', 'consume_carts', 'force')
'invoice_address', 'positions', 'checkin_attention', 'payment_info', 'payment_date', 'consume_carts', 'force')
def validate_payment_provider(self, pp):
if pp not in self.context['event'].get_payment_providers():
@@ -533,6 +534,7 @@ class OrderCreateSerializer(I18nAwareModelSerializer):
positions_data = validated_data.pop('positions') if 'positions' in validated_data else []
payment_provider = validated_data.pop('payment_provider')
payment_info = validated_data.pop('payment_info', '{}')
payment_date = validated_data.pop('payment_date', now())
force = validated_data.pop('force', False)
if 'invoice_address' in validated_data:
@@ -617,7 +619,7 @@ class OrderCreateSerializer(I18nAwareModelSerializer):
amount=order.total,
provider=payment_provider,
info=payment_info,
payment_date=now(),
payment_date=payment_date,
state=OrderPayment.PAYMENT_STATE_CONFIRMED
)
elif payment_provider:
+6
View File
@@ -2428,6 +2428,7 @@ def test_order_create_paid_generate_invoice(token_client, organizer, event, item
event.settings.invoice_generate = 'paid'
res = copy.deepcopy(ORDER_CREATE_PAYLOAD)
res['status'] = 'p'
res['payment_date'] = '2019-04-01 08:20:00Z'
res['positions'][0]['item'] = item.pk
res['positions'][0]['answers'][0]['question'] = question.pk
resp = token_client.post(
@@ -2443,6 +2444,11 @@ def test_order_create_paid_generate_invoice(token_client, organizer, event, item
assert p.provider == "banktransfer"
assert p.amount == o.total
assert p.state == "confirmed"
assert p.payment_date.year == 2019
assert p.payment_date.month == 4
assert p.payment_date.day == 1
assert p.payment_date.hour == 8
assert p.payment_date.minute == 20
REFUND_CREATE_PAYLOAD = {