diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-11 19:55:28 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-11 19:55:28 -0400 |
commit | ecb3a2afa27257816b34e4e959d98424ef123033 (patch) | |
tree | 7c75fe2d6e4a11357d26b24f0a3e70ba0ee4f0ce /src/testing/testing_api_cmd_post_orders.c | |
parent | d299f7e7d288309dc696962edd9ce257d2c1a926 (diff) | |
download | merchant-ecb3a2afa27257816b34e4e959d98424ef123033.tar.gz merchant-ecb3a2afa27257816b34e4e959d98424ef123033.tar.bz2 merchant-ecb3a2afa27257816b34e4e959d98424ef123033.zip |
clean up testing post orders cmd
Diffstat (limited to 'src/testing/testing_api_cmd_post_orders.c')
-rw-r--r-- | src/testing/testing_api_cmd_post_orders.c | 101 |
1 files changed, 91 insertions, 10 deletions
diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c index 0e4f47af..3a489026 100644 --- a/src/testing/testing_api_cmd_post_orders.c +++ b/src/testing/testing_api_cmd_post_orders.c @@ -38,7 +38,7 @@ struct OrdersState /** * The order. */ - const char *order; + char *order; /** * Expected status code. @@ -505,32 +505,101 @@ orders_cleanup (void *cls, } json_decref (ps->contract_terms); + GNUNET_free (ps->order); GNUNET_free_nz ((void *) ps->order_id); GNUNET_free (ps); } /** - * Make the "orders" command. + * Constructs the json for a POST order request. + * + * @param order_id the name of the order to add. + * @param refund_deadline the deadline for refunds on this order. + * @param pay_deadline the deadline for payment on this order. + * @param amount the amount this order is for. + * @param order[out] where to write the json string. + */ +static void +make_order_json (const char *order_id, + struct GNUNET_TIME_Absolute refund_deadline, + struct GNUNET_TIME_Absolute pay_deadline, + const char *amount, + char **order) +{ + struct GNUNET_TIME_Absolute refund_deadline_round = refund_deadline; + char rd_str[64]; + + struct GNUNET_TIME_Absolute pay_deadline_round = pay_deadline; + char pd_str[64]; + + GNUNET_TIME_round_abs (&refund_deadline_round); + GNUNET_TIME_round_abs (&pay_deadline_round); + + GNUNET_snprintf (rd_str, + 64, + "{\"t_ms\":%llu}", + refund_deadline_round.abs_value_us / 1000LL); + if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == pay_deadline.abs_value_us) + { + GNUNET_snprintf (pd_str, + 64, + "{\"t_ms\":\"never\"}"); + } + else + { + GNUNET_snprintf (pd_str, + 64, + "{\"t_ms\":%llu}", + pay_deadline_round.abs_value_us / 1000LL); + } + GNUNET_asprintf (order, + "{\"max_fee\":\"EUR:0.5\",\ + \"order_id\":\"%s\",\ + \"refund_deadline\":%s,\ + \"pay_deadline\":%s,\ + \"amount\":\"%s\",\ + \"summary\":\"merchant-lib testcase\",\ + \"fulfillment_url\":\"https://example.com/\"}", + order_id, + rd_str, + pd_str, + amount); +} + + +/** + * Make the "proposal" command. * * @param label command label * @param merchant_url base URL of the merchant serving - * the orders request. + * the proposal request. * @param http_status expected HTTP status. - * @param order the order to PUT to the merchant. - * + * @param order_id the name of the order to add. + * @param refund_deadline the deadline for refunds on this order. + * @param pay_deadline the deadline for payment on this order. + * @param amount the amount this order is for. * @return the command */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_post_orders (const char *label, const char *merchant_url, unsigned int http_status, - const char *order) + const char *order_id, + struct GNUNET_TIME_Absolute + refund_deadline, + struct GNUNET_TIME_Absolute + pay_deadline, + const char *amount) { struct OrdersState *ps; ps = GNUNET_new (struct OrdersState); - ps->order = order; + make_order_json (order_id, + refund_deadline, + pay_deadline, + amount, + &ps->order); ps->http_status = http_status; ps->merchant_url = merchant_url; { @@ -554,7 +623,10 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label, * @param merchant_url base URL of the merchant serving * the proposal request. * @param http_status expected HTTP status. - * @param order the order to PUT to the merchant. + * @param order_id the name of the order to add. + * @param refund_deadline the deadline for refunds on this order. + * @param pay_deadline the deadline for payment on this order. + * @param amount the amount this order is for. * @param payment_target payment target for the order. * @param products a string indicating the products this order will be * purchasing. Should be formatted as @@ -567,7 +639,12 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_post_orders2 (const char *label, const char *merchant_url, unsigned int http_status, - const char *order, + const char *order_id, + struct GNUNET_TIME_Absolute + refund_deadline, + struct GNUNET_TIME_Absolute + pay_deadline, + const char *amount, const char *payment_target, const char *products, const char *locks) @@ -575,7 +652,11 @@ TALER_TESTING_cmd_merchant_post_orders2 (const char *label, struct OrdersState *ps; ps = GNUNET_new (struct OrdersState); - ps->order = order; + make_order_json (order_id, + refund_deadline, + pay_deadline, + amount, + &ps->order); ps->http_status = http_status; ps->merchant_url = merchant_url; ps->payment_target = payment_target; |