merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 31e40f3859569a924eff59a1b99f4c5b4e5188c4
parent defba7f452f51385f79e3131db460f74af09e6ea
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 23 Dec 2024 22:52:25 +0100

work a bit on contract choice parse logic, much more to be done

Diffstat:
Msrc/backend/taler-merchant-httpd_contract.h | 12++++++++++++
Msrc/backend/taler-merchant-httpd_private-post-orders.c | 22++++++++++++++--------
2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_contract.h b/src/backend/taler-merchant-httpd_contract.h @@ -231,6 +231,18 @@ struct TALER_MerchantContractOutput */ struct TALER_MerchantContractChoice { + + /** + * Amount to be paid for this choice. + */ + struct TALER_Amount amount; + + /** + * Maximum fee the merchant is willing to pay for this choice. + * Set to an invalid amount to use instance defaults (zero or STEFAN). + */ + struct TALER_Amount max_fee; + /** * List of inputs the wallet must provision (all of them) to satisfy the * conditions for the contract. diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -2663,7 +2663,6 @@ parse_order (struct OrderContext *oc) if (0 == version) { oc->parse_order.version = TALER_MCV_V0; - if (NULL != oc->parse_order.choices) { GNUNET_break_op (0); @@ -2678,15 +2677,14 @@ parse_order (struct OrderContext *oc) else if (1 == version) { oc->parse_order.version = TALER_MCV_V1; - - if (! json_is_array (oc->parse_order.choices)) + if (NULL == oc->parse_order.choices) { GNUNET_break_op (0); GNUNET_JSON_parse_free (spec); reply_with_error (oc, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, - "order.choices is not a valid array"); + "order.choices is required in v1 contracts"); return; } } @@ -3022,11 +3020,19 @@ parse_choices (struct OrderContext *oc) json_array_size (oc->parse_order.choices)); for (unsigned int i = 0; i<oc->parse_choices.choices_len; i++) { + struct TALER_MerchantContractChoice *choice + = &oc->parse_choices.choices[i]; const char *error_name; unsigned int error_line; const json_t *jinputs; const json_t *joutputs; struct GNUNET_JSON_Specification spec[] = { + TALER_JSON_spec_amount_any ("amount", + &choice->amount), + GNUNET_JSON_spec_mark_optional ( + TALER_JSON_spec_amount_any ("max_fee", + &choice->max_fee), + NULL), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_array_const ("inputs", &jinputs), @@ -3139,8 +3145,8 @@ parse_choices (struct OrderContext *oc) return; } - GNUNET_array_append (oc->parse_choices.choices[i].inputs, - oc->parse_choices.choices[i].inputs_len, + GNUNET_array_append (choice->inputs, + choice->inputs_len, input); } } @@ -3251,8 +3257,8 @@ parse_choices (struct OrderContext *oc) return; } - GNUNET_array_append (oc->parse_choices.choices[i].outputs, - oc->parse_choices.choices[i].outputs_len, + GNUNET_array_append (choice->outputs, + choice->outputs_len, output); } }