merchant

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

commit a5f6348f7a738774fdef49a1b26f56ff88aeedf1
parent e5096a1efbe27caa3802372046f06175cae24f69
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Wed,  3 Nov 2021 00:18:31 +0100

fix post order trait usage

Diffstat:
Msrc/backend/taler-merchant-httpd_private-post-orders.c | 1-
Msrc/include/taler_merchant_service.h | 2+-
Msrc/include/taler_merchant_testing_lib.h | 1+
Msrc/testing/testing_api_cmd_post_orders.c | 91+++++++++++++++++++++++++++++++------------------------------------------------
4 files changed, 38 insertions(+), 57 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -905,7 +905,6 @@ patch_order (struct MHD_Connection *connection, MHD_HTTP_BAD_REQUEST, TALER_EC_MERCHANT_PRIVATE_POST_ORDERS_REFUND_AFTER_WIRE_DEADLINE, "order:wire_transfer_deadline;order:refund_deadline"); - } /* Note: total amount currency match checked diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h @@ -679,7 +679,7 @@ struct TALER_MERCHANT_Account /** * salt used to compute h_wire */ - struct GNUNET_HashCode salt; + struct TALER_WireSalt salt; /** * payto:// URI of the account. diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h @@ -1500,6 +1500,7 @@ TALER_TESTING_cmd_tip_pickup (const char *label, 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_PrivateContractHash) \ op (proposal_reference, const char *) diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c @@ -36,11 +36,6 @@ struct OrdersState { /** - * The order. - */ - char *order; - - /** * Expected status code. */ unsigned int http_status; @@ -61,6 +56,11 @@ struct OrdersState json_t *contract_terms; /** + * Order submitted to the backend. + */ + json_t *order_terms; + + /** * Contract terms hash code. */ struct TALER_PrivateContractHash h_contract_terms; @@ -159,6 +159,7 @@ orders_traits (void *cls, struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_order_id (&ps->order_id), TALER_TESTING_make_trait_contract_terms (ps->contract_terms), + TALER_TESTING_make_trait_order_terms (ps->order_terms), TALER_TESTING_make_trait_h_contract_terms (&ps->h_contract_terms), TALER_TESTING_make_trait_merchant_sig (&ps->merchant_sig), TALER_TESTING_make_trait_merchant_pub (&ps->merchant_pub), @@ -368,23 +369,9 @@ orders_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct OrdersState *ps = cls; - json_t *order; - json_error_t error; ps->is = is; - order = json_loads (ps->order, - JSON_REJECT_DUPLICATES, - &error); - if (NULL == order) - { - // human error here. - GNUNET_break (0); - fprintf (stderr, "%s\n", error.text); - TALER_TESTING_interpreter_fail (is); - return; - } - - if (NULL == json_object_get (order, + if (NULL == json_object_get (ps->order_terms, "order_id")) { struct GNUNET_TIME_Absolute now; @@ -396,7 +383,7 @@ orders_run (void *cls, (&now.abs_value_us, sizeof (now.abs_value_us)); GNUNET_assert (0 == - json_object_set_new (order, + json_object_set_new (ps->order_terms, "order_id", json_string (order_id))); GNUNET_free (order_id); @@ -406,11 +393,10 @@ orders_run (void *cls, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); ps->po = TALER_MERCHANT_orders_post (is->ctx, ps->merchant_url, - order, + ps->order_terms, GNUNET_TIME_UNIT_ZERO, &order_cb, ps); - json_decref (order); GNUNET_assert (NULL != ps->po); } @@ -428,8 +414,7 @@ orders_run2 (void *cls, struct TALER_TESTING_Interpreter *is) { struct OrdersState *ps = cls; - const char *order_str = ps->order; - json_t *order; + const json_t *order; json_error_t error; char *products_string = GNUNET_strdup (ps->products); char *locks_string = GNUNET_strdup (ps->locks); @@ -449,21 +434,35 @@ orders_run2 (void *cls, is, ps->duplicate_of); if (GNUNET_OK != - TALER_TESTING_get_trait_contract_terms (order_cmd, - &ct)) + TALER_TESTING_get_trait_order_terms (order_cmd, + &ct)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not fetch previous order string\n"); TALER_TESTING_interpreter_fail (is); return; } - order = json_incref ((json_t *) ct); + order = (json_t *) ct; } else { - order = json_loads (order_str, - JSON_REJECT_DUPLICATES, - &error); + if (NULL == json_object_get (ps->order_terms, + "order_id")) + { + struct GNUNET_TIME_Absolute now; + char *order_id; + + // FIXME: should probably use get_monotone() to ensure uniqueness! + now = GNUNET_TIME_absolute_get (); + order_id = GNUNET_STRINGS_data_to_string_alloc + (&now.abs_value_us, + sizeof (now.abs_value_us)); + json_object_set_new (ps->order_terms, + "order_id", + json_string (order_id)); + GNUNET_free (order_id); + } + order = ps->order_terms; } if (NULL == order) { @@ -474,22 +473,6 @@ orders_run2 (void *cls, return; } - if (NULL == json_object_get (order, - "order_id")) - { - struct GNUNET_TIME_Absolute now; - char *order_id; - - // FIXME: should probably use get_monotone() to ensure uniqueness! - now = GNUNET_TIME_absolute_get (); - order_id = GNUNET_STRINGS_data_to_string_alloc - (&now.abs_value_us, - sizeof (now.abs_value_us)); - json_object_set_new (order, - "order_id", - json_string (order_id)); - GNUNET_free (order_id); - } GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &ps->nonce, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); @@ -561,7 +544,6 @@ orders_run2 (void *cls, ps->make_claim_token, &order_cb, ps); - json_decref (order); GNUNET_free (products_string); GNUNET_free (locks_string); GNUNET_array_grow (products, @@ -606,7 +588,7 @@ orders_cleanup (void *cls, } json_decref (ps->contract_terms); - GNUNET_free (ps->order); + json_decref (ps->order_terms); GNUNET_free_nz ((void *) ps->order_id); GNUNET_free (ps); } @@ -644,7 +626,7 @@ make_order_json (const char *order_id, struct GNUNET_TIME_Absolute refund_deadline, struct GNUNET_TIME_Absolute pay_deadline, const char *amount, - char **order) + json_t **order) { struct GNUNET_TIME_Absolute refund = refund_deadline; struct GNUNET_TIME_Absolute pay = pay_deadline; @@ -678,8 +660,7 @@ make_order_json (const char *order_id, "$.dummy_array[*].item", &mark_forgettable, NULL)); - *order = json_dumps (contract_terms, 0); - json_decref (contract_terms); + *order = contract_terms; } @@ -700,7 +681,7 @@ TALER_TESTING_cmd_merchant_post_orders_no_claim ( refund_deadline, pay_deadline, amount, - &ps->order); + &ps->order_terms); ps->http_status = http_status; ps->expected_order_id = order_id; ps->merchant_url = merchant_url; @@ -736,7 +717,7 @@ TALER_TESTING_cmd_merchant_post_orders ( refund_deadline, pay_deadline, amount, - &ps->order); + &ps->order_terms); ps->http_status = http_status; ps->expected_order_id = order_id; ps->merchant_url = merchant_url; @@ -777,7 +758,7 @@ TALER_TESTING_cmd_merchant_post_orders2 ( refund_deadline, pay_deadline, amount, - &ps->order); + &ps->order_terms); ps->http_status = http_status; ps->expected_order_id = order_id; ps->merchant_url = merchant_url;