taler_merchantdb_plugin.h (190490B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Lesser General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file taler_merchantdb_plugin.h 18 * @brief database access for the merchant 19 * @author Florian Dold 20 * @author Christian Grothoff 21 * @author Priscilla Huang 22 */ 23 #ifndef TALER_MERCHANTDB_PLUGIN_H 24 #define TALER_MERCHANTDB_PLUGIN_H 25 26 #include <gnunet/gnunet_common.h> 27 #include <gnunet/gnunet_time_lib.h> 28 #include <gnunet/gnunet_util_lib.h> 29 #include <gnunet/gnunet_db_lib.h> 30 #include <taler/taler_merchant_util.h> 31 #include <taler/taler_exchange_service.h> 32 #include <jansson.h> 33 #include <donau/donau_service.h> 34 #include <donau/donau_util.h> 35 36 37 /** 38 * Handle to interact with the database. 39 */ 40 struct TALER_MERCHANTDB_Plugin; 41 42 43 GNUNET_NETWORK_STRUCT_BEGIN 44 45 46 /** 47 * Format of the data hashed to generate the notification 48 * string whenever the KYC status for an account has 49 * changed. 50 */ 51 struct TALER_MERCHANTDB_MerchantKycStatusChangeEventP 52 { 53 /** 54 * Type is TALER_DBEVENT_MERCHANT_EXCHANGE_KYC_STATUS_CHANGED. 55 */ 56 struct GNUNET_DB_EventHeaderP header; 57 58 /** 59 * Salted hash of the affected account. 60 */ 61 struct TALER_MerchantWireHashP h_wire; 62 }; 63 64 /** 65 * Event triggered when an order is paid. 66 */ 67 struct TMH_OrderPayEventP 68 { 69 /** 70 * Type is #TALER_DBEVENT_MERCHANT_ORDER_PAID 71 */ 72 struct GNUNET_DB_EventHeaderP header; 73 74 /** 75 * Always zero (for alignment). 76 */ 77 uint32_t reserved GNUNET_PACKED; 78 79 /** 80 * Merchant's public key 81 */ 82 struct TALER_MerchantPublicKeyP merchant_pub; 83 84 /** 85 * Hash of the order ID. 86 */ 87 struct GNUNET_HashCode h_order_id; 88 }; 89 90 91 GNUNET_NETWORK_STRUCT_END 92 93 /** 94 * Current exposed deposit limits by an exchange 95 * for a merchant (until other rules may apply). 96 */ 97 struct TALER_MERCHANTDB_DepositLimits 98 { 99 /** 100 * Maximum amount to be deposited within @a timeframe. 101 */ 102 struct TALER_Amount threshold; 103 104 /** 105 * Timeframe over which the limit applies. 106 */ 107 struct GNUNET_TIME_Relative timeframe; 108 109 /** 110 * True if this is a soft limit that could be 111 * raised (by AML staff or by passing KYC checks). 112 */ 113 bool soft_limit; 114 }; 115 116 /** 117 * Details about a wire account of the merchant. 118 */ 119 struct TALER_MERCHANTDB_AccountDetails 120 { 121 /** 122 * Hash of the wire details (@e payto_uri and @e salt). 123 */ 124 struct TALER_MerchantWireHashP h_wire; 125 126 /** 127 * Salt value used for hashing @e payto_uri. 128 */ 129 struct TALER_WireSaltP salt; 130 131 /** 132 * Instance ID. Do not free (may be aliased with 133 * the instance ID given in the query!). 134 * FIXME: set in all functions involving this struct! 135 */ 136 const char *instance_id; 137 138 /** 139 * Actual account address as a payto://-URI. 140 */ 141 struct TALER_FullPayto payto_uri; 142 143 /** 144 * Where can the taler-merchant-wirewatch helper 145 * download information about incoming transfers? 146 * NULL if not available. 147 */ 148 char *credit_facade_url; 149 150 /** 151 * JSON with credentials to use to access the 152 * @e credit_facade_url. 153 */ 154 json_t *credit_facade_credentials; 155 156 /** 157 * Additional meta data to include in wire transfers to this 158 * account. Can be NULL if not used. 159 */ 160 char *extra_wire_subject_metadata; 161 162 /** 163 * Is the account set for active use in new contracts? 164 */ 165 bool active; 166 167 }; 168 169 170 /** 171 * Binary login token. Just a vanilla token made out 172 * of random bits. 173 */ 174 struct TALER_MERCHANTDB_LoginTokenP 175 { 176 /** 177 * 32 bytes of entropy. 178 */ 179 uint64_t data[32 / 8]; 180 }; 181 182 /** 183 * Authentication settings for an instance. 184 */ 185 struct TALER_MERCHANTDB_InstanceAuthSettings 186 { 187 /** 188 * Hash used for authentication. All zero if authentication is off. 189 */ 190 struct TALER_MerchantAuthenticationHashP auth_hash; 191 192 /** 193 * Salt used to hash the "Authentication" header, the result must then 194 * match the @e auth_hash. 195 */ 196 struct TALER_MerchantAuthenticationSaltP auth_salt; 197 }; 198 199 /** 200 * General settings for an instance. 201 */ 202 struct TALER_MERCHANTDB_InstanceSettings 203 { 204 /** 205 * prefix for the instance under "/instances/" 206 */ 207 char *id; 208 209 /** 210 * legal name of the instance 211 */ 212 char *name; 213 214 /** 215 * merchant's site url 216 */ 217 char *website; 218 219 /** 220 * email contact for password reset / possibly admin / customers 221 */ 222 char *email; 223 224 /** 225 * phone contact for password reset / possibly admin / customers 226 */ 227 char *phone; 228 229 /** 230 * merchant's logo data uri 231 */ 232 char *logo; 233 234 /** 235 * Address of the business 236 */ 237 json_t *address; 238 239 /** 240 * jurisdiction of the business 241 */ 242 json_t *jurisdiction; 243 244 /** 245 * Use STEFAN curves to determine acceptable 246 * fees by default (otherwise: accept no fees by default). 247 */ 248 bool use_stefan; 249 250 /** 251 * True of @e phone was validated. 252 */ 253 bool phone_validated; 254 255 /** 256 * True of @e email was validated. 257 */ 258 bool email_validated; 259 260 /** 261 * If the frontend does NOT specify an execution date, how long should 262 * we tell the exchange to wait to aggregate transactions before 263 * executing the wire transfer? This delay is added to the current 264 * time when we generate the advisory execution time for the exchange. 265 */ 266 struct GNUNET_TIME_Relative default_wire_transfer_delay; 267 268 /** 269 * If the frontend does NOT specify a payment deadline, how long should 270 * offers we make be valid by default? 271 */ 272 struct GNUNET_TIME_Relative default_pay_delay; 273 274 /** 275 * If the frontend does NOT specify a refund deadline, how long should 276 * refunds be possible? 277 */ 278 struct GNUNET_TIME_Relative default_refund_delay; 279 280 /** 281 * How much should we round up the wire transfer deadline computed by 282 * adding the @e default_wire_transfer_delay to the refund deadline. 283 */ 284 enum GNUNET_TIME_RounderInterval default_wire_transfer_rounding_interval; 285 286 }; 287 288 289 /** 290 * Typically called by `lookup_instances`. 291 * 292 * @param cls closure 293 * @param merchant_pub public key of the instance 294 * @param merchant_priv private key of the instance, NULL if not available 295 * @param is general instance settings 296 * @param ias instance authentication settings 297 */ 298 typedef void 299 (*TALER_MERCHANTDB_InstanceCallback)( 300 void *cls, 301 const struct TALER_MerchantPublicKeyP *merchant_pub, 302 const struct TALER_MerchantPrivateKeyP *merchant_priv, 303 const struct TALER_MERCHANTDB_InstanceSettings *is, 304 const struct TALER_MERCHANTDB_InstanceAuthSettings *ias); 305 306 307 /** 308 * Callback invoked with information about a bank account. 309 * 310 * @param cls closure 311 * @param merchant_priv private key of the merchant instance 312 * @param ad details about the account 313 */ 314 typedef void 315 (*TALER_MERCHANTDB_AccountCallback)( 316 void *cls, 317 const struct TALER_MerchantPrivateKeyP *merchant_priv, 318 const struct TALER_MERCHANTDB_AccountDetails *ad); 319 320 321 /** 322 * Determines the maximum @a amount for a particular 323 * type of operation for a given @a exchange_url. 324 * 325 * @param cls closure 326 * @param exchange_url base URL of the exchange to get 327 * the limit for 328 * @param[in,out] amount lowered to the maximum amount 329 * allowed at the exchange 330 */ 331 typedef void 332 (*TALER_MERCHANTDB_OperationLimitCallback)( 333 void *cls, 334 const char *exchange_url, 335 struct TALER_Amount *amount); 336 337 338 /** 339 * Typically called by `lookup_products`. 340 * 341 * @param cls a `json_t *` JSON array to build 342 * @param product_serial row ID of the product 343 * @param product_id ID of the product 344 */ 345 typedef void 346 (*TALER_MERCHANTDB_ProductsCallback)( 347 void *cls, 348 uint64_t product_serial, 349 const char *product_id); 350 351 352 /** 353 * Details about a product. 354 * 355 * FIXME: reuse TALER_MERCHANT_Product as a member in this structure! 356 */ 357 struct TALER_MERCHANTDB_ProductDetails 358 { 359 /** 360 * Name of the product. 361 */ 362 char *product_name; 363 364 /** 365 * Description of the product. 366 */ 367 char *description; 368 369 /** 370 * Internationalized description. 371 */ 372 json_t *description_i18n; 373 374 /** 375 * Unit in which the product is sold. 376 */ 377 char *unit; 378 379 /** 380 * Optional list of per-unit prices. When NULL or empty, @e price 381 * must be used as the canonical single price. 382 */ 383 struct TALER_Amount *price_array; 384 385 /** 386 * Number of entries in @e price_array. 387 */ 388 size_t price_array_length; 389 390 /** 391 * Base64-encoded product image, or an empty string. 392 */ 393 char *image; 394 395 /** 396 * Hash of the product image data, or NULL. 397 */ 398 char *image_hash; 399 400 /** 401 * List of taxes the merchant pays for this product. Never NULL, 402 * but can be an empty array. 403 */ 404 json_t *taxes; 405 406 /** 407 * Number of units of the product in stock in sum in total, including all 408 * existing sales and lost product, in product-specific units. UINT64_MAX 409 * indicates "infinite". 410 */ 411 uint64_t total_stock; 412 413 /** 414 * Fractional part of stock in units of 1/1000000 of the base value. 415 */ 416 uint32_t total_stock_frac; 417 418 /** 419 * Honor fractional stock if TRUE, else only integer stock. 420 */ 421 bool allow_fractional_quantity; 422 423 /** 424 * Precision level (number of decimal places) to apply when 425 * fractional quantities are enabled. 426 */ 427 uint32_t fractional_precision_level; 428 429 /** 430 * Number of units of the product in sold, in product-specific units. 431 */ 432 uint64_t total_sold; 433 434 /** 435 * Fractional part of units sold in units of 1/1000000 of the base value. 436 */ 437 uint32_t total_sold_frac; 438 439 /** 440 * Number of units of stock lost. 441 */ 442 uint64_t total_lost; 443 444 /** 445 * Fractional part of lost units in units of 1/1000000 of the base value. 446 */ 447 uint32_t total_lost_frac; 448 449 /** 450 * Identifies where the product is in stock, possibly an empty map. 451 */ 452 json_t *address; 453 454 /** 455 * Identifies when the product will be restocked. 0 for unknown, 456 * #GNUNET_TIME_UNIT_FOREVER_ABS for never. 457 */ 458 struct GNUNET_TIME_Timestamp next_restock; 459 460 /** 461 * Minimum required age for consumers buying this product. 462 * Default is 0. Only enforced of an exchange supports age 463 * restrictions. 464 */ 465 uint32_t minimum_age; 466 467 /** 468 * Group in which the product is in. 0 for default group. 469 */ 470 uint64_t product_group_id; 471 472 /** 473 * Money pot into which sales of this product should go into by default. 474 */ 475 uint64_t money_pot_id; 476 477 /** 478 * True if the price for this product is given in net, 479 * False if its the gross price. 480 */ 481 bool price_is_net; 482 483 }; 484 485 /** 486 * Minimal product details for inventory templates. 487 */ 488 struct TALER_MERCHANTDB_InventoryProductDetails 489 { 490 /** 491 * Name of the product. 492 */ 493 char *product_name; 494 495 /** 496 * Description of the product. 497 */ 498 char *description; 499 500 /** 501 * Internationalized description. 502 */ 503 json_t *description_i18n; 504 505 /** 506 * Unit in which the product is sold. 507 */ 508 char *unit; 509 510 /** 511 * List of per-unit prices. 512 */ 513 struct TALER_Amount *price_array; 514 515 /** 516 * Number of entries in @e price_array. 517 */ 518 size_t price_array_length; 519 520 /** 521 * Hash of the product image data, or NULL. 522 */ 523 char *image_hash; 524 525 /** 526 * Honor fractional stock if TRUE, else only integer stock. 527 */ 528 bool allow_fractional_quantity; 529 530 /** 531 * Precision level (number of decimal places) to apply when 532 * fractional quantities are enabled. 533 */ 534 uint32_t fractional_precision_level; 535 536 /** 537 * Remaining units after sold/lost/locked deductions. 538 */ 539 uint64_t remaining_stock; 540 541 /** 542 * Fractional part of remaining units in units of 1/1000000 of the base value. 543 */ 544 uint32_t remaining_stock_frac; 545 546 /** 547 * List of taxes the merchant pays for this product. Never NULL, 548 * but can be an empty array. 549 */ 550 json_t *taxes; 551 }; 552 553 554 /** 555 * Details about an inventory measurement unit. 556 */ 557 struct TALER_MERCHANTDB_UnitDetails 558 { 559 560 /** 561 * Database serial. 562 */ 563 uint64_t unit_serial; 564 565 /** 566 * Backend identifier used in product payloads. 567 */ 568 char *unit; 569 570 /** 571 * Default long label (fallback string). 572 */ 573 char *unit_name_long; 574 575 /** 576 * Default short label (fallback string). 577 */ 578 char *unit_name_short; 579 580 /** 581 * Internationalised long labels. 582 */ 583 json_t *unit_name_long_i18n; 584 585 /** 586 * Internationalised short labels. 587 */ 588 json_t *unit_name_short_i18n; 589 590 /** 591 * Whether fractional quantities are enabled by default. 592 */ 593 bool unit_allow_fraction; 594 595 /** 596 * Maximum number of fractional digits honoured by default. 597 */ 598 uint32_t unit_precision_level; 599 600 /** 601 * Hidden from selectors when false. 602 */ 603 bool unit_active; 604 605 /** 606 * Built-in units cannot be deleted. 607 */ 608 bool unit_builtin; 609 }; 610 611 612 /** 613 * Typically called by `lookup_all_products`. 614 * 615 * @param cls a `json_t *` JSON array to build 616 * @param product_serial row ID of the product 617 * @param product_id ID of the product 618 * @param pd full product details 619 * @param num_categories length of @a categories array 620 * @param categories array of categories the 621 * product is in 622 */ 623 typedef void 624 (*TALER_MERCHANTDB_ProductCallback)( 625 void *cls, 626 uint64_t product_serial, 627 const char *product_id, 628 const struct TALER_MERCHANTDB_ProductDetails *pd, 629 size_t num_categories, 630 const uint64_t *categories); 631 632 /** 633 * Typically called by `lookup_inventory_products`. 634 * 635 * @param cls a `json_t *` JSON array to build 636 * @param product_id ID of the product 637 * @param pd inventory product details 638 * @param num_categories length of @a categories array 639 * @param categories array of categories the 640 * product is in 641 */ 642 typedef void 643 (*TALER_MERCHANTDB_InventoryProductCallback)( 644 void *cls, 645 const char *product_id, 646 const struct TALER_MERCHANTDB_InventoryProductDetails *pd, 647 size_t num_categories, 648 const uint64_t *categories); 649 650 651 /** 652 * Callback function typically used by `select_donau_instances` to handle 653 * the details of each Donau instance retrieved from the database. 654 * 655 * @param cls Closure to pass additional context or data to the callback function. 656 * @param donau_url The URL of the Donau instance. 657 */ 658 typedef void 659 (*TALER_MERCHANTDB_DonauInstanceFilteredCallback)( 660 void *cls, 661 const char *donau_url 662 ); 663 664 /** 665 * Callback function typically used by `select_donau_instances` to handle 666 * the details of each Donau instance retrieved from the database. 667 * 668 * @param cls Closure to pass additional context or data to the callback function. 669 * @param donau_instance_serial Serial number of the Donau instance in the merchant database. 670 * @param donau_url The URL of the Donau instance. 671 * @param charity_name The name of the charity associated with the Donau instance. 672 * @param charity_pub_key Pointer to the charity's public key used for cryptographic operations. 673 * @param charity_id The unique identifier for the charity within the Donau instance. 674 * @param charity_max_per_year Maximum allowed donations to the charity for the current year. 675 * @param charity_receipts_to_date Total donations received by the charity so far in the current year. 676 * @param current_year The year for which the donation data is being tracked. 677 * @param donau_keys_json JSON object containing additional key-related information for the Donau instance, NULL if not (yet) available. 678 */ 679 typedef void 680 (*TALER_MERCHANTDB_DonauInstanceCallback)( 681 void *cls, 682 uint64_t donau_instance_serial, 683 const char *donau_url, 684 const char *charity_name, 685 const struct DONAU_CharityPublicKeyP *charity_pub_key, 686 uint64_t charity_id, 687 const struct TALER_Amount *charity_max_per_year, 688 const struct TALER_Amount *charity_receipts_to_date, 689 int64_t current_year, 690 const json_t *donau_keys_json 691 ); 692 693 694 /** 695 * Structure to hold Donau instance details from the database. 696 */ 697 struct TALER_MERCHANTDB_DonauInstance 698 { 699 /** 700 * Donau instance serial 701 */ 702 uint64_t donau_instance_serial; 703 704 /** 705 * The URL for the Donau instance. 706 */ 707 char *donau_url; 708 709 /** 710 * The name of the charity associated with the Donau instance. 711 */ 712 char *charity_name; 713 714 /** 715 * Pointer to the public key of the charity, used for cryptographic operations. 716 * This is represented as an EDDSA public key structure. 717 */ 718 struct DONAU_CharityPublicKeyP *charity_pub_key; 719 720 /** 721 * A unique identifier for the charity in the Donau instance. 722 */ 723 uint64_t charity_id; 724 725 /** 726 * The maximum allowable amount for donations to this charity in the current year. 727 * This is tracked for regulatory or internal business constraints. 728 */ 729 struct TALER_Amount charity_max_per_year; 730 731 /** 732 * The total amount of donations received by the charity in the current year. 733 * This field helps track progress toward the yearly donation limit. 734 */ 735 struct TALER_Amount charity_receipts_to_date; 736 737 /** 738 * The current year being tracked for donations. 739 * This is used to differentiate donation data between years. 740 */ 741 int64_t current_year; 742 743 /** 744 * A JSON object containing key information specific to the Donau instance, 745 * such as cryptographic keys or other relevant details. 746 */ 747 json_t *donau_keys_json; 748 }; 749 750 /** 751 * Typically called by `lookup_login_tokens`. 752 * 753 * @param cls a `json_t *` JSON array to build 754 * @param creation_time creation time of the token 755 * @param expiration_time expiration time of the token 756 * @param scope validity scope of the token 757 * @param description description of the token 758 * @param serial serial number of the token 759 */ 760 typedef void 761 (*TALER_MERCHANTDB_LoginTokensCallback)( 762 void *cls, 763 struct GNUNET_TIME_Timestamp creation_time, 764 struct GNUNET_TIME_Timestamp expiration_time, 765 uint32_t scope, 766 const char *description, 767 uint64_t serial); 768 769 770 /** 771 * Typically called by `lookup_templates`. 772 * 773 * @param cls closure 774 * @param template_id ID of the template 775 * @param template_description description of the template 776 */ 777 typedef void 778 (*TALER_MERCHANTDB_TemplatesCallback)( 779 void *cls, 780 const char *template_id, 781 const char *template_description); 782 783 784 /** 785 * Typically called by `lookup_otp_devices`. 786 * 787 * @param cls closure 788 * @param otp_id ID of the OTP device 789 * @param otp_description description of the OTP device 790 */ 791 typedef void 792 (*TALER_MERCHANTDB_OtpDeviceCallback)( 793 void *cls, 794 const char *otp_id, 795 const char *otp_description); 796 797 798 /** 799 * Details about a template. 800 */ 801 struct TALER_MERCHANTDB_TemplateDetails 802 { 803 /** 804 * Description of the template. 805 */ 806 char *template_description; 807 808 /** 809 * In this template contract, we can have additional information. 810 */ 811 json_t *template_contract; 812 813 /** 814 * ID of the OTP device linked to the template, or NULL. 815 */ 816 char *otp_id; 817 818 /** 819 * Editable default values for fields not specified 820 * in the @e template_contract. NULL if the user 821 * cannot edit anything. 822 */ 823 json_t *editable_defaults; 824 825 }; 826 827 828 /** 829 * Details about an OTP device. 830 */ 831 struct TALER_MERCHANTDB_OtpDeviceDetails 832 { 833 834 /** 835 * Description of the device. 836 */ 837 char *otp_description; 838 839 /** 840 * Current usage counter value. 841 */ 842 uint64_t otp_ctr; 843 844 /** 845 * Base64-encoded key. 846 */ 847 char *otp_key; 848 849 /** 850 * Algorithm used to compute purchase confirmations. 851 */ 852 enum TALER_MerchantConfirmationAlgorithm otp_algorithm; 853 }; 854 855 856 /** 857 * Typically called by `lookup_categories`. 858 * 859 * @param cls closure 860 * @param category_id ID of the category 861 * @param category_name name of the category 862 * @param category_name_i18n translations of the @a category_name 863 * @param product_count number of products in the category 864 */ 865 typedef void 866 (*TALER_MERCHANTDB_CategoriesCallback)( 867 void *cls, 868 uint64_t category_id, 869 const char *category_name, 870 const json_t *category_name_i18n, 871 uint64_t product_count); 872 873 874 /** 875 * Typically called by `lookup_units`. 876 * 877 * @param cls closure 878 * @param unit_serial database identifier 879 * @param ud measurement unit details (borrowed) 880 */ 881 typedef void 882 (*TALER_MERCHANTDB_UnitsCallback)( 883 void *cls, 884 uint64_t unit_serial, 885 const struct TALER_MERCHANTDB_UnitDetails *ud); 886 887 888 /** 889 * Details about a product category. 890 */ 891 struct TALER_MERCHANTDB_CategoryDetails 892 { 893 894 /** 895 * Name of the category. 896 */ 897 char *category_name; 898 899 /** 900 * Translations of the name of the category. 901 */ 902 json_t *category_name_i18n; 903 904 }; 905 906 907 /** 908 * Typically called by `lookup_webhooks`. 909 * 910 * @param cls a `json_t *` JSON array to build 911 * @param webhook_id ID of the webhook 912 * @param event_type event of the webhook 913 */ 914 typedef void 915 (*TALER_MERCHANTDB_WebhooksCallback)( 916 void *cls, 917 const char *webhook_id, 918 const char *event_type); 919 920 921 /** 922 * Details about a webhook. 923 */ 924 struct TALER_MERCHANTDB_WebhookDetails 925 { 926 927 /** 928 * event of the webhook. 929 */ 930 char *event_type; 931 932 /** 933 * URL of the webhook. The customer will be redirected on this url. 934 */ 935 char *url; 936 937 /** 938 * Http method used by the webhook. 939 */ 940 char *http_method; 941 942 /** 943 * Header template of the webhook. 944 */ 945 char *header_template; 946 947 /** 948 * Body template of the webhook. 949 */ 950 char *body_template; 951 952 }; 953 954 955 /** 956 * Typically called by `lookup_webhook_by_event`. 957 * 958 * @param cls a `json_t *` JSON array to build 959 * @param webhook_serial reference to the configured webhook template. 960 * @param event_type which type of event triggers this type of webhook 961 * @param url the HTTP URL to make the webhook request to 962 * @param http_method HTTP method use for the webhook 963 * @param header_template template for the header of the webhook 964 * @param body_template template for the body of the webhook 965 */ 966 typedef void 967 (*TALER_MERCHANTDB_WebhookDetailCallback)( 968 void *cls, 969 uint64_t webhook_serial, 970 const char *event_type, 971 const char *url, 972 const char *http_method, 973 const char *header_template, 974 const char *body_template); 975 976 977 /** 978 * Typically called by `lookup_pending_webhooks`. 979 * 980 * @param cls a `json_t *` JSON array to build 981 * @param webhook_pending_serial reference to the configured webhook template. 982 * @param next_attempt is the time we should make the next request to the webhook. 983 * @param retries how often have we tried this request to the webhook. 984 * @param url to make request to 985 * @param http_method use for the webhook 986 * @param header of the webhook 987 * @param body of the webhook 988 */ 989 typedef void 990 (*TALER_MERCHANTDB_PendingWebhooksCallback)( 991 void *cls, 992 uint64_t webhook_pending_serial, 993 struct GNUNET_TIME_Absolute 994 next_attempt, 995 uint32_t retries, 996 const char *url, 997 const char *http_method, 998 const char *header, 999 const char *body); 1000 1001 1002 /** 1003 * Details about the pending webhook. 1004 */ 1005 struct TALER_MERCHANTDB_PendingWebhookDetails 1006 { 1007 1008 /** 1009 * Identifies when we should make the next request to the webhook. 0 for unknown, 1010 * #GNUNET_TIME_UNIT_FOREVER_ABS for never. 1011 */ 1012 struct GNUNET_TIME_Absolute next_attempt; 1013 1014 /** 1015 * How often have we tried this request so far. 1016 */ 1017 uint32_t retries; 1018 1019 /** 1020 * URL of the webhook. The customer will be redirected on this url. 1021 */ 1022 char *url; 1023 1024 /** 1025 * Http method used for the webhook. 1026 */ 1027 char *http_method; 1028 1029 /** 1030 * Header of the webhook. 1031 */ 1032 char *header; 1033 1034 /** 1035 * Body of the webhook. 1036 */ 1037 char *body; 1038 1039 }; 1040 1041 1042 /** 1043 * Filter preferences. 1044 */ 1045 struct TALER_MERCHANTDB_OrderFilter 1046 { 1047 /** 1048 * Filter orders by this fulfillment URL. 1049 */ 1050 const char *fulfillment_url; 1051 1052 /** 1053 * Filter orders by this session ID. 1054 */ 1055 const char *session_id; 1056 1057 /** 1058 * Filter by payment status. 1059 */ 1060 enum TALER_EXCHANGE_YesNoAll paid; 1061 1062 /** 1063 * Filter by refund status. 1064 */ 1065 enum TALER_EXCHANGE_YesNoAll refunded; 1066 1067 /** 1068 * Filter by wire transfer status. 1069 */ 1070 enum TALER_EXCHANGE_YesNoAll wired; 1071 1072 /** 1073 * Filter orders by date, exact meaning depends on @e delta. 1074 */ 1075 struct GNUNET_TIME_Timestamp date; 1076 1077 /** 1078 * Filter orders by order serial number, exact meaning depends on @e delta. 1079 */ 1080 uint64_t start_row; 1081 1082 /** 1083 * takes value of the form N (-N), so that at most N values strictly older 1084 * (younger) than start and date are returned. 1085 */ 1086 int64_t delta; 1087 1088 /** 1089 * Timeout for long-polling. 1090 */ 1091 struct GNUNET_TIME_Relative timeout; 1092 1093 /** 1094 * Filter to apply on the summary of the order. 1095 */ 1096 const char *summary_filter; 1097 1098 }; 1099 1100 1101 /** 1102 * Typically called by `lookup_orders`. 1103 * 1104 * @param cls a `json_t *` JSON array to build 1105 * @param order_id ID of the order 1106 * @param order_serial row of the order in the database 1107 * @param timestamp creation time of the order in the database 1108 */ 1109 typedef void 1110 (*TALER_MERCHANTDB_OrdersCallback)(void *cls, 1111 const char *order_id, 1112 uint64_t order_serial, 1113 struct GNUNET_TIME_Timestamp timestamp); 1114 1115 1116 /** 1117 * Typically called by `select_order_blinded_sigs` 1118 * 1119 * @param cls closure 1120 * @param hash hash of the token 1121 * @param blinded_sig blinded signature for the token 1122 */ 1123 typedef void 1124 (*TALER_MERCHANTDB_BlindedSigCallback)( 1125 void *cls, 1126 struct GNUNET_HashCode *hash, 1127 struct GNUNET_CRYPTO_BlindedSignature *blinded_sig); 1128 1129 /** 1130 * Function called with information about a coin that was deposited. 1131 * 1132 * @param cls closure 1133 * @param exchange_url exchange where @a coin_pub was deposited 1134 * @param coin_pub public key of the coin 1135 * @param amount_with_fee amount the exchange will deposit for this coin 1136 * @param deposit_fee fee the exchange will charge for this coin 1137 * @param refund_fee fee the exchange will charge for refunding this coin 1138 */ 1139 typedef void 1140 (*TALER_MERCHANTDB_DepositsCallback)( 1141 void *cls, 1142 const char *exchange_url, 1143 const struct TALER_CoinSpendPublicKeyP *coin_pub, 1144 const struct TALER_Amount *amount_with_fee, 1145 const struct TALER_Amount *deposit_fee, 1146 const struct TALER_Amount *refund_fee); 1147 1148 1149 /** 1150 * Function called with information about a refund. 1151 * 1152 * @param cls closure 1153 * @param coin_pub public coin from which the refund comes from 1154 * @param refund_amount refund amount which is being taken from @a coin_pub 1155 */ 1156 typedef void 1157 (*TALER_MERCHANTDB_RefundCallback)( 1158 void *cls, 1159 const struct TALER_CoinSpendPublicKeyP *coin_pub, 1160 const struct TALER_Amount *refund_amount); 1161 1162 1163 /** 1164 * Typically called by `lookup_transfer_details_by_order`. 1165 * 1166 * @param cls closure 1167 * @param wtid wire transfer subject of the wire transfer for the coin 1168 * @param exchange_url base URL of the exchange that made the payment 1169 * @param execution_time when was the payment made 1170 * @param deposit_value contribution of the coin to the total wire transfer value 1171 * @param deposit_fee deposit fee charged by the exchange for the coin 1172 * @param transfer_confirmed did the merchant confirm that a wire transfer with 1173 * @a wtid over the total amount happened? 1174 * @param expected_credit_serial row of the expected wire transfer, usable 1175 * as ``offset`` for the ``/private/incoming`` endpoint 1176 */ 1177 typedef void 1178 (*TALER_MERCHANTDB_OrderTransferDetailsCallback)( 1179 void *cls, 1180 const struct TALER_WireTransferIdentifierRawP *wtid, 1181 const char *exchange_url, 1182 struct GNUNET_TIME_Timestamp execution_time, 1183 const struct TALER_Amount *deposit_value, 1184 const struct TALER_Amount *deposit_fee, 1185 bool transfer_confirmed, 1186 uint64_t expected_credit_serial); 1187 1188 1189 /** 1190 * Function called with detailed information about a refund. 1191 * 1192 * @param cls closure 1193 * @param refund_serial unique serial number of the refund 1194 * @param timestamp time of the refund (for grouping of refunds in the wallet UI) 1195 * @param coin_pub public coin from which the refund comes from 1196 * @param exchange_url URL of the exchange that issued @a coin_pub 1197 * @param rtransaction_id identificator of the refund 1198 * @param reason human-readable explanation of the refund 1199 * @param refund_amount refund amount which is being taken from @a coin_pub 1200 * @param pending true if the this refund was not yet processed by the wallet/exchange 1201 */ 1202 typedef void 1203 (*TALER_MERCHANTDB_RefundDetailCallback)( 1204 void *cls, 1205 uint64_t refund_serial, 1206 struct GNUNET_TIME_Timestamp timestamp, 1207 const struct TALER_CoinSpendPublicKeyP *coin_pub, 1208 const char *exchange_url, 1209 uint64_t rtransaction_id, 1210 const char *reason, 1211 const struct TALER_Amount *refund_amount, 1212 bool pending); 1213 1214 1215 /** 1216 * Function called from ``account_kyc_get_status`` 1217 * with KYC status information for this merchant. 1218 * 1219 * @param cls closure 1220 * @param h_wire hash of the wire account 1221 * @param payto_uri payto:// URI of the merchant's bank account 1222 * @param exchange_url base URL of the exchange for which this is a status 1223 * @param last_check when did we last get an update on our KYC status from the exchange 1224 * @param kyc_ok true if we satisfied the KYC requirements 1225 * @param access_token access token for the KYC SPA, NULL if we cannot access it yet (need KYC auth wire transfer) 1226 * @param last_http_status last HTTP status from /kyc-check 1227 * @param last_ec last Taler error code from /kyc-check 1228 * @param in_aml_review true if the account is pending review 1229 * @param jlimits JSON array of applicable AccountLimits, or NULL if unknown (like defaults apply) 1230 */ 1231 typedef void 1232 (*TALER_MERCHANTDB_KycCallback)( 1233 void *cls, 1234 const struct TALER_MerchantWireHashP *h_wire, 1235 struct TALER_FullPayto payto_uri, 1236 const char *exchange_url, 1237 struct GNUNET_TIME_Timestamp last_check, 1238 bool kyc_ok, 1239 const struct TALER_AccountAccessTokenP *access_token, 1240 unsigned int last_http_status, 1241 enum TALER_ErrorCode last_ec, 1242 bool in_aml_review, 1243 const json_t *jlimits); 1244 1245 1246 /** 1247 * Function called from ``account_kyc_get_outdated`` 1248 * with information about outdated KYC status information. 1249 * 1250 * @param cls closure 1251 * @param instance_id which instance is this about 1252 * @param exchange_url base URL of the exchange for which the status is dated 1253 * @param h_wire hash of the wire account for which the status is dated 1254 */ 1255 typedef void 1256 (*TALER_MERCHANTDB_KycOutdatedCallback)( 1257 void *cls, 1258 const char *instance_id, 1259 const char *exchange_url, 1260 const struct TALER_MerchantWireHashP *h_wire); 1261 1262 1263 /** 1264 * Function called about the ``/keys`` status of every exchange 1265 * we are working with. 1266 * 1267 * @param cls closure 1268 * @param exchange_url base URL of the exchange 1269 * @param next_download when will be the next download 1270 * @param keys_expiration when does the current ``/keys`` response expire 1271 * @param http_status last HTTP status from ``/keys`` 1272 * @param ec last error code from fetching ``/keys`` 1273 */ 1274 typedef void 1275 (*TALER_MERCHANTDB_ExchangesCallback)( 1276 void *cls, 1277 const char *exchange_url, 1278 struct GNUNET_TIME_Absolute next_download, 1279 struct GNUNET_TIME_Absolute keys_expiration, 1280 unsigned int http_status, 1281 enum TALER_ErrorCode ec); 1282 1283 /** 1284 * Results from trying to increase a refund. 1285 */ 1286 enum TALER_MERCHANTDB_RefundStatus 1287 { 1288 1289 /** 1290 * Refund amount exceeds legal exchange limits. 1291 */ 1292 TALER_MERCHANTDB_RS_LEGAL_FAILURE = -5, 1293 1294 /** 1295 * Refund amount currency does not match original payment. 1296 */ 1297 TALER_MERCHANTDB_RS_BAD_CURRENCY = -4, 1298 1299 /** 1300 * Refund amount exceeds original payment. 1301 */ 1302 TALER_MERCHANTDB_RS_TOO_HIGH = -3, 1303 1304 /** 1305 * Hard database failure. 1306 */ 1307 TALER_MERCHANTDB_RS_HARD_ERROR = -2, 1308 1309 /** 1310 * Soft database failure. 1311 */ 1312 TALER_MERCHANTDB_RS_SOFT_ERROR = -1, 1313 1314 /** 1315 * Order not found. 1316 */ 1317 TALER_MERCHANTDB_RS_NO_SUCH_ORDER = 0, 1318 1319 /** 1320 * Refund is now at or above the requested amount. 1321 */ 1322 TALER_MERCHANTDB_RS_SUCCESS = 1 1323 1324 }; 1325 1326 1327 /** 1328 * Function called with information about a wire transfer identifier. 1329 * 1330 * @param cls closure 1331 * @param order_id the order to which the deposits belong 1332 * @param deposit_value the amount deposited under @a order_id 1333 * @param deposit_fee the fee charged for @a deposit_value 1334 */ 1335 typedef void 1336 (*TALER_MERCHANTDB_TransferSummaryCallback)( 1337 void *cls, 1338 const char *order_id, 1339 const struct TALER_Amount *deposit_value, 1340 const struct TALER_Amount *deposit_fee); 1341 1342 1343 /** 1344 * Function called with information about wire transfers 1345 * that taler-merchant-exchange still needs to process. 1346 * 1347 * @param cls closure 1348 * @param rowid row of the transfer in the merchant database 1349 * @param instance_id instance that received the transfer 1350 * @param exchange_url URL of the exchange that is making the deposit 1351 * @param payto_uri account of the merchant that received the transfer 1352 * @param wtid wire transfer subject identifying the aggregation 1353 * @param next_attempt when should we next try to interact with the exchange 1354 */ 1355 typedef void 1356 (*TALER_MERCHANTDB_OpenTransferCallback)( 1357 void *cls, 1358 uint64_t rowid, 1359 const char *instance_id, 1360 const char *exchange_url, 1361 struct TALER_FullPayto payto_uri, 1362 const struct TALER_WireTransferIdentifierRawP *wtid, 1363 struct GNUNET_TIME_Absolute next_attempt); 1364 1365 1366 /** 1367 * Callback for results from `lookup_pending_deposits`. 1368 * 1369 * @param cls NULL 1370 * @param deposit_serial identifies the deposit operation 1371 * @param wire_deadline when is the wire due 1372 * @param retry_time when to next try the exchange again 1373 * @param h_contract_terms hash of the contract terms 1374 * @param merchant_priv private key of the merchant 1375 * @param instance_id name of the instance 1376 * @param h_wire hash of the merchant's wire account into 1377 * @param amount_with_fee amount the exchange will deposit for this coin 1378 * @param deposit_fee fee the exchange will charge for this coin which the deposit was made 1379 * @param coin_pub public key of the deposited coin 1380 */ 1381 typedef void 1382 (*TALER_MERCHANTDB_PendingDepositsCallback) ( 1383 void *cls, 1384 uint64_t deposit_serial, 1385 struct GNUNET_TIME_Absolute wire_deadline, 1386 struct GNUNET_TIME_Absolute retry_time, 1387 const struct TALER_PrivateContractHashP *h_contract_terms, 1388 const struct TALER_MerchantPrivateKeyP *merchant_priv, 1389 const char *instance_id, 1390 const struct TALER_MerchantWireHashP *h_wire, 1391 const struct TALER_Amount *amount_with_fee, 1392 const struct TALER_Amount *deposit_fee, 1393 const struct TALER_CoinSpendPublicKeyP *coin_pub); 1394 1395 1396 /** 1397 * Function called with detailed information about a wire transfer and 1398 * the underlying deposits that are being aggregated. 1399 * 1400 * @param cls closure 1401 * @param current_offset offset in the exchange reply we are at 1402 * @param ttd details about the transfer at @a current_offset 1403 */ 1404 typedef void 1405 (*TALER_MERCHANTDB_TransferDetailsCallback)( 1406 void *cls, 1407 unsigned int current_offset, 1408 const struct TALER_TrackTransferDetails *ttd); 1409 1410 1411 /** 1412 * Function called with information about a accounts 1413 * the wirewatcher should monitor. 1414 * 1415 * @param cls closure 1416 * @param instance instance that owns the account 1417 * @param payto_uri account URI 1418 * @param credit_facade_url URL for the credit facade 1419 * @param credit_facade_credentials account access credentials 1420 * @param last_serial last transaction serial (inclusive) we have seen from this account 1421 */ 1422 typedef void 1423 (*TALER_MERCHANTDB_WirewatchWorkCallback)( 1424 void *cls, 1425 const char *instance, 1426 struct TALER_FullPayto payto_uri, 1427 const char *credit_facade_url, 1428 const json_t *credit_facade_credentials, 1429 uint64_t last_serial); 1430 1431 1432 /** 1433 * Function called with information about a wire transfer. 1434 * 1435 * @param cls closure with a `json_t *` array to build up the response 1436 * @param expected_credit_amount how we expect to see wired to the merchant (minus fees), NULL if unknown 1437 * @param wtid wire transfer identifier 1438 * @param payto_uri target account that received the wire transfer 1439 * @param exchange_url base URL of the exchange that made the wire transfer 1440 * @param transfer_serial_id serial number identifying the transfer in the backend 1441 * @param expected_transfer_serial_id serial number identifying the expected transfer in the backend, 0 if not @a expected 1442 * @param execution_time when did the exchange make the transfer, #GNUNET_TIME_UNIT_FOREVER_ABS 1443 * if it did not yet happen 1444 * @param expected true if the merchant acknowledged the wire transfer reception 1445 */ 1446 typedef void 1447 (*TALER_MERCHANTDB_TransferCallback)( 1448 void *cls, 1449 const struct TALER_Amount *expected_credit_amount, 1450 const struct TALER_WireTransferIdentifierRawP *wtid, 1451 struct TALER_FullPayto payto_uri, 1452 const char *exchange_url, 1453 uint64_t transfer_serial_id, 1454 uint64_t expected_transfer_serial_id, 1455 struct GNUNET_TIME_Absolute execution_time, 1456 bool expected); 1457 1458 1459 /** 1460 * Function called with information about expected incoming wire transfers. 1461 * 1462 * @param cls closure with a `json_t *` array to build up the response 1463 * @param expected_credit_amount how we expect to see wired to the merchant (minus fees), NULL if unknown 1464 * @param wtid wire transfer identifier 1465 * @param payto_uri target account that received the wire transfer 1466 * @param exchange_url base URL of the exchange that made the wire transfer 1467 * @param expected_transfer_serial_id serial number identifying the expected transfer in the backend 1468 * @param execution_time when did the exchange claim to have made the transfer 1469 * @param confirmed true if the merchant confirmed this wire transfer 1470 * false if it is so far only claimed to have been made by the exchange 1471 * @param validated true if the reconciliation succeeded 1472 * @param last_http_status HTTP status of our last request to the exchange for this transfer 1473 * @param last_ec last error code we got back (otherwise #TALER_EC_NONE) 1474 * @param last_error_detail last detail we got back (or NULL for none) 1475 */ 1476 typedef void 1477 (*TALER_MERCHANTDB_IncomingCallback)( 1478 void *cls, 1479 const struct TALER_Amount *expected_credit_amount, 1480 const struct TALER_WireTransferIdentifierRawP *wtid, 1481 struct TALER_FullPayto payto_uri, 1482 const char *exchange_url, 1483 uint64_t expected_transfer_serial_id, 1484 struct GNUNET_TIME_Timestamp execution_time, 1485 bool confirmed, 1486 bool validated, 1487 unsigned int last_http_status, 1488 enum TALER_ErrorCode last_ec, 1489 const char *last_error_detail); 1490 1491 1492 /** 1493 * If the given account is feasible, add it to the array 1494 * of accounts we return. 1495 * 1496 * @param cls closure 1497 * @param payto_uri URI of the account 1498 * @param conversion_url URL of a conversion service 1499 * @param debit_restrictions restrictions for debits from account 1500 * @param credit_restrictions restrictions for credits to account 1501 * @param master_sig signature affirming the account 1502 */ 1503 typedef void 1504 (*TALER_MERCHANTDB_ExchangeAccountCallback) ( 1505 void *cls, 1506 struct TALER_FullPayto payto_uri, 1507 const char *conversion_url, 1508 const json_t *debit_restrictions, 1509 const json_t *credit_restrictions, 1510 const struct TALER_MasterSignatureP *master_sig); 1511 1512 1513 /** 1514 * Function called with information about a coin that was deposited. 1515 * 1516 * @param cls closure 1517 * @param deposit_serial which deposit operation is this about 1518 * @param exchange_url URL of the exchange that issued the coin 1519 * @param h_wire hash of merchant's wire details 1520 * @param deposit_timestamp when was the deposit made 1521 * @param amount_with_fee amount the exchange will deposit for this coin 1522 * @param deposit_fee fee the exchange will charge for this coin 1523 * @param coin_pub public key of the coin 1524 */ 1525 typedef void 1526 (*TALER_MERCHANTDB_DepositedCoinsCallback)( 1527 void *cls, 1528 uint64_t deposit_serial, 1529 const char *exchange_url, 1530 const struct TALER_MerchantWireHashP *h_wire, 1531 struct GNUNET_TIME_Timestamp deposit_timestamp, 1532 const struct TALER_Amount *amount_with_fee, 1533 const struct TALER_Amount *deposit_fee, 1534 const struct TALER_CoinSpendPublicKeyP *coin_pub); 1535 1536 1537 /** 1538 * Function called with information about a coin that was deposited. 1539 * 1540 * @param cls closure 1541 * @param exchange_url URL of the exchange that issued the coin 1542 * @param amount_with_fee amount the exchange will deposit for this coin 1543 * @param deposit_fee fee the exchange will charge for this coin 1544 * @param refund_fee fee the exchange will charge for refunding this coin 1545 * @param wire_fee wire fee the exchange charges 1546 * @param h_wire hash of merchant's wire details 1547 * @param deposit_timestamp when did the exchange receive the deposit 1548 * @param refund_deadline until when are refunds allowed 1549 * @param exchange_sig signature by the exchange 1550 * @param exchange_pub exchange signing key used for @a exchange_sig 1551 */ 1552 typedef void 1553 (*TALER_MERCHANTDB_CoinDepositCallback)( 1554 void *cls, 1555 const char *exchange_url, 1556 const struct TALER_Amount *amount_with_fee, 1557 const struct TALER_Amount *deposit_fee, 1558 const struct TALER_Amount *refund_fee, 1559 const struct TALER_Amount *wire_fee, 1560 const struct TALER_MerchantWireHashP *h_wire, 1561 struct GNUNET_TIME_Timestamp deposit_timestamp, 1562 struct GNUNET_TIME_Timestamp refund_deadline, 1563 const struct TALER_ExchangeSignatureP *exchange_sig, 1564 const struct TALER_ExchangePublicKeyP *exchange_pub); 1565 1566 1567 /** 1568 * Possible token family kinds. 1569 */ 1570 enum TALER_MERCHANTDB_TokenFamilyKind 1571 { 1572 1573 /** 1574 * Token family representing a discount token 1575 */ 1576 TALER_MERCHANTDB_TFK_Discount = 0, 1577 1578 /** 1579 * Token family representing a subscription token 1580 */ 1581 TALER_MERCHANTDB_TFK_Subscription = 1, 1582 1583 }; 1584 1585 1586 /** 1587 * Typically called by `lookup_token_families`. 1588 * 1589 * @param cls closure 1590 * @param slug slug of the token family 1591 * @param name name of the token family 1592 * @param description description of the token family 1593 * @param description_i18n Internationalized token family description. 1594 * @param start_time start time of the token family's validity period 1595 * @param expiration end time of the token family's validity period 1596 * @param kind kind of the token family 1597 */ 1598 typedef void 1599 (*TALER_MERCHANTDB_TokenFamiliesCallback)( 1600 void *cls, 1601 const char *slug, 1602 const char *name, 1603 const char *description, 1604 const json_t *description_i18n, 1605 struct GNUNET_TIME_Timestamp start_time, 1606 struct GNUNET_TIME_Timestamp expiration, 1607 const char *kind); 1608 1609 1610 /** 1611 * Typically called by `select_money_pots`. 1612 * 1613 * @param cls closure 1614 * @param name set to name of the pot 1615 * @param pot_total_len length of @a pot_totals array 1616 * @param pot_totals amounts currently in the pot 1617 */ 1618 typedef void 1619 (*TALER_MERCHANTDB_MoneyPotsCallback)( 1620 void *cls, 1621 uint64_t money_pot_id, 1622 const char *name, 1623 size_t pot_total_len, 1624 const struct TALER_Amount *pot_totals); 1625 1626 1627 /** 1628 * Typically called by `select_reports`. 1629 * 1630 * @param cls closure 1631 * @param name name of the report 1632 * @param description description of the report 1633 * @param frequency the report frequency 1634 */ 1635 typedef void 1636 (*TALER_MERCHANTDB_ReportsCallback)( 1637 void *cls, 1638 uint64_t report_id, 1639 const char *report_description, 1640 struct GNUNET_TIME_Relative frequency); 1641 1642 1643 /** 1644 * Typically called by `lookup_reports_pending`. 1645 * 1646 * @param cls closure 1647 * @param instance_id name of the instance 1648 * @param report_id serial number of the report 1649 * @param report_program_section configuration section of program 1650 * for report generation 1651 * @param report_description text describing the report 1652 * @param mime_type mime type to request 1653 * @param report_token token to authorize access to the data source 1654 * @param target_address where to send report data 1655 * @param frequency report frequency 1656 * @param frequency_shift how much to shift the report time from a 1657 * multiple of the report @a frequency 1658 * @param next_transmission when is the next transmission of this report 1659 * due 1660 * @param one_shot true if the report should be removed from the 1661 * list after generation instead of being repeated 1662 */ 1663 typedef void 1664 (*TALER_MERCHANTDB_ReportsPendingCallback)( 1665 void *cls, 1666 const char *instance_id, 1667 uint64_t report_id, 1668 const char *report_program_section, 1669 const char *report_description, 1670 const char *mime_type, 1671 const struct TALER_MERCHANT_ReportToken *report_token, 1672 const char *target_address, 1673 struct GNUNET_TIME_Relative frequency, 1674 struct GNUNET_TIME_Relative frequency_shift, 1675 struct GNUNET_TIME_Absolute next_transmission, 1676 bool one_shot); 1677 1678 1679 /** 1680 * Typically called by `select_product_groups`. 1681 * 1682 * @param cls closure 1683 * @param product_group_id ID of the product group 1684 * @param group_name set to name of the group 1685 * @param group_description set to description of the group 1686 */ 1687 typedef void 1688 (*TALER_MERCHANTDB_ProductGroupsCallback)( 1689 void *cls, 1690 uint64_t product_group_id, 1691 const char *group_name, 1692 const char *group_description); 1693 1694 1695 /** 1696 * Details about a token family. 1697 */ 1698 struct TALER_MERCHANTDB_TokenFamilyDetails 1699 { 1700 /** 1701 * Token family slug used for identification. 1702 */ 1703 char *slug; 1704 1705 /** 1706 * User readable name of the token family. 1707 */ 1708 char *name; 1709 1710 /** 1711 * Description of the token family. 1712 */ 1713 char *description; 1714 1715 /** 1716 * Internationalized token family description. 1717 */ 1718 json_t *description_i18n; 1719 1720 /** 1721 * Meta-data associated with the token family. 1722 * Includes information like "trusted_domains" or 1723 * "expected_domains", if set. 1724 */ 1725 json_t *extra_data; 1726 1727 /** 1728 * Cipher that should be used for this token family. Note: We do not expose 1729 * this over the API and do not let clients set it. NULL for default (when 1730 * calling database). 1731 */ 1732 char *cipher_spec; 1733 1734 /** 1735 * Start time of the token family duration. 1736 */ 1737 struct GNUNET_TIME_Timestamp valid_after; 1738 1739 /** 1740 * End time of the token family duration. 1741 */ 1742 struct GNUNET_TIME_Timestamp valid_before; 1743 1744 /** 1745 * Validity duration of the token family. Must be larger or 1746 * equal to @a rounding plus @a start_offset_s. 1747 */ 1748 struct GNUNET_TIME_Relative duration; 1749 1750 /** 1751 * Rounding duration of the token family. 1752 */ 1753 struct GNUNET_TIME_Relative validity_granularity; 1754 1755 /** 1756 * Offset (in seconds) to subtract from the rounded 1757 * validity start period. 1758 */ 1759 struct GNUNET_TIME_Relative start_offset; 1760 1761 /** 1762 * Token family kind. 1763 */ 1764 enum TALER_MERCHANTDB_TokenFamilyKind kind; 1765 1766 /** 1767 * Counter for each issued token of this family. 1768 */ 1769 uint64_t issued; 1770 1771 /** 1772 * Counter for each used token of this family. 1773 */ 1774 uint64_t used; 1775 }; 1776 1777 1778 /** 1779 * Details about a token key. 1780 */ 1781 struct TALER_MERCHANTDB_TokenFamilyKeyDetails 1782 { 1783 /** 1784 * Tokens signed with this key are valid from this date on. 1785 * This is the time the key was created. 1786 */ 1787 struct GNUNET_TIME_Timestamp signature_validity_start; // valid_after; 1788 1789 /** 1790 * Tokens signed with this key are valid until this date. 1791 */ 1792 struct GNUNET_TIME_Timestamp signature_validity_end; // valid_before; 1793 1794 /** 1795 * Private key expires for use at this time. Signatures can 1796 * only be created until this point. 1797 */ 1798 struct GNUNET_TIME_Timestamp private_key_deleted_at; 1799 1800 /** 1801 * Token family public key. 1802 */ 1803 struct TALER_TokenIssuePublicKey pub; 1804 1805 /** 1806 * Token family private key. 1807 */ 1808 struct TALER_TokenIssuePrivateKey priv; 1809 1810 /** 1811 * Details about the token family this key belongs to. 1812 */ 1813 struct TALER_MERCHANTDB_TokenFamilyDetails token_family; 1814 }; 1815 1816 1817 /** 1818 * Function called with applicable token keys. 1819 * 1820 * @param cls closure 1821 * @param details details about an applicable key 1822 */ 1823 typedef void 1824 (*TALER_MERCHANTDB_TokenKeyCallback) ( 1825 void *cls, 1826 const struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details); 1827 1828 1829 /** 1830 * Details about a spent token. 1831 */ 1832 struct TALER_MERCHANTDB_SpentTokenDetails 1833 { 1834 /** 1835 * Public key of the spent token. 1836 */ 1837 struct TALER_TokenUsePublicKeyP pub; 1838 1839 /** 1840 * Signature that this token was spent on the specified order. 1841 */ 1842 struct TALER_TokenUseSignatureP sig; 1843 1844 /** 1845 * Blind signature for the spent token to prove validity of it. 1846 */ 1847 struct TALER_BlindedTokenIssueSignature blind_sig; 1848 }; 1849 1850 1851 /** 1852 * Function called with information about a token that was used. 1853 * 1854 * @param cls closure 1855 * @param spent_token_serial which used token is this about 1856 * @param h_contract_terms hash of the contract terms this token was used on 1857 * @param h_issue_pub hash of the token issue public key 1858 * @param use_pub token use public key 1859 * @param use_sig token use signature 1860 * @param issue_sig unblinded token issue signature 1861 */ 1862 typedef void 1863 (*TALER_MERCHANTDB_UsedTokensCallback)( 1864 void *cls, 1865 uint64_t spent_token_serial, 1866 const struct TALER_PrivateContractHashP *h_contract_terms, 1867 const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub, 1868 const struct TALER_TokenUsePublicKeyP *use_pub, 1869 const struct TALER_TokenUseSignatureP *use_sig, 1870 const struct TALER_TokenIssueSignature *issue_sig); 1871 1872 1873 /** 1874 * Returns amount-valued statistics by bucket. 1875 * Called by `lookup_statistics_amount_by_bucket`. 1876 * 1877 * @param cls closure 1878 * @param description description of the statistic 1879 * @param bucket_start start time of the bucket 1880 * @param bucket_end end time of the bucket 1881 * @param bucket_range range of the bucket 1882 * @param cumulative_amounts_len the length of @a cumulative_amounts 1883 * @param cumulative_amounts the cumulative amounts array 1884 */ 1885 typedef void 1886 (*TALER_MERCHANTDB_AmountByBucketStatisticsCallback)( 1887 void *cls, 1888 const char *description, 1889 struct GNUNET_TIME_Timestamp bucket_start, 1890 struct GNUNET_TIME_Timestamp bucket_end, 1891 const char *bucket_range, 1892 unsigned int cumulative_amounts_len, 1893 const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); 1894 1895 1896 /** 1897 * Returns amount-valued statistics by bucket. 1898 * Called by `lookup_statistics_amount_by_bucket2`. 1899 * 1900 * @param cls closure 1901 * @param bucket_start start time of the bucket 1902 * @param cumulative_amounts_len the length of @a cumulative_amounts 1903 * @param cumulative_amounts the cumulative amounts array 1904 */ 1905 typedef void 1906 (*TALER_MERCHANTDB_AmountByBucketStatisticsCallback2)( 1907 void *cls, 1908 struct GNUNET_TIME_Timestamp bucket_start, 1909 unsigned int cumulative_amounts_len, 1910 const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); 1911 1912 1913 /** 1914 * Returns amount-valued statistics over a particular time interval. 1915 * Called by `lookup_statistics_amount_by_interval`. 1916 * 1917 * @param cls closure 1918 * @param description description of the statistic 1919 * @param interval_start start time of the bucket 1920 * @param cumulative_amounts_len the length of @a cumulative_amounts 1921 * @param cumulative_amounts the cumulative amounts array 1922 */ 1923 typedef void 1924 (*TALER_MERCHANTDB_AmountByIntervalStatisticsCallback)( 1925 void *cls, 1926 const char *description, 1927 struct GNUNET_TIME_Timestamp interval_start, 1928 unsigned int cumulative_amounts_len, 1929 const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); 1930 1931 1932 /** 1933 * Function returning integer-valued statistics for a bucket. 1934 * Called by `lookup_statistics_counter_by_bucket`. 1935 * 1936 * @param cls closure 1937 * @param description description of the statistic 1938 * @param bucket_start start time of the bucket 1939 * @param bucket_end end time of the bucket 1940 * @param bucket_range range of the bucket 1941 * @param cumulative_counter counter value 1942 */ 1943 typedef void 1944 (*TALER_MERCHANTDB_CounterByBucketStatisticsCallback)( 1945 void *cls, 1946 const char *description, 1947 struct GNUNET_TIME_Timestamp bucket_start, 1948 struct GNUNET_TIME_Timestamp bucket_end, 1949 const char *bucket_range, 1950 uint64_t cumulative_counter); 1951 1952 1953 /** 1954 * Function returning reconciliation details for an 1955 * expected incoming wire transfer. 1956 * Called by `lookup_reconciliation_details`. 1957 * 1958 * @param cls closure 1959 * @param order_id order that was paid and then aggregated 1960 * @param remaining_deposit deposited amount minus any refunds 1961 * @param deposit_fee deposit fees paid to the exchange for the order 1962 */ 1963 typedef void 1964 (*TALER_MERCHANTDB_ReconciliationDetailsCallback)( 1965 void *cls, 1966 const char *order_id, 1967 const struct TALER_Amount *remaining_deposit, 1968 const struct TALER_Amount *deposit_fee); 1969 1970 1971 /** 1972 * Details about a statistic with counter. 1973 */ 1974 struct TALER_MERCHANTDB_StatisticsCounterByBucketDetails 1975 { 1976 /** 1977 * Start time of the bucket (inclusive). 1978 */ 1979 struct GNUNET_TIME_Timestamp start_time; 1980 1981 /** 1982 * End time of the bucket (exclusive). 1983 */ 1984 struct GNUNET_TIME_Timestamp end_time; 1985 1986 /** 1987 * Description of the statistic 1988 */ 1989 char*description; 1990 1991 /** 1992 * Range of the bucket 1993 */ 1994 char *range; 1995 1996 /** 1997 * Sum of all counters falling under the given 1998 * SLUG within this timeframe 1999 */ 2000 uint64_t cumulative_number; 2001 }; 2002 2003 /** 2004 * Details about a statistic with counter. 2005 */ 2006 struct TALER_MERCHANTDB_StatisticsCounterByIntervalDetails 2007 { 2008 /** 2009 * Start time of the interval. 2010 * The interval always ends at the response generation time. 2011 */ 2012 struct GNUNET_TIME_Timestamp start_time; 2013 2014 /** 2015 * Sum of all counters falling under the given 2016 * SLUG within this timeframe 2017 */ 2018 uint64_t cumulative_counter; 2019 }; 2020 2021 2022 /** 2023 * Function returning integer-valued statistics for a time interval. 2024 * Called by `lookup_statistics_counter_by_interval`. 2025 * 2026 * @param cls closure 2027 * @param description description of the statistic 2028 * @param interval_start start time of the interval 2029 * @param cumulative_counter counter value 2030 */ 2031 typedef void 2032 (*TALER_MERCHANTDB_CounterByIntervalStatisticsCallback)( 2033 void *cls, 2034 const char *description, 2035 struct GNUNET_TIME_Timestamp interval_start, 2036 uint64_t cumulative_counter); 2037 2038 2039 /** 2040 * Function returning integer-valued statistics for a bucket. 2041 * Called by `lookup_statistics_counter_by_bucket2`. 2042 * 2043 * @param cls closure 2044 * @param bucket_start start time of the bucket 2045 * @param counters_len the length of @a cumulative_amounts 2046 * @param descriptions description for the counter in the bucket 2047 * @param counters the counters in the bucket 2048 */ 2049 typedef void 2050 (*TALER_MERCHANTDB_CounterByBucketStatisticsCallback2)( 2051 void *cls, 2052 struct GNUNET_TIME_Timestamp bucket_start, 2053 unsigned int counters_len, 2054 const char *descriptions[static counters_len], 2055 uint64_t counters[static counters_len]); 2056 2057 2058 /** 2059 * Handle to interact with the database. 2060 * 2061 * Functions ending with "_TR" run their OWN transaction scope 2062 * and MUST NOT be called from within a transaction setup by the 2063 * caller. Functions ending with "_NT" require the caller to 2064 * setup a transaction scope. Functions without a suffix are 2065 * simple, single SQL queries that MAY be used either way. 2066 */ 2067 struct TALER_MERCHANTDB_Plugin 2068 { 2069 2070 /** 2071 * Closure for all callbacks. 2072 */ 2073 void *cls; 2074 2075 /** 2076 * Name of the library which generated this plugin. Set by the 2077 * plugin loader. 2078 */ 2079 char *library_name; 2080 2081 /** 2082 * Connect to the database. 2083 * 2084 * @param cls closure 2085 */ 2086 enum GNUNET_GenericReturnValue 2087 (*connect)(void *cls); 2088 2089 /** 2090 * Drop merchant tables. Used for testcases and to reset the DB. 2091 * 2092 * @param cls closure 2093 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 2094 */ 2095 enum GNUNET_GenericReturnValue 2096 (*drop_tables)(void *cls); 2097 2098 /** 2099 * Garbage collect database. Removes unnecessary data. 2100 * 2101 * @param cls closure 2102 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 2103 */ 2104 enum GNUNET_GenericReturnValue 2105 (*gc)(void *cls); 2106 2107 /** 2108 * Initialize merchant tables 2109 * 2110 * @param cls closure 2111 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 2112 */ 2113 enum GNUNET_GenericReturnValue 2114 (*create_tables)(void *cls); 2115 2116 /** 2117 * Register callback to be invoked on events of type @a es. 2118 * 2119 * @param cls database context to use 2120 * @param es specification of the event to listen for 2121 * @param timeout how long to wait for the event 2122 * @param cb function to call when the event happens, possibly 2123 * multiple times (until cancel is invoked) 2124 * @param cb_cls closure for @a cb 2125 * @return handle useful to cancel the listener 2126 */ 2127 struct GNUNET_DB_EventHandler * 2128 (*event_listen)(void *cls, 2129 const struct GNUNET_DB_EventHeaderP *es, 2130 struct GNUNET_TIME_Relative timeout, 2131 GNUNET_DB_EventCallback cb, 2132 void *cb_cls); 2133 2134 /** 2135 * Stop notifications. 2136 * 2137 * @param eh handle to unregister. 2138 */ 2139 void 2140 (*event_listen_cancel)(struct GNUNET_DB_EventHandler *eh); 2141 2142 2143 /** 2144 * Notify all that listen on @a es of an event. 2145 * 2146 * @param cls database context to use 2147 * @param es specification of the event to generate 2148 * @param extra additional event data provided 2149 * @param extra_size number of bytes in @a extra 2150 */ 2151 void 2152 (*event_notify)(void *cls, 2153 const struct GNUNET_DB_EventHeaderP *es, 2154 const void *extra, 2155 size_t extra_size); 2156 2157 2158 /** 2159 * Do a pre-flight check that we are not in an uncommitted transaction. If 2160 * we are, die. Does not return anything, as we will continue regardless of 2161 * the outcome. 2162 * 2163 * @param cls the `struct PostgresClosure` with the plugin-specific state 2164 */ 2165 void 2166 (*preflight) (void *cls); 2167 2168 /** 2169 * Start a transaction. 2170 * 2171 * @param cls the `struct PostgresClosure` with the plugin-specific state 2172 * @param name unique name identifying the transaction (for debugging), 2173 * must point to a constant 2174 * @return #GNUNET_OK on success 2175 */ 2176 enum GNUNET_GenericReturnValue 2177 (*start)(void *cls, 2178 const char *name); 2179 2180 /** 2181 * Start a transaction with isolation level 'read committed'. 2182 * 2183 * @param cls the `struct PostgresClosure` with the plugin-specific state 2184 * @param name unique name identifying the transaction (for debugging), 2185 * must point to a constant 2186 * @return #GNUNET_OK on success 2187 */ 2188 enum GNUNET_GenericReturnValue 2189 (*start_read_committed)(void *cls, 2190 const char *name); 2191 2192 /** 2193 * Roll back the current transaction of a database connection. 2194 * 2195 * @param cls the `struct PostgresClosure` with the plugin-specific state 2196 */ 2197 void 2198 (*rollback) (void *cls); 2199 2200 /** 2201 * Commit the current transaction of a database connection. 2202 * 2203 * @param cls the `struct PostgresClosure` with the plugin-specific state 2204 * @return transaction status 2205 */ 2206 enum GNUNET_DB_QueryStatus 2207 (*commit)(void *cls); 2208 2209 /** 2210 * Lookup all of the instances this backend has configured. 2211 * 2212 * @param cls closure 2213 * @param active_only only find 'active' instances 2214 * @param cb function to call on all instances found 2215 * @param cb_cls closure for @a cb 2216 */ 2217 enum GNUNET_DB_QueryStatus 2218 (*lookup_instances)(void *cls, 2219 bool active_only, 2220 TALER_MERCHANTDB_InstanceCallback cb, 2221 void *cb_cls); 2222 2223 /** 2224 * Lookup one of the instances this backend has configured. 2225 * 2226 * @param cls closure 2227 * @param id ID of instance to look up 2228 * @param active_only only find 'active' instances 2229 * @param cb function to call on all instances found 2230 * @param cb_cls closure for @a cb 2231 */ 2232 enum GNUNET_DB_QueryStatus 2233 (*lookup_instance)(void *cls, 2234 const char *id, 2235 bool active_only, 2236 TALER_MERCHANTDB_InstanceCallback cb, 2237 void *cb_cls); 2238 2239 /** 2240 * Lookup authentication data of an instance. 2241 * 2242 * @param cls closure 2243 * @param instance_id instance to query 2244 * @param[out] ias where to store the auth data 2245 */ 2246 enum GNUNET_DB_QueryStatus 2247 (*lookup_instance_auth)(void *cls, 2248 const char *instance_id, 2249 struct TALER_MERCHANTDB_InstanceAuthSettings *ias); 2250 2251 2252 /** 2253 * Insert information about an instance into our database. 2254 * 2255 * @param cls closure 2256 * @param merchant_pub public key of the instance 2257 * @param merchant_priv private key of the instance 2258 * @param is details about the instance 2259 * @param validation_needed true if validation is 2260 * required before the instance can be used 2261 * @return database result code 2262 */ 2263 enum GNUNET_DB_QueryStatus 2264 (*insert_instance)(void *cls, 2265 const struct TALER_MerchantPublicKeyP *merchant_pub, 2266 const struct TALER_MerchantPrivateKeyP *merchant_priv, 2267 const struct TALER_MERCHANTDB_InstanceSettings *is, 2268 const struct TALER_MERCHANTDB_InstanceAuthSettings *ias, 2269 bool validation_needed); 2270 2271 2272 /** 2273 * Insert information about an instance's account into our database. 2274 * 2275 * @param cls closure 2276 * @param account_details details about the account 2277 * @return database result code 2278 */ 2279 enum GNUNET_DB_QueryStatus 2280 (*insert_account)( 2281 void *cls, 2282 const struct TALER_MERCHANTDB_AccountDetails *account_details); 2283 2284 2285 /** 2286 * Insert instance login token into our database. 2287 * 2288 * @param cls closure 2289 * @param id identifier of the instance 2290 * @param token value of the token 2291 * @param creation_time the current time 2292 * @param expiration_time when does the token expire 2293 * @param validity_scope scope of the token 2294 * @param description description of the token 2295 * @return database result code 2296 */ 2297 enum GNUNET_DB_QueryStatus 2298 (*insert_login_token)( 2299 void *cls, 2300 const char *id, 2301 const struct TALER_MERCHANTDB_LoginTokenP *token, 2302 struct GNUNET_TIME_Timestamp creation_time, 2303 struct GNUNET_TIME_Timestamp expiration_time, 2304 uint32_t validity_scope, 2305 const char *description); 2306 2307 2308 /** 2309 * Lookup information about a login token from database. 2310 * 2311 * @param cls closure 2312 * @param id identifier of the instance 2313 * @param token value of the token 2314 * @param[out] expiration_time set to expiration time 2315 * @param[out] validity_scope set to scope of the token 2316 * @return database result code 2317 */ 2318 enum GNUNET_DB_QueryStatus 2319 (*select_login_token)( 2320 void *cls, 2321 const char *id, 2322 const struct TALER_MERCHANTDB_LoginTokenP *token, 2323 struct GNUNET_TIME_Timestamp *expiration_time, 2324 uint32_t *validity_scope); 2325 2326 /** 2327 * Lookup login tokens for instance. 2328 * 2329 * @param cls closure 2330 * @param instance_id instance to lookup tokens for 2331 * @param offset transfer_serial number of the transfer we want to offset from 2332 * @param limit number of entries to return, negative for descending, 2333 * positive for ascending 2334 * @param cb function to call on all products found 2335 * @param cb_cls closure for @a cb 2336 * @return database result code 2337 */ 2338 enum GNUNET_DB_QueryStatus 2339 (*lookup_login_tokens)(void *cls, 2340 const char *instance_id, 2341 uint64_t offset, 2342 int64_t limit, 2343 TALER_MERCHANTDB_LoginTokensCallback cb, 2344 void *cb_cls); 2345 2346 /** 2347 * Delete login token from database. 2348 * 2349 * @param cls closure 2350 * @param id identifier of the instance 2351 * @param token value of the token 2352 * @return database result code 2353 */ 2354 enum GNUNET_DB_QueryStatus 2355 (*delete_login_token)( 2356 void *cls, 2357 const char *id, 2358 const struct TALER_MERCHANTDB_LoginTokenP *token); 2359 2360 /** 2361 * Delete login token from database by serial. 2362 * 2363 * @param cls closure 2364 * @param id identifier of the instance 2365 * @param serial serial of the token 2366 * @return database result code 2367 */ 2368 enum GNUNET_DB_QueryStatus 2369 (*delete_login_token_serial)( 2370 void *cls, 2371 const char *id, 2372 uint64_t serial); 2373 2374 2375 /** 2376 * Update information about an instance's account into our database. 2377 * 2378 * @param cls closure 2379 * @param id identifier of the instance 2380 * @param h_wire which account to update 2381 * @param extra_wire_subject_metadata additional metadata to include in wire transfer subjects 2382 * @param credit_facade_url new facade URL, can be NULL 2383 * @param credit_facade_credentials new credentials, can be NULL 2384 * @return database result code 2385 */ 2386 enum GNUNET_DB_QueryStatus 2387 (*update_account)( 2388 void *cls, 2389 const char *id, 2390 const struct TALER_MerchantWireHashP *h_wire, 2391 const char *extra_wire_subject_metadata, 2392 const char *credit_facade_url, 2393 const json_t *credit_facade_credentials); 2394 2395 2396 /** 2397 * Obtain information about an instance's accounts. 2398 * 2399 * @param cls closure 2400 * @param id identifier of the instance 2401 * @param cb function to call on each account 2402 * @param cb_cls closure for @a cb 2403 * @return database result code 2404 */ 2405 enum GNUNET_DB_QueryStatus 2406 (*select_accounts)( 2407 void *cls, 2408 const char *id, 2409 TALER_MERCHANTDB_AccountCallback cb, 2410 void *cb_cls); 2411 2412 2413 /** 2414 * Obtain detailed information about an instance's account. 2415 * 2416 * @param cls closure 2417 * @param id identifier of the instance 2418 * @param h_wire wire hash of the account 2419 * @param[out] ad account details returned 2420 * @return database result code 2421 */ 2422 enum GNUNET_DB_QueryStatus 2423 (*select_account)( 2424 void *cls, 2425 const char *id, 2426 const struct TALER_MerchantWireHashP *h_wire, 2427 struct TALER_MERCHANTDB_AccountDetails *ad); 2428 2429 2430 /** 2431 * Obtain detailed information about an instance's account. 2432 * 2433 * @param cls closure 2434 * @param id identifier of the instance 2435 * @param payto_uri URI of the account 2436 * @param[out] ad account details returned 2437 * @return database result code 2438 */ 2439 enum GNUNET_DB_QueryStatus 2440 (*select_account_by_uri)( 2441 void *cls, 2442 const char *id, 2443 struct TALER_FullPayto payto_uri, 2444 struct TALER_MERCHANTDB_AccountDetails *ad); 2445 2446 2447 /** 2448 * Delete private key of an instance from our database. 2449 * 2450 * @param cls closure 2451 * @param merchant_id identifier of the instance 2452 * @return database result code 2453 */ 2454 enum GNUNET_DB_QueryStatus 2455 (*delete_instance_private_key)( 2456 void *cls, 2457 const char *merchant_id); 2458 2459 /** 2460 * Purge an instance and all associated information from our database. 2461 * Highly likely to cause undesired data loss. Use with caution. 2462 * 2463 * @param cls closure 2464 * @param merchant_id identifier of the instance 2465 * @return database result code 2466 */ 2467 enum GNUNET_DB_QueryStatus 2468 (*purge_instance)(void *cls, 2469 const char *merchant_id); 2470 2471 /** 2472 * Update information about an instance into our database. 2473 * 2474 * @param cls closure 2475 * @param is details about the instance 2476 * @return database result code 2477 */ 2478 enum GNUNET_DB_QueryStatus 2479 (*update_instance)(void *cls, 2480 const struct TALER_MERCHANTDB_InstanceSettings *is); 2481 2482 /** 2483 * Update information about an instance's authentication settings 2484 * into our database. 2485 * 2486 * @param cls closure 2487 * @param merchant_id merchant backend instance ID 2488 * @param ias instance auth settings 2489 * @return database result code 2490 */ 2491 enum GNUNET_DB_QueryStatus 2492 (*update_instance_auth)( 2493 void *cls, 2494 const char *merchant_id, 2495 const struct TALER_MERCHANTDB_InstanceAuthSettings *ias); 2496 2497 /** 2498 * Set an instance's account in our database to "inactive". 2499 * 2500 * @param cls closure 2501 * @param merchant_id merchant backend instance ID 2502 * @param h_wire hash of the wire account to set to inactive 2503 * @return database result code 2504 */ 2505 enum GNUNET_DB_QueryStatus 2506 (*inactivate_account)(void *cls, 2507 const char *merchant_id, 2508 const struct TALER_MerchantWireHashP *h_wire); 2509 2510 2511 /** 2512 * Set an instance's account in our database to "active". 2513 * 2514 * @param cls closure 2515 * @param account_details details of the account to actiate 2516 * @param[out] h_wire set to the hash of the salted payto URI 2517 * @param[out] salt set to salt used for computing @a h_wire 2518 * @param[out] not_found set to true if the instance was not found 2519 * @param[out] conflict set to true if a conflicting account is active 2520 * @return database result code 2521 */ 2522 enum GNUNET_DB_QueryStatus 2523 (*activate_account)( 2524 void *cls, 2525 const struct TALER_MERCHANTDB_AccountDetails *account_details, 2526 struct TALER_MerchantWireHashP *h_wire, 2527 struct TALER_WireSaltP *salt, 2528 bool *not_found, 2529 bool *conflict); 2530 2531 2532 /** 2533 * Check an instance's account's KYC status. Triggers 2534 * a request to taler-merchant-kyccheck to get a 2535 * KYC status update as a side-effect! 2536 * 2537 * @param cls closure 2538 * @param merchant_id merchant backend instance ID 2539 * @param h_wire hash of the wire account to check, 2540 * NULL to check all accounts of the merchant 2541 * @param exchange_url base URL of the exchange to check, 2542 * NULL to check all exchanges 2543 * @param kyc_cb KYC status callback to invoke 2544 * @param kyc_cb_cls closure for @a kyc_cb 2545 * @return database result code 2546 */ 2547 enum GNUNET_DB_QueryStatus 2548 (*account_kyc_get_status)( 2549 void *cls, 2550 const char *merchant_id, 2551 const struct TALER_MerchantWireHashP *h_wire, 2552 const char *exchange_url, 2553 TALER_MERCHANTDB_KycCallback kyc_cb, 2554 void *kyc_cb_cls); 2555 2556 2557 /** 2558 * Find accounts requiring KYC checks. 2559 * 2560 * @param cls closure 2561 * @param kyc_cb status callback to invoke 2562 * @param kyc_cb_cls closure for @a kyc_cb 2563 * @return database result code 2564 */ 2565 enum GNUNET_DB_QueryStatus 2566 (*account_kyc_get_outdated)( 2567 void *cls, 2568 TALER_MERCHANTDB_KycOutdatedCallback kyc_cb, 2569 void *kyc_cb_cls); 2570 2571 2572 /** 2573 * Check an account's KYC status at an exchange. 2574 * 2575 * @param cls closure 2576 * @param merchant_payto_uri merchant backend instance ID 2577 * @param instance_id the instance for which to check 2578 * @param exchange_url base URL of the exchange 2579 * @param[out] auth_ok true if @a access_token was set 2580 * @param[out] access_token set to access token for /kyc-info 2581 * @param[out] kyc_ok true if no urgent KYC work must be done for this account 2582 * @param[out] last_http_status set to last HTTP status from exchange on /kyc-check 2583 * @param[out] last_ec set to last Taler error code from exchange on /kyc-check 2584 * @param[out] rule_gen set to decision row at the exchange, 0 if no 2585 * known decision of the exchange exists for this record; used 2586 * for long-polling for changes to exchange decisions 2587 * @param[out] last_kyc_check set to time of last KYC check 2588 * @param[out] next_kyc_poll when should we check the KYC status next 2589 * @param[out] kyc_backoff current back-off frequency for KYC checks 2590 * @param[out] aml_review set to true if the account is under AML review (if this exposed) 2591 * @param[out] jlimits set to JSON array with AccountLimits, NULL if unknown (and likely defaults apply or KYC auth is urgently needed, see @a auth_ok) 2592 * @return database result code 2593 */ 2594 enum GNUNET_DB_QueryStatus 2595 (*get_kyc_status)( 2596 void *cls, 2597 struct TALER_FullPayto merchant_account_uri, 2598 const char *instance_id, 2599 const char *exchange_url, 2600 bool *auth_ok, 2601 struct TALER_AccountAccessTokenP *access_token, 2602 bool *kyc_ok, 2603 unsigned int *last_http_status, 2604 enum TALER_ErrorCode *last_ec, 2605 uint64_t *rule_gen, 2606 struct GNUNET_TIME_Timestamp *last_kyc_check, 2607 struct GNUNET_TIME_Absolute *next_kyc_poll, 2608 struct GNUNET_TIME_Relative *kyc_backoff, 2609 bool *aml_review, 2610 json_t **jlimits); 2611 2612 2613 /** 2614 * Check an account's KYC limits at an exchange. 2615 * 2616 * @param cls closure 2617 * @param merchant_payto_uri merchant backend instance ID 2618 * @param instance_id the instance for which to check 2619 * @param exchange_url base URL of the exchange 2620 * @param[out] kyc_ok true if no urgent KYC work must be done for this account 2621 * @param[out] no_access_token true if we do not have a valid KYC access token (KYC auth missing) 2622 * @param[out] jlimits set to JSON array with AccountLimits, NULL if unknown (and likely defaults apply or KYC auth is urgently needed, see @a auth_ok) 2623 * @return database result code 2624 */ 2625 enum GNUNET_DB_QueryStatus 2626 (*get_kyc_limits)( 2627 void *cls, 2628 struct TALER_FullPayto merchant_account_uri, 2629 const char *instance_id, 2630 const char *exchange_url, 2631 bool *kyc_ok, 2632 bool *no_access_token, 2633 json_t **jlimits); 2634 2635 2636 /** 2637 * Update an instance's account's KYC status. 2638 * 2639 * @param cls closure 2640 * @param merchant_id merchant backend instance ID 2641 * @param h_wire hash of the wire account to check 2642 * @param exchange_url base URL of the exchange to check 2643 * @param timestamp timestamp to store 2644 * @param next_time when should we next check the KYC status 2645 * @param kyc_backoff what is the current backoff between KYC status checks 2646 * @param exchange_http_status HTTP status code returned last by the exchange 2647 * @param exchange_ec_code Taler error code returned last by the exchange 2648 * @param rule_gen generation of the rule in the exchange database 2649 * (useful for long-polling to wait for rule changes) 2650 * @param access_token access token for the KYC process, NULL for none 2651 * @param jlimits JSON array with AccountLimits returned by the exchange 2652 * @param in_aml_review true if the exchange says the account is under review 2653 * @param kyc_ok current KYC status (true for satisfied) 2654 * @return database result code 2655 */ 2656 enum GNUNET_DB_QueryStatus 2657 (*account_kyc_set_status)( 2658 void *cls, 2659 const char *merchant_id, 2660 const struct TALER_MerchantWireHashP *h_wire, 2661 const char *exchange_url, 2662 struct GNUNET_TIME_Timestamp timestamp, 2663 struct GNUNET_TIME_Absolute next_time, 2664 struct GNUNET_TIME_Relative kyc_backoff, 2665 unsigned int exchange_http_status, 2666 enum TALER_ErrorCode exchange_ec_code, 2667 uint64_t rule_gen, 2668 const struct TALER_AccountAccessTokenP *access_token, 2669 const json_t *jlimits, 2670 bool in_aml_review, 2671 bool kyc_ok); 2672 2673 2674 /** 2675 * Set an instance's account's KYC status to failed. 2676 * 2677 * @param cls closure 2678 * @param merchant_id merchant backend instance ID 2679 * @param h_wire hash of the wire account to check 2680 * @param exchange_url base URL of the exchange to check 2681 * @param timestamp timestamp to store 2682 * @param exchange_http_status HTTP status code returned last by the exchange 2683 * @param kyc_ok current KYC status (should be false) 2684 * @return database result code 2685 */ 2686 enum GNUNET_DB_QueryStatus 2687 (*account_kyc_set_failed)( 2688 void *cls, 2689 const char *merchant_id, 2690 const struct TALER_MerchantWireHashP *h_wire, 2691 const char *exchange_url, 2692 struct GNUNET_TIME_Timestamp timestamp, 2693 unsigned int exchange_http_status, 2694 bool kyc_ok); 2695 2696 2697 /** 2698 * Lookup all of the products the given instance has configured. 2699 * 2700 * @param cls closure 2701 * @param instance_id instance to lookup products for 2702 * @param offset transfer_serial number of the transfer we want to offset from 2703 * @param limit number of entries to return, negative for descending, 2704 * positive for ascending 2705 * @param category_filter filter products by category, NULL to not filter; 2706 * uses the Postgresql "LIKE" pattern matcher, so 2707 * "%" stands for any sequence of zero or more characters, 2708 * "_" stands for any single character; 2709 * use "\%" and "\_" to exactly match "%" or "_". 2710 * We will always use case-insensitive searches, for case-sensitive 2711 * matching the client should filter the result set. 2712 * @param name_filter filter products by name, NULL to not filter 2713 * uses the Postgresql "LIKE" pattern matcher, so 2714 * "%" stands for any sequence of zero or more characters, 2715 * "_" stands for any single character 2716 * use "\%" and "\_" to exactly match "%" or "_". 2717 * We will always use case-insensitive searches, for case-sensitive 2718 * matching the client should filter the result set. 2719 * @param description_filter filter products by description, NULL to not filter 2720 * uses the Postgresql "LIKE" pattern matcher, so 2721 * "%" stands for any sequence of zero or more characters, 2722 * "_" stands for any single character 2723 * use "\%" and "\_" to exactly match "%" or "_". 2724 * We will always use case-insensitive searches, for case-sensitive 2725 * matching the client should filter the result set. 2726 * @param product_group_id_filter only return products in where the 2727 * product group ID matches the given ID, 0 to not filter 2728 * @param cb function to call on all products found 2729 * @param cb_cls closure for @a cb 2730 * @return database result code 2731 */ 2732 enum GNUNET_DB_QueryStatus 2733 (*lookup_products)(void *cls, 2734 const char *instance_id, 2735 uint64_t offset, 2736 int64_t limit, 2737 const char *category_filter, 2738 const char *name_filter, 2739 const char *description_filter, 2740 uint64_t product_group_id_filter, 2741 TALER_MERCHANTDB_ProductsCallback cb, 2742 void *cb_cls); 2743 2744 2745 /** 2746 * Lookup full details of all of the products the given instance has configured (expensive). 2747 * 2748 * @param cls closure 2749 * @param instance_id instance to lookup products for 2750 * @param cb function to call on all products found 2751 * @param cb_cls closure for @a cb 2752 * @return database result code 2753 */ 2754 enum GNUNET_DB_QueryStatus 2755 (*lookup_all_products)(void *cls, 2756 const char *instance_id, 2757 TALER_MERCHANTDB_ProductCallback cb, 2758 void *cb_cls); 2759 2760 /** 2761 * Lookup inventory details for all products of an instance. 2762 * 2763 * @param cls closure 2764 * @param instance_id instance to lookup products for 2765 * @param cb function to call on all products found 2766 * @param cb_cls closure for @a cb 2767 * @return database result code 2768 */ 2769 enum GNUNET_DB_QueryStatus 2770 (*lookup_inventory_products)(void *cls, 2771 const char *instance_id, 2772 TALER_MERCHANTDB_InventoryProductCallback cb, 2773 void *cb_cls); 2774 2775 /** 2776 * Lookup inventory details for a subset of products. 2777 * 2778 * @param cls closure 2779 * @param instance_id instance to lookup products for 2780 * @param product_ids product IDs to include (can be NULL/empty) 2781 * @param num_product_ids number of entries in @a product_ids 2782 * @param categories category IDs to include (can be NULL/empty) 2783 * @param num_categories number of entries in @a categories 2784 * @param cb function to call on all products found 2785 * @param cb_cls closure for @a cb 2786 * @return database result code 2787 */ 2788 enum GNUNET_DB_QueryStatus 2789 (*lookup_inventory_products_filtered)( 2790 void *cls, 2791 const char *instance_id, 2792 const char *const *product_ids, 2793 size_t num_product_ids, 2794 const uint64_t *categories, 2795 size_t num_categories, 2796 TALER_MERCHANTDB_InventoryProductCallback cb, 2797 void *cb_cls); 2798 2799 /** 2800 * Call @a cb on each exchange we have in the database. 2801 * 2802 * @param cls closure 2803 * @param cb callback to invoke 2804 * @param cb_cls closure for @a cb 2805 * @return transaction status code 2806 */ 2807 enum GNUNET_DB_QueryStatus 2808 (*select_exchanges) (void *cls, 2809 TALER_MERCHANTDB_ExchangesCallback cb, 2810 void *cb_cls); 2811 2812 /** 2813 * Lookup details about a particular product. 2814 * 2815 * @param cls closure 2816 * @param instance_id instance to lookup products for 2817 * @param product_id product to lookup 2818 * @param[out] pd set to the product details on success, can be NULL 2819 * (in that case we only want to check if the product exists) 2820 * @param[out] num_categories set to length of @a categories array 2821 * @param[out] categories set to array of categories the 2822 * product is in, caller must free() it. 2823 * @return database result code 2824 */ 2825 enum GNUNET_DB_QueryStatus 2826 (*lookup_product)(void *cls, 2827 const char *instance_id, 2828 const char *product_id, 2829 struct TALER_MERCHANTDB_ProductDetails *pd, 2830 size_t *num_categories, 2831 uint64_t **categories); 2832 2833 /** 2834 * Lookup product image by its hash. 2835 * 2836 * @param cls closure 2837 * @param instance_id instance to lookup products for 2838 * @param image_hash lowercase hexadecimal representation of the SHA256 hash 2839 * @param[out] image set to base64-encoded data URL on success, caller must free() 2840 * @return database result code 2841 */ 2842 enum GNUNET_DB_QueryStatus 2843 (*lookup_product_image_by_hash)(void *cls, 2844 const char *instance_id, 2845 const char *image_hash, 2846 char **image); 2847 2848 /** 2849 * Delete information about a product. Note that the transaction must 2850 * enforce that no stocks are currently locked. 2851 * 2852 * @param cls closure 2853 * @param instance_id instance to delete product of 2854 * @param product_id product to delete 2855 * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 2856 * if locks prevent deletion OR product unknown 2857 */ 2858 enum GNUNET_DB_QueryStatus 2859 (*delete_product)(void *cls, 2860 const char *instance_id, 2861 const char *product_id); 2862 2863 /** 2864 * Insert details about a particular product. 2865 * 2866 * @param cls closure 2867 * @param instance_id instance to insert product for 2868 * @param product_id product identifier of product to insert 2869 * @param pd the product details to insert 2870 * @param num_cats length of @a cats array 2871 * @param cats array of categories the product is in 2872 * @param[out] no_instance set to true if @a instance_id is unknown 2873 * @param[out] conflict set to true if a conflicting 2874 * product already exists in the database 2875 * @param[out] no_cat set to index of non-existing category from @a cats, or -1 if all @a cats were found 2876 * @param[out] no_group set to true if the product group in @a pd is unknown 2877 * @param[out] no_pot set to true if the money pot in @a pd is unknown 2878 * @return database result code 2879 */ 2880 enum GNUNET_DB_QueryStatus 2881 (*insert_product)(void *cls, 2882 const char *instance_id, 2883 const char *product_id, 2884 const struct TALER_MERCHANTDB_ProductDetails *pd, 2885 size_t num_cats, 2886 const uint64_t *cats, 2887 bool *no_instance, 2888 bool *conflict, 2889 ssize_t *no_cat, 2890 bool *no_group, 2891 bool *no_pot); 2892 2893 /** 2894 * Update details about a particular product. Note that the 2895 * transaction must enforce that the sold/stocked/lost counters 2896 * are not reduced (i.e. by expanding the WHERE clause on the existing 2897 * values). 2898 * 2899 * @param cls closure 2900 * @param instance_id instance to lookup products for 2901 * @param product_id product to lookup 2902 * @param pd product details with updated values 2903 * @param num_cats length of @a cats array 2904 * @param cats number of categories the product is in 2905 * @param[out] no_instance the update failed as the instance is unknown 2906 * @param[out] no_cat set to -1 on success, otherwise the update failed and this is set 2907 * to the index of a category in @a cats that is unknown 2908 * @param[out] no_product the @a product_id is unknown 2909 * @param[out] lost_reduced the update failed as the counter of units lost would have been lowered 2910 * @param[out] sold_reduced the update failed as the counter of units sold would have been lowered 2911 * @param[out] stocked_reduced the update failed as the counter of units stocked would have been lowered 2912 * @param[out] no_group set to true if the product group in @a pd is unknown 2913 * @param[out] no_pot set to true if the money pot in @a pd is unknown 2914 * @return database result code 2915 */ 2916 enum GNUNET_DB_QueryStatus 2917 (*update_product)(void *cls, 2918 const char *instance_id, 2919 const char *product_id, 2920 const struct TALER_MERCHANTDB_ProductDetails *pd, 2921 size_t num_cats, 2922 const uint64_t *cats, 2923 bool *no_instance, 2924 ssize_t *no_cat, 2925 bool *no_product, 2926 bool *lost_reduced, 2927 bool *sold_reduced, 2928 bool *stocked_reduced, 2929 bool *no_group, 2930 bool *no_pot); 2931 2932 2933 /** 2934 * Lock stocks of a particular product. Note that the transaction must 2935 * enforce that the "stocked-sold-lost >= locked" constraint holds. 2936 * 2937 * @param cls closure 2938 * @param instance_id instance to lookup products for 2939 * @param product_id product to lookup 2940 * @param uuid the UUID that holds the lock 2941 * @param quantity how many units should be locked 2942 * @param quantity_frac fractional component of units to lock, in units of 2943 * 1/1000000 of the base value 2944 * @param expiration_time when should the lock expire 2945 * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the 2946 * product is unknown OR if there insufficient stocks remaining 2947 */ 2948 enum GNUNET_DB_QueryStatus 2949 (*lock_product)(void *cls, 2950 const char *instance_id, 2951 const char *product_id, 2952 const struct GNUNET_Uuid *uuid, 2953 uint64_t quantity, 2954 uint32_t quantity_frac, 2955 struct GNUNET_TIME_Timestamp expiration_time); 2956 2957 2958 /** 2959 * Release all expired product locks, including 2960 * those from expired offers -- across all 2961 * instances. 2962 * 2963 * @param cls closure 2964 * @return database result code 2965 */ 2966 enum GNUNET_DB_QueryStatus 2967 (*expire_locks)(void *cls); 2968 2969 2970 /** 2971 * Delete information about an order. Note that the transaction must 2972 * enforce that the order is not awaiting payment anymore. 2973 * 2974 * @param cls closure 2975 * @param instance_id instance to delete order of 2976 * @param order_id order to delete 2977 * @param force force deletion of claimed but unpaid orders 2978 * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 2979 * if locks prevent deletion OR order unknown 2980 */ 2981 enum GNUNET_DB_QueryStatus 2982 (*delete_order)(void *cls, 2983 const char *instance_id, 2984 const char *order_id, 2985 bool force); 2986 2987 2988 /** 2989 * Retrieve order given its @a order_id and the @a instance_id. 2990 * 2991 * @param cls closure 2992 * @param instance_id instance to obtain order of 2993 * @param order_id order id used to perform the lookup 2994 * @param[out] claim_token the claim token generated for the order, 2995 * NULL to only test if the order exists 2996 * @param[out] h_post_data set to the hash of the POST data that created the order 2997 * @param[out] contract_terms where to store the retrieved contract terms, 2998 * NULL to only test if the order exists 2999 * @return transaction status 3000 */ 3001 enum GNUNET_DB_QueryStatus 3002 (*lookup_order)(void *cls, 3003 const char *instance_id, 3004 const char *order_id, 3005 struct TALER_ClaimTokenP *claim_token, 3006 struct TALER_MerchantPostDataHashP *h_post_data, 3007 json_t **contract_terms); 3008 3009 3010 /** 3011 * Retrieve order summary given its @a order_id and the @a instance_id. 3012 * 3013 * @param cls closure 3014 * @param instance_id instance to obtain order of 3015 * @param order_id order id used to perform the lookup 3016 * @param[out] timestamp when was the order created 3017 * @param[out] order_serial under which serial do we keep this order 3018 * @return transaction status 3019 */ 3020 enum GNUNET_DB_QueryStatus 3021 (*lookup_order_summary)(void *cls, 3022 const char *instance_id, 3023 const char *order_id, 3024 struct GNUNET_TIME_Timestamp *timestamp, 3025 uint64_t *order_serial); 3026 3027 3028 /** 3029 * Retrieve orders given the @a instance_id. 3030 * 3031 * @param cls closure 3032 * @param instance_id instance to obtain order of 3033 * @param of filter to apply when looking up orders 3034 * @param[out] contract_terms where to store the retrieved contract terms, 3035 * NULL to only test if the order exists 3036 * @return transaction status 3037 */ 3038 enum GNUNET_DB_QueryStatus 3039 (*lookup_orders)(void *cls, 3040 const char *instance_id, 3041 const struct TALER_MERCHANTDB_OrderFilter *of, 3042 TALER_MERCHANTDB_OrdersCallback cb, 3043 void *cb_cls); 3044 3045 3046 /** 3047 * Insert order into db. 3048 * 3049 * @param cls closure 3050 * @param instance_id identifies the instance responsible for the order 3051 * @param order_id alphanumeric string that uniquely identifies the order 3052 * @param session_id session ID for the order 3053 * @param h_post_data hash of the POST data for idempotency checks 3054 * @param pay_deadline how long does the customer have to pay for the order 3055 * @param claim_token token to use for access control 3056 * @param contract_terms proposal data to store 3057 * @param pos_key encoded key for payment verification 3058 * @param pos_algorithm algorithm to compute the payment verification 3059 * @return transaction status 3060 */ 3061 enum GNUNET_DB_QueryStatus 3062 (*insert_order)(void *cls, 3063 const char *instance_id, 3064 const char *order_id, 3065 const char *session_id, 3066 const struct TALER_MerchantPostDataHashP *h_post_data, 3067 struct GNUNET_TIME_Timestamp pay_deadline, 3068 const struct TALER_ClaimTokenP *claim_token, 3069 const json_t *contract_terms, 3070 const char *pos_key, 3071 enum TALER_MerchantConfirmationAlgorithm pos_algorithm); 3072 3073 3074 /** 3075 * Insert unclaim signature into DB and unclaim the order. 3076 * 3077 * @param cls closure 3078 * @param instance_id instance of the operation (checked) 3079 * @param merchant_pub public key of the instance (for notifications) 3080 * @param order_id identifies the order to unclaim 3081 * @param nonce claim nonce of the original claim 3082 * @param h_contract hash of the contract to unclaim 3083 * @param nsig signature by the nonce private key authorizing the unclaim 3084 * @return transaction status, 0 if an order with this @a nonce 3085 * and @a h_contract was not found; 1 if the request is idempotent 3086 */ 3087 enum GNUNET_DB_QueryStatus 3088 (*insert_unclaim_signature)( 3089 void *cls, 3090 const char *instance_id, 3091 const struct TALER_MerchantPublicKeyP *merchant_pub, 3092 const char *order_id, 3093 const struct GNUNET_CRYPTO_EddsaPublicKey *nonce, 3094 const struct GNUNET_HashCode *h_contract, 3095 const struct GNUNET_CRYPTO_EddsaSignature *nsig); 3096 3097 3098 /** 3099 * Insert blinded signatures for an order. 3100 * 3101 * @param cls closure 3102 * @param order_id order ID to insert blinded signatures for 3103 * @param i index of the blinded signature in the output array 3104 * @param hash hash of the token 3105 * @param blinded_sigs JSON array of blinded signatures 3106 */ 3107 enum GNUNET_DB_QueryStatus 3108 (*insert_order_blinded_sigs)( 3109 void *cls, 3110 const char *order_id, 3111 uint32_t i, 3112 const struct GNUNET_HashCode *hash, 3113 const struct GNUNET_CRYPTO_BlindedSignature *blind_sig); 3114 3115 3116 /** 3117 * Release an inventory lock by UUID. Releases ALL stocks locked under 3118 * the given UUID. 3119 * 3120 * @param cls closure 3121 * @param uuid the UUID to release locks for 3122 * @return transaction status, 3123 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means there are no locks under @a uuid 3124 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT indicates success 3125 */ 3126 enum GNUNET_DB_QueryStatus 3127 (*unlock_inventory)(void *cls, 3128 const struct GNUNET_Uuid *uuid); 3129 3130 3131 /** 3132 * Lock inventory stock to a particular order. 3133 * 3134 * @param cls closure 3135 * @param instance_id identifies the instance responsible for the order 3136 * @param order_id alphanumeric string that uniquely identifies the order 3137 * @param product_id uniquely identifies the product to be locked 3138 * @param quantity how many units should be locked to the @a order_id 3139 * @param quantity_frac fractional component of the quantity to be locked, 3140 * in units of 1/1000000 of the base value 3141 * @return transaction status, 3142 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means there are insufficient stocks 3143 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT indicates success 3144 */ 3145 enum GNUNET_DB_QueryStatus 3146 (*insert_order_lock)(void *cls, 3147 const char *instance_id, 3148 const char *order_id, 3149 const char *product_id, 3150 uint64_t quantity, 3151 uint32_t quantity_frac); 3152 3153 3154 /** 3155 * Select blinded signatures for an order. 3156 * 3157 * @param cls closure 3158 * @param order_id order ID to select blinded signatures for 3159 * @param cb callback to call for each blinded signature found 3160 * @param cb_cls closure for @a cb 3161 */ 3162 enum GNUNET_DB_QueryStatus 3163 (*select_order_blinded_sigs)( 3164 void *cls, 3165 const char *order_id, 3166 TALER_MERCHANTDB_BlindedSigCallback cb, 3167 void *cb_cls); 3168 3169 3170 /** 3171 * Retrieve contract terms given its @a order_id 3172 * 3173 * @param cls closure 3174 * @param instance_id instance's identifier 3175 * @param order_id order_id used to lookup. 3176 * @param[out] contract_terms where to store the result, NULL to only check for existence 3177 * @param[out] order_serial set to the order's serial number 3178 * @param[out] paid set to true if the order is fully paid 3179 * @param[out] claim_token set to the claim token, NULL to only check for existence 3180 * @param[out] pos_key encoded key for payment verification 3181 * @param[out] pos_algorithm set to algorithm to compute the payment verification 3182 * @return transaction status 3183 */ 3184 enum GNUNET_DB_QueryStatus 3185 (*lookup_contract_terms2)( 3186 void *cls, 3187 const char *instance_id, 3188 const char *order_id, 3189 json_t **contract_terms, 3190 uint64_t *order_serial, 3191 bool *paid, 3192 struct TALER_ClaimTokenP *claim_token, 3193 char **pos_key, 3194 enum TALER_MerchantConfirmationAlgorithm *pricing_algorithm); 3195 3196 3197 /** 3198 * Retrieve contract terms given its @a order_id 3199 * 3200 * @param cls closure 3201 * @param instance_id instance's identifier 3202 * @param order_id order_id used to lookup 3203 * @param session_id session_id to compare, can be NULL 3204 * @param[out] contract_terms where to store the result, NULL to only check for existence 3205 * @param[out] order_serial set to the order's serial number 3206 * @param[out] paid set to true if the order is fully paid 3207 * @param[out] wired set to true if the exchange wired the funds 3208 * @param[out] session_matches set to true if @a session_id matches session stored for this contract 3209 * @param[out] claim_token set to the claim token, NULL to only check for existence 3210 * @param[out] choice_index set to the choice index, -1 if not set 3211 * @return transaction status 3212 */ 3213 enum GNUNET_DB_QueryStatus 3214 (*lookup_contract_terms3)( 3215 void *cls, 3216 const char *instance_id, 3217 const char *order_id, 3218 const char *session_id, 3219 json_t **contract_terms, 3220 uint64_t *order_serial, 3221 bool *paid, 3222 bool *wired, 3223 bool *session_matches, 3224 struct TALER_ClaimTokenP *claim_token, 3225 int16_t *choice_index); 3226 3227 3228 /** 3229 * Retrieve contract terms given its @a order_id 3230 * 3231 * @param cls closure 3232 * @param instance_id instance's identifier 3233 * @param order_id order_id used to lookup. 3234 * @param[out] contract_terms where to store the result, NULL to only check for existence 3235 * @param[out] order_serial set to the order's serial number 3236 * @param[out] claim_token set to the claim token, NULL to only check for existence 3237 * @return transaction status 3238 */ 3239 enum GNUNET_DB_QueryStatus 3240 (*lookup_contract_terms)( 3241 void *cls, 3242 const char *instance_id, 3243 const char *order_id, 3244 json_t **contract_terms, 3245 uint64_t *order_serial, 3246 struct TALER_ClaimTokenP *claim_token); 3247 3248 3249 /** 3250 * Store contract terms given its @a order_id. Note that some attributes are 3251 * expected to be calculated inside of the function, like the hash of the 3252 * contract terms (to be hashed), the creation_time and pay_deadline (to be 3253 * obtained from the merchant_orders table). The "session_id" should be 3254 * initially set to the empty string. The "fulfillment_url" and "refund_deadline" 3255 * must be extracted from @a contract_terms. 3256 * 3257 * @param cls closure 3258 * @param instance_id instance's identifier 3259 * @param order_id order_id used to store 3260 * @param claim_token the token belonging to the order 3261 * @param[out] order_serial set to the serial of the order 3262 * @return transaction status, #GNUNET_DB_STATUS_HARD_ERROR if @a contract_terms 3263 * is malformed 3264 */ 3265 enum GNUNET_DB_QueryStatus 3266 (*insert_contract_terms)( 3267 void *cls, 3268 const char *instance_id, 3269 const char *order_id, 3270 json_t *contract_terms, 3271 uint64_t *order_serial); 3272 3273 3274 /** 3275 * Update the contract terms stored for @a order_id. Note that some attributes are 3276 * expected to be calculated inside of the function, like the hash of the 3277 * contract terms (to be hashed), the creation_time and pay_deadline (to be 3278 * obtained from the merchant_orders table). The "session_id" should be 3279 * initially set to the empty string. The "fulfillment_url" and "refund_deadline" 3280 * must be extracted from @a contract_terms. 3281 * 3282 * @param cls closure 3283 * @param instance_id instance's identifier 3284 * @param order_id order_id used to store 3285 * @param contract_terms contract to store 3286 * @return transaction status, #GNUNET_DB_STATUS_HARD_ERROR if @a contract_terms 3287 * is malformed 3288 */ 3289 enum GNUNET_DB_QueryStatus 3290 (*update_contract_terms)(void *cls, 3291 const char *instance_id, 3292 const char *order_id, 3293 json_t *contract_terms); 3294 3295 3296 /** 3297 * Delete information about a contract. Note that the transaction must 3298 * enforce that the contract is not awaiting payment anymore AND was not 3299 * paid, or is past the legal expiration. 3300 * 3301 * @param cls closure 3302 * @param instance_id instance to delete order of 3303 * @param order_id order to delete 3304 * @param legal_expiration how long do we need to keep (paid) contracts on 3305 * file for legal reasons (i.e. taxation) 3306 * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 3307 * if locks prevent deletion OR order unknown 3308 */ 3309 enum GNUNET_DB_QueryStatus 3310 (*delete_contract_terms)(void *cls, 3311 const char *instance_id, 3312 const char *order_id, 3313 struct GNUNET_TIME_Relative legal_expiration); 3314 3315 3316 /** 3317 * Lookup information about coins that were successfully deposited for a 3318 * given contract. 3319 * 3320 * @param cls closure 3321 * @param instance_id instance to lookup deposits for 3322 * @param h_contract_terms proposal data's hashcode 3323 * @param cb function to call with payment data 3324 * @param cb_cls closure for @a cb 3325 * @return transaction status 3326 */ 3327 enum GNUNET_DB_QueryStatus 3328 (*lookup_deposits)(void *cls, 3329 const char *instance_id, 3330 const struct TALER_PrivateContractHashP *h_contract_terms 3331 , 3332 TALER_MERCHANTDB_DepositsCallback cb, 3333 void *cb_cls); 3334 3335 3336 /** 3337 * Insert an exchange signing key into our database. 3338 * 3339 * @param cls closure 3340 * @param master_pub exchange master public key used for @a master_sig 3341 * @param exchange_pub exchange signing key to insert 3342 * @param start_date when does the signing key become valid 3343 * @param expire_date when does the signing key stop being used 3344 * @param end_date when does the signing key become void as proof 3345 * @param master_sig signature of @a master_pub over the @a exchange_pub and the dates 3346 */ 3347 enum GNUNET_DB_QueryStatus 3348 (*insert_exchange_signkey)( 3349 void *cls, 3350 const struct TALER_MasterPublicKeyP *master_pub, 3351 const struct TALER_ExchangePublicKeyP *exchange_pub, 3352 struct GNUNET_TIME_Timestamp start_date, 3353 struct GNUNET_TIME_Timestamp expire_date, 3354 struct GNUNET_TIME_Timestamp end_date, 3355 const struct TALER_MasterSignatureP *master_sig); 3356 3357 3358 /** 3359 * Insert deposit confirmation from the exchange into the database. 3360 * 3361 * @param cls closure 3362 * @param instance_id instance to lookup deposits for 3363 * @param deposit_timestamp time when the exchange generated the deposit confirmation 3364 * @param h_contract_terms proposal data's hashcode 3365 * @param exchange_url URL of the exchange that issued @a coin_pub 3366 * @param wire_transfer_deadline when do we expect the wire transfer from the exchange 3367 * @param total_without_fees deposited total in the batch without fees 3368 * @param wire_fee wire fee the exchange charges 3369 * @param h_wire hash of the wire details of the target account of the merchant 3370 * @param exchange_sig signature from exchange that coin was accepted 3371 * @param exchange_pub signing key that was used for @a exchange_sig 3372 * @param[out] batch_deposit_serial_id set to the table row 3373 * @return transaction status 3374 */ 3375 enum GNUNET_DB_QueryStatus 3376 (*insert_deposit_confirmation)( 3377 void *cls, 3378 const char *instance_id, 3379 struct GNUNET_TIME_Timestamp deposit_timestamp, 3380 const struct TALER_PrivateContractHashP *h_contract_terms, 3381 const char *exchange_url, 3382 struct GNUNET_TIME_Timestamp wire_transfer_deadline, 3383 const struct TALER_Amount *total_without_fees, 3384 const struct TALER_Amount *wire_fee, 3385 const struct TALER_MerchantWireHashP *h_wire, 3386 const struct TALER_ExchangeSignatureP *exchange_sig, 3387 const struct TALER_ExchangePublicKeyP *exchange_pub, 3388 uint64_t *batch_deposit_serial_id); 3389 3390 3391 /** 3392 * Insert information about coin deposited as part of 3393 * a batch into the database. 3394 * 3395 * @param cls closure 3396 * @param offset offset of the coin in the batch 3397 * @param deposit_confirmation_serial_id deposit confirmation for the batch the coin is part of 3398 * @param coin_pub public key of the coin 3399 * @param coin_sig deposit signature of the coin 3400 * @param amount_with_fee amount the exchange will deposit for this coin 3401 * @param deposit_fee fee the exchange will charge for this coin 3402 * @param refund_fee fee the exchange will charge for refunds of coin 3403 * @param check_time at what time should we check the deposit status 3404 * with the exchange (for settlement) 3405 * @return transaction status 3406 */ 3407 enum GNUNET_DB_QueryStatus 3408 (*insert_deposit)( 3409 void *cls, 3410 uint32_t offset, 3411 uint64_t deposit_confirmation_serial_id, 3412 const struct TALER_CoinSpendPublicKeyP *coin_pub, 3413 const struct TALER_CoinSpendSignatureP *coin_sig, 3414 const struct TALER_Amount *amount_with_fee, 3415 const struct TALER_Amount *deposit_fee, 3416 const struct TALER_Amount *refund_fee, 3417 struct GNUNET_TIME_Absolute check_time); 3418 3419 3420 /** 3421 * Obtain refunds associated with a contract. 3422 * 3423 * @param cls closure, typically a connection to the db 3424 * @param instance_id instance to lookup refunds for 3425 * @param h_contract_terms hash code of the contract 3426 * @param rc function to call for each coin on which there is a refund 3427 * @param rc_cls closure for @a rc 3428 * @return transaction status 3429 */ 3430 enum GNUNET_DB_QueryStatus 3431 (*lookup_refunds)(void *cls, 3432 const char *instance_id, 3433 const struct TALER_PrivateContractHashP *h_contract_terms, 3434 TALER_MERCHANTDB_RefundCallback rc, 3435 void *rc_cls); 3436 3437 3438 /** 3439 * Retrieve details about tokens that were used for an order. 3440 * 3441 * @param cls closure 3442 * @param order_serial identifies the order 3443 * @param cb function to call for each used token 3444 * @param cb_cls closure for @a cb 3445 * @return transaction status 3446 */ 3447 enum GNUNET_DB_QueryStatus 3448 (*lookup_spent_tokens_by_order)(void *cls, 3449 uint64_t order_serial, 3450 TALER_MERCHANTDB_UsedTokensCallback cb, 3451 void *cb_cls); 3452 3453 3454 /** 3455 * Mark contract as paid and store the current @a session_id 3456 * for which the contract was paid. Deletes the underlying order 3457 * and marks the locked stocks of the order as sold. 3458 * 3459 * @param cls closure 3460 * @param instance_id instance to mark contract as paid for 3461 * @param h_contract_terms hash of the contract that is now paid 3462 * @param session_id the session that paid the contract 3463 * @return transaction status 3464 */ 3465 enum GNUNET_DB_QueryStatus 3466 (*mark_contract_paid)( 3467 void *cls, 3468 const char *instance_id, 3469 const struct TALER_PrivateContractHashP *h_contract_terms, 3470 const char *session_id, 3471 int16_t choice_index); 3472 3473 3474 /** 3475 * Update session associated with a contract and return 3476 * the fulfillment URL and the refund status. 3477 * 3478 * @param cls closure 3479 * @param instance_id instance to mark contract as paid for 3480 * @param h_contract_terms hash of the contract that is now paid 3481 * @param session_id the session that paid the contract 3482 * @param[out] fulfillment_url set to the fulfillment URL (possibly NULL) 3483 * @param[out] refunded set to true if the order was refunded 3484 * @return transaction status 3485 */ 3486 enum GNUNET_DB_QueryStatus 3487 (*update_contract_session)( 3488 void *cls, 3489 const char *instance_id, 3490 const struct TALER_PrivateContractHashP *h_contract_terms, 3491 const char *session_id, 3492 char **fulfillment_url, 3493 bool *refunded); 3494 3495 3496 /** 3497 * Function called during aborts to refund a coin. Marks the 3498 * respective coin as refunded. 3499 * 3500 * @param cls closure 3501 * @param instance_id instance to refund payment for 3502 * @param h_contract_terms hash of the contract to refund coin for 3503 * @param refund_timestamp timestamp of when the coin was refunded 3504 * @param coin_pub public key of the coin to refund (fully) 3505 * @param reason text justifying the refund 3506 * @return transaction status 3507 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a coin_pub is unknown to us; 3508 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the request is valid, 3509 * regardless of whether it actually increased the refund 3510 */ 3511 enum GNUNET_DB_QueryStatus 3512 (*refund_coin)(void *cls, 3513 const char *instance_id, 3514 const struct TALER_PrivateContractHashP *h_contract_terms, 3515 struct GNUNET_TIME_Timestamp refund_timestamp, 3516 const struct TALER_CoinSpendPublicKeyP *coin_pub, 3517 const char *reason); 3518 3519 3520 /** 3521 * Retrieve contract terms given its @a order_id 3522 * 3523 * @param cls closure 3524 * @param instance_id instance's identifier 3525 * @param order_id order to lookup contract for 3526 * @param[out] h_contract_terms set to the hash of the contract. 3527 * @param[out] paid set to the payment status of the contract 3528 * @return transaction status 3529 */ 3530 enum GNUNET_DB_QueryStatus 3531 (*lookup_order_status)(void *cls, 3532 const char *instance_id, 3533 const char *order_id, 3534 struct TALER_PrivateContractHashP *h_contract_terms, 3535 bool *paid); 3536 3537 /** 3538 * Retrieve contract terms given its @a order_serial 3539 * 3540 * @param cls closure 3541 * @param instance_id instance's identifier 3542 * @param order_serial serial ID of the order to look up 3543 * @param[out] order_id set to ID of the order 3544 * @param[out] h_contract_terms set to the hash of the contract. 3545 * @param[out] paid set to the payment status of the contract 3546 * @return transaction status 3547 */ 3548 enum GNUNET_DB_QueryStatus 3549 (*lookup_order_status_by_serial)(void *cls, 3550 const char *instance_id, 3551 uint64_t order_serial, 3552 char **order_id, 3553 struct TALER_PrivateContractHashP * 3554 h_contract_terms, 3555 bool *paid); 3556 3557 3558 /** 3559 * Retrieve details about coins that were deposited for an order. 3560 * 3561 * @param cls closure 3562 * @param order_serial identifies the order 3563 * @param cb function to call for each deposited coin 3564 * @param cb_cls closure for @a cb 3565 * @return transaction status 3566 */ 3567 enum GNUNET_DB_QueryStatus 3568 (*lookup_deposits_by_order)(void *cls, 3569 uint64_t order_serial, 3570 TALER_MERCHANTDB_DepositedCoinsCallback cb, 3571 void *cb_cls); 3572 3573 3574 /** 3575 * Retrieve wire transfer details for all deposits associated with 3576 * a given @a order_serial. 3577 * 3578 * @param cls closure 3579 * @param order_serial identifies the order 3580 * @param cb function called with the wire transfer details 3581 * @param cb_cls closure for @a cb 3582 * @return transaction status 3583 */ 3584 enum GNUNET_DB_QueryStatus 3585 (*lookup_transfer_details_by_order)( 3586 void *cls, 3587 uint64_t order_serial, 3588 TALER_MERCHANTDB_OrderTransferDetailsCallback cb, 3589 void *cb_cls); 3590 3591 3592 /** 3593 * Update transfer status. 3594 * 3595 * @param cls closure 3596 * @param exchange_url the exchange that made the transfer 3597 * @param wtid wire transfer subject 3598 * @param next_attempt when should we try again (if ever) 3599 * @param http_status last HTTP status code from the server, 0 for timeout 3600 * @param ec current error state of checking the transfer 3601 * @param detail last error detail from the server, possibly NULL 3602 * @param needs_retry true if we should retry the request 3603 * @return database transaction status 3604 */ 3605 enum GNUNET_DB_QueryStatus 3606 (*update_transfer_status)( 3607 void *cls, 3608 const char *exchange_url, 3609 const struct TALER_WireTransferIdentifierRawP *wtid, 3610 struct GNUNET_TIME_Absolute next_attempt, 3611 unsigned int http_status, 3612 enum TALER_ErrorCode ec, 3613 const char *detail, 3614 bool needs_retry); 3615 3616 3617 /** 3618 * Finalize transfer status with success. 3619 * 3620 * @param cls closure 3621 * @param exchange_url the exchange that made the transfer 3622 * @param wtid wire transfer subject 3623 * @param h_details hash over all of the aggregated deposits 3624 * @param total_amount total amount exchange claimed to have transferred 3625 * @param wire_fee wire fee charged by the exchange 3626 * @param exchange_pub key used to make @e exchange_sig 3627 * @param exchange_sig signature of the exchange over reconciliation data 3628 * @return database transaction status 3629 */ 3630 enum GNUNET_DB_QueryStatus 3631 (*finalize_transfer_status)( 3632 void *cls, 3633 const char *exchange_url, 3634 const struct TALER_WireTransferIdentifierRawP *wtid, 3635 const struct GNUNET_HashCode *h_details, 3636 const struct TALER_Amount *total_amount, 3637 const struct TALER_Amount *wire_fee, 3638 const struct TALER_ExchangePublicKeyP *exchange_pub, 3639 const struct TALER_ExchangeSignatureP *exchange_sig); 3640 3641 3642 /** 3643 * Retrieve wire transfer details of wire details 3644 * that taler-merchant-exchange still needs to 3645 * investigate. 3646 * 3647 * @param cls closure 3648 * @param limit maximum number of results to return 3649 * @param cb function called with the wire transfer data 3650 * @param cb_cls closure for @a cb 3651 * @return transaction status 3652 */ 3653 enum GNUNET_DB_QueryStatus 3654 (*select_open_transfers)( 3655 void *cls, 3656 uint64_t limit, 3657 TALER_MERCHANTDB_OpenTransferCallback cb, 3658 void *cb_cls); 3659 3660 3661 /** 3662 * Insert wire transfer details for a deposit. 3663 * 3664 * @param cls closure 3665 * @param deposit_serial serial number of the deposit 3666 * @param h_wire hash of the merchant's account that should receive the deposit 3667 * @param exchange_url URL of the exchange that is making the deposit 3668 * @param dd deposit transfer data from the exchange to store 3669 * @return transaction status 3670 */ 3671 enum GNUNET_DB_QueryStatus 3672 (*insert_deposit_to_transfer)(void *cls, 3673 uint64_t deposit_serial, 3674 const struct TALER_MerchantWireHashP *h_wire, 3675 const char *exchange_url, 3676 const struct TALER_EXCHANGE_DepositData *dd); 3677 3678 3679 /** 3680 * Set 'wired' status for an order to 'true'. 3681 * 3682 * @param cls closure 3683 * @param order_serial serial number of the order 3684 * @return transaction status 3685 */ 3686 enum GNUNET_DB_QueryStatus 3687 (*mark_order_wired)(void *cls, 3688 uint64_t order_serial); 3689 3690 3691 /** 3692 * Function called when some backoffice staff decides to award or 3693 * increase the refund on an existing contract. This function 3694 * MUST be called from within a transaction scope setup by the 3695 * caller as it executes multiple SQL statements. 3696 * 3697 * @param cls closure 3698 * @param instance_id instance identifier 3699 * @param order_id the order to increase the refund for 3700 * @param refund maximum refund to return to the customer for this contract 3701 * @param olc function to call to obtain legal refund 3702 * limits per exchange, NULL for no limits 3703 * @param olc_cls closure for @a olc 3704 * @param reason 0-terminated UTF-8 string giving the reason why the customer 3705 * got a refund (free form, business-specific) 3706 * @return transaction status 3707 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a refund is ABOVE the amount we 3708 * were originally paid and thus the transaction failed; 3709 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the request is valid, 3710 * regardless of whether it actually increased the refund beyond 3711 * what was already refunded (idempotency!) 3712 */ 3713 enum TALER_MERCHANTDB_RefundStatus 3714 (*increase_refund)( 3715 void *cls, 3716 const char *instance_id, 3717 const char *order_id, 3718 const struct TALER_Amount *refund, 3719 TALER_MERCHANTDB_OperationLimitCallback olc, 3720 void *olc_cls, 3721 const char *reason); 3722 3723 3724 /** 3725 * Obtain detailed refund data associated with a contract. 3726 * 3727 * @param cls closure, typically a connection to the db 3728 * @param instance_id instance to lookup refunds for 3729 * @param h_contract_terms hash code of the contract 3730 * @param rc function to call for each coin on which there is a refund 3731 * @param rc_cls closure for @a rc 3732 * @return transaction status 3733 */ 3734 enum GNUNET_DB_QueryStatus 3735 (*lookup_refunds_detailed)( 3736 void *cls, 3737 const char *instance_id, 3738 const struct TALER_PrivateContractHashP *h_contract_terms, 3739 TALER_MERCHANTDB_RefundDetailCallback rc, 3740 void *rc_cls); 3741 3742 /** 3743 * Insert refund proof data from the exchange into the database. 3744 * 3745 * @param cls closure 3746 * @param refund_serial serial number of the refund 3747 * @param exchange_sig signature from exchange that coin was refunded 3748 * @param exchange_pub signing key that was used for @a exchange_sig 3749 * @return transaction status 3750 */ 3751 enum GNUNET_DB_QueryStatus 3752 (*insert_refund_proof)( 3753 void *cls, 3754 uint64_t refund_serial, 3755 const struct TALER_ExchangeSignatureP *exchange_sig, 3756 const struct TALER_ExchangePublicKeyP *exchange_pub); 3757 3758 3759 /** 3760 * Insert used token into the database. 3761 * 3762 * @param cls closure 3763 * @param h_contract_terms hash of the contract the token was used for 3764 * @param h_issue_pub hash of the token issue public key 3765 * @param use_pub token use public key 3766 * @param use_sig token use signature 3767 * @param issue_sig token issue signature 3768 * @return database result code 3769 */ 3770 enum GNUNET_DB_QueryStatus 3771 (*insert_spent_token)( 3772 void *cls, 3773 const struct TALER_PrivateContractHashP * 3774 h_contract_terms, 3775 const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub, 3776 const struct TALER_TokenUsePublicKeyP *use_pub, 3777 const struct TALER_TokenUseSignatureP *use_sig, 3778 const struct TALER_TokenIssueSignature *issue_sig); 3779 3780 3781 /** 3782 * Insert issued token into the database. 3783 * 3784 * @param cls closure 3785 * @param h_contract_terms hash of the contract the token was issued for 3786 * @param h_issue_pub hash of the token issue public key used to sign the issued token 3787 * @param blind_sig resulting blind token issue signature 3788 * @return database result code 3789 */ 3790 enum GNUNET_DB_QueryStatus 3791 (*insert_issued_token)( 3792 void *cls, 3793 const struct TALER_PrivateContractHashP *h_contract_terms, 3794 const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub, 3795 const struct TALER_BlindedTokenIssueSignature *blind_sig); 3796 3797 3798 /** 3799 * Lookup refund proof data. 3800 * 3801 * @param cls closure 3802 * @param refund_serial serial number of the refund 3803 * @param[out] exchange_sig set to signature from exchange 3804 * @param[out] exchange_pub signing key that was used for @a exchange_sig 3805 * @return transaction status 3806 */ 3807 enum GNUNET_DB_QueryStatus 3808 (*lookup_refund_proof)( 3809 void *cls, 3810 uint64_t refund_serial, 3811 struct TALER_ExchangeSignatureP *exchange_sig, 3812 struct TALER_ExchangePublicKeyP *exchange_pub); 3813 3814 3815 /** 3816 * Retrieve the order ID that was used to pay for a resource within a session. 3817 * 3818 * @param cls closure 3819 * @param instance_id instance to lookup the order from 3820 * @param fulfillment_url URL that canonically identifies the resource 3821 * being paid for 3822 * @param session_id session id 3823 * @param allow_refunded_for_repurchase true to include refunded orders in repurchase detection 3824 * @param[out] order_id location to store the order ID that was used when 3825 * paying for the resource URL 3826 * @return transaction status 3827 */ 3828 enum GNUNET_DB_QueryStatus 3829 (*lookup_order_by_fulfillment)( 3830 void *cls, 3831 const char *instance_id, 3832 const char *fulfillment_url, 3833 const char *session_id, 3834 bool allow_refunded_for_repurchase, 3835 char **order_id); 3836 3837 /** 3838 * Update information about progress made by taler-merchant-wirewatch. 3839 * 3840 * @param cls closure 3841 * @param instance which instance does the account belong to 3842 * @param payto_uri which account is this about 3843 * @param last_serial last serial imported from the bank 3844 * @return transaction status 3845 */ 3846 enum GNUNET_DB_QueryStatus 3847 (*update_wirewatch_progress)( 3848 void *cls, 3849 const char *instance, 3850 struct TALER_FullPayto payto_uri, 3851 uint64_t last_serial); 3852 3853 3854 /** 3855 * Select information about accounts which taler-merchant-wirewatch should work on. 3856 * 3857 * @param cls closure 3858 * @param cb function to call with results 3859 * @param cb_cls closure for @a cb 3860 * @return transaction status 3861 */ 3862 enum GNUNET_DB_QueryStatus 3863 (*select_wirewatch_accounts)( 3864 void *cls, 3865 TALER_MERCHANTDB_WirewatchWorkCallback cb, 3866 void *cb_cls); 3867 3868 3869 /** 3870 * Insert information about a wire transfer the merchant has received. 3871 * Idempotent, will do nothing if the same wire transfer is already known. 3872 * Updates the @a bank_serial_id if an equivalent transfer exists where 3873 * the @a bank_serial_id was set to 0 (unknown). 3874 * 3875 * @param cls closure 3876 * @param instance_id instance to lookup the order from 3877 * @param exchange_url which exchange made the transfer 3878 * @param wtid identifier of the wire transfer 3879 * @param credit_amount how much did we receive 3880 * @param payto_uri what is the merchant's bank account that received the transfer 3881 * @param bank_serial_id bank serial transfer ID, 0 for none (use NULL in DB!) 3882 * @param[out] no_instance instance unknown to backend 3883 * @param[out] no_account bank account with @a payto_uri unknown to backend 3884 * @param[out] conflict transfer with same @a wtid but different @a credit_amount exists 3885 * @return transaction status 3886 */ 3887 enum GNUNET_DB_QueryStatus 3888 (*insert_transfer)( 3889 void *cls, 3890 const char *instance_id, 3891 const char *exchange_url, 3892 const struct TALER_WireTransferIdentifierRawP *wtid, 3893 const struct TALER_Amount *credit_amount, 3894 struct TALER_FullPayto payto_uri, 3895 uint64_t bank_serial_id, 3896 bool *no_instance, 3897 bool *no_account, 3898 bool *conflict); 3899 3900 3901 /** 3902 * Delete information about a transfer. Note that transfers 3903 * confirmed by the exchange cannot be deleted anymore. 3904 * 3905 * @param cls closure 3906 * @param instance_id instance to delete transfer of 3907 * @param transfer_serial_id transfer to delete 3908 * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 3909 * if deletion is prohibited OR transfer is unknown 3910 */ 3911 enum GNUNET_DB_QueryStatus 3912 (*delete_transfer)(void *cls, 3913 const char *instance_id, 3914 uint64_t transfer_serial_id); 3915 3916 3917 /** 3918 * Check if information about a transfer exists with the 3919 * backend. Returns no data, only the query status. 3920 * 3921 * @param cls closure 3922 * @param instance_id instance to delete transfer of 3923 * @param transfer_serial_id transfer to delete 3924 * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT 3925 * if the transfer record exists 3926 */ 3927 enum GNUNET_DB_QueryStatus 3928 (*check_transfer_exists)(void *cls, 3929 const char *instance_id, 3930 uint64_t transfer_serial_id); 3931 3932 3933 /** 3934 * Lookup account serial by payto URI. 3935 * 3936 * @param cls closure 3937 * @param instance_id instance to lookup the account from 3938 * @param payto_uri what is the merchant's bank account to lookup 3939 * @param[out] account_serial serial number of the account 3940 * @return transaction status 3941 */ 3942 enum GNUNET_DB_QueryStatus 3943 (*lookup_account)(void *cls, 3944 const char *instance_id, 3945 struct TALER_FullPayto payto_uri, 3946 uint64_t *account_serial); 3947 3948 3949 /** 3950 * Insert information about a wire transfer the merchant has received. 3951 * 3952 * @param cls closure 3953 * @param instance_id instance to provide transfer details for 3954 * @param exchange_url which exchange made the transfer 3955 * @param payto_uri what is the merchant's bank account that received the transfer 3956 * @param wtid identifier of the wire transfer 3957 * @param td transfer details to store 3958 * @return transaction status, 3959 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the @a wtid and @a exchange_uri are not known for this @a instance_id 3960 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT on success 3961 */ 3962 enum GNUNET_DB_QueryStatus 3963 (*insert_transfer_details)( 3964 void *cls, 3965 const char *instance_id, 3966 const char *exchange_url, 3967 struct TALER_FullPayto payto_uri, 3968 const struct TALER_WireTransferIdentifierRawP *wtid, 3969 const struct TALER_EXCHANGE_TransferData *td); 3970 3971 3972 /** 3973 * Obtain information about wire fees charged by an exchange, 3974 * including signature (so we have proof). 3975 * 3976 * @param cls closure 3977 * @param master_pub master public key of the exchange 3978 * @param h_wire_method hash of wire method 3979 * @param contract_date date of the contract to use for the lookup 3980 * @param[out] fees set to wire fees charged 3981 * @param[out] start_date start of fee being used 3982 * @param[out] end_date end of fee being used 3983 * @param[out] master_sig signature of exchange over fee structure 3984 * @return transaction status code 3985 */ 3986 enum GNUNET_DB_QueryStatus 3987 (*lookup_wire_fee)( 3988 void *cls, 3989 const struct TALER_MasterPublicKeyP *master_pub, 3990 const char *wire_method, 3991 struct GNUNET_TIME_Timestamp contract_date, 3992 struct TALER_WireFeeSet *fees, 3993 struct GNUNET_TIME_Timestamp *start_date, 3994 struct GNUNET_TIME_Timestamp *end_date, 3995 struct TALER_MasterSignatureP *master_sig); 3996 3997 3998 /** 3999 * Obtain information about an expected incoming wire transfer. 4000 * 4001 * @param cls closure 4002 * @param instance_id instance to lookup payments for 4003 * @param expected_incoming_serial serial number of the transfer 4004 * @param[out] expected_time expected date of the transfer 4005 * @param[out] wtid expected wire transfer subject 4006 * @param[out] payto_uri target bank account 4007 * @param[out] exchange_url URL of the exchange 4008 * @param[out] execution_time, set to 0 if unknown 4009 * @param[out] confirmed set if the transfer was confirmed 4010 * @param[out] master_pub master public key of the exchange 4011 * @return transaction status code 4012 */ 4013 enum GNUNET_DB_QueryStatus 4014 (*lookup_expected_transfer)( 4015 void *cls, 4016 const char *instance_id, 4017 uint64_t expected_incoming_serial, 4018 struct GNUNET_TIME_Timestamp *expected_time, 4019 struct TALER_Amount *expected_credit_amount, 4020 struct TALER_WireTransferIdentifierRawP *wtid, 4021 struct TALER_FullPayto *payto_uri, 4022 char **exchange_url, 4023 struct GNUNET_TIME_Timestamp *execution_time, 4024 bool *confirmed, 4025 struct TALER_MasterPublicKeyP *master_pub); 4026 4027 4028 /** 4029 * Obtain reconciliation details for an expected incoming wire transfer. 4030 * 4031 * @param cls closure 4032 * @param instance_id instance to lookup payments for 4033 * @param expected_incoming_serial serial number of the transfer 4034 * @param cb callback to invoke 4035 * @param cb_cls closure for @a cb 4036 * @return transaction status code 4037 */ 4038 enum GNUNET_DB_QueryStatus 4039 (*lookup_reconciliation_details)( 4040 void *cls, 4041 const char *instance_id, 4042 uint64_t expected_incoming_serial, 4043 TALER_MERCHANTDB_ReconciliationDetailsCallback cb, 4044 void *cb_cls); 4045 4046 4047 /** 4048 * Lookup information about coin payments by @a h_contract_terms and 4049 * @a coin_pub. 4050 * 4051 * @param cls closure 4052 * @param instance_id instance to lookup payments for 4053 * @param h_contract_terms proposal data's hashcode 4054 * @param coin_pub public key to use for the search 4055 * @param cb function to call with payment data 4056 * @param cb_cls closure for @a cb 4057 * @return transaction status 4058 */ 4059 enum GNUNET_DB_QueryStatus 4060 (*lookup_deposits_by_contract_and_coin)( 4061 void *cls, 4062 const char *instance_id, 4063 const struct TALER_PrivateContractHashP *h_contract_terms, 4064 const struct TALER_CoinSpendPublicKeyP *coin_pub, 4065 TALER_MERCHANTDB_CoinDepositCallback cb, 4066 void *cb_cls); 4067 4068 4069 /** 4070 * Lookup transfer summary (used if we already verified the details). 4071 * 4072 * @param cls closure 4073 * @param exchange_url the exchange that made the transfer 4074 * @param wtid wire transfer subject 4075 * @param cb function to call with detailed transfer data 4076 * @param cb_cls closure for @a cb 4077 * @return transaction status 4078 */ 4079 enum GNUNET_DB_QueryStatus 4080 (*lookup_transfer_summary)( 4081 void *cls, 4082 const char *exchange_url, 4083 const struct TALER_WireTransferIdentifierRawP *wtid, 4084 TALER_MERCHANTDB_TransferSummaryCallback cb, 4085 void *cb_cls); 4086 4087 4088 /** 4089 * Lookup transfer details. Used if we still need to verify the details. 4090 * 4091 * @param cls closure 4092 * @param exchange_url the exchange that made the transfer 4093 * @param wtid wire transfer subject 4094 * @param cb function to call with detailed transfer data 4095 * @param cb_cls closure for @a cb 4096 * @return transaction status 4097 */ 4098 enum GNUNET_DB_QueryStatus 4099 (*lookup_transfer_details)( 4100 void *cls, 4101 const char *exchange_url, 4102 const struct TALER_WireTransferIdentifierRawP *wtid, 4103 TALER_MERCHANTDB_TransferDetailsCallback cb, 4104 void *cb_cls); 4105 4106 4107 /** 4108 * Lookup transfers. 4109 * 4110 * @param cls closure 4111 * @param instance_id instance to lookup payments for 4112 * @param payto_uri account that we are interested in transfers to 4113 * @param before timestamp for the earliest transfer we care about 4114 * @param after timestamp for the last transfer we care about 4115 * @param limit number of entries to return, negative for descending in execution time, 4116 * positive for ascending in execution time 4117 * @param offset transfer_serial number of the transfer we want to offset from 4118 * @param expected filter for transfers that were expected 4119 * @param cb function to call with detailed transfer data 4120 * @param cb_cls closure for @a cb 4121 * @return transaction status 4122 */ 4123 enum GNUNET_DB_QueryStatus 4124 (*lookup_transfers)( 4125 void *cls, 4126 const char *instance_id, 4127 struct TALER_FullPayto payto_uri, 4128 struct GNUNET_TIME_Timestamp before, 4129 struct GNUNET_TIME_Timestamp after, 4130 int64_t limit, 4131 uint64_t offset, 4132 enum TALER_EXCHANGE_YesNoAll expected, 4133 TALER_MERCHANTDB_TransferCallback cb, 4134 void *cb_cls); 4135 4136 4137 /** 4138 * Lookup expected incoming transfers. 4139 * 4140 * @param cls closure 4141 * @param instance_id instance to lookup payments for 4142 * @param payto_uri account that we are interested in transfers to 4143 * @param before timestamp for the earliest transfer we care about 4144 * @param after timestamp for the last transfer we care about 4145 * @param limit number of entries to return, negative for descending in execution time, 4146 * positive for ascending in execution time 4147 * @param offset expected_transfer_serial number of the transfer we want to offset from 4148 * @param confirmed filter by confirmation status 4149 * @param verified filter by verification status 4150 * @param cb function to call with detailed transfer data 4151 * @param cb_cls closure for @a cb 4152 * @return transaction status 4153 */ 4154 enum GNUNET_DB_QueryStatus 4155 (*lookup_expected_transfers)( 4156 void *cls, 4157 const char *instance_id, 4158 struct TALER_FullPayto payto_uri, 4159 struct GNUNET_TIME_Timestamp before, 4160 struct GNUNET_TIME_Timestamp after, 4161 int64_t limit, 4162 uint64_t offset, 4163 enum TALER_EXCHANGE_YesNoAll confirmed, 4164 enum TALER_EXCHANGE_YesNoAll verified, 4165 TALER_MERCHANTDB_IncomingCallback cb, 4166 void *cb_cls); 4167 4168 4169 /** 4170 * Store information about wire fees charged by an exchange, 4171 * including signature (so we have proof). 4172 * 4173 * @param cls closure 4174 * @param master_pub master public key of the exchange 4175 * @param h_wire_method hash of wire method 4176 * @param fees wire fees charged 4177 * @param start_date start of fee being used 4178 * @param end_date end of fee being used 4179 * @param master_sig signature of exchange over fee structure 4180 * @return transaction status code 4181 */ 4182 enum GNUNET_DB_QueryStatus 4183 (*store_wire_fee_by_exchange)( 4184 void *cls, 4185 const struct TALER_MasterPublicKeyP *master_pub, 4186 const struct GNUNET_HashCode *h_wire_method, 4187 const struct TALER_WireFeeSet *fees, 4188 struct GNUNET_TIME_Timestamp start_date, 4189 struct GNUNET_TIME_Timestamp end_date, 4190 const struct TALER_MasterSignatureP *master_sig); 4191 4192 4193 /** 4194 * Delete information about wire accounts of an exchange. (Used when we got new account data.) 4195 * 4196 * @param cls closure 4197 * @param master_pub public key of the exchange 4198 * @return transaction status code 4199 */ 4200 enum GNUNET_DB_QueryStatus 4201 (*delete_exchange_accounts)( 4202 void *cls, 4203 const struct TALER_MasterPublicKeyP *master_pub); 4204 4205 4206 /** 4207 * Return information about wire accounts of an exchange. 4208 * 4209 * @param cls closure 4210 * @param master_pub public key of the exchange 4211 * @param cb function to call on each account 4212 * @param cb_cls closure for @a cb 4213 * @return transaction status code 4214 */ 4215 enum GNUNET_DB_QueryStatus 4216 (*select_accounts_by_exchange)( 4217 void *cls, 4218 const struct TALER_MasterPublicKeyP *master_pub, 4219 TALER_MERCHANTDB_ExchangeAccountCallback cb, 4220 void *cb_cls); 4221 4222 4223 /** 4224 * Insert information about a wire account of an exchange. 4225 * 4226 * @param cls closure 4227 * @param master_pub public key of the exchange 4228 * @param payto_uri URI of the bank account 4229 * @param conversion_url conversion service, NULL if there is no conversion required 4230 * @param debit_restrictions JSON array of debit restrictions on the account 4231 * @param credit_restrictions JSON array of debit restrictions on the account 4232 * @param master_sig signature affirming the account of the exchange 4233 * @return transaction status code 4234 */ 4235 enum GNUNET_DB_QueryStatus 4236 (*insert_exchange_account)( 4237 void *cls, 4238 const struct TALER_MasterPublicKeyP *master_pub, 4239 const struct TALER_FullPayto payto_uri, 4240 const char *conversion_url, 4241 const json_t *debit_restrictions, 4242 const json_t *credit_restrictions, 4243 const struct TALER_MasterSignatureP *master_sig); 4244 4245 4246 /** 4247 * Lookup all of the templates the given instance has configured. 4248 * 4249 * @param cls closure 4250 * @param instance_id instance to lookup template for 4251 * @param cb function to call on all template found 4252 * @param cb_cls closure for @a cb 4253 * @return database result code 4254 */ 4255 enum GNUNET_DB_QueryStatus 4256 (*lookup_templates)(void *cls, 4257 const char *instance_id, 4258 TALER_MERCHANTDB_TemplatesCallback cb, 4259 void *cb_cls); 4260 4261 4262 /** 4263 * Lookup details about a particular template. 4264 * 4265 * @param cls closure 4266 * @param instance_id instance to lookup template for 4267 * @param template_id template to lookup 4268 * @param[out] td set to the template details on success, can be NULL 4269 * (in that case we only want to check if the template exists) 4270 * @return database result code 4271 */ 4272 enum GNUNET_DB_QueryStatus 4273 (*lookup_template)(void *cls, 4274 const char *instance_id, 4275 const char *template_id, 4276 struct TALER_MERCHANTDB_TemplateDetails *td); 4277 4278 /** 4279 * Delete information about a template. 4280 * 4281 * @param cls closure 4282 * @param instance_id instance to delete template of 4283 * @param template_id template to delete 4284 * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 4285 * if template unknown. 4286 */ 4287 enum GNUNET_DB_QueryStatus 4288 (*delete_template)(void *cls, 4289 const char *instance_id, 4290 const char *template_id); 4291 4292 4293 /** 4294 * Insert details about a particular template. 4295 * 4296 * @param cls closure 4297 * @param instance_id instance to insert template for 4298 * @param template_id template identifier of template to insert 4299 * @param otp_serial_id 0 if no OTP device is associated 4300 * @param td the template details to insert 4301 * @return database result code 4302 */ 4303 enum GNUNET_DB_QueryStatus 4304 (*insert_template)(void *cls, 4305 const char *instance_id, 4306 const char *template_id, 4307 uint64_t otp_serial_id, 4308 const struct TALER_MERCHANTDB_TemplateDetails *td); 4309 4310 4311 /** 4312 * Update details about a particular template. 4313 * 4314 * @param cls closure 4315 * @param instance_id instance to update template for 4316 * @param template_id template to update 4317 * @param td update to the template details on success, can be NULL 4318 * (in that case we only want to check if the template exists) 4319 * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template 4320 * does not yet exist. 4321 */ 4322 enum GNUNET_DB_QueryStatus 4323 (*update_template)(void *cls, 4324 const char *instance_id, 4325 const char *template_id, 4326 const struct TALER_MERCHANTDB_TemplateDetails *td); 4327 4328 4329 /** 4330 * Delete information about an OTP device. 4331 * 4332 * @param cls closure 4333 * @param instance_id instance to delete OTP device of 4334 * @param otp_id otp device to delete 4335 * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 4336 * if template unknown. 4337 */ 4338 enum GNUNET_DB_QueryStatus 4339 (*delete_otp)(void *cls, 4340 const char *instance_id, 4341 const char *otp_id); 4342 4343 /** 4344 * Insert details about a particular OTP device. 4345 * 4346 * @param cls closure 4347 * @param instance_id instance to insert OTP device for 4348 * @param otp_id otp identifier of OTP device to insert 4349 * @param td the OTP device details to insert 4350 * @return database result code 4351 */ 4352 enum GNUNET_DB_QueryStatus 4353 (*insert_otp)(void *cls, 4354 const char *instance_id, 4355 const char *otp_id, 4356 const struct TALER_MERCHANTDB_OtpDeviceDetails *td); 4357 4358 4359 /** 4360 * Update details about a particular OTP device. 4361 * 4362 * @param cls closure 4363 * @param instance_id instance to update OTP device for 4364 * @param otp_id OTP device to update 4365 * @param td update to the OTP device details on success, can be NULL 4366 * (in that case we only want to check if the template exists) 4367 * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template 4368 * does not yet exist. 4369 */ 4370 enum GNUNET_DB_QueryStatus 4371 (*update_otp)(void *cls, 4372 const char *instance_id, 4373 const char *otp_id, 4374 const struct TALER_MERCHANTDB_OtpDeviceDetails *td); 4375 4376 /** 4377 * Lookup all of the OTP devices the given instance has configured. 4378 * 4379 * @param cls closure 4380 * @param instance_id instance to lookup OTP devices for 4381 * @param cb function to call on all OTP devices found 4382 * @param cb_cls closure for @a cb 4383 * @return database result code 4384 */ 4385 enum GNUNET_DB_QueryStatus 4386 (*lookup_otp_devices)(void *cls, 4387 const char *instance_id, 4388 TALER_MERCHANTDB_OtpDeviceCallback cb, 4389 void *cb_cls); 4390 4391 4392 /** 4393 * Lookup details about an OTP device. 4394 * 4395 * @param cls closure 4396 * @param instance_id instance to lookup template for 4397 * @param otp_id OTP device to lookup 4398 * @param[out] td set to the OTP device details on success, can be NULL 4399 * (in that case we only want to check if the template exists) 4400 * @return database result code 4401 */ 4402 enum GNUNET_DB_QueryStatus 4403 (*select_otp)(void *cls, 4404 const char *instance_id, 4405 const char *otp_id, 4406 struct TALER_MERCHANTDB_OtpDeviceDetails *td); 4407 4408 4409 /** 4410 * Lookup serial number of an OTP device. 4411 * 4412 * @param cls closure 4413 * @param instance_id instance to lookup template for 4414 * @param otp_id OTP device to lookup 4415 * @param[out] serial set to the OTP device serial number * @return database result code 4416 */ 4417 enum GNUNET_DB_QueryStatus 4418 (*select_otp_serial)(void *cls, 4419 const char *instance_id, 4420 const char *otp_id, 4421 uint64_t *serial); 4422 4423 /** 4424 * Delete information about a measurement unit. 4425 * 4426 * @param cls closure 4427 * @param instance_id instance to delete unit from 4428 * @param unit_id symbolic identifier of the unit 4429 * @param[out] no_instance set to true if @a instance_id is unknown 4430 * @param[out] no_unit set to true if the unit does not exist 4431 * @param[out] builtin_conflict set to true if the unit is builtin and may not be deleted 4432 * @return DB status code 4433 */ 4434 enum GNUNET_DB_QueryStatus 4435 (*delete_unit)(void *cls, 4436 const char *instance_id, 4437 const char *unit_id, 4438 bool *no_instance, 4439 bool *no_unit, 4440 bool *builtin_conflict); 4441 4442 /** 4443 * Insert a measurement unit definition. 4444 * 4445 * @param cls closure 4446 * @param instance_id instance to insert unit for 4447 * @param ud unit details to store (unit_serial ignored) 4448 * @param[out] no_instance set to true if @a instance_id is unknown 4449 * @param[out] conflict set to true if a conflicting unit already exists 4450 * @param[out] unit_serial set to the inserted serial on success 4451 * @return database result code 4452 */ 4453 enum GNUNET_DB_QueryStatus 4454 (*insert_unit)(void *cls, 4455 const char *instance_id, 4456 const struct TALER_MERCHANTDB_UnitDetails *ud, 4457 bool *no_instance, 4458 bool *conflict, 4459 uint64_t *unit_serial); 4460 4461 /** 4462 * Update a measurement unit definition. 4463 * 4464 * @param cls closure 4465 * @param instance_id instance owning the unit 4466 * @param unit_id symbolic identifier of the unit 4467 * @param unit_name_long optional new long label (NULL to keep current) 4468 * @param unit_name_long_i18n optional new long-label translations (NULL to keep current) 4469 * @param unit_name_short optional new short label (NULL to keep current) 4470 * @param unit_name_short_i18n optional new short-label translations (NULL to keep current) 4471 * @param unit_allow_fraction optional new fractional toggle (NULL to keep current) 4472 * @param unit_precision_level optional new fractional precision (NULL to keep current) 4473 * @param unit_active optional new visibility flag (NULL to keep current) 4474 * @param[out] no_instance set if instance unknown 4475 * @param[out] no_unit set if unit unknown 4476 * @param[out] builtin_conflict set if immutable builtin fields touched 4477 * @return database result code 4478 */ 4479 enum GNUNET_DB_QueryStatus 4480 (*update_unit)(void *cls, 4481 const char *instance_id, 4482 const char *unit_id, 4483 const char *unit_name_long, 4484 const json_t *unit_name_long_i18n, 4485 const char *unit_name_short, 4486 const json_t *unit_name_short_i18n, 4487 const bool *unit_allow_fraction, 4488 const uint32_t *unit_precision_level, 4489 const bool *unit_active, 4490 bool *no_instance, 4491 bool *no_unit, 4492 bool *builtin_conflict); 4493 4494 /** 4495 * Lookup all measurement units of an instance. 4496 * 4497 * @param cls closure 4498 * @param instance_id instance to fetch units for 4499 * @param cb function to call per unit 4500 * @param cb_cls closure for @a cb 4501 * @return database result code 4502 */ 4503 enum GNUNET_DB_QueryStatus 4504 (*lookup_units)(void *cls, 4505 const char *instance_id, 4506 TALER_MERCHANTDB_UnitsCallback cb, 4507 void *cb_cls); 4508 4509 /** 4510 * Lookup custom measurement units by name. 4511 * 4512 * @param cls closure 4513 * @param instance_id instance to fetch units for 4514 * @param units array of unit identifiers 4515 * @param num_units length of @a units 4516 * @param cb function to call per unit 4517 * @param cb_cls closure for @a cb 4518 * @return database result code 4519 */ 4520 enum GNUNET_DB_QueryStatus 4521 (*lookup_custom_units_by_names)(void *cls, 4522 const char *instance_id, 4523 const char *const *units, 4524 size_t num_units, 4525 TALER_MERCHANTDB_UnitsCallback cb, 4526 void *cb_cls); 4527 /** 4528 * Lookup a single measurement unit. 4529 * 4530 * @param cls closure 4531 * @param instance_id instance to fetch unit for 4532 * @param unit_id symbolic identifier 4533 * @param[out] ud unit details on success; may be NULL to test existence 4534 * @return database result code 4535 */ 4536 enum GNUNET_DB_QueryStatus 4537 (*select_unit)(void *cls, 4538 const char *instance_id, 4539 const char *unit_id, 4540 struct TALER_MERCHANTDB_UnitDetails *ud); 4541 4542 4543 /** 4544 * Delete information about a product category. 4545 * 4546 * @param cls closure 4547 * @param instance_id instance to delete category of 4548 * @param category_id identifies the category to delete 4549 * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 4550 * if template unknown. 4551 */ 4552 enum GNUNET_DB_QueryStatus 4553 (*delete_category)(void *cls, 4554 const char *instance_id, 4555 uint64_t category_id); 4556 4557 /** 4558 * Insert new product category. 4559 * 4560 * @param cls closure 4561 * @param instance_id instance to insert OTP device for 4562 * @param category_name name of the category 4563 * @param category_name_i18n translations of the category name 4564 * @param[out] category_id set to the category id on success 4565 * @return database result code 4566 */ 4567 enum GNUNET_DB_QueryStatus 4568 (*insert_category)(void *cls, 4569 const char *instance_id, 4570 const char *category_name, 4571 const json_t *category_name_i18n, 4572 uint64_t *category_id); 4573 4574 4575 /** 4576 * Update descriptions of a product category. 4577 * 4578 * @param cls closure 4579 * @param instance_id instance to update OTP device for 4580 * @param category_id category to update 4581 * @param category_name name of the category 4582 * @param category_name_i18n translations of the category name 4583 * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template 4584 * does not yet exist. 4585 */ 4586 enum GNUNET_DB_QueryStatus 4587 (*update_category)(void *cls, 4588 const char *instance_id, 4589 uint64_t category_id, 4590 const char *category_name, 4591 const json_t *category_name_i18n); 4592 4593 /** 4594 * Lookup all of the product categories the given instance has configured. 4595 * 4596 * @param cls closure 4597 * @param instance_id instance to lookup OTP devices for 4598 * @param cb function to call on all categories found 4599 * @param cb_cls closure for @a cb 4600 * @return database result code 4601 */ 4602 enum GNUNET_DB_QueryStatus 4603 (*lookup_categories)(void *cls, 4604 const char *instance_id, 4605 TALER_MERCHANTDB_CategoriesCallback cb, 4606 void *cb_cls); 4607 4608 /** 4609 * Lookup product categories by ID. 4610 * 4611 * @param cls closure 4612 * @param instance_id instance to lookup categories for 4613 * @param category_ids array of category IDs 4614 * @param num_category_ids length of @a category_ids 4615 * @param cb function to call on all categories found 4616 * @param cb_cls closure for @a cb 4617 * @return database result code 4618 */ 4619 enum GNUNET_DB_QueryStatus 4620 (*lookup_categories_by_ids)(void *cls, 4621 const char *instance_id, 4622 const uint64_t *category_ids, 4623 size_t num_category_ids, 4624 TALER_MERCHANTDB_CategoriesCallback cb, 4625 void *cb_cls); 4626 4627 4628 /** 4629 * Lookup details about product category. 4630 * 4631 * @param cls closure 4632 * @param instance_id instance to lookup template for 4633 * @param category_id category to update 4634 * @param[out] cd set to the category details on success, can be NULL 4635 * (in that case we only want to check if the category exists) 4636 * @param[out] num_products set to length of @a products array 4637 * @param[out] products set to buffer with @a num_products 0-terminated strings with the product IDs, caller must free() it. 4638 * @return database result code 4639 */ 4640 enum GNUNET_DB_QueryStatus 4641 (*select_category)(void *cls, 4642 const char *instance_id, 4643 uint64_t category_id, 4644 struct TALER_MERCHANTDB_CategoryDetails *cd, 4645 size_t *num_products, 4646 char **products); 4647 4648 4649 /** 4650 * Lookup details about product category by name. 4651 * 4652 * @param cls closure 4653 * @param instance_id instance to lookup template for 4654 * @param category_name category name to look for 4655 * @param[out] name_i18n category name translation 4656 * @param[out] category_id category ID 4657 * @return database result code 4658 */ 4659 enum GNUNET_DB_QueryStatus 4660 (*select_category_by_name)(void *cls, 4661 const char *instance_id, 4662 const char *category_name, 4663 json_t **name_i18n, 4664 uint64_t *category_id); 4665 4666 4667 /** 4668 * Lookup all of the webhooks the given instance has configured. 4669 * 4670 * @param cls closure 4671 * @param instance_id instance to lookup webhook for 4672 * @param cb function to call on all webhook found 4673 * @param cb_cls closure for @a cb 4674 * @return database result code 4675 */ 4676 enum GNUNET_DB_QueryStatus 4677 (*lookup_webhooks)(void *cls, 4678 const char *instance_id, 4679 TALER_MERCHANTDB_WebhooksCallback cb, 4680 void *cb_cls); 4681 4682 4683 /** 4684 * Lookup details about a particular webhook. 4685 * 4686 * @param cls closure 4687 * @param instance_id instance to lookup webhook for 4688 * @param webhook_id webhook to lookup 4689 * @param[out] wb set to the webhook details on success, can be NULL 4690 * (in that case we only want to check if the webhook exists) 4691 * @return database result code 4692 */ 4693 enum GNUNET_DB_QueryStatus 4694 (*lookup_webhook)(void *cls, 4695 const char *instance_id, 4696 const char *webhook_id, 4697 struct TALER_MERCHANTDB_WebhookDetails *wb); 4698 4699 /** 4700 * Delete information about a webhook. 4701 * 4702 * @param cls closure 4703 * @param instance_id instance to delete webhook of 4704 * @param webhook_id webhook to delete 4705 * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 4706 * if webhook unknown. 4707 */ 4708 enum GNUNET_DB_QueryStatus 4709 (*delete_webhook)(void *cls, 4710 const char *instance_id, 4711 const char *webhook_id); 4712 4713 4714 /** 4715 * Insert details about a particular webhook. 4716 * 4717 * @param cls closure 4718 * @param instance_id instance to insert webhook for 4719 * @param webhook_id webhook identifier of webhook to insert 4720 * @param wb the webhook details to insert 4721 * @return database result code 4722 */ 4723 enum GNUNET_DB_QueryStatus 4724 (*insert_webhook)(void *cls, 4725 const char *instance_id, 4726 const char *webhook_id, 4727 const struct TALER_MERCHANTDB_WebhookDetails *wb); 4728 4729 4730 /** 4731 * Update details about a particular webhook. 4732 * 4733 * @param cls closure 4734 * @param instance_id instance to update webhook for 4735 * @param webhook_id webhook to update 4736 * @param wb update to the webhook details on success, can be NULL 4737 * (in that case we only want to check if the webhook exists) 4738 * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the webhook 4739 * does not yet exist. 4740 */ 4741 enum GNUNET_DB_QueryStatus 4742 (*update_webhook)(void *cls, 4743 const char *instance_id, 4744 const char *webhook_id, 4745 const struct TALER_MERCHANTDB_WebhookDetails *wb); 4746 4747 /** 4748 * Lookup webhook by event 4749 * 4750 * @param cls closure 4751 * @param instance_id instance to lookup webhook for 4752 * @param event_type event that we need to put in the pending webhook 4753 * @param[out] cb set to the webhook details on success 4754 * @param cb_cls callback closure 4755 * @return database result code 4756 */ 4757 enum GNUNET_DB_QueryStatus 4758 (*lookup_webhook_by_event)(void *cls, 4759 const char *instance_id, 4760 const char *event_type, 4761 TALER_MERCHANTDB_WebhookDetailCallback cb, 4762 void *cb_cls); 4763 4764 /** 4765 * Insert webhook in the pending webhook. 4766 * 4767 * @param cls closure 4768 * @param instance_id instance to insert webhook for 4769 * @param webhook_serial webhook to insert in the pending webhook 4770 * @param url to make the request to 4771 * @param http_method for the webhook 4772 * @param header of the webhook 4773 * @param body of the webhook 4774 * @return database result code 4775 */ 4776 enum GNUNET_DB_QueryStatus 4777 (*insert_pending_webhook)(void *cls, 4778 const char *instance_id, 4779 uint64_t webhook_serial, 4780 const char *url, 4781 const char *http_method, 4782 const char *header, 4783 const char *body); 4784 /** 4785 * Lookup the webhook that need to be send in priority. These webhooks are not successfully 4786 * send. 4787 * 4788 * @param cls closure 4789 * @param cb pending webhook callback 4790 * @param cb_cls callback closure 4791 */ 4792 // WHERE next_attempt <= now ORDER BY next_attempt ASC 4793 enum GNUNET_DB_QueryStatus 4794 (*lookup_pending_webhooks)(void *cls, 4795 TALER_MERCHANTDB_PendingWebhooksCallback cb, 4796 void *cb_cls); 4797 4798 /** 4799 * Lookup future webhook in the pending webhook that need to be send. 4800 * With that we can know how long the system can 'sleep'. 4801 * 4802 * @param cls closure 4803 * @param cb pending webhook callback 4804 * @param cb_cls callback closure 4805 */ 4806 // ORDER BY next_attempt ASC LIMIT 1 4807 enum GNUNET_DB_QueryStatus 4808 (*lookup_future_webhook)(void *cls, 4809 TALER_MERCHANTDB_PendingWebhooksCallback cb, 4810 void *cb_cls); 4811 4812 /** 4813 * Lookup all the webhooks in the pending webhook. 4814 * Use by the administrator 4815 * 4816 * @param cls closure 4817 * @param instance_id to lookup webhooks for this instance particularly 4818 * @param min_row to see the list of the pending webhook that it is started with this minimum row. 4819 * @param max_results to see the list of the pending webhook that it is end with this max results. 4820 * @param cb pending webhook callback 4821 * @param cb_cls callback closure 4822 */ 4823 // WHERE webhook_pending_serial > min_row ORDER BY webhook_pending_serial ASC LIMIT max_results 4824 enum GNUNET_DB_QueryStatus 4825 (*lookup_all_webhooks)(void *cls, 4826 const char *instance_id, 4827 uint64_t min_row, 4828 uint32_t max_results, 4829 TALER_MERCHANTDB_PendingWebhooksCallback cb, 4830 void *cb_cls); 4831 4832 4833 /** 4834 * Update the pending webhook. It is use if the webhook can't be send. 4835 * 4836 * @param cls closure 4837 * @param webhook_serial webhook that need to be update 4838 * @param next_attempt when we should make the next request to the webhook 4839 * @return database result code 4840 */ 4841 enum GNUNET_DB_QueryStatus 4842 (*update_pending_webhook)(void *cls, 4843 uint64_t webhook_pending_serial, 4844 struct GNUNET_TIME_Absolute next_attempt); 4845 // maybe add: http status of failure? 4846 4847 4848 /** 4849 * Delete a webhook in the pending webhook after the 4850 * webhook was completed successfully. 4851 * 4852 * @param cls closure 4853 * @param webhook_serial webhook that need to be delete in the pending webhook 4854 * @return database result code 4855 */ 4856 enum GNUNET_DB_QueryStatus 4857 (*delete_pending_webhook)(void *cls, 4858 uint64_t webhook_pending_serial); 4859 4860 4861 /** 4862 * Retrieve exchange's keys from the database. 4863 * 4864 * @param cls plugin closure 4865 * @param exchange_url base URL of the exchange 4866 * @param[out] first_retry set to earliest we may retry fetching the keys 4867 * @param[out] keys set to the keys of the exchange 4868 * @return transaction status 4869 */ 4870 enum GNUNET_DB_QueryStatus 4871 (*select_exchange_keys)(void *cls, 4872 const char *exchange_url, 4873 struct GNUNET_TIME_Absolute *first_retry, 4874 struct TALER_EXCHANGE_Keys **keys); 4875 4876 4877 /** 4878 * Insert or update @a keys into the database. 4879 * 4880 * @param cls plugin closure 4881 * @param exchange_url base URL of the exchange 4882 * @param keys data to store 4883 * @param first_retry earliest we may retry fetching the keys 4884 * @param http_status latest HTTP status of the exchange 4885 * @param ec latest error code from fetching /keys 4886 * @return transaction status 4887 */ 4888 enum GNUNET_DB_QueryStatus 4889 (*insert_exchange_keys)(void *cls, 4890 const char *exchange_url, 4891 const struct TALER_EXCHANGE_Keys *keys, 4892 struct GNUNET_TIME_Absolute first_retry, 4893 uint32_t http_status, 4894 enum TALER_ErrorCode ec); 4895 4896 4897 /** 4898 * Lookup all of the token families the given instance has configured. 4899 * 4900 * @param cls closure 4901 * @param instance_id instance to lookup token families for 4902 * @param cb function to call on all token families found 4903 * @param cb_cls closure for @a cb 4904 * @return database result code 4905 */ 4906 enum GNUNET_DB_QueryStatus 4907 (*lookup_token_families)(void *cls, 4908 const char *instance_id, 4909 TALER_MERCHANTDB_TokenFamiliesCallback cb, 4910 void *cb_cls); 4911 4912 /** 4913 * Lookup details about a particular token family. 4914 * 4915 * @param cls closure 4916 * @param instance_id instance to lookup token family for 4917 * @param token_family_slug token family to lookup 4918 * @param[out] details set to the token family details on success, can be NULL 4919 * (in that case we only want to check if the token family exists) 4920 * @return database result code 4921 */ 4922 enum GNUNET_DB_QueryStatus 4923 (*lookup_token_family)(void *cls, 4924 const char *instance_id, 4925 const char *token_family_slug, 4926 struct TALER_MERCHANTDB_TokenFamilyDetails *details); 4927 4928 /** 4929 * Delete information about a token family. 4930 * 4931 * @param cls closure 4932 * @param instance_id instance to delete token family of 4933 * @param token_family_slug slug of token family to delete 4934 * @return database result code 4935 */ 4936 enum GNUNET_DB_QueryStatus 4937 (*delete_token_family)(void *cls, 4938 const char *instance_id, 4939 const char *token_family_slug); 4940 4941 /** 4942 * Update details about a particular token family. 4943 * 4944 * @param cls closure 4945 * @param instance_id instance to update token family for 4946 * @param token_family_slug slug of token family to update 4947 * @param details set to the updated token family on success, can be NULL 4948 * (in that case we only want to check if the token family exists) 4949 * @return database result code 4950 */ 4951 enum GNUNET_DB_QueryStatus 4952 (*update_token_family)( 4953 void *cls, 4954 const char *instance_id, 4955 const char *token_family_slug, 4956 const struct TALER_MERCHANTDB_TokenFamilyDetails *details); 4957 4958 4959 /** 4960 * Insert details about a particular token family. 4961 * 4962 * @param cls closure 4963 * @param instance_id instance to insert token family for 4964 * @param token_family_slug slug of token family to insert 4965 * @param details the token family details to insert 4966 * @return database result code 4967 */ 4968 enum GNUNET_DB_QueryStatus 4969 (*insert_token_family)( 4970 void *cls, 4971 const char *instance_id, 4972 const char *token_family_slug, 4973 const struct TALER_MERCHANTDB_TokenFamilyDetails *details); 4974 4975 4976 /** 4977 * Lookup details about a particular token family key. 4978 * 4979 * @param cls closure 4980 * @param instance_id instance to lookup token family key for 4981 * @param token_family_slug slug of token family to lookup 4982 * @param valid_at find a key with a validity period that includes this time 4983 * @param sign_until find a private key that can sign until this time 4984 * @param[out] details set to the token family key details on success, can be NULL 4985 * (in that case we only want to check if the token family key exists) 4986 * @return database result code 4987 */ 4988 enum GNUNET_DB_QueryStatus 4989 (*lookup_token_family_key)( 4990 void *cls, 4991 const char *instance_id, 4992 const char *token_family_slug, 4993 struct GNUNET_TIME_Timestamp valid_at, 4994 struct GNUNET_TIME_Timestamp sign_until, 4995 struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details); 4996 4997 4998 /** 4999 * Lookup token family keys that may be used for a payment. 5000 * 5001 * @param cls closure 5002 * @param instance_id instance to lookup token family key for 5003 * @param token_family_slug slug of token family to lookup 5004 * @param start_time signature validity start the keys must fall into 5005 * @param end_time signature validity end the keys must fall into 5006 * @param cb function to call with each matching key 5007 * @param cb_cls closure for @a cb 5008 * @return database result code 5009 */ 5010 enum GNUNET_DB_QueryStatus 5011 (*lookup_token_family_keys)( 5012 void *cls, 5013 const char *instance_id, 5014 const char *token_family_slug, 5015 struct GNUNET_TIME_Timestamp start_time, 5016 struct GNUNET_TIME_Timestamp end_time, 5017 TALER_MERCHANTDB_TokenKeyCallback cb, 5018 void *cb_cls); 5019 5020 5021 /** 5022 * Insert details a key pair for a token family. 5023 * 5024 * @param cls closure 5025 * @param merchant_id instance name 5026 * @param token_family_slug slug of token family to insert the key pair for 5027 * @param pub token family public key 5028 * @param priv token family private key 5029 * @param key_expires when does the private key expire (because 5030 * the validity period of the next token family key starts) 5031 * @param valid_after start of validity period for signatures with this key 5032 * @param valid_before end of validity period for signatures with this key 5033 * @return database result code 5034 */ 5035 enum GNUNET_DB_QueryStatus 5036 (*insert_token_family_key)( 5037 void *cls, 5038 const char *merchant_id, 5039 const char *token_family_slug, 5040 const struct TALER_TokenIssuePublicKey *pub, 5041 const struct TALER_TokenIssuePrivateKey *priv, 5042 struct GNUNET_TIME_Timestamp key_expires, 5043 struct GNUNET_TIME_Timestamp valid_after, 5044 struct GNUNET_TIME_Timestamp valid_before); 5045 5046 /** 5047 * Lookup deposits that are finished and awaiting a wire transfer. 5048 * 5049 * @param cls closure 5050 * @param exchange_url exchange to filter deposits by 5051 * @param limit maximum number of deposits to return 5052 * @param allow_future true to allow deposits with wire deadline in the future 5053 * @param cb function to call with deposit data 5054 * @param cb_cls closure for @a cb 5055 * @return transaction status 5056 */ 5057 enum GNUNET_DB_QueryStatus 5058 (*lookup_pending_deposits)( 5059 void *cls, 5060 const char *exchange_url, 5061 uint64_t limit, 5062 bool allow_future, 5063 TALER_MERCHANTDB_PendingDepositsCallback cb, 5064 void *cb_cls); 5065 5066 5067 /** 5068 * Update the deposit confirmation status associated with 5069 * the given @a deposit_serial. 5070 * 5071 * @param cls closure 5072 * @param deposit_serial deposit to update status for 5073 * @param retry_needed true if the HTTP request should be retried 5074 * @param retry_time when should we ask the exchange again 5075 * @param last_http_status HTTP status code of the last reply 5076 * @param last_ec Taler error code of the last reply 5077 * @param last_detail detail from error message to record, possibly NULL 5078 * @return database result code 5079 */ 5080 enum GNUNET_DB_QueryStatus 5081 (*update_deposit_confirmation_status)( 5082 void *cls, 5083 uint64_t deposit_serial, 5084 bool retry_needed, 5085 struct GNUNET_TIME_Timestamp retry_time, 5086 uint32_t last_http_status, 5087 enum TALER_ErrorCode last_ec, 5088 const char *last_detail); 5089 5090 5091 /** 5092 * Update the amount of receipts for a Donau instance. 5093 * 5094 * @param cls closure 5095 * @param donau_instances_serial serial number of the Donau instance 5096 * @param new_amount new receipts_to_date amount 5097 * @return database result code 5098 */ 5099 enum GNUNET_DB_QueryStatus 5100 (*update_donau_instance_receipts_amount)( 5101 void *cls, 5102 uint64_t *donau_instances_serial, 5103 const struct TALER_Amount *new_amount 5104 ); 5105 5106 5107 /** 5108 * Check if a new matching multi-factor authorization (MFA) challenge 5109 * exists in the database. 5110 * 5111 * @param cls closure 5112 * @param challenge_id set to the ID of the challenge 5113 * @param h_body hash of the request body 5114 * @param[out] salt salt used to compute @a h_body 5115 * @param[out] required address set to where the challenge is to be send 5116 * @param[out] op operation that triggered the MFA request 5117 * @param[out] confirmation_date when was the challenge solved, 5118 * set to "GNUNET_TIME_ABSOLUTE_NEVER" if unsolved 5119 * @param[out] retransmission_date set to when a fresh challenge 5120 * may be transmitted 5121 * @param[out] retry_counter set to the number of attempts that remain 5122 * for solving the challenge (after this time) 5123 * @param[out] tan_channel which channel was used 5124 * @param[out] instance_name name of the instance for which the 5125 * challenge is being issued 5126 * @return database result code 5127 */ 5128 enum GNUNET_DB_QueryStatus 5129 (*lookup_mfa_challenge)( 5130 void *cls, 5131 uint64_t challenge_id, 5132 const struct TALER_MERCHANT_MFA_BodyHash *h_body, 5133 struct TALER_MERCHANT_MFA_BodySalt *salt, 5134 char **required_address, 5135 enum TALER_MERCHANT_MFA_CriticalOperation *op, 5136 struct GNUNET_TIME_Absolute *confirmation_date, 5137 struct GNUNET_TIME_Absolute *retransmission_date, 5138 uint32_t *retry_counter, 5139 enum TALER_MERCHANT_MFA_Channel *tan_channel, 5140 char **instance_name); 5141 5142 5143 /** 5144 * Attempt to solve new multi-factor authorization (MFA) challenge. 5145 * Checks the solution against the code in the database and updates 5146 * the solution state and (on failure) retry counter depending on 5147 * the result. 5148 * 5149 * @param cls closure 5150 * @param challenge_id challenge ID to be solved 5151 * @param h_body body of the operation the challenge authorizes 5152 * @param solution proposed solution to be checked against the actual code 5153 * @param[out] solved set to true if the challenge was solved by 5154 * @a solution 5155 * @param[out] retry_counter set to the number of attempts that remain 5156 * for solving the challenge (after this time) 5157 * @return database result code 5158 */ 5159 enum GNUNET_DB_QueryStatus 5160 (*solve_mfa_challenge)( 5161 void *cls, 5162 uint64_t challenge_id, 5163 const struct TALER_MERCHANT_MFA_BodyHash *h_body, 5164 const char *solution, 5165 bool *solved, 5166 uint32_t *retry_counter); 5167 5168 5169 /** 5170 * Update the state of an MFA challenge as we have now 5171 * retransmitted the challenge code. 5172 * 5173 * @param cls closure 5174 * @param challenge_id challenge ID to be solved 5175 * @param code new challenge code 5176 * @param retry_counter number of attempts that remain 5177 * for solving the challenge 5178 * @param expiration_date when should the challenge expire 5179 * @param retransmission_date set to when a fresh challenge 5180 * may be transmitted next 5181 * @return database result code 5182 */ 5183 enum GNUNET_DB_QueryStatus 5184 (*update_mfa_challenge)( 5185 void *cls, 5186 uint64_t challenge_id, 5187 const char *code, 5188 uint32_t retry_counter, 5189 struct GNUNET_TIME_Absolute expiration_date, 5190 struct GNUNET_TIME_Absolute retransmission_date); 5191 5192 5193 /** 5194 * Create new multi-factor authorization (MFA) challenge in the database. 5195 * 5196 * @param cls closure 5197 * @param op operation that triggered the MFA request 5198 * @param h_body hash of the request body 5199 * @param salt salt used to compute @a h_body 5200 * @param code challenge code sent to the user 5201 * @param expiration_date when should the challenge expire 5202 * @param retansmission_date when do we next allow retransmission 5203 * of the challenge 5204 * @param tan_channel which channel was used 5205 * @param required_address address 5206 * where the challenge is to be sent 5207 * @param instance_id name of the instance for which the challenge 5208 * is being created 5209 * @param[out] challenge_id set to the ID of the new challenge 5210 * @return database result code 5211 */ 5212 enum GNUNET_DB_QueryStatus 5213 (*create_mfa_challenge)( 5214 void *cls, 5215 enum TALER_MERCHANT_MFA_CriticalOperation op, 5216 const struct TALER_MERCHANT_MFA_BodyHash *h_body, 5217 const struct TALER_MERCHANT_MFA_BodySalt *salt, 5218 const char *code, 5219 struct GNUNET_TIME_Absolute expiration_date, 5220 struct GNUNET_TIME_Absolute retransmission_date, 5221 enum TALER_MERCHANT_MFA_Channel tan_channel, 5222 const char *required_address, 5223 const char *instance_id, 5224 uint64_t *challenge_id); 5225 5226 5227 /** 5228 * Insert information about a Donau instance. 5229 * 5230 * @param cls closure 5231 * @param donau_url URL of the Donau instance 5232 * @param charity details of the charity 5233 * @param charity_id charity ID of the Donau instance 5234 */ 5235 enum GNUNET_DB_QueryStatus 5236 (*insert_donau_instance)( 5237 void *cls, 5238 const char *donau_url, 5239 const struct DONAU_Charity *charity, 5240 uint64_t charity_id 5241 ); 5242 5243 5244 /** 5245 * Check if information about a Donau instance exists. 5246 * 5247 * @param cls closure 5248 * @param merchant_pub public key of the instance 5249 * @param donau_url URL of the Donau instance 5250 * @param charity_id charity ID of the Donau instance 5251 */ 5252 enum GNUNET_DB_QueryStatus 5253 (*check_donau_instance)( 5254 void *cls, 5255 const struct TALER_MerchantPublicKeyP *merchant_pub, 5256 const char *donau_url, 5257 uint64_t charity_id 5258 ); 5259 5260 /** 5261 * Select donau instance by serial number. 5262 * 5263 * @param cls closure 5264 * @param serial serial number of the Donau instance in DB 5265 * @param[out] donau_url set to the URL of the Donau instance 5266 * @param[out] charity_id set to the charity ID of the Donau instance 5267 */ 5268 enum GNUNET_DB_QueryStatus 5269 (*select_donau_instance_by_serial)( 5270 void *cls, 5271 uint64_t serial, 5272 char **donau_url, 5273 uint64_t *charity_id); 5274 5275 /** 5276 * Select all Donau instances. Note that this callback only 5277 * returns Donau instances for which we have successfully 5278 * retrieved /keys. 5279 * 5280 * @param cls closure 5281 * @param id instance to restrict to 5282 * @param cb function to call on all Donau instances found 5283 * @param cb_cls closure for @a cb 5284 */ 5285 enum GNUNET_DB_QueryStatus 5286 (*select_donau_instances)( 5287 void *cls, 5288 const char *id, 5289 TALER_MERCHANTDB_DonauInstanceCallback cb, 5290 void *cb_cls); 5291 5292 5293 /** 5294 * Select all Donau instances, regardless of instance and also 5295 * regardless of whether we got a /keys response. 5296 * 5297 * @param cls closure 5298 * @param cb function to call on all Donau instances found 5299 * @param cb_cls closure for @a cb 5300 */ 5301 enum GNUNET_DB_QueryStatus 5302 (*select_all_donau_instances)( 5303 void *cls, 5304 TALER_MERCHANTDB_DonauInstanceCallback cb, 5305 void *cb_cls); 5306 5307 5308 /** 5309 * Select all Donau instances, but only the donau_url 5310 * and charity_max_per_year. 5311 * 5312 * @param cls closure 5313 * @param cb function to call on all Donau instances found 5314 * @param cb_cls closure for @a cb 5315 */ 5316 enum GNUNET_DB_QueryStatus 5317 (*select_donau_instances_filtered)( 5318 void *cls, 5319 const char *currency, 5320 TALER_MERCHANTDB_DonauInstanceFilteredCallback cb, 5321 void *cb_cls); 5322 5323 /** 5324 * Lookup Donau keys by URL. 5325 * 5326 * @param cls closure 5327 * @param donau_url URL of the Donau instance 5328 * @param[out] keys set to the Donau keys on success 5329 */ 5330 enum GNUNET_DB_QueryStatus 5331 (*lookup_donau_keys)( 5332 void *cls, 5333 const char *donau_url, 5334 struct GNUNET_TIME_Absolute *first_retry, 5335 struct DONAU_Keys **keys); 5336 5337 /** 5338 * Lookup a Donau instance by its instance ID and URL. 5339 * 5340 * @param cls closure 5341 * @param instance_id instance ID of the Donau instance 5342 * @param donau_url URL of the Donau instance 5343 * @param charity_id set to the charity ID of the Donau instance 5344 * @param charity_priv set to the private key of the charity 5345 * @param charity_max_per_year set to the maximum amount 5346 * the charity can receive per year 5347 * @param charity_receipts_to_date set to the total amount 5348 * the charity has received to date 5349 * @param donau_keys_json set to the JSON representation of the 5350 * Donau keys 5351 */ 5352 enum GNUNET_DB_QueryStatus 5353 (*lookup_order_charity)( 5354 void *cls, 5355 const char *instance_id, 5356 const char *donau_url, 5357 uint64_t *charity_id, 5358 struct DONAU_CharityPrivateKeyP *charity_priv, 5359 struct TALER_Amount *charity_max_per_year, 5360 struct TALER_Amount *charity_receipts_to_date, 5361 json_t **donau_keys_json, 5362 uint64_t *donau_instance_serial); 5363 5364 /** 5365 * Upsert Donau keys into the database. 5366 * 5367 * @param cls closure 5368 * @param keys Donau keys to insert or update 5369 */ 5370 enum GNUNET_DB_QueryStatus 5371 (*upsert_donau_keys)( 5372 void *cls, 5373 const struct DONAU_Keys *keys, 5374 struct GNUNET_TIME_Absolute first_retry); 5375 5376 /** 5377 * Update information about a Donau instance. 5378 * 5379 * @param cls closure 5380 * @param donau_url URL of the Donau instance 5381 * @param charity details of the charity 5382 * @param charity_id charity ID of the Donau instance 5383 */ 5384 enum GNUNET_DB_QueryStatus 5385 (*update_donau_instance)( 5386 void *cls, 5387 const char *donau_url, 5388 const struct DONAU_Charity *charity, 5389 uint64_t charity_id); 5390 5391 /** 5392 * Delete information about a Donau instance. 5393 * 5394 * @param cls closure 5395 * @param charity_id charity ID of the Donau instance to delete 5396 */ 5397 enum GNUNET_DB_QueryStatus 5398 (*delete_donau_instance)( 5399 void *cls, 5400 const char *id, 5401 uint64_t charity_id); 5402 5403 /** 5404 * Lookup amount statistics for instance and slug by bucket. 5405 * 5406 * @param cls closure 5407 * @param instance_id instance to lookup statistics for 5408 * @param slug instance to lookup statistics for 5409 * @param cb function to call on all token families found 5410 * @param cb_cls closure for @a cb 5411 * @return database result code 5412 */ 5413 enum GNUNET_DB_QueryStatus 5414 (*lookup_statistics_amount_by_bucket)( 5415 void *cls, 5416 const char *instance_id, 5417 const char *slug, 5418 TALER_MERCHANTDB_AmountByBucketStatisticsCallback cb, 5419 void *cb_cls); 5420 5421 /** 5422 * Lookup amount statistics for instance and slug by bucket, 5423 * restricting to a fixed number of buckets at a given granularity. 5424 * 5425 * @param cls closure 5426 * @param instance_id instance to lookup statistics for 5427 * @param slug instance to lookup statistics for 5428 * @param granularity limit to buckets of this size 5429 * @param counter requested number of buckets 5430 * @param cb function to call on all token families found 5431 * @param cb_cls closure for @a cb 5432 * @return database result code 5433 */ 5434 enum GNUNET_DB_QueryStatus 5435 (*lookup_statistics_amount_by_bucket2)( 5436 void *cls, 5437 const char *instance_id, 5438 const char *slug, 5439 const char *granularity, 5440 uint64_t counter, 5441 TALER_MERCHANTDB_AmountByBucketStatisticsCallback2 cb, 5442 void *cb_cls); 5443 5444 5445 /** 5446 * Lookup counter statistics for instance and slug by bucket. 5447 * 5448 * @param cls closure 5449 * @param instance_id instance to lookup statistics for 5450 * @param slug instance to lookup statistics for 5451 * @param cb function to call on all token families found 5452 * @param cb_cls closure for @a cb 5453 * @return database result code 5454 */ 5455 enum GNUNET_DB_QueryStatus 5456 (*lookup_statistics_counter_by_bucket)( 5457 void *cls, 5458 const char *instance_id, 5459 const char *slug, 5460 TALER_MERCHANTDB_CounterByBucketStatisticsCallback cb, 5461 void *cb_cls); 5462 5463 /** 5464 * Lookup counter statistics for instance and slug-prefix by bucket. 5465 * 5466 * @param cls closure 5467 * @param instance_id instance to lookup statistics for 5468 * @param prefix slug prefix to lookup statistics under 5469 * @param granularity limit to buckets of this size 5470 * @param counter requested number of buckets 5471 * @param cb function to call on all token families found 5472 * @param cb_cls closure for @a cb 5473 * @return database result code 5474 */ 5475 enum GNUNET_DB_QueryStatus 5476 (*lookup_statistics_counter_by_bucket2)( 5477 void *cls, 5478 const char *instance_id, 5479 const char *prefix, 5480 const char *granularity, 5481 uint64_t counter, 5482 TALER_MERCHANTDB_CounterByBucketStatisticsCallback2 cb, 5483 void *cb_cls); 5484 5485 5486 /** 5487 * Lookup amount statistics for instance and slug by interval. 5488 * 5489 * @param cls closure 5490 * @param instance_id instance to lookup statistics for 5491 * @param slug instance to lookup statistics for 5492 * @param cb function to call on all token families found 5493 * @param cb_cls closure for @a cb 5494 * @return database result code 5495 */ 5496 enum GNUNET_DB_QueryStatus 5497 (*lookup_statistics_amount_by_interval)( 5498 void *cls, 5499 const char *instance_id, 5500 const char *slug, 5501 TALER_MERCHANTDB_AmountByIntervalStatisticsCallback cb, 5502 void *cb_cls); 5503 5504 /** 5505 * Lookup counter statistics for instance and slug by interval. 5506 * 5507 * @param cls closure 5508 * @param instance_id instance to lookup statistics for 5509 * @param slug instance to lookup statistics for 5510 * @param cb function to call on all token families found 5511 * @param cb_cls closure for @a cb 5512 * @return database result code 5513 */ 5514 enum GNUNET_DB_QueryStatus 5515 (*lookup_statistics_counter_by_interval)( 5516 void *cls, 5517 const char *instance_id, 5518 const char *slug, 5519 TALER_MERCHANTDB_CounterByIntervalStatisticsCallback cb, 5520 void *cb_cls); 5521 5522 5523 /** 5524 * Lookup all of the money pots the given instance has configured. 5525 * 5526 * @param cls closure 5527 * @param instance_id instance to lookup money pots for 5528 * @param limit number of entries to return, negative for descending in execution time, 5529 * positive for ascending in execution time 5530 * @param offset number of the money pot we want to offset from 5531 * @param cb function to call on all money pots found 5532 * @param cb_cls closure for @a cb 5533 * @return database result code 5534 */ 5535 enum GNUNET_DB_QueryStatus 5536 (*select_money_pots)(void *cls, 5537 const char *instance_id, 5538 int64_t limit, 5539 uint64_t offset, 5540 TALER_MERCHANTDB_MoneyPotsCallback cb, 5541 void *cb_cls); 5542 5543 5544 /** 5545 * Check that all of the money pots given exist at the instance, 5546 * returning one that does *not* exist (for generating an error) 5547 * if the check fails. 5548 * 5549 * @param cls closure 5550 * @param instance_id instance to lookup token families for 5551 * @param pots_len length of the @a pots array 5552 * @param pots money pot identifiers to check if they exist 5553 * @param[out] pot_missing set to ID of pot not known at the instance 5554 * @return transaction status, 5555 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means that all pots exist 5556 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT indicates that 5557 * @a pot_missing was initialized to a missing pot 5558 */ 5559 enum GNUNET_DB_QueryStatus 5560 (*check_money_pots)(void *cls, 5561 const char *instance_id, 5562 unsigned int pots_len, 5563 uint64_t pots[static pots_len], 5564 uint64_t *pot_missing); 5565 5566 /** 5567 * Lookup details about a particular money pot. 5568 * 5569 * @param cls closure 5570 * @param instance_id instance to lookup money pot for 5571 * @param money_pot_id serial number of the pot to lookup 5572 * @param [out] name set to name of the pot, 5573 * must be freed by caller 5574 * @param[out] description set to description of the pot, 5575 * must be freed by caller 5576 * @param[out] pot_total_len set to length of @a pot_totals array 5577 * @param[out] pot_totals set to amounts currently in the pot; 5578 * array must be freed by caller 5579 * @return database result code 5580 */ 5581 enum GNUNET_DB_QueryStatus 5582 (*select_money_pot)(void *cls, 5583 const char *instance_id, 5584 uint64_t money_pot_id, 5585 char **name, 5586 char **description, 5587 size_t *pot_total_len, 5588 struct TALER_Amount **pot_totals); 5589 5590 /** 5591 * Delete information about a money pot. 5592 * 5593 * @param cls closure 5594 * @param instance_id instance to delete money pot of 5595 * @param money_pot_id serial number of the pot to delete 5596 * @return database result code 5597 */ 5598 enum GNUNET_DB_QueryStatus 5599 (*delete_money_pot)(void *cls, 5600 const char *instance_id, 5601 uint64_t money_pot_id); 5602 5603 /** 5604 * Update details about a particular money pot. 5605 * 5606 * @param cls closure 5607 * @param instance_id instance to update money pot for 5608 * @param money_pot_id serial number of the pot to delete 5609 * @param name set to name of the pot 5610 * @param description set to description of the pot 5611 * @param opt_len length of @a old_pot_totals 5612 * @param old_pot_totals amounts expected currently in the pot, 5613 * NULL to not check (non-NULL but @a opt_len=0 checks for []) 5614 * @param npt_len length of @a new_pot_totals 5615 * @param new_pot_totals new amounts in the pot, 5616 * NULL to not update (non-NULL but @a npt_len=0 resets to []) 5617 * @param[out] conflict_total set to true if @a old_pot_total does not match 5618 * @param[out] conflict_name set to true if @a name is used by another pot 5619 * @return database result code 5620 */ 5621 enum GNUNET_DB_QueryStatus 5622 (*update_money_pot)( 5623 void *cls, 5624 const char *instance_id, 5625 uint64_t money_pot_id, 5626 const char *name, 5627 const char *description, 5628 size_t opt_len, 5629 const struct TALER_Amount *old_pot_totals, 5630 size_t npt_len, 5631 const struct TALER_Amount *new_pot_totals, 5632 bool *conflict_total, 5633 bool *conflict_name); 5634 5635 5636 /** 5637 * Increment amounts in money pots. If a money pot does not exist, 5638 * it is simply skipped (without causing an error!). 5639 * 5640 * @param cls closure 5641 * @param instance_id instance to update money pot for 5642 * @param money_pots_len length of the @a money_pots_ids 5643 * and @a pot_increments arrays 5644 * @param money_pot_ids serial numbers of the pots to increment 5645 * @param pot_increments new amounts to add to the respective pot 5646 * @return database result code 5647 */ 5648 enum GNUNET_DB_QueryStatus 5649 (*increment_money_pots)( 5650 void *cls, 5651 const char *instance_id, 5652 size_t money_pots_len, 5653 const uint64_t *money_pot_ids, 5654 const struct TALER_Amount *pot_increments); 5655 5656 5657 /** 5658 * Insert details about a particular pot. 5659 * 5660 * @param cls closure 5661 * @param instance_id instance to insert pot for 5662 * @param name set to name of the pot 5663 * @param description set to description of the pot 5664 * @param[out] money_pot_id serial number of the new pot 5665 * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 5666 * on conflict (@a name already in use at @a instance_id). 5667 */ 5668 enum GNUNET_DB_QueryStatus 5669 (*insert_money_pot)( 5670 void *cls, 5671 const char *instance_id, 5672 const char *name, 5673 const char *description, 5674 uint64_t *money_pot_id); 5675 5676 // Reports 5677 5678 /** 5679 * Lookup all of the reports the given instance has configured. 5680 * 5681 * @param cls closure 5682 * @param instance_id instance to lookup reports for 5683 * @param limit number of entries to return, negative for descending in execution time, 5684 * positive for ascending in execution time 5685 * @param offset expected_transfer_serial number of the transfer we want to offset from 5686 * @param cb function to call on all reports found 5687 * @param cb_cls closure for @a cb 5688 * @return database result code 5689 */ 5690 enum GNUNET_DB_QueryStatus 5691 (*select_reports)(void *cls, 5692 const char *instance_id, 5693 int64_t limit, 5694 uint64_t offset, 5695 TALER_MERCHANTDB_ReportsCallback cb, 5696 void *cb_cls); 5697 5698 5699 /** 5700 * Lookup all of the reports pending for the given backend. 5701 * 5702 * @param cls closure 5703 * @param cb function to call on all reports found 5704 * @param cb_cls closure for @a cb 5705 * @return database result code 5706 */ 5707 enum GNUNET_DB_QueryStatus 5708 (*lookup_reports_pending)(void *cls, 5709 TALER_MERCHANTDB_ReportsPendingCallback cb, 5710 void *cb_cls); 5711 5712 /** 5713 * Lookup details about a particular report. 5714 * 5715 * @param cls closure 5716 * @param instance_id instance to lookup reports for 5717 * @param report_id serial number of the report to lookup 5718 * @param[out] report_program_section configuration section of program 5719 * for report generation 5720 * @param[out] report_description text describing the report 5721 * @param[out] mime_type mime type to request from the @a data_source 5722 * @param[out] data_source relative URL (to instance base URL) 5723 * to request report data from 5724 * @param[out] target_address where to send report data 5725 * @param[out] frequency report frequency 5726 * @param[out] frequency_shift how much to shift the report time from a 5727 * multiple of the report @a frequency 5728 * @param[out] next_transmission when will the report be generated next 5729 * @param[out] last_error_code status of the last report 5730 * @param[out] last_error_detail details about failures of last generation 5731 * @return database result code 5732 */ 5733 enum GNUNET_DB_QueryStatus 5734 (*select_report)(void *cls, 5735 const char *instance_id, 5736 uint64_t report_id, 5737 char **report_program_section, 5738 char **report_description, 5739 char **mime_type, 5740 char **data_source, 5741 char **target_address, 5742 struct GNUNET_TIME_Relative *frequency, 5743 struct GNUNET_TIME_Relative *frequency_shift, 5744 struct GNUNET_TIME_Absolute *next_transmission, 5745 enum TALER_ErrorCode *last_error_code, 5746 char **last_error_detail); 5747 5748 /** 5749 * Check that a particular report is scheduled under the 5750 * given @a report_id and @a report_token. Does not 5751 * validate that the report is actually due. 5752 * 5753 * @param cls closure 5754 * @param report_id serial number of the report to lookup 5755 * @param report_token report token to check 5756 * @param mime_type mime type to request from the @a data_source 5757 * @param[out] instance_id instance to lookup reports for 5758 * @param[out] data_source relative URL (to instance base URL) 5759 * to request report data from 5760 * @return database result code 5761 */ 5762 enum GNUNET_DB_QueryStatus 5763 (*check_report)(void *cls, 5764 uint64_t report_id, 5765 const struct TALER_MERCHANT_ReportToken *report_token, 5766 const char *mime_type, 5767 char **instance_id, 5768 char **data_source); 5769 5770 5771 /** 5772 * Delete information about a report. 5773 * 5774 * @param cls closure 5775 * @param instance_id instance to delete report of 5776 * @param report_id serial number of the pot to delete 5777 * @return database result code 5778 */ 5779 enum GNUNET_DB_QueryStatus 5780 (*delete_report)(void *cls, 5781 const char *instance_id, 5782 uint64_t report_id); 5783 5784 /** 5785 * Update transmission status about a particular report. 5786 * 5787 * @param cls closure 5788 * @param instance_id instance to update report for 5789 * @param report_id serial number of the pot to update 5790 * @param next_tranmission when should the report be generated next 5791 * @param last_error_code #TALER_EC_NONE on success 5792 * @param last_error_detail NULL on success 5793 * @return database result code 5794 */ 5795 enum GNUNET_DB_QueryStatus 5796 (*update_report_status)( 5797 void *cls, 5798 const char *instance_id, 5799 uint64_t report_id, 5800 struct GNUNET_TIME_Timestamp next_transmission, 5801 enum TALER_ErrorCode last_error_code, 5802 const char *last_error_detail); 5803 5804 5805 /** 5806 * Update details about a particular report. 5807 * 5808 * @param cls closure 5809 * @param instance_id instance to update report for 5810 * @param report_id serial number of the report to update 5811 * @param report_program_section configuration section of program 5812 * for report generation 5813 * @param report_description text describing the report 5814 * @param mime_type mime type to request from the @a data_source 5815 * @param data_source relative URL (to instance base URL) 5816 * to request report data from 5817 * @param target_address where to send report data 5818 * @param frequency report frequency 5819 * @param frequency_shift how much to shift the report time from a 5820 * multiple of the report @a frequency 5821 * @return database result code 5822 */ 5823 enum GNUNET_DB_QueryStatus 5824 (*update_report)( 5825 void *cls, 5826 const char *instance_id, 5827 uint64_t report_id, 5828 const char *report_program_section, 5829 const char *report_description, 5830 const char *mime_type, 5831 const char *data_source, 5832 const char *target_address, 5833 struct GNUNET_TIME_Relative frequency, 5834 struct GNUNET_TIME_Relative frequency_shift); 5835 5836 5837 /** 5838 * Insert details about a particular report. 5839 * 5840 * @param cls closure 5841 * @param instance_id instance to insert report for 5842 * @param report_program_section configuration section of program 5843 * for report generation 5844 * @param report_description text describing the report 5845 * @param mime_type mime type to request from the @a data_source 5846 * @param data_source relative URL (to instance base URL) 5847 * to request report data from 5848 * @param target_address where to send report data 5849 * @param frequency report frequency 5850 * @param frequency_shift how much to shift the report time from a 5851 * multiple of the report @a frequency 5852 * @param[out] report_id serial number of the new pot 5853 * @return database result code 5854 */ 5855 enum GNUNET_DB_QueryStatus 5856 (*insert_report)( 5857 void *cls, 5858 const char *instance_id, 5859 const char *report_program_section, 5860 const char *report_description, 5861 const char *mime_type, 5862 const char *data_source, 5863 const char *target_address, 5864 struct GNUNET_TIME_Relative frequency, 5865 struct GNUNET_TIME_Relative frequency_shift, 5866 uint64_t *report_id); 5867 5868 5869 // groups 5870 5871 /** 5872 * Lookup all of the product groups the given instance has configured. 5873 * 5874 * @param cls closure 5875 * @param instance_id instance to lookup product groups for 5876 * @param limit number of entries to return, negative for descending in execution time, 5877 * positive for ascending in execution time 5878 * @param offset expected_transfer_serial number of the transfer we want to offset from 5879 * @param cb function to call on all groups found 5880 * @param cb_cls closure for @a cb 5881 * @return database result code 5882 */ 5883 enum GNUNET_DB_QueryStatus 5884 (*select_product_groups)(void *cls, 5885 const char *instance_id, 5886 int64_t limit, 5887 uint64_t offset, 5888 TALER_MERCHANTDB_ProductGroupsCallback cb, 5889 void *cb_cls); 5890 5891 /** 5892 * Delete information about a product group. 5893 * 5894 * @param cls closure 5895 * @param instance_id instance to delete product group of 5896 * @param product_group_id serial number of the group to delete 5897 * @return database result code 5898 */ 5899 enum GNUNET_DB_QueryStatus 5900 (*delete_product_group)(void *cls, 5901 const char *instance_id, 5902 uint64_t product_group_id); 5903 5904 /** 5905 * Update details about a particular product group. 5906 * 5907 * @param cls closure 5908 * @param instance_id instance to update product group for 5909 * @param product_group_id serial number of the group to update 5910 * @param name set to name of the group 5911 * @param description set to description of the group 5912 * @param[out] conflict set to true if @a name is already used 5913 * @return database result code 5914 */ 5915 enum GNUNET_DB_QueryStatus 5916 (*update_product_group)( 5917 void *cls, 5918 const char *instance_id, 5919 uint64_t product_group_id, 5920 const char *name, 5921 const char *description, 5922 bool *conflict); 5923 5924 5925 /** 5926 * Insert details about a particular product group. 5927 * 5928 * @param cls closure 5929 * @param instance_id instance to insert group for 5930 * @param name set to name of the group 5931 * @param description set to description of the group 5932 * @param[out] product_group_id serial number of the new group 5933 * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS 5934 * on conflict (@a name already in use at @a instance_id). 5935 */ 5936 enum GNUNET_DB_QueryStatus 5937 (*insert_product_group)( 5938 void *cls, 5939 const char *instance_id, 5940 const char *name, 5941 const char *description, 5942 uint64_t *product_group_id); 5943 5944 }; 5945 5946 #endif