summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_pay_order.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_pay_order.c')
-rw-r--r--src/testing/testing_api_cmd_pay_order.c101
1 files changed, 88 insertions, 13 deletions
diff --git a/src/testing/testing_api_cmd_pay_order.c b/src/testing/testing_api_cmd_pay_order.c
index cd589965..0b84c8a6 100644
--- a/src/testing/testing_api_cmd_pay_order.c
+++ b/src/testing/testing_api_cmd_pay_order.c
@@ -68,6 +68,11 @@ struct PayState
const char *merchant_url;
/**
+ * Total amount to be paid.
+ */
+ struct TALER_Amount total_amount;
+
+ /**
* Amount to be paid, plus the deposit fee.
*/
const char *amount_with_fee;
@@ -91,6 +96,17 @@ struct PayState
* The session for which the payment is made.
*/
const char *session_id;
+
+ /**
+ * base64-encoded key
+ */
+ const char *pos_key;
+
+ /**
+ * Option that add amount of the order
+ */
+ enum TALER_MerchantConfirmationAlgorithm pos_alg;
+
};
@@ -117,6 +133,14 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc,
const char *amount_without_fee)
{
char *token;
+ struct TALER_EXCHANGE_Keys *keys;
+
+ keys = TALER_TESTING_get_keys (is);
+ if (NULL == keys)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
for (token = strtok (coins, ";");
NULL != token;
@@ -127,7 +151,7 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc,
unsigned int ci;
struct TALER_MERCHANT_PayCoin *icoin;
const struct TALER_EXCHANGE_DenomPublicKey *dpk;
- const char **exchange_url;
+ const char *exchange_url;
/* Token syntax is "LABEL[/NUMBER]" */
ctok = strchr (token, '/');
@@ -194,7 +218,7 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc,
icoin->h_age_commitment = h_age_commitment;
}
GNUNET_assert (NULL != (dpk =
- TALER_TESTING_find_pk (is->keys,
+ TALER_TESTING_find_pk (keys,
&icoin->denom_value,
false)));
@@ -205,7 +229,7 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc,
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_exchange_url (coin_cmd,
&exchange_url));
- icoin->exchange_url = *exchange_url;
+ icoin->exchange_url = exchange_url;
}
return GNUNET_OK;
@@ -238,7 +262,43 @@ pay_cb (void *cls,
}
if (MHD_HTTP_OK == pr->hr.http_status)
{
- ps->merchant_sig = pr->details.success.merchant_sig;
+ ps->merchant_sig = pr->details.ok.merchant_sig;
+ if (NULL != ps->pos_key)
+ {
+ char *pc;
+ bool found = false;
+
+ if (NULL == pr->details.ok.pos_confirmation)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ps->is);
+ return;
+ }
+ pc = TALER_build_pos_confirmation (ps->pos_key,
+ ps->pos_alg,
+ &ps->total_amount,
+ GNUNET_TIME_timestamp_get ());
+ /* Check if *any* of our TOTP codes overlaps
+ with any of the returned TOTP codes. */
+ for (const char *tok = strtok (pc, "\n");
+ NULL != tok;
+ tok = strtok (NULL, "\n"))
+ {
+ if (NULL != strstr (pr->details.ok.pos_confirmation,
+ tok))
+ {
+ found = true;
+ break;
+ }
+ }
+ GNUNET_free (pc);
+ if (! found)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ps->is);
+ return;
+ }
+ }
}
TALER_TESTING_interpreter_next (ps->is);
}
@@ -266,13 +326,13 @@ pay_run (void *cls,
struct TALER_MerchantPublicKeyP merchant_pub;
struct TALER_MerchantWireHashP h_wire;
const struct TALER_PrivateContractHashP *h_proposal;
- struct TALER_Amount total_amount;
struct TALER_Amount max_fee;
- const char *error_name;
- unsigned int error_line;
+ const char *error_name = NULL;
+ unsigned int error_line = 0;
struct TALER_MERCHANT_PayCoin *pay_coins;
unsigned int npay_coins;
const struct TALER_MerchantSignatureP *merchant_sig;
+ const enum TALER_MerchantConfirmationAlgorithm *alg_ptr;
ps->is = is;
proposal_cmd = TALER_TESTING_interpreter_lookup_command (
@@ -286,6 +346,17 @@ pay_run (void *cls,
TALER_TESTING_get_trait_contract_terms (proposal_cmd,
&contract_terms))
TALER_TESTING_FAIL (is);
+ if (NULL == contract_terms)
+ TALER_TESTING_FAIL (is);
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_otp_key (proposal_cmd,
+ &ps->pos_key))
+ ps->pos_key = NULL;
+ if ( (GNUNET_OK ==
+ TALER_TESTING_get_trait_otp_alg (proposal_cmd,
+ &alg_ptr)) &&
+ (NULL != alg_ptr) )
+ ps->pos_alg = *alg_ptr;
{
/* Get information that needs to be put verbatim in the
* deposit permission */
@@ -303,7 +374,7 @@ pay_run (void *cls,
GNUNET_JSON_spec_fixed_auto ("h_wire",
&h_wire),
TALER_JSON_spec_amount_any ("amount",
- &total_amount),
+ &ps->total_amount),
TALER_JSON_spec_amount_any ("max_fee",
&max_fee),
/* FIXME oec: parse minimum age, use data later? */
@@ -362,11 +433,13 @@ pay_run (void *cls,
&h_proposal))
TALER_TESTING_FAIL (is);
ps->h_contract_terms = *h_proposal;
- ps->oph = TALER_MERCHANT_order_pay (is->ctx,
+ ps->oph = TALER_MERCHANT_order_pay (TALER_TESTING_interpreter_get_context (
+ is),
ps->merchant_url,
ps->session_id,
h_proposal,
- &total_amount,
+ NULL,
+ &ps->total_amount,
&max_fee,
&merchant_pub,
merchant_sig,
@@ -429,7 +502,7 @@ pay_traits (void *cls,
{
struct PayState *ps = cls;
- const char **order_id;
+ const char *order_id;
const struct TALER_TESTING_Command *proposal_cmd;
const struct TALER_MerchantPublicKeyP *merchant_pub;
@@ -465,13 +538,15 @@ pay_traits (void *cls,
&amount_with_fee));
{
struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_proposal_reference (&ps->proposal_reference),
+ TALER_TESTING_make_trait_proposal_reference (ps->proposal_reference),
TALER_TESTING_make_trait_coin_reference (0,
- &ps->coin_reference),
+ ps->coin_reference),
TALER_TESTING_make_trait_order_id (order_id),
TALER_TESTING_make_trait_merchant_pub (merchant_pub),
TALER_TESTING_make_trait_merchant_sig (&ps->merchant_sig),
TALER_TESTING_make_trait_amount (&amount_with_fee),
+ TALER_TESTING_make_trait_otp_key (ps->pos_key),
+ TALER_TESTING_make_trait_otp_alg (&ps->pos_alg),
TALER_TESTING_trait_end ()
};