diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/taler_merchant_service.h | 182 | ||||
-rw-r--r-- | src/include/taler_merchant_testing_lib.h | 69 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 95 |
3 files changed, 332 insertions, 14 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index 263a6fec..537a2485 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -34,7 +34,7 @@ /** * Library version (in hex) for compatibility tests. */ -#define TALER_MERCHANT_SERVICE_VERSION 0x00090403 +#define TALER_MERCHANT_SERVICE_VERSION 0x00100000 /** @@ -949,7 +949,7 @@ TALER_MERCHANT_instance_delete_cancel ( * @param arg request to cancel. */ #define TALER_MERCHANT_instance_purge_cancel(arg) \ - TALER_MERCHANT_instance_delete_cancel (arg) + TALER_MERCHANT_instance_delete_cancel (arg) /* *************** Accounts **************** */ @@ -1516,12 +1516,12 @@ struct TALER_MERCHANT_ProductGetResponse struct TALER_Amount price; /** - * base64-encoded product image + * base64-encoded product image, can be NULL if none is set. */ const char *image; /** - * list of taxes paid by the merchant + * list of taxes paid by the merchant, can be NULL if no taxes were specified. */ const json_t *taxes; @@ -1544,7 +1544,7 @@ struct TALER_MERCHANT_ProductGetResponse uint64_t total_lost; /** - * where the product is in stock + * where the product is in stock, can be NULL if no location was given. */ const json_t *location; @@ -1895,6 +1895,172 @@ TALER_MERCHANT_product_delete_cancel ( struct TALER_MERCHANT_ProductDeleteHandle *pdh); +/* ********************* /tokenfamilies ************************** */ + +/** + * Handle for a GET /tokenfamilies/$SLUG operation. + */ +struct TALER_MERCHANT_TokenFamilyGetHandle; + + +/** + * Response to GET /tokenfamilies/$SLUG operation. + */ +struct TALER_MERCHANT_TokenFamilyGetResponse +{ + /** + * HTTP response details + */ + struct TALER_MERCHANT_HttpResponse hr; + + /** + * Details depending on HTTP status. + */ + union + { + /** + * Details for #MHD_HTTP_OK. + */ + struct + { + + /** + * Identifier for the token family consisting of unreserved characters + * according to RFC 3986. + */ + const char *slug; + + /** + * Human-readable name for the token family. + */ + const char *name; + + /** + * description of the token family + */ + const char *description; + + /** + * Optional map from IETF BCP 47 language tags to localized descriptions. + */ + const json_t *description_i18n; + + /** + * Start time of the token family's validity period. + */ + struct GNUNET_TIME_Timestamp valid_after; + + /** + * End time of the token family's validity period. + */ + struct GNUNET_TIME_Timestamp valid_before; + + /** + * Validity duration of an issued token. + */ + struct GNUNET_TIME_Relative duration; + + /** + * Kind of token family, "subscription" or "discount". + */ + const char *kind; + + /** + * How many tokens have been issued for this family. + */ + uint64_t issued; + + /** + * How many tokens have been redeemed for this family. + */ + uint64_t redeemed; + } ok; + + } details; + +}; + +/** + * Cancel GET /tokenfamilies/$SLUG operation. + * + * @param handle operation to cancel + */ +void +TALER_MERCHANT_token_family_get_cancel ( + struct TALER_MERCHANT_TokenFamilyGetHandle *handle); + + +/** + * Function called with the result of the GET /tokenfamilies/$SLUG operation. + * + * @param cls closure + * @param pgr response details + */ +typedef void +(*TALER_MERCHANT_TokenFamilyGetCallback)( + void *cls, + const struct TALER_MERCHANT_TokenFamilyGetResponse *pgr); + +/** + * Handle for a POST /tokenfamilies operation. + */ +struct TALER_MERCHANT_TokenFamiliesPostHandle; + + +/** + * Function called with the result of the POST /tokenfamilies operation. + * + * @param cls closure + * @param hr HTTP response details + */ +typedef void +(*TALER_MERCHANT_TokenFamiliesPostCallback)( + void *cls, + const struct TALER_MERCHANT_HttpResponse *hr); + + +/** + * Make a POST /tokenfamilies request to add a token family to the + * merchant instance. + * + * @param ctx the context + * @param backend_url HTTP base URL for the backend + * @param slug short, url-safe identifier for the token family + * @param name human-readable name for the token family + * @param description description of the token family + * @param description_i18n Map from IETF BCP 47 language tags to localized descriptions + * @param valid_after when the token family becomes valid + * @param valid_before when the token family expires + * @param duration how long tokens issued by this token family are valid for + * @param kind kind of token family, "subscription" or "discount" + * @param cb function to call with the backend's result + * @param cb_cls closure for @a cb + * @return the request handle; NULL upon error + */ +struct TALER_MERCHANT_TokenFamiliesPostHandle * +TALER_MERCHANT_token_families_post ( + struct GNUNET_CURL_Context *ctx, + const char *backend_url, + const char *slug, + const char *name, + const char *description, + const json_t *description_i18n, + struct GNUNET_TIME_Timestamp valid_after, + struct GNUNET_TIME_Timestamp valid_before, + struct GNUNET_TIME_Relative duration, + const char *kind, + TALER_MERCHANT_TokenFamiliesPostCallback cb, + void *cb_cls); + +/** + * Cancel POST /tokenfamilies operation. + * + * @param handle operation to cancel + */ +void +TALER_MERCHANT_token_families_post_cancel ( + struct TALER_MERCHANT_TokenFamiliesPostHandle *handle); + /* ********************* /orders ************************** */ @@ -2664,6 +2830,12 @@ struct TALER_MERCHANT_OrderStatusResponse */ bool wired; + /** + * Time of the last payment made on this order. + * Only available if the server supports protocol + * **v14** or higher, otherwise zero. + */ + struct GNUNET_TIME_Timestamp last_payment; } paid; /** diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index b1de5292..47d081fc 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -27,6 +27,7 @@ #ifndef TALER_MERCHANT_TESTING_LIB_H #define TALER_MERCHANT_TESTING_LIB_H +#include <gnunet/gnunet_time_lib.h> #include <taler/taler_testing_lib.h> #include "taler_merchant_service.h" @@ -605,6 +606,35 @@ TALER_TESTING_cmd_merchant_post_orders3 ( /** + * Create an order with a choices array with input and output tokens. + * + * @param label command label + * @param cfg configuration to use + * @param merchant_url base URL of the merchant serving + * the proposal request. + * @param http_status expected HTTP status. + * @param token_family_reference label of the POST /tokenfamilies cmd. + * @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_choices ( + const char *label, + const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *merchant_url, + unsigned int http_status, + const char *token_family_reference, + const char *order_id, + struct GNUNET_TIME_Timestamp refund_deadline, + struct GNUNET_TIME_Timestamp pay_deadline, + const char *amount); + + +/** * Define a "GET /orders" CMD. * * @param label command label. @@ -1473,6 +1503,40 @@ TALER_TESTING_cmd_merchant_post_using_templates ( unsigned int http_status); +/* ****** Token Families ******* */ + + +/** + * Define a "POST /tokenfamilies" CMD. + * + * @param label command label. + * @param merchant_url base URL of the merchant serving the + * POST /tokenfamilies request. + * @param http_status expected HTTP response code. + * @param slug slug of the token family. + * @param name name of the token family. + * @param description description of the token family. + * @param description_i18n internationalized description of the token family. + * @param valid_after start of the validity time of the token family. + * @param valid_before end of the validity time of the token family. + * @param duration validity duration of an issued token of the token family. + * @param kind kind of the token family. either "subscription" or "discount". + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_post_tokenfamilies ( + const char *label, + const char *merchant_url, + unsigned int http_status, + const char *slug, + const char *name, + const char *description, + json_t *description_i18n, + struct GNUNET_TIME_Timestamp valid_after, + struct GNUNET_TIME_Timestamp valid_before, + struct GNUNET_TIME_Relative duration, + const char *kind); + /* ****** Webhooks ******* */ @@ -1737,7 +1801,10 @@ TALER_TESTING_cmd_checkserver2 (const char *label, op (http_method, const char) \ op (header_template, const char) \ op (body_template, const char) \ - op (summary, const char) + op (summary, const char) \ + op (token_family_slug, const char) \ + op (token_family_duration, const struct GNUNET_TIME_Relative) \ + op (token_family_kind, const char) /** diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index e7eb2d0f..12b13e33 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -23,6 +23,8 @@ #ifndef TALER_MERCHANTDB_PLUGIN_H #define TALER_MERCHANTDB_PLUGIN_H +#include <gnunet/gnunet_common.h> +#include <gnunet/gnunet_time_lib.h> #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_db_lib.h> #include <taler/taler_exchange_service.h> @@ -333,6 +335,22 @@ struct TALER_MERCHANTDB_ProductDetails /** + * Typically called by `lookup_all_products`. + * + * @param cls a `json_t *` JSON array to build + * @param product_serial row ID of the product + * @param product_id ID of the product + * @param pd full product details + */ +typedef void +(*TALER_MERCHANTDB_ProductCallback)( + void *cls, + uint64_t product_serial, + const char *product_id, + const struct TALER_MERCHANTDB_ProductDetails *pd); + + +/** * Typically called by `lookup_templates`. * * @param cls closure @@ -932,9 +950,10 @@ typedef void * @param cls closure * @param deposit_serial which deposit operation is this about * @param exchange_url URL of the exchange that issued the coin + * @param h_wire hash of merchant's wire details + * @param deposit_timestamp when was the deposit made * @param amount_with_fee amount the exchange will deposit for this coin * @param deposit_fee fee the exchange will charge for this coin - * @param h_wire hash of merchant's wire details * @param coin_pub public key of the coin */ typedef void @@ -943,6 +962,7 @@ typedef void uint64_t deposit_serial, const char *exchange_url, const struct TALER_MerchantWireHashP *h_wire, + struct GNUNET_TIME_Timestamp deposit_timestamp, const struct TALER_Amount *amount_with_fee, const struct TALER_Amount *deposit_fee, const struct TALER_CoinSpendPublicKeyP *coin_pub); @@ -1092,17 +1112,17 @@ struct TALER_MERCHANTDB_TokenFamilyKeyDetails /** * Token family public key. */ - struct TALER_TokenFamilyPublicKey pub; + struct TALER_TokenFamilyPublicKey *pub; /** - * Hash of the token family public key. + * Token family private key. */ - struct TALER_TokenFamilyPublicKeyHash pub_h; + struct TALER_TokenFamilyPrivateKey *priv; /** - * Token family private key. - */ - struct TALER_TokenFamilyPrivateKey priv; + * Details about the token family this key belongs to. + */ + struct TALER_MERCHANTDB_TokenFamilyDetails token_family; }; /** @@ -1615,6 +1635,22 @@ struct TALER_MERCHANTDB_Plugin TALER_MERCHANTDB_ProductsCallback cb, void *cb_cls); + + /** + * Lookup full details of all of the products the given instance has configured (expensive). + * + * @param cls closure + * @param instance_id instance to lookup products for + * @param cb function to call on all products found + * @param cb_cls closure for @a cb + * @return database result code + */ + enum GNUNET_DB_QueryStatus + (*lookup_all_products)(void *cls, + const char *instance_id, + TALER_MERCHANTDB_ProductCallback cb, + void *cb_cls); + /** * Lookup details about a particular product. * @@ -3238,7 +3274,7 @@ struct TALER_MERCHANTDB_Plugin * Insert details about a particular token family. * * @param cls closure - * @param instance_id instance to insert product for + * @param instance_id instance to insert token family for * @param token_family_slug slug of token family to insert * @param details the token family details to insert * @return database result code @@ -3250,6 +3286,49 @@ struct TALER_MERCHANTDB_Plugin const char *token_family_slug, const struct TALER_MERCHANTDB_TokenFamilyDetails *details); + + /** + * Lookup details about a particular token family key. + * + * @param cls closure + * @param instance_id instance to lookup token family key for + * @param token_family_slug slug of token family to lookup + * @param min_valid_after lower bound of the start of the key validation period + * @param max_valid_after upper bound of the start of the key validation period + * @param[out] details set to the token family key details on success, can be NULL + * (in that case we only want to check if the token family key exists) + * @return database result code + */ + enum GNUNET_DB_QueryStatus + (*lookup_token_family_key) ( + void *cls, + const char *instance_id, + const char *token_family_slug, + struct GNUNET_TIME_Timestamp min_valid_after, + struct GNUNET_TIME_Timestamp max_valid_after, + struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details); + + + /** + * Insert details a key pair for a token family. + * + * @param cls closure + * @param token_family_slug slug of token family to insert the key pair for + * @param pub token family public key + * @param priv token family private key + * @param valid_after start of the key validation period + * @param valid_before end of the key validation period + * @return database result code + */ + enum GNUNET_DB_QueryStatus + (*insert_token_family_key)( + void *cls, + const char *token_family_slug, + const struct TALER_TokenFamilyPublicKey *pub, + const struct TALER_TokenFamilyPrivateKey *priv, + struct GNUNET_TIME_Timestamp valid_after, + struct GNUNET_TIME_Timestamp valid_before); + /** * Lookup deposits that are finished and awaiting a wire transfer. * |