diff options
Diffstat (limited to 'src/testing/testing_api_cmd_wallet_get_order.c')
-rw-r--r-- | src/testing/testing_api_cmd_wallet_get_order.c | 174 |
1 files changed, 117 insertions, 57 deletions
diff --git a/src/testing/testing_api_cmd_wallet_get_order.c b/src/testing/testing_api_cmd_wallet_get_order.c index ac448499..d55ff0a7 100644 --- a/src/testing/testing_api_cmd_wallet_get_order.c +++ b/src/testing/testing_api_cmd_wallet_get_order.c @@ -59,6 +59,18 @@ struct WalletGetOrderState const char *order_reference; /** + * Reference to a command that created a paid + * equivalent order that we expect to be referred + * to during repurchase detection, or NULL. + */ + const char *repurchase_order_ref; + + /** + * Session Id the order needs to be bound to. + */ + const char *session_id; + + /** * Whether the order was paid or not. */ bool paid; @@ -103,14 +115,14 @@ wallet_get_order_cb ( switch (hr->http_status) { case MHD_HTTP_OK: - if (gos->refunded != owgr->details.success.refunded) + if (gos->refunded != owgr->details.ok.refunded) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Order refunded does not match\n"); TALER_TESTING_interpreter_fail (gos->is); return; } - if (gos->refund_pending != owgr->details.success.refund_pending) + if (gos->refund_pending != owgr->details.ok.refund_pending) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Order refund pending does not match\n"); @@ -122,9 +134,34 @@ wallet_get_order_cb ( { struct TALER_MERCHANT_PayUriData pud; const struct TALER_TESTING_Command *order_cmd; - const char **order_id; + const char *order_id; const struct TALER_ClaimTokenP *claim_token; + if (NULL != gos->repurchase_order_ref) + { + const struct TALER_TESTING_Command *rep_cmd; + const char *rep_id; + const char *ri; + + rep_cmd = TALER_TESTING_interpreter_lookup_command ( + gos->is, + gos->repurchase_order_ref); + if (GNUNET_OK != + TALER_TESTING_get_trait_order_id (rep_cmd, + &rep_id)) + { + TALER_TESTING_FAIL (gos->is); + } + ri = owgr->details.payment_required.already_paid_order_id; + if ( (NULL == ri) || + (0 != + strcmp (ri, + rep_id)) ) + { + TALER_TESTING_FAIL (gos->is); + } + } + if (GNUNET_OK != TALER_MERCHANT_parse_pay_uri ( owgr->details.payment_required.taler_pay_uri, @@ -158,29 +195,13 @@ wallet_get_order_cb ( } { - char *port; char *host; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (gos->is->cfg, - "merchant", - "PORT", - &port)) - { - /* How did we get here without a configured port? */ - GNUNET_break (0); - TALER_TESTING_interpreter_fail (gos->is); - TALER_MERCHANT_parse_pay_uri_free (&pud); - return; - } - GNUNET_asprintf (&host, - "localhost:%s", - port); - GNUNET_free (port); + host = TALER_MERCHANT_TESTING_extract_host (gos->merchant_url); if ((0 != strcmp (host, pud.merchant_host)) || (NULL != pud.merchant_prefix_path) || - (0 != strcmp (*order_id, + (0 != strcmp (order_id, pud.order_id)) || (NULL != pud.ssid)) { @@ -235,7 +256,7 @@ wallet_get_order_run (void *cls, { struct WalletGetOrderState *gos = cls; const struct TALER_TESTING_Command *order_cmd; - const char **order_id; + const char *order_id; const struct TALER_PrivateContractHashP *h_contract; order_cmd = TALER_TESTING_interpreter_lookup_command ( @@ -253,16 +274,17 @@ wallet_get_order_run (void *cls, TALER_TESTING_FAIL (is); gos->is = is; - gos->ogh = TALER_MERCHANT_wallet_order_get (is->ctx, - gos->merchant_url, - *order_id, - h_contract, - GNUNET_TIME_UNIT_ZERO, - NULL, - NULL, - false, - &wallet_get_order_cb, - gos); + gos->ogh = TALER_MERCHANT_wallet_order_get ( + TALER_TESTING_interpreter_get_context (is), + gos->merchant_url, + order_id, + h_contract, + GNUNET_TIME_UNIT_ZERO, + gos->session_id, + NULL, + false, + &wallet_get_order_cb, + gos); } @@ -281,7 +303,7 @@ wallet_get_order_cleanup (void *cls, if (NULL != gos->ogh) { - TALER_LOG_WARNING ("Get tip operation did not complete\n"); + TALER_LOG_WARNING ("Get order operation did not complete\n"); TALER_MERCHANT_wallet_order_get_cancel (gos->ogh); } GNUNET_free (gos); @@ -289,13 +311,48 @@ wallet_get_order_cleanup (void *cls, struct TALER_TESTING_Command -TALER_TESTING_cmd_wallet_get_order (const char *label, - const char *merchant_url, - const char *order_reference, - bool paid, - bool refunded, - bool refund_pending, - unsigned int http_status) +TALER_TESTING_cmd_wallet_get_order ( + const char *label, + const char *merchant_url, + const char *order_reference, + bool paid, + bool refunded, + bool refund_pending, + unsigned int http_status) +{ + struct WalletGetOrderState *gos; + + gos = GNUNET_new (struct WalletGetOrderState); + gos->merchant_url = merchant_url; + gos->order_reference = order_reference; + gos->http_status = http_status; + gos->paid = paid; + gos->refunded = refunded; + gos->refund_pending = refund_pending; + { + struct TALER_TESTING_Command cmd = { + .cls = gos, + .label = label, + .run = &wallet_get_order_run, + .cleanup = &wallet_get_order_cleanup + }; + + return cmd; + } +} + + +struct TALER_TESTING_Command +TALER_TESTING_cmd_wallet_get_order2 ( + const char *label, + const char *merchant_url, + const char *order_reference, + const char *session_id, + bool paid, + bool refunded, + bool refund_pending, + const char *repurchase_order_ref, + unsigned int http_status) { struct WalletGetOrderState *gos; @@ -304,8 +361,10 @@ TALER_TESTING_cmd_wallet_get_order (const char *label, gos->order_reference = order_reference; gos->http_status = http_status; gos->paid = paid; + gos->session_id = session_id; gos->refunded = refunded; gos->refund_pending = refund_pending; + gos->repurchase_order_ref = repurchase_order_ref; { struct TALER_TESTING_Command cmd = { .cls = gos, @@ -554,10 +613,10 @@ wallet_poll_order_cb ( { case MHD_HTTP_OK: pos->paid = true; - pos->refunded = owgr->details.success.refunded; - pos->refund_pending = owgr->details.success.refund_pending; - if (owgr->details.success.refunded) - pos->refund_available = owgr->details.success.refund_amount; + pos->refunded = owgr->details.ok.refunded; + pos->refund_pending = owgr->details.ok.refund_pending; + if (owgr->details.ok.refunded) + pos->refund_available = owgr->details.ok.refund_amount; break; case MHD_HTTP_PAYMENT_REQUIRED: if (NULL != owgr->details.payment_required.already_paid_order_id) @@ -593,7 +652,7 @@ wallet_poll_order_start_run (void *cls, { struct WalletPollOrderStartState *pos = cls; const struct TALER_TESTING_Command *order_cmd; - const char **order_id; + const char *order_id; const struct TALER_PrivateContractHashP *h_contract; order_cmd = TALER_TESTING_interpreter_lookup_command ( @@ -615,18 +674,19 @@ wallet_poll_order_start_run (void *cls, = GNUNET_TIME_absolute_add (GNUNET_TIME_relative_to_absolute (pos->timeout), GNUNET_TIME_UNIT_SECONDS); pos->is = is; - pos->ogh = TALER_MERCHANT_wallet_order_get (is->ctx, - pos->merchant_url, - *order_id, - h_contract, - pos->timeout, - pos->session_id, - pos->wait_for_refund - ? &pos->refund_threshold - : NULL, - false, /* await_refund_obtained */ - &wallet_poll_order_cb, - pos); + pos->ogh = TALER_MERCHANT_wallet_order_get ( + TALER_TESTING_interpreter_get_context (is), + pos->merchant_url, + order_id, + h_contract, + pos->timeout, + pos->session_id, + pos->wait_for_refund + ? &pos->refund_threshold + : NULL, + false, /* await_refund_obtained */ + &wallet_poll_order_cb, + pos); GNUNET_assert (NULL != pos->ogh); /* We CONTINUE to run the interpreter while the long-polled command completes asynchronously! */ |