merchant

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

commit 6d59e14e8f0c4fa717fc60528c5094dbb9e5a724
parent 892b30800777824ca9432f75cfb72c19e2b3ec3b
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date:   Fri,  8 Aug 2025 01:46:11 +0200

making test pass on C machine

Diffstat:
Msrc/include/taler_merchant_testing_lib.h | 126++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/testing/test_merchant_api.c | 15++++++++-------
Msrc/testing/testing_api_cmd_pay_order.c | 51++++++++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 118 insertions(+), 74 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h @@ -38,7 +38,7 @@ #define MERCHANT_FAIL() \ - do {GNUNET_break (0); return NULL; } while (0) + do {GNUNET_break (0); return NULL; } while (0) /** @@ -1117,6 +1117,7 @@ TALER_TESTING_cmd_merchant_pay_order_choices ( * @param amount_with_fee amount to pay, including the deposit * fee * @param amount_without_fee amount to pay, no fees included. + * @param amount_donation amount for which the BKPS will be received. * @param session_id the session id to use for the payment (can be NULL). * @param choice_index index of the selected choice for the payment. * @param year year of the donation @@ -1133,6 +1134,7 @@ TALER_TESTING_cmd_merchant_pay_order_donau ( const char *coin_reference, const char *amount_with_fee, const char *amount_without_fee, + const char *amount_donation, const char *session_id, int choice_index, const char *charity_reference, @@ -2048,53 +2050,53 @@ TALER_TESTING_cmd_merchant_get_statisticsamount (const char *label, */ // FIXME: rename: refund_entry->refund_detail #define TALER_MERCHANT_TESTING_SIMPLE_TRAITS(op) \ - op (claim_nonce, const struct GNUNET_CRYPTO_EddsaPublicKey) \ - op (pickup_id, const struct TALER_PickupIdentifierP) \ - op (instance_name, const char) \ - op (instance_id, const char) \ - op (address, const json_t) \ - op (product_description, const char) \ - op (product_image, const char) \ - op (product_stock, const int64_t) \ - op (product_unit, const char) \ - op (product_id, const char) \ - op (reason, const char) \ - op (lock_uuid, const char) \ - op (auth_token, const char) \ - op (bearer_token, const char) \ - op (paths_length, const uint32_t) \ - op (payto_length, const uint32_t) \ - op (num_planchets, const uint32_t) \ - op (i18n_description, const json_t) \ - op (taxes, const json_t) \ - op (fee, const struct TALER_Amount) \ - op (use_stefan, const bool) \ - op (jurisdiction, const json_t) \ - op (wire_delay, const struct GNUNET_TIME_Relative) \ - op (pay_delay, const struct GNUNET_TIME_Relative) \ - op (refund_entry, const struct TALER_MERCHANT_RefundDetail) \ - op (order_terms, const json_t) \ - op (h_contract_terms, const struct TALER_PrivateContractHashP) \ - op (h_wire, const struct TALER_MerchantWireHashP) \ - op (proposal_reference, const char) \ - op (template_description, const char) \ - op (otp_device_description, const char) \ - op (otp_id, const char) \ - op (otp_key, const char) \ - op (otp_alg, const enum TALER_MerchantConfirmationAlgorithm) \ - op (template_id, const char) \ - op (template_contract, const json_t) \ - op (event_type, const char) \ - op (webhook_id, const char) \ - op (merchant_base_url, const char) \ - op (url, const char) \ - op (http_method, const char) \ - op (header_template, const char) \ - op (body_template, const char) \ - op (summary, const char) \ - op (token_family_slug, const char) \ - op (token_family_duration, const struct GNUNET_TIME_Relative) \ - op (token_family_kind, const char) + op (claim_nonce, const struct GNUNET_CRYPTO_EddsaPublicKey) \ + op (pickup_id, const struct TALER_PickupIdentifierP) \ + op (instance_name, const char) \ + op (instance_id, const char) \ + op (address, const json_t) \ + op (product_description, const char) \ + op (product_image, const char) \ + op (product_stock, const int64_t) \ + op (product_unit, const char) \ + op (product_id, const char) \ + op (reason, const char) \ + op (lock_uuid, const char) \ + op (auth_token, const char) \ + op (bearer_token, const char) \ + op (paths_length, const uint32_t) \ + op (payto_length, const uint32_t) \ + op (num_planchets, const uint32_t) \ + op (i18n_description, const json_t) \ + op (taxes, const json_t) \ + op (fee, const struct TALER_Amount) \ + op (use_stefan, const bool) \ + op (jurisdiction, const json_t) \ + op (wire_delay, const struct GNUNET_TIME_Relative) \ + op (pay_delay, const struct GNUNET_TIME_Relative) \ + op (refund_entry, const struct TALER_MERCHANT_RefundDetail) \ + op (order_terms, const json_t) \ + op (h_contract_terms, const struct TALER_PrivateContractHashP) \ + op (h_wire, const struct TALER_MerchantWireHashP) \ + op (proposal_reference, const char) \ + op (template_description, const char) \ + op (otp_device_description, const char) \ + op (otp_id, const char) \ + op (otp_key, const char) \ + op (otp_alg, const enum TALER_MerchantConfirmationAlgorithm) \ + op (template_id, const char) \ + op (template_contract, const json_t) \ + op (event_type, const char) \ + op (webhook_id, const char) \ + op (merchant_base_url, const char) \ + op (url, const char) \ + op (http_method, const char) \ + op (header_template, const char) \ + op (body_template, const char) \ + op (summary, const char) \ + op (token_family_slug, const char) \ + op (token_family_duration, const struct GNUNET_TIME_Relative) \ + op (token_family_kind, const char) /** @@ -2103,20 +2105,20 @@ TALER_TESTING_cmd_merchant_get_statisticsamount (const char *label, * @param op macro to call */ #define TALER_MERCHANT_TESTING_INDEXED_TRAITS(op) \ - op (coin_reference, const char) \ - op (paths, const char) \ - op (payto_uris, const struct TALER_FullPayto) \ - op (h_wires, const struct TALER_MerchantWireHashP) \ - op (amounts, const struct TALER_Amount) \ - op (urls, const char) \ - op (http_methods, const char) \ - op (http_header, const char) \ - op (http_body, const void) \ - op (http_body_size, const size_t) \ - op (planchet_secrets, const struct TALER_PlanchetMasterSecretP) \ - op (token_priv, const struct TALER_TokenUsePrivateKeyP) \ - op (token_issue_sig, const struct TALER_TokenIssueSignature) \ - op (token_issue_pub, const struct TALER_TokenIssuePublicKey) + op (coin_reference, const char) \ + op (paths, const char) \ + op (payto_uris, const struct TALER_FullPayto) \ + op (h_wires, const struct TALER_MerchantWireHashP) \ + op (amounts, const struct TALER_Amount) \ + op (urls, const char) \ + op (http_methods, const char) \ + op (http_header, const char) \ + op (http_body, const void) \ + op (http_body_size, const size_t) \ + op (planchet_secrets, const struct TALER_PlanchetMasterSecretP) \ + op (token_priv, const struct TALER_TokenUsePrivateKeyP) \ + op (token_issue_sig, const struct TALER_TokenIssueSignature) \ + op (token_issue_pub, const struct TALER_TokenIssuePublicKey) TALER_MERCHANT_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_DECL_SIMPLE_TRAIT) diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c @@ -48,7 +48,7 @@ * commands should NOT wait for this timeout! */ #define POLL_ORDER_TIMEOUT \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) /** * The 'poll-orders-conclude-1x' and other 'conclude' @@ -56,7 +56,7 @@ * here we use a short value! */ #define POLL_ORDER_SHORT_TIMEOUT \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) /** * Configuration file we use. One (big) configuration is used @@ -176,8 +176,8 @@ cmd_exec_wirewatch (const char *label) * @param label label to use for the command. */ #define CMD_EXEC_AGGREGATOR(label) \ - TALER_TESTING_cmd_exec_aggregator (label "-aggregator", config_file), \ - TALER_TESTING_cmd_exec_transfer (label "-transfer", config_file) + TALER_TESTING_cmd_exec_aggregator (label "-aggregator", config_file), \ + TALER_TESTING_cmd_exec_transfer (label "-transfer", config_file) /** @@ -1901,15 +1901,16 @@ run (void *cls, "donau", GNUNET_TIME_UNIT_ZERO_TS, GNUNET_TIME_UNIT_FOREVER_TS, - "EUR:0.05"), + "EUR:1"), TALER_TESTING_cmd_merchant_pay_order_donau ( "pay-donau-order", merchant_url, MHD_HTTP_OK, "create-donau-order", "withdraw-coin-3", - "EUR:0.05", /* full amount */ - "EUR:0.04", /* amount without fees */ + "EUR:1", /* full amount */ + "EUR:0.99", /* amount without fees */ + "EUR:1", /* donation amount */ NULL, 0, "post-charity", diff --git a/src/testing/testing_api_cmd_pay_order.c b/src/testing/testing_api_cmd_pay_order.c @@ -95,9 +95,14 @@ struct MerchantDonauPayData uint64_t charity_id; /** + * Amount of the donation + */ + struct TALER_Amount donation_amount; + + /** * Number of BUDIs to create or fetch. Example only. */ - size_t num_bkps; + uint32_t num_bkps; /** * Year of the donation @@ -105,6 +110,11 @@ struct MerchantDonauPayData uint64_t year; /** + * Selected donation unit pub keys for this pay order request + */ + struct DONAU_DonationUnitPublicKey *selected_pks; + + /** * BUDI key pairs used in the payment (blinded_udi + pubkey). */ struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps; @@ -194,6 +204,32 @@ prepare_donau_data (struct TALER_TESTING_Interpreter *is, ss->keys = keys; } + /* Get selected_pks + num_bkps*/ + { + enum GNUNET_GenericReturnValue sret; + + sret = DONAU_select_donation_unit_keys_for_amount ( + ss->keys, + &ss->donation_amount, + ss->year, + &ss->selected_pks, + &ss->num_bkps); + + if (GNUNET_SYSERR == sret) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return GNUNET_SYSERR; + } + if ((GNUNET_NO == sret) || (0 == ss->num_bkps)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Could not compose exact amount from donation units\n"); + TALER_TESTING_interpreter_fail (is); + return GNUNET_NO; + } + } + /* Get BUDIsKP */ { ss->bkps @@ -220,7 +256,7 @@ prepare_donau_data (struct TALER_TESTING_Interpreter *is, struct DONAU_BlindedUniqueDonorIdentifier *blinded_udi; struct DONAU_UniqueDonorIdentifierHashP *udi_hash; - DONAU_donation_unit_pub_hash (&ss->keys->donation_unit_keys[0].key, + DONAU_donation_unit_pub_hash (&ss->selected_pks[cnt], &ss->bkps[cnt].h_donation_unit_pub); ss->receipts[cnt].h_donation_unit_pub @@ -237,7 +273,7 @@ prepare_donau_data (struct TALER_TESTING_Interpreter *is, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, udi_nonce, sizeof (*udi_nonce)); - switch (ss->keys->donation_unit_keys[0].key.bsign_pub_key->cipher) + switch (ss->selected_pks[cnt].bsign_pub_key->cipher) { case GNUNET_CRYPTO_BSA_RSA: alg_values = DONAU_donation_unit_ewv_rsa_singleton (); @@ -246,7 +282,7 @@ prepare_donau_data (struct TALER_TESTING_Interpreter *is, &ss->blinding_secrets[cnt]); GNUNET_assert (GNUNET_OK == DONAU_donation_unit_blind ( - &ss->keys->donation_unit_keys[0].key, + &ss->selected_pks[cnt], &ss->blinding_secrets[cnt], NULL, /* no cs-nonce needed for rsa */ udi_nonce, @@ -271,7 +307,7 @@ prepare_donau_data (struct TALER_TESTING_Interpreter *is, csr_data->csr_handle = DONAU_csr_issue ( TALER_TESTING_interpreter_get_context (is), TALER_TESTING_get_donau_url (is), - &ss->keys->donation_unit_keys[0].key, + &ss->selected_pks[cnt], &csr_data->nonce.cs_nonce, &cs_stage_two_callback, csr_data); @@ -1538,6 +1574,7 @@ TALER_TESTING_cmd_merchant_pay_order_donau ( const char *coin_reference, const char *amount_with_fee, const char *amount_without_fee, + const char *amount_donation, const char *session_id, int choice_index, const char *charity_reference, @@ -1560,6 +1597,10 @@ TALER_TESTING_cmd_merchant_pay_order_donau ( ps->donau_data.year = year; ps->donau_data.num_bkps = 5; ps->donau_data.charity_reference = charity_reference; + if (GNUNET_OK != + TALER_string_to_amount (amount_donation, + &ps->donau_data.donation_amount)) + /* Compute h_donor_tax_id directly into ps->donau_data: */ // FIXME: donau should export a helper function for this! {