merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

taler-merchant-httpd_contract.c (2077B)


      1 /*
      2   This file is part of TALER
      3   (C) 2024 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.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file taler-merchant-httpd_contract.c
     18  * @brief shared logic for contract terms handling
     19  * @author Christian Blättler
     20  */
     21 #include "platform.h"
     22 #include <gnunet/gnunet_common.h>
     23 #include <jansson.h>
     24 #include <stdint.h>
     25 #include <taler/taler_json_lib.h>
     26 #include "taler-merchant-httpd_contract.h"
     27 
     28 
     29 enum GNUNET_GenericReturnValue
     30 TMH_find_token_family_key (
     31   const char *slug,
     32   struct GNUNET_TIME_Timestamp valid_after,
     33   const struct TALER_MERCHANT_ContractTokenFamily *families,
     34   unsigned int families_len,
     35   struct TALER_MERCHANT_ContractTokenFamily *family,
     36   struct TALER_MERCHANT_ContractTokenFamilyKey *key)
     37 {
     38   for (unsigned int i = 0; i < families_len; i++)
     39   {
     40     const struct TALER_MERCHANT_ContractTokenFamily *fami
     41       = &families[i];
     42 
     43     if (0 != strcmp (fami->slug,
     44                      slug))
     45       continue;
     46     if (NULL != family)
     47       *family = *fami;
     48     for (unsigned int k = 0; k < fami->keys_len; k++)
     49     {
     50       struct TALER_MERCHANT_ContractTokenFamilyKey *ki = &fami->keys[k];
     51 
     52       if (GNUNET_TIME_timestamp_cmp (ki->valid_after,
     53                                      ==,
     54                                      valid_after))
     55       {
     56         if (NULL != key)
     57           *key = *ki;
     58         return GNUNET_OK;
     59       }
     60     }
     61     /* matching family found, but no key. */
     62     return GNUNET_NO;
     63   }
     64 
     65   /* no matching family found */
     66   return GNUNET_SYSERR;
     67 }