summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-09 21:17:55 +0200
committerChristian Grothoff <christian@grothoff.org>2016-06-09 21:17:55 +0200
commit7046337c78d9bcebe3c0c8a9ce7e7131df707962 (patch)
tree0375d8a9e1b1b8794b3908672a85f7c001eaeb49
parent1fe7e885c9f3ac200c8dc6c1badbe09e7235a980 (diff)
downloadmerchant-7046337c78d9bcebe3c0c8a9ce7e7131df707962.tar.gz
merchant-7046337c78d9bcebe3c0c8a9ce7e7131df707962.tar.bz2
merchant-7046337c78d9bcebe3c0c8a9ce7e7131df707962.zip
add skeleton for calling /track/transaction to testcase
-rw-r--r--src/include/taler_merchant_service.h43
-rw-r--r--src/lib/merchant_api_track_transaction.c8
-rw-r--r--src/lib/merchant_api_track_transfer.c9
-rw-r--r--src/lib/test_merchant_api.c142
4 files changed, 170 insertions, 32 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index 48274db1..7aa91125 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -300,17 +300,33 @@ TALER_MERCHANT_pay_cancel (struct TALER_MERCHANT_Pay *ph);
/* ********************* /track/transfer *********************** */
/**
- * @brief Handle to a /contract operation at a merchant's backend.
+ * @brief Handle to a /track/transfer operation at a merchant's backend.
*/
struct TALER_MERCHANT_TrackTransferHandle;
/**
* Callbacks of this type are used to work the result of submitting a /track/transfer request to a merchant
+ *
+ * @param cls closure
+ * @param http_status HTTP status code we got, 0 on exchange protocol violation
+ * @param sign_key exchange key used to sign @a json, or NULL
+ * @param json original json reply (may include signatures, those have then been
+ * validated already)
+ * @param h_wire hash of the wire transfer address the transfer went to, or NULL on error
+ * @param total_amount total amount of the wire transfer, or NULL if the exchange could
+ * not provide any @a wtid (set only if @a http_status is #MHD_HTTP_OK)
+ * @param details_length length of the @a details array
+ * @param details array with details about the combined transactions
*/
typedef void
(*TALER_MERCHANT_TrackTransferCallback) (void *cls,
- unsigned int http_status,
- const json_t *obj);
+ unsigned int http_status,
+ const struct TALER_ExchangePublicKeyP *sign_key,
+ const json_t *json,
+ const struct GNUNET_HashCode *h_wire,
+ const struct TALER_Amount *total_amount,
+ unsigned int details_length,
+ const struct TALER_TrackTransferDetails *details);
/**
* Request backend to return deposits associated with a given wtid.
@@ -345,17 +361,32 @@ TALER_MERCHANT_track_transfer_cancel (struct TALER_MERCHANT_TrackTransferHandle
/* ********************* /track/transaction *********************** */
/**
- * @brief Handle to a /contract operation at a merchant's backend.
+ * @brief Handle to a /track/transaction operation at a merchant's backend.
*/
struct TALER_MERCHANT_TrackTransactionHandle;
/**
* Callbacks of this type are used to work the result of submitting a /track/transaction request to a merchant
- */
+ *
+ * @param cls closure
+ * @param http_status HTTP status code we got, 0 on exchange protocol violation
+ * @param sign_key exchange key used to sign @a json, or NULL
+ * @param json original json reply (may include signatures, those have then been
+ * validated already)
+ * @param wtid wire transfer identifier used by the exchange, NULL if exchange did not
+ * yet execute the transaction
+ * @param execution_time actual or planned execution time for the wire transfer
+ * @param coin_contribution contribution to the @a total_amount of the deposited coin (may be NULL)
+*/
typedef void
(*TALER_MERCHANT_TrackTransactionCallback) (void *cls,
unsigned int http_status,
- const json_t *obj);
+ const struct TALER_ExchangePublicKeyP *sign_key,
+ const json_t *json,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ struct GNUNET_TIME_Absolute execution_time,
+ const struct TALER_Amount *coin_contribution);
+
/**
* Request backend to return deposits associated with a given wtid.
diff --git a/src/lib/merchant_api_track_transaction.c b/src/lib/merchant_api_track_transaction.c
index dcb7e531..84f6f32e 100644
--- a/src/lib/merchant_api_track_transaction.c
+++ b/src/lib/merchant_api_track_transaction.c
@@ -118,10 +118,14 @@ handle_tracktransaction_finished (void *cls,
response_code = 0;
break;
}
- /* FIXME: figure out which parameters ought to be passed back */
+ /* FIXME: pass proper results back! */
tdo->cb (tdo->cb_cls,
response_code,
- json);
+ NULL,
+ json,
+ NULL,
+ GNUNET_TIME_UNIT_ZERO_ABS,
+ NULL);
}
diff --git a/src/lib/merchant_api_track_transfer.c b/src/lib/merchant_api_track_transfer.c
index 111934d6..9dfaf2f7 100644
--- a/src/lib/merchant_api_track_transfer.c
+++ b/src/lib/merchant_api_track_transfer.c
@@ -118,10 +118,15 @@ handle_track_transfer_finished (void *cls,
response_code = 0;
break;
}
- /* FIXME: figure out which parameters ought to be passed back */
+ /* FIXME: pass proper results back! */
tdo->cb (tdo->cb_cls,
response_code,
- json);
+ NULL,
+ json,
+ NULL,
+ NULL,
+ 0,
+ NULL);
}
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index cd4d147c..21c839ab 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -139,9 +139,14 @@ enum OpCode
OC_CHECK_BANK_TRANSFERS_EMPTY,
/**
- * Retrieve deposit permissions for a given wire transfer
+ * Retrieve deposit details for a given wire transfer
*/
- OC_TRACK_DEPOSIT
+ OC_TRACK_TRANSFER,
+
+ /**
+ * Retrieve wire transfer details for a given transaction
+ */
+ OC_TRACK_TRANSACTION
};
@@ -410,6 +415,11 @@ struct Command
*/
struct TALER_MERCHANT_Pay *ph;
+ /**
+ * Set to the transaction ID of the respective contract.
+ */
+ uint64_t transaction_id;
+
} pay;
struct {
@@ -461,9 +471,24 @@ struct Command
/**
* Handle to a /track/transfer operation
*/
- struct TALER_MERCHANT_TrackTransferHandle *tdo;
+ struct TALER_MERCHANT_TrackTransferHandle *tdo;
- } track_deposit;
+ } track_transfer;
+
+ struct {
+
+ /**
+ * #OC_PAY command from which we should grab
+ * the WTID.
+ */
+ char *pay_ref;
+
+ /**
+ * Handle to a /track/transaction operation
+ */
+ struct TALER_MERCHANT_TrackTransactionHandle *tth;
+
+ } track_transaction;
} details;
@@ -948,17 +973,29 @@ maint_child_death (void *cls)
*
* @param cls closure for this function
* @param http_status HTTP response code returned by the server
- * @param obj server response's body
+ * @param sign_key exchange key used to sign @a json, or NULL
+ * @param json original json reply (may include signatures, those have then been
+ * validated already)
+ * @param h_wire hash of the wire transfer address the transfer went to, or NULL on error
+ * @param total_amount total amount of the wire transfer, or NULL if the exchange could
+ * not provide any @a wtid (set only if @a http_status is #MHD_HTTP_OK)
+ * @param details_length length of the @a details array
+ * @param details array with details about the combined transactions
*/
static void
-track_deposit_cb (void *cls,
- unsigned int http_status,
- const json_t *obj)
+track_transfer_cb (void *cls,
+ unsigned int http_status,
+ const struct TALER_ExchangePublicKeyP *sign_key,
+ const json_t *json,
+ const struct GNUNET_HashCode *h_wire,
+ const struct TALER_Amount *total_amount,
+ unsigned int details_length,
+ const struct TALER_TrackTransferDetails *details)
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
- cmd->details.track_deposit.tdo = NULL;
+ cmd->details.track_transfer.tdo = NULL;
/* FIXME: properly test result vs. expecations... */
if (MHD_HTTP_OK == http_status)
{
@@ -977,6 +1014,49 @@ track_deposit_cb (void *cls,
/**
+ * Function called with detailed wire transfer data.
+ *
+ * @param cls closure
+ * @param http_status HTTP status code we got, 0 on exchange protocol violation
+ * @param sign_key exchange key used to sign @a json, or NULL
+ * @param json original json reply (may include signatures, those have then been
+ * validated already)
+ * @param wtid wire transfer identifier used by the exchange, NULL if exchange did not
+ * yet execute the transaction
+ * @param execution_time actual or planned execution time for the wire transfer
+ * @param coin_contribution contribution to the @a total_amount of the deposited coin (may be NULL)
+ */
+static void
+track_transaction_cb (void *cls,
+ unsigned int http_status,
+ const struct TALER_ExchangePublicKeyP *sign_key,
+ const json_t *json,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ struct GNUNET_TIME_Absolute execution_time,
+ const struct TALER_Amount *coin_contribution)
+{
+ struct InterpreterState *is = cls;
+ struct Command *cmd = &is->commands[is->ip];
+
+ cmd->details.track_transaction.tth = NULL;
+ /* FIXME: properly test result vs. expecations... */
+ if (MHD_HTTP_OK == http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Ok from /track/transaction handler\n");
+ result = GNUNET_OK;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Not Ok from /track/transaction handler\n");
+ result = GNUNET_SYSERR;
+ }
+ next_command (is);
+}
+
+
+/**
* Find denomination key matching the given amount.
*
* @param keys array of keys to search
@@ -1305,7 +1385,8 @@ interpreter_run (void *cls)
fail (is);
return;
}
- }
+ cmd->details.pay.transaction_id = transaction_id;
+ }
TALER_JSON_hash (ref->details.contract.contract,
&h_contract);
@@ -1443,18 +1524,30 @@ interpreter_run (void *cls)
next_command (is);
return;
}
- case OC_TRACK_DEPOSIT:
+ case OC_TRACK_TRANSFER:
ref = find_command (is,
- cmd->details.track_deposit.check_bank_ref);
+ cmd->details.track_transfer.check_bank_ref);
GNUNET_assert (NULL != ref);
- cmd->details.track_deposit.tdo =
+ cmd->details.track_transfer.tdo =
TALER_MERCHANT_track_transfer (ctx,
MERCHANT_URI,
&ref->details.check_bank_transfer.wtid,
EXCHANGE_URI,
- &track_deposit_cb,
+ &track_transfer_cb,
is);
return;
+ case OC_TRACK_TRANSACTION:
+ ref = find_command (is,
+ cmd->details.track_transaction.pay_ref);
+ GNUNET_assert (NULL != ref);
+ cmd->details.track_transaction.tth =
+ TALER_MERCHANT_track_transaction (ctx,
+ MERCHANT_URI,
+ ref->details.pay.transaction_id,
+ EXCHANGE_URI,
+ &track_transaction_cb,
+ is);
+ return;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unknown instruction %d at %u (%s)\n",
@@ -1592,13 +1685,18 @@ do_shutdown (void *cls)
break;
case OC_CHECK_BANK_TRANSFERS_EMPTY:
break;
- case OC_TRACK_DEPOSIT:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "shutting down /track/transfer\n");
- if (NULL != cmd->details.track_deposit.tdo)
+ case OC_TRACK_TRANSFER:
+ if (NULL != cmd->details.track_transfer.tdo)
+ {
+ TALER_MERCHANT_track_transfer_cancel (cmd->details.track_transfer.tdo);
+ cmd->details.track_transfer.tdo = NULL;
+ }
+ break;
+ case OC_TRACK_TRANSACTION:
+ if (NULL != cmd->details.track_transaction.tth)
{
- TALER_MERCHANT_track_transfer_cancel (cmd->details.track_deposit.tdo);
- cmd->details.track_deposit.tdo = NULL;
+ TALER_MERCHANT_track_transaction_cancel (cmd->details.track_transaction.tth);
+ cmd->details.track_transaction.tth = NULL;
}
break;
default:
@@ -1792,10 +1890,10 @@ run (void *cls)
.label = "check_bank_empty" },
/* Trace the WTID back to the original transaction */
- { .oc = OC_TRACK_DEPOSIT,
+ { .oc = OC_TRACK_TRANSFER,
.label = "track-deposit-1",
.expected_response_code = MHD_HTTP_OK,
- .details.track_deposit.check_bank_ref = "check_bank_transfer-499c"
+ .details.track_transfer.check_bank_ref = "check_bank_transfer-499c"
/* FIXME: more needed here for actual checking... */
},