merchant

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

commit 22f879704438bea407108e49e842741e07549180
parent a5df06c1c53ae28f2526a10a500e236de5e79c9a
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 27 Dec 2024 14:21:35 +0100

rename stuff, move stuff, fix FTBFS with donau

Diffstat:
Msrc/backend/taler-merchant-httpd_contract.c | 60++++++++++++++++++++++++++++++------------------------------
Msrc/backend/taler-merchant-httpd_contract.h | 587++-----------------------------------------------------------------------------
Msrc/backend/taler-merchant-httpd_post-orders-ID-pay.c | 50+++++++++++++++++++++++++-------------------------
Msrc/backend/taler-merchant-httpd_private-post-orders.c | 121++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Msrc/include/taler_merchant_util.h | 3+--
5 files changed, 140 insertions(+), 681 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c @@ -26,39 +26,39 @@ #include "taler-merchant-httpd_contract.h" -enum TALER_MerchantContractInputType +enum TALER_MERCHANT_ContractInputType TMH_contract_input_type_from_string (const char *str) { /* For now, only 'token' is the only supported option. */ if (0 == strcmp ("token", str)) { - return TALER_MCIT_TOKEN; + return TALER_MERCHANT_CONTRACT_INPUT_TYPE_TOKEN; } - return TALER_MCIT_INVALID; + return TALER_MERCHANT_CONTRACT_INPUT_TYPE_INVALID; } -enum TALER_MerchantContractOutputType +enum TALER_MERCHANT_ContractOutputType TMH_contract_output_type_from_string (const char *str) { /* For now, only 'token' is the only supported option. */ if (0 == strcmp ("token", str)) { - return TALER_MCOT_TOKEN; + return TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_TOKEN; } - return TALER_MCOT_INVALID; + return TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_INVALID; } const char * -TMH_string_from_contract_input_type (enum TALER_MerchantContractInputType t) +TMH_string_from_contract_input_type (enum TALER_MERCHANT_ContractInputType t) { switch (t) { - case TALER_MCIT_TOKEN: + case TALER_MERCHANT_CONTRACT_INPUT_TYPE_TOKEN: return "token"; - case TALER_MCIT_COIN: + case TALER_MERCHANT_CONTRACT_INPUT_TYPE_COIN: return "coin"; default: return "invalid"; @@ -67,16 +67,16 @@ TMH_string_from_contract_input_type (enum TALER_MerchantContractInputType t) const char * -TMH_string_from_contract_output_type (enum TALER_MerchantContractOutputType t) +TMH_string_from_contract_output_type (enum TALER_MERCHANT_ContractOutputType t) { switch (t) { - case TALER_MCOT_TOKEN: + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_TOKEN: return "token"; - case TALER_MCOT_COIN: + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_COIN: return "coin"; - case TALER_MCOT_TAX_RECEIPT: - return "tax_receipt"; + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_DONATION_RECEIPT: + return "donation_receipt"; default: return "invalid"; } @@ -96,7 +96,7 @@ parse_choices (void *cls, json_t *root, struct GNUNET_JSON_Specification *ospec) { - struct TALER_MerchantContractChoice **choices = ospec->ptr; + struct TALER_MERCHANT_ContractChoice **choices = ospec->ptr; unsigned int *choices_len = cls; if (! json_is_array (root)) @@ -111,7 +111,7 @@ parse_choices (void *cls, for (unsigned int i = 0; i<*choices_len; i++) { - struct TALER_MerchantContractChoice *choice = &(*choices)[i]; + struct TALER_MERCHANT_ContractChoice *choice = &(*choices)[i]; const json_t *jinputs; const json_t *joutputs; struct GNUNET_JSON_Specification spec[] = { @@ -150,7 +150,7 @@ parse_choices (void *cls, size_t idx; json_array_foreach ((json_t *) jinputs, idx, jinput) { - struct TALER_MerchantContractInput input = { + struct TALER_MERCHANT_ContractInput input = { .details.token.count = 1 }; const char *kind; @@ -185,7 +185,7 @@ parse_choices (void *cls, input.type = TMH_contract_input_type_from_string (kind); - if (TALER_MCIT_INVALID == input.type) + if (TALER_MERCHANT_CONTRACT_INPUT_TYPE_INVALID == input.type) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Field 'kind' invalid in input #%u\n", @@ -211,7 +211,7 @@ parse_choices (void *cls, size_t idx; json_array_foreach ((json_t *) joutputs, idx, joutput) { - struct TALER_MerchantContractOutput output = { + struct TALER_MERCHANT_ContractOutput output = { .details.token.count = 1 }; const char *kind; @@ -249,7 +249,7 @@ parse_choices (void *cls, output.details.token.key_index = ki; output.type = TMH_contract_output_type_from_string (kind); - if (TALER_MCOT_INVALID == output.type) + if (TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_INVALID == output.type) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Field 'kind' invalid in output #%u\n", @@ -276,7 +276,7 @@ parse_choices (void *cls, struct GNUNET_JSON_Specification TALER_JSON_spec_choices (const char *name, - struct TALER_MerchantContractChoice **choices, + struct TALER_MERCHANT_ContractChoice **choices, unsigned int *choices_len) { struct GNUNET_JSON_Specification ret = { @@ -304,7 +304,7 @@ parse_token_families (void *cls, json_t *root, struct GNUNET_JSON_Specification *ospec) { - struct TALER_MerchantContractTokenFamily **families = ospec->ptr; + struct TALER_MERCHANT_ContractTokenFamily **families = ospec->ptr; unsigned int *families_len = cls; json_t *jfamily; const char *slug; @@ -317,7 +317,7 @@ parse_token_families (void *cls, json_object_foreach (root, slug, jfamily) { const json_t *keys; - struct TALER_MerchantContractTokenFamily family = { + struct TALER_MERCHANT_ContractTokenFamily family = { .slug = GNUNET_strdup (slug) }; struct GNUNET_JSON_Specification spec[] = { @@ -350,7 +350,7 @@ parse_token_families (void *cls, for (unsigned int i = 0; i<family.keys_len; i++) { - struct TALER_MerchantContractTokenFamilyKey *key = &family.keys[i]; + struct TALER_MERCHANT_ContractTokenFamilyKey *key = &family.keys[i]; struct GNUNET_JSON_Specification key_spec[] = { TALER_JSON_spec_token_pub ( "public_key", @@ -393,7 +393,7 @@ parse_token_families (void *cls, struct GNUNET_JSON_Specification TALER_JSON_spec_token_families ( const char *name, - struct TALER_MerchantContractTokenFamily **families, + struct TALER_MERCHANT_ContractTokenFamily **families, unsigned int *families_len) { struct GNUNET_JSON_Specification ret = { @@ -411,14 +411,14 @@ enum GNUNET_GenericReturnValue TMH_find_token_family_key ( const char *slug, struct GNUNET_TIME_Timestamp valid_after, - const struct TALER_MerchantContractTokenFamily *families, + const struct TALER_MERCHANT_ContractTokenFamily *families, unsigned int families_len, - struct TALER_MerchantContractTokenFamily *family, - struct TALER_MerchantContractTokenFamilyKey *key) + struct TALER_MERCHANT_ContractTokenFamily *family, + struct TALER_MERCHANT_ContractTokenFamilyKey *key) { for (unsigned int i = 0; i < families_len; i++) { - const struct TALER_MerchantContractTokenFamily *fami + const struct TALER_MERCHANT_ContractTokenFamily *fami = &families[i]; if (0 != strcmp (fami->slug, @@ -428,7 +428,7 @@ TMH_find_token_family_key ( *family = *fami; for (unsigned int k = 0; k < fami->keys_len; k++) { - struct TALER_MerchantContractTokenFamilyKey *ki = &fami->keys[k]; + struct TALER_MERCHANT_ContractTokenFamilyKey *ki = &fami->keys[k]; if (GNUNET_TIME_timestamp_cmp (ki->valid_after, ==, diff --git a/src/backend/taler-merchant-httpd_contract.h b/src/backend/taler-merchant-httpd_contract.h @@ -24,585 +24,24 @@ #include "taler-merchant-httpd.h" #include <gnunet/gnunet_common.h> #include <gnunet/gnunet_time_lib.h> +#include "taler_merchant_util.h" #include <jansson.h> -/** - * Possible versions of the contract terms. - */ -enum TALER_MerchantContractVersion -{ - - /** - * Version 0 - */ - TALER_MCV_V0 = 0, - - /** - * Version 1 - */ - TALER_MCV_V1 = 1 -}; - -/** - * Possible token kinds. - */ -enum TALER_MerchantContractTokenKind -{ - - /** - * Subscription token kind - */ - TALER_MCTK_SUBSCRIPTION = 0, - - /** - * Discount token kind - */ - TALER_MCTK_DISCOUNT = 1 -}; - -/** - * Possible input types for the contract terms. - */ -enum TALER_MerchantContractInputType -{ - - /** - * Input type invalid - */ - TALER_MCIT_INVALID = 0, - - /** - * Input type coin - */ - TALER_MCIT_COIN = 1, - - /** - * Input type token - */ - TALER_MCIT_TOKEN = 2 -}; - -/** - * Contract input (part of the v1 contract terms). - */ -struct TALER_MerchantContractInput -{ - /** - * Type of the input. - */ - enum TALER_MerchantContractInputType type; - - union - { - /** - * Coin-based input (ration). (Future work, only here for reference) - */ - // struct - // { - // /** - // * Price to be paid. - // */ - // struct TALER_Amount price; - - // /** - // * Base URL of the ration authority. - // */ - // const char *ration_authority_url; - // } coin; - - /** - * Token-based input. - */ - struct - { - /** - * Slug of the token family to be used. - */ - const char *token_family_slug; - - /** - * Number of tokens of this type required. Defaults to one if the - * field is not provided. - */ - unsigned int count; - } token; - } details; -}; - -/** - * Possible output types for the contract terms. - */ -enum TALER_MerchantContractOutputType -{ - - /** - * Invalid output type - */ - TALER_MCOT_INVALID = 0, - - /** - * Output type coin - */ - TALER_MCOT_COIN = 1, - - /** - * Output type token - */ - TALER_MCOT_TOKEN = 2, - - /** - * Output type tax-receipt - */ - TALER_MCOT_TAX_RECEIPT = 3 - -}; - -/** - * Contract output (part of the v1 contract terms). - */ -struct TALER_MerchantContractOutput -{ - /** - * Type of the output. - */ - enum TALER_MerchantContractOutputType type; - - union - { - /** - * Coin-based output. - */ - struct - { - /** - * Coins that will be yielded. This excludes any applicable withdraw fees. - */ - struct TALER_Amount brutto_yield; - - /** - * Base URL of the exchange that will issue the coins. - */ - const char *exchange_url; - - } coin; - - /** - * Tax-receipt output. - */ - struct - { - /** - * Base URL of the donation authority that will issue the tax receipt. - */ - const char *donau_url; - } tax_receipt; - - /** - * Token-based output. - */ - struct - { - /** - * Slug of the token family to be issued. - */ - const char *token_family_slug; - - /** - * Index of the public key in the @a token_family_slug's token family - * ``keys`` array that this output token will have. - */ - unsigned int key_index; - - /** - * Number of tokens of this type required. Defaults to one if the - * field is not provided. - */ - unsigned int count; - - // FIXME: add support for clients picking a validity - // period in the future for output tokens! - - } token; - - } details; - -}; - -/** - * Contract choice (part of the v1 contract terms). - */ -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. - */ - struct TALER_MerchantContractInput *inputs; - - /** - * Length of the @e inputs array. - */ - unsigned int inputs_len; - - /** - * List of outputs the merchant promises to yield (all of them) once - * the contract is paid. - */ - struct TALER_MerchantContractOutput *outputs; - - /** - * Length of the @e outputs array. - */ - unsigned int outputs_len; -}; - -/** - * Public key and corresponding metadata for a token family. - */ -struct TALER_MerchantContractTokenFamilyKey -{ - /** - * Public key. - */ - struct TALER_TokenIssuePublicKey pub; - - /** - * Start time of the token family duration. - */ - struct GNUNET_TIME_Timestamp valid_after; - - /** - * Tokens signed by this key will be valid until this time. - */ - struct GNUNET_TIME_Timestamp valid_before; -}; - -struct TALER_MerchantContractTokenFamily -{ - /** - * Slug of the token family. - */ - char *slug; - - /** - * Human-readable name of the token family. - */ - char *name; - - /** - * Human-readable description of the semantics of the tokens issued by - * this token family. - */ - char *description; - - /** - * Map from IETF BCP 47 language tags to localized description. - */ - json_t *description_i18n; - - /** - * Relevant public keys of this token family for the given contract. - */ - struct TALER_MerchantContractTokenFamilyKey *keys; - - /** - * Length of the @e keys array. - */ - unsigned int keys_len; - - /** - * Must a wallet understand this token type to process contracts that - * consume or yield it? - */ - bool critical; - - /** - * Kind of the token family. - */ - enum TALER_MerchantContractTokenKind kind; - - /** - * Kind-specific information about the token. - */ - union - { - /** - * Subscription token. - */ - struct - { - /** - * Array of domain names where this subscription can be safely used - * (e.g. the issuer warrants that these sites will re-issue tokens of - * this type if the respective contract says so). May contain "*" for - * any domain or subdomain. - */ - char **trusted_domains; - - /** - * Length of the @e trusted_domains array. - */ - size_t trusted_domains_len; - } subscription; - - /** - * Discount token. - */ - struct - { - /** - * Array of domain names where this discount token is intended to be - * used. May contain "*" for any domain or subdomain. Users should be - * warned about sites proposing to consume discount tokens of this - * type that are not in this list that the merchant is accepting a - * coupon from a competitor and thus may be attaching different - * semantics (like get 20% discount for my competitors 30% discount - * token). - */ - char **expected_domains; - - /** - * Length of the @e expected_domains array. - */ - unsigned int expected_domains_len; - - } discount; - } details; -}; - - -/** - * Struct to hold contract terms. - */ -struct TALER_MerchantContract -{ - /** - * URL where the same contract could be ordered again (if available). - */ - const char *public_reorder_url; - - /** - * Our order ID. - */ - const char *order_id; - - /** - * Merchant base URL. - */ - char *merchant_base_url; - - /** - * Merchant information. - */ - struct - { - /** - * Legal name of the instance - */ - char *name; - - /** - * Merchant's site url - */ - char *website; - - /** - * Email contact for customers - */ - char *email; - - /** - * merchant's logo data uri - */ - char *logo; - - /** - * Merchant address - */ - json_t *address; - - /** - * Jurisdiction of the business - */ - json_t *jurisdiction; - - } merchant; - - /** - * Summary of the contract. - */ - const char *summary; - - /** - * Internationalized summary. - */ - json_t *summary_i18n; - - /** - * URL that will show that the contract was successful - * after it has been paid for. - */ - const char *fulfillment_url; - - /** - * Message shown to the customer after paying for the contract. - * Either fulfillment_url or fulfillment_message must be specified. - */ - const char *fulfillment_message; - - /** - * Map from IETF BCP 47 language tags to localized fulfillment messages. - */ - json_t *fulfillment_message_i18n; - - /** - * Array of products that are part of the purchase. - */ - const json_t *products; - - /** - * Timestamp of the contract. - */ - struct GNUNET_TIME_Timestamp timestamp; - - /** - * Deadline for refunds. - */ - struct GNUNET_TIME_Timestamp refund_deadline; - - /** - * Specifies for how long the wallet should try to get an - * automatic refund for the purchase. - */ - struct GNUNET_TIME_Relative auto_refund; - - /** - * Payment deadline. - */ - struct GNUNET_TIME_Timestamp pay_deadline; - - /** - * Wire transfer deadline. - */ - struct GNUNET_TIME_Timestamp wire_deadline; - - /** - * Delivery date. - */ - struct GNUNET_TIME_Timestamp delivery_date; - - /** - * Delivery location. - */ - json_t *delivery_location; - - /** - * Nonce generated by the wallet and echoed by the merchant - * in this field when the proposal is generated. - */ - const char *nonce; - - /** - * Extra data that is only interpreted by the merchant frontend. - */ - const json_t *extra; - - /** - * Specified version of the contract. - */ - enum TALER_MerchantContractVersion version; - - /** - * Details depending on the @e version. - */ - union - { - - /** - * Details for v0 contracts. - */ - struct - { - - /** - * Price to be paid for the transaction. Could be 0. The price is in addition - * to other instruments, such as rations and tokens. - * The exchange will subtract deposit fees from that amount - * before transferring it to the merchant. - */ - struct TALER_Amount brutto; - - /** - * Maximum fee as given by the client request. - */ - struct TALER_Amount max_fee; - - } v0; - - /** - * Details for v1 contracts. - */ - struct - { - - /** - * Array of possible specific contracts the wallet/customer may choose - * from by selecting the respective index when signing the deposit - * confirmation. - */ - struct TALER_MerchantContractChoice *choices; - - /** - * Length of the @e choices array. - */ - unsigned int choices_len; - - /** - * Array of token authorities. - */ - struct TALER_MerchantContractTokenFamily *token_authorities; - - /** - * Length of the @e token_authorities array. - */ - unsigned int token_authorities_len; - - } v1; - - } details; - - // FIXME: Add exchanges array? - -}; - - -enum TALER_MerchantContractInputType +enum TALER_MERCHANT_ContractInputType TMH_contract_input_type_from_string (const char *str); -enum TALER_MerchantContractOutputType +enum TALER_MERCHANT_ContractOutputType TMH_contract_output_type_from_string (const char *str); const char * -TMH_string_from_contract_input_type (enum TALER_MerchantContractInputType t); +TMH_string_from_contract_input_type (enum TALER_MERCHANT_ContractInputType t); const char * -TMH_string_from_contract_output_type (enum TALER_MerchantContractOutputType t); +TMH_string_from_contract_output_type (enum TALER_MERCHANT_ContractOutputType t); /** * Serialize @a contract to a JSON object, ready to be stored in the database. @@ -617,21 +56,21 @@ TMH_string_from_contract_output_type (enum TALER_MerchantContractOutputType t); * #GNUNET_SYSERR on failure */ enum GNUNET_GenericReturnValue -TMH_serialize_contract (const struct TALER_MerchantContract *contract, +TMH_serialize_contract (const struct TALER_MERCHANT_Contract *contract, const struct TMH_MerchantInstance *instance, json_t *exchanges, json_t **out); enum GNUNET_GenericReturnValue -TMH_serialize_contract_v0 (const struct TALER_MerchantContract *contract, +TMH_serialize_contract_v0 (const struct TALER_MERCHANT_Contract *contract, const struct TMH_MerchantInstance *instance, json_t *exchanges, json_t **out); enum GNUNET_GenericReturnValue -TMH_serialize_contract_v1 (const struct TALER_MerchantContract *contract, +TMH_serialize_contract_v1 (const struct TALER_MERCHANT_Contract *contract, const struct TMH_MerchantInstance *instance, json_t *exchanges, json_t **out); @@ -648,7 +87,7 @@ TMH_serialize_contract_v1 (const struct TALER_MerchantContract *contract, struct GNUNET_JSON_Specification TALER_JSON_spec_choices ( const char *name, - struct TALER_MerchantContractChoice **choices, + struct TALER_MERCHANT_ContractChoice **choices, unsigned int *choices_len); @@ -664,7 +103,7 @@ TALER_JSON_spec_choices ( struct GNUNET_JSON_Specification TALER_JSON_spec_token_families ( const char *name, - struct TALER_MerchantContractTokenFamily **families, + struct TALER_MERCHANT_ContractTokenFamily **families, unsigned int *families_len); @@ -685,9 +124,9 @@ enum GNUNET_GenericReturnValue TMH_find_token_family_key ( const char *slug, struct GNUNET_TIME_Timestamp valid_after, - const struct TALER_MerchantContractTokenFamily *families, + const struct TALER_MERCHANT_ContractTokenFamily *families, unsigned int families_len, - struct TALER_MerchantContractTokenFamily *family, - struct TALER_MerchantContractTokenFamilyKey *key); + struct TALER_MERCHANT_ContractTokenFamily *family, + struct TALER_MERCHANT_ContractTokenFamilyKey *key); #endif diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c @@ -500,7 +500,7 @@ struct PayContext /** * Version of the contract terms. */ - enum TALER_MerchantContractVersion version; + enum TALER_MERCHANT_ContractVersion version; /** * @e version dependent details from our contract. @@ -532,12 +532,12 @@ struct PayContext /** * Array with @e choices_len choices from the contract terms. */ - struct TALER_MerchantContractChoice *choices; + struct TALER_MERCHANT_ContractChoice *choices; /** * Array with @e token_families_len token families from the contract terms. */ - struct TALER_MerchantContractTokenFamily *token_families; + struct TALER_MERCHANT_ContractTokenFamily *token_families; /** * Length of the @e choices array. @@ -2514,7 +2514,7 @@ phase_execute_pay_transaction (struct PayContext *pc) static enum GNUNET_GenericReturnValue find_valid_input_tokens ( struct PayContext *pc, - const struct TALER_MerchantContractTokenFamily *family, + const struct TALER_MERCHANT_ContractTokenFamily *family, unsigned int index, unsigned int expected_num) { @@ -2525,11 +2525,11 @@ find_valid_input_tokens ( for (unsigned int j = 0; j < expected_num; j++) { struct TokenUseConfirmation *tuc = &pc->tokens[index + j]; - const struct TALER_MerchantContractTokenFamilyKey *key = NULL; + const struct TALER_MERCHANT_ContractTokenFamilyKey *key = NULL; for (unsigned int i=0; i<family->keys_len; i++) { - const struct TALER_MerchantContractTokenFamilyKey *ki + const struct TALER_MERCHANT_ContractTokenFamilyKey *ki = &family->keys[i]; if (GNUNET_TIME_timestamp_cmp (ki->valid_after, >, now) || @@ -2624,7 +2624,7 @@ find_valid_input_tokens ( static enum GNUNET_GenericReturnValue sign_token_envelopes (struct PayContext *pc, - struct TALER_MerchantContractTokenFamilyKey *key, + struct TALER_MERCHANT_ContractTokenFamilyKey *key, struct TALER_TokenIssuePrivateKey *priv, bool critical, unsigned int index, @@ -2695,13 +2695,13 @@ sign_token_envelopes (struct PayContext *pc, * @param slug slug to search for * @return NULL if @a slug was not found */ -static const struct TALER_MerchantContractTokenFamily * +static const struct TALER_MERCHANT_ContractTokenFamily * find_family (const struct PayContext *pc, const char *slug) { for (unsigned int i = 0; i<pc->details.v1.token_families_len; i++) { - const struct TALER_MerchantContractTokenFamily *tfi + const struct TALER_MERCHANT_ContractTokenFamily *tfi = &pc->details.v1.token_families[i]; if (0 == strcmp (tfi->slug, @@ -2731,15 +2731,15 @@ phase_validate_tokens (struct PayContext *pc) { switch (pc->version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: /* No tokens to validate */ pc->phase = PP_PAY_TRANSACTION; pc->validate_tokens.max_fee = pc->details.v0.max_fee; pc->validate_tokens.brutto = pc->details.v0.amount; break; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: { - const struct TALER_MerchantContractChoice *selected + const struct TALER_MERCHANT_ContractChoice *selected = &pc->details.v1.choices[pc->choice_index]; pc->validate_tokens.max_fee = selected->max_fee; @@ -2747,11 +2747,11 @@ phase_validate_tokens (struct PayContext *pc) for (unsigned int i = 0; i<selected->inputs_len; i++) { - const struct TALER_MerchantContractInput *input + const struct TALER_MERCHANT_ContractInput *input = &selected->inputs[i]; - const struct TALER_MerchantContractTokenFamily *family; + const struct TALER_MERCHANT_ContractTokenFamily *family; - if (input->type != TALER_MCIT_TOKEN) + if (input->type != TALER_MERCHANT_CONTRACT_INPUT_TYPE_TOKEN) { /* only validate inputs of type token (for now) */ continue; @@ -2791,12 +2791,12 @@ phase_validate_tokens (struct PayContext *pc) { enum GNUNET_DB_QueryStatus qs; struct TALER_MERCHANTDB_TokenFamilyKeyDetails details; - const struct TALER_MerchantContractOutput *output + const struct TALER_MERCHANT_ContractOutput *output = &selected->outputs[i]; - const struct TALER_MerchantContractTokenFamily *family; - struct TALER_MerchantContractTokenFamilyKey *key; + const struct TALER_MERCHANT_ContractTokenFamily *family; + struct TALER_MERCHANT_ContractTokenFamilyKey *key; - if (output->type != TALER_MCOT_TOKEN) + if (output->type != TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_TOKEN) { /* only validate outputs of type tokens (for now) */ continue; @@ -3313,7 +3313,7 @@ phase_check_contract (struct PayContext *pc) return; } } - pc->version = TALER_MCV_V0; + pc->version = TALER_MERCHANT_CONTRACT_VERSION_0; break; case 1: { @@ -3371,7 +3371,7 @@ phase_check_contract (struct PayContext *pc) return; } } - pc->version = TALER_MCV_V1; + pc->version = TALER_MERCHANT_CONTRACT_VERSION_1; break; default: GNUNET_break (0); @@ -3880,12 +3880,12 @@ pay_context_cleanup (void *cls) GNUNET_free (pc->egs); switch (pc->version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: break; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: for (unsigned int i = 0; i< pc->details.v1.token_families_len; i++) { - struct TALER_MerchantContractTokenFamily *tf + struct TALER_MERCHANT_ContractTokenFamily *tf = &pc->details.v1.token_families[i]; GNUNET_free (tf->slug); @@ -3894,7 +3894,7 @@ pay_context_cleanup (void *cls) json_decref (tf->description_i18n); for (unsigned int j = 0; j<tf->keys_len; j++) { - struct TALER_MerchantContractTokenFamilyKey *key + struct TALER_MERCHANT_ContractTokenFamilyKey *key = &tf->keys[j]; TALER_token_issue_pub_free (&key->pub); diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -350,7 +350,7 @@ struct OrderContext /** * Version of the contract terms. */ - enum TALER_MerchantContractVersion version; + enum TALER_MERCHANT_ContractVersion version; /** * Details present depending on @e version. @@ -398,7 +398,7 @@ struct OrderContext * from by selecting the respective index when signing the deposit * confirmation. */ - struct TALER_MerchantContractChoice *choices; + struct TALER_MERCHANT_ContractChoice *choices; /** * Length of the @e choices array. @@ -408,7 +408,7 @@ struct OrderContext /** * Array of token families referenced in the contract. */ - struct TALER_MerchantContractTokenFamily *token_families; + struct TALER_MERCHANT_ContractTokenFamily *token_families; /** * Length of the @e token_families array. @@ -632,6 +632,10 @@ struct OrderContext ORDER_PHASE_PARSE_REQUEST, ORDER_PHASE_PARSE_ORDER, ORDER_PHASE_PARSE_CHOICES, +#ifdef HAVE_DONAU_DONAU_SERVICE_H + // TODO: PLACE HOLDER FOR THE PARSE DONAU INSTANCES, maybe it needs to be lower in the order + ORDER_PHASE_PARSE_DONAU, +#endif ORDER_PHASE_MERGE_INVENTORY, ORDER_PHASE_ADD_PAYMENT_DETAILS, ORDER_PHASE_SET_EXCHANGES, @@ -777,9 +781,9 @@ clean_order (void *cls) GNUNET_free (oc->set_exchanges.total_exchange_limits); switch (oc->parse_order.version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: break; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: GNUNET_free (oc->set_max_fee.details.v1.max_fees); GNUNET_free (oc->set_exchanges.details.v1.max_stefan_fees); break; @@ -803,7 +807,7 @@ clean_order (void *cls) 0); for (unsigned int i = 0; i<oc->parse_choices.token_families_len; i++) { - struct TALER_MerchantContractTokenFamily *mctf + struct TALER_MERCHANT_ContractTokenFamily *mctf = &oc->parse_choices.token_families[i]; GNUNET_free (mctf->slug); @@ -812,12 +816,12 @@ clean_order (void *cls) json_decref (mctf->description_i18n); switch (mctf->kind) { - case TALER_MCTK_SUBSCRIPTION: + case TALER_MERCHANT_CONTRACT_TOKEN_KIND_SUBSCRIPTION: for (size_t j = 0; j<mctf->details.subscription.trusted_domains_len; j++) GNUNET_free (mctf->details.subscription.trusted_domains[j]); GNUNET_free (mctf->details.subscription.trusted_domains); break; - case TALER_MCTK_DISCOUNT: + case TALER_MERCHANT_CONTRACT_TOKEN_KIND_DISCOUNT: for (size_t j = 0; j<mctf->details.discount.expected_domains_len; j++) GNUNET_free (mctf->details.discount.expected_domains[j]); GNUNET_free (mctf->details.discount.expected_domains); @@ -1373,7 +1377,7 @@ get_rounded_time_interval (struct GNUNET_TIME_Relative precision, * @param slug slug to search for * @return NULL if @a slug was not found */ -static struct TALER_MerchantContractTokenFamily * +static struct TALER_MERCHANT_ContractTokenFamily * find_family (const struct OrderContext *oc, const char *slug) { @@ -1405,14 +1409,14 @@ add_family_key (void *cls, { struct OrderContext *oc = cls; const struct TALER_MERCHANTDB_TokenFamilyDetails *tf = &tfkd->token_family; - struct TALER_MerchantContractTokenFamily *family; + struct TALER_MERCHANT_ContractTokenFamily *family; family = find_family (oc, tf->slug); if (NULL == family) { /* Family not yet in our contract terms, create new entry */ - struct TALER_MerchantContractTokenFamily new_family = { + struct TALER_MERCHANT_ContractTokenFamily new_family = { .slug = GNUNET_strdup (tf->slug), .name = GNUNET_strdup (tf->name), .description = GNUNET_strdup (tf->description), @@ -1428,7 +1432,7 @@ add_family_key (void *cls, json_t *dom; size_t i; - new_family.kind = TALER_MCTK_SUBSCRIPTION; + new_family.kind = TALER_MERCHANT_CONTRACT_TOKEN_KIND_SUBSCRIPTION; new_family.critical = true; new_family.details.subscription.trusted_domains_len = json_array_size (tdomains); @@ -1457,7 +1461,7 @@ add_family_key (void *cls, json_t *dom; size_t i; - new_family.kind = TALER_MCTK_DISCOUNT; + new_family.kind = TALER_MERCHANT_CONTRACT_TOKEN_KIND_DISCOUNT; new_family.critical = false; new_family.details.discount.expected_domains_len = json_array_size (edomains); @@ -1499,7 +1503,7 @@ add_family_key (void *cls, } { - struct TALER_MerchantContractTokenFamilyKey key; + struct TALER_MERCHANT_ContractTokenFamilyKey key; TALER_token_issue_pub_copy (&key.pub, &tfkd->pub); @@ -1578,7 +1582,7 @@ add_input_token_family (struct OrderContext *oc, * @return #GNUNET_OK if a matching key was found */ static enum GNUNET_GenericReturnValue -find_key_index (struct TALER_MerchantContractTokenFamily *family, +find_key_index (struct TALER_MERCHANT_ContractTokenFamily *family, struct GNUNET_TIME_Timestamp valid_at, unsigned int *key_index) { @@ -1663,7 +1667,7 @@ add_output_token_family (struct OrderContext *oc, unsigned int *key_index) { struct TALER_MERCHANTDB_TokenFamilyKeyDetails key_details; - struct TALER_MerchantContractTokenFamily *family; + struct TALER_MERCHANT_ContractTokenFamily *family; enum GNUNET_DB_QueryStatus qs; family = find_family (oc, @@ -1746,7 +1750,7 @@ add_output_token_family (struct OrderContext *oc, /* No suitable key exists, create one! */ { - struct TALER_MerchantContractTokenFamilyKey key; + struct TALER_MERCHANT_ContractTokenFamilyKey key; enum GNUNET_DB_QueryStatus iqs; struct TALER_TokenIssuePrivateKey token_priv; struct GNUNET_TIME_Timestamp key_expires; @@ -1895,7 +1899,7 @@ output_token_families (struct OrderContext *oc) GNUNET_assert (NULL != token_families); for (unsigned int i = 0; i<oc->parse_choices.token_families_len; i++) { - const struct TALER_MerchantContractTokenFamily *family + const struct TALER_MERCHANT_ContractTokenFamily *family = &oc->parse_choices.token_families[i]; json_t *keys; json_t *jfamily; @@ -1904,7 +1908,7 @@ output_token_families (struct OrderContext *oc) GNUNET_assert (NULL != keys); for (unsigned int j = 0; j<family->keys_len; j++) { - const struct TALER_MerchantContractTokenFamilyKey *key + const struct TALER_MERCHANT_ContractTokenFamilyKey *key = &family->keys[j]; json_t *jkey = GNUNET_JSON_PACK ( TALER_JSON_pack_token_pub ("public_key", @@ -1959,7 +1963,7 @@ output_contract_choices (struct OrderContext *oc) GNUNET_assert (NULL != choices); for (unsigned int i = 0; i<oc->parse_choices.choices_len; i++) { - const struct TALER_MerchantContractChoice *choice + const struct TALER_MERCHANT_ContractChoice *choice = &oc->parse_choices.choices[i]; json_t *inputs = json_array (); json_t *outputs = json_array (); @@ -1968,12 +1972,12 @@ output_contract_choices (struct OrderContext *oc) GNUNET_assert (NULL != outputs); for (unsigned int j = 0; j<choice->inputs_len; j++) { - const struct TALER_MerchantContractInput *input + const struct TALER_MERCHANT_ContractInput *input = &choice->inputs[j]; json_t *jinput; /* For now, only tokens are supported for inputs */ - GNUNET_assert (TALER_MCIT_TOKEN == input->type); + GNUNET_assert (TALER_MERCHANT_CONTRACT_INPUT_TYPE_TOKEN == input->type); jinput = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("kind", TMH_string_from_contract_input_type ( @@ -1991,13 +1995,13 @@ output_contract_choices (struct OrderContext *oc) for (unsigned int j = 0; j<choice->outputs_len; j++) { - struct TALER_MerchantContractOutput *output = &choice->outputs[j]; + struct TALER_MERCHANT_ContractOutput *output = &choice->outputs[j]; json_t *joutput; /* For now, only tokens are supported */ switch (output->type) { - case TALER_MCOT_INVALID: + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_INVALID: /* How did we get here? */ GNUNET_assert (0); /* mostly to make compiler happy... */ @@ -2005,7 +2009,7 @@ output_contract_choices (struct OrderContext *oc) MHD_NO); json_decref (choices); return NULL; - case TALER_MCOT_TOKEN: + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_TOKEN: joutput = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("kind", TMH_string_from_contract_output_type ( @@ -2018,7 +2022,7 @@ output_contract_choices (struct OrderContext *oc) output->details.token.key_index) ); break; - case TALER_MCOT_COIN: + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_COIN: /* Not implemented, how did we get here? */ GNUNET_break (0); reply_with_error (oc, @@ -2027,7 +2031,7 @@ output_contract_choices (struct OrderContext *oc) "currency conversion not supported"); json_decref (choices); return NULL; - case TALER_MCOT_TAX_RECEIPT: + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_DONATION_RECEIPT: // FIXME: generate JSON for DONAU here instead of killing // the connection! GNUNET_break (0); @@ -2186,14 +2190,14 @@ serialize_order (struct OrderContext *oc) switch (oc->parse_order.version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: xtra = GNUNET_JSON_PACK ( TALER_JSON_pack_amount ("max_fee", &oc->set_max_fee.details.v0.max_fee), TALER_JSON_pack_amount ("amount", &oc->parse_order.details.v0.brutto)); break; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: { json_t *token_families = output_token_families (oc); json_t *choices = output_contract_choices (oc); @@ -2295,14 +2299,14 @@ set_max_fee (struct OrderContext *oc) { switch (oc->parse_order.version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: compute_fee (oc, &oc->parse_order.details.v0.brutto, &oc->parse_order.details.v0.max_fee, &oc->set_exchanges.details.v0.max_stefan_fee, &oc->set_max_fee.details.v0.max_fee); break; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: oc->set_max_fee.details.v1.max_fees = GNUNET_new_array (oc->parse_choices.choices_len, struct TALER_Amount); @@ -2407,12 +2411,12 @@ update_stefan (struct OrderContext *oc, { switch (oc->parse_order.version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: compute_stefan_fee (keys, &oc->parse_order.details.v0.brutto, &oc->set_exchanges.details.v0.max_stefan_fee); break; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: oc->set_exchanges.details.v1.max_stefan_fees = GNUNET_new_array (oc->parse_choices.choices_len, struct TALER_Amount); @@ -2579,7 +2583,7 @@ keys_cb ( switch (oc->parse_order.version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: if (0 == strcasecmp (keys->currency, oc->parse_order.details.v0.brutto.currency)) { @@ -2587,7 +2591,7 @@ keys_cb ( currency_ok = true; } break; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: for (unsigned int i = 0; i<oc->parse_choices.choices_len; i++) { const struct TALER_Amount *amount @@ -2786,11 +2790,11 @@ set_exchanges (struct OrderContext *oc) } switch (oc->parse_order.version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: need_exchange = ! TALER_amount_is_zero ( &oc->parse_order.details.v0.brutto); break; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: need_exchange = false; for (unsigned int i = 0; i<oc->parse_choices.choices_len; i++) if (! TALER_amount_is_zero (&oc->parse_choices.choices[i].amount)) @@ -2882,12 +2886,12 @@ set_exchanges (struct OrderContext *oc) switch (oc->parse_order.version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: ea = oc->parse_order.details.v0.brutto; ok = check_exchange_limits (oc, &ea); break; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: ok = true; for (unsigned int i = 0; i<oc->parse_choices.choices_len; i++) { @@ -3105,7 +3109,7 @@ parse_order (struct OrderContext *oc) "choices array must be null for v0 contracts"); return; } - oc->parse_order.version = TALER_MCV_V0; + oc->parse_order.version = TALER_MERCHANT_CONTRACT_VERSION_0; break; } case 1: @@ -3127,7 +3131,7 @@ parse_order (struct OrderContext *oc) ret); return; } - oc->parse_order.version = TALER_MCV_V1; + oc->parse_order.version = TALER_MERCHANT_CONTRACT_VERSION_1; break; } default: @@ -3417,6 +3421,17 @@ parse_order (struct OrderContext *oc) } +#ifdef HAVE_DONAU_DONAU_SERVICE_H + +static void +parse_donau_instances (struct OrderContext *oc) +{ + return; +} + + +#endif + /** * Parse the inputs for a particular choice. * @@ -3428,7 +3443,7 @@ parse_order (struct OrderContext *oc) */ static enum GNUNET_GenericReturnValue parse_order_inputs (struct OrderContext *oc, - struct TALER_MerchantContractChoice *choice, + struct TALER_MERCHANT_ContractChoice *choice, const json_t *jinputs) { const json_t *jinput; @@ -3436,7 +3451,7 @@ parse_order_inputs (struct OrderContext *oc, json_array_foreach ((json_t *) jinputs, idx, jinput) { - struct TALER_MerchantContractInput input = { + struct TALER_MERCHANT_ContractInput input = { .details.token.count = 1 }; const char *kind; @@ -3473,7 +3488,7 @@ parse_order_inputs (struct OrderContext *oc, } input.type = TMH_contract_input_type_from_string (kind); - if (TALER_MCIT_INVALID == input.type) + if (TALER_MERCHANT_CONTRACT_INPUT_TYPE_INVALID == input.type) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Field 'kind' invalid in input #%u\n", @@ -3518,7 +3533,7 @@ parse_order_inputs (struct OrderContext *oc, */ static enum GNUNET_GenericReturnValue parse_order_outputs (struct OrderContext *oc, - struct TALER_MerchantContractChoice *choice, + struct TALER_MERCHANT_ContractChoice *choice, const json_t *joutputs) { const json_t *joutput; @@ -3526,7 +3541,7 @@ parse_order_outputs (struct OrderContext *oc, json_array_foreach ((json_t *) joutputs, idx, joutput) { - struct TALER_MerchantContractOutput output = { + struct TALER_MERCHANT_ContractOutput output = { .details.token.count = 1 }; const char *kind; @@ -3592,7 +3607,7 @@ parse_order_outputs (struct OrderContext *oc, } output.type = TMH_contract_output_type_from_string (kind); - if (TALER_MCOT_INVALID == output.type) + if (TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_INVALID == output.type) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Field 'kind' invalid in output #%u\n", @@ -3641,10 +3656,10 @@ parse_choices (struct OrderContext *oc) switch (oc->parse_order.version) { - case TALER_MCV_V0: + case TALER_MERCHANT_CONTRACT_VERSION_0: oc->phase++; return; - case TALER_MCV_V1: + case TALER_MERCHANT_CONTRACT_VERSION_1: /* handle below */ break; default: @@ -3657,7 +3672,7 @@ parse_choices (struct OrderContext *oc) json_array_size (choices)); for (unsigned int i = 0; i<oc->parse_choices.choices_len; i++) { - struct TALER_MerchantContractChoice *choice + struct TALER_MERCHANT_ContractChoice *choice = &oc->parse_choices.choices[i]; const char *error_name; unsigned int error_line; @@ -4159,6 +4174,12 @@ TMH_private_post_orders ( case ORDER_PHASE_PARSE_CHOICES: parse_choices (oc); break; +#ifdef HAVE_DONAU_DONAU_SERVICE_H + // TODO: PLACE HOLDER FOR THE PARSE DONAU INSTANCES, maybe it needs to be lower in the order + case ORDER_PHASE_PARSE_DONAU: + parse_donau_instances (oc); + break; +#endif case ORDER_PHASE_MERGE_INVENTORY: merge_inventory (oc); break; diff --git a/src/include/taler_merchant_util.h b/src/include/taler_merchant_util.h @@ -25,7 +25,6 @@ #include <taler/taler_util.h> #include <jansson.h> - /** * Return default project data used by Taler merchant. */ @@ -118,6 +117,7 @@ struct TALER_MERCHANT_ContractInput const char *ration_authority_url; } coin; #endif + /** * Token-based input. */ @@ -214,7 +214,6 @@ struct TALER_MERCHANT_ContractOutput /** * Base URLs of the donation authorities that will issue the tax receipt. */ - // FIXME // const char *donau_url; } donation_receipt;