/*
This file is part of TALER
(C) 2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see
*/
/**
* @file taler-merchant-httpd_contract.c
* @brief shared logic for contract terms handling
* @author Christian Blättler
*/
#include "platform.h"
#include
#include "taler-merchant-httpd_contract.h"
enum GNUNET_GenericReturnValue
TMH_serialize_contract_v0 (const struct TALER_MerchantContract *contract,
const struct TMH_MerchantInstance *instance,
const struct TMH_WireMethod *wm,
json_t *exchanges,
json_t *products,
struct TALER_Amount *max_fee,
json_t **out)
{
json_t *merchant;
{
merchant = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("name",
instance->settings.name),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("website",
instance->settings.website)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("email",
instance->settings.email)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("logo",
instance->settings.logo)));
GNUNET_assert (NULL != merchant);
{
json_t *loca;
/* Handle merchant address */
loca = instance->settings.address;
if (NULL != loca)
{
loca = json_deep_copy (loca);
GNUNET_assert (NULL != loca);
GNUNET_assert (0 ==
json_object_set_new (merchant,
"address",
loca));
}
}
{
json_t *juri;
/* Handle merchant jurisdiction */
juri = instance->settings.jurisdiction;
if (NULL != juri)
{
juri = json_deep_copy (juri);
GNUNET_assert (NULL != juri);
GNUNET_assert (0 ==
json_object_set_new (merchant,
"jurisdiction",
juri));
}
}
}
*out = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("summary",
contract->v0.summary),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("summary_i18n",
contract->v0.summary_i18n)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("public_reorder_url",
contract->public_reorder_url)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("fulfillment_message",
contract->v0.fulfillment_message)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("fulfillment_message_i18n",
contract->v0.fulfillment_message_i18n)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("fulfillment_url",
contract->v0.fulfillment_url)),
GNUNET_JSON_pack_array_incref ("products",
products),
GNUNET_JSON_pack_data_auto ("h_wire",
&wm->h_wire),
GNUNET_JSON_pack_string ("wire_method",
wm->wire_method),
GNUNET_JSON_pack_string ("order_id",
contract->order_id),
GNUNET_JSON_pack_timestamp ("timestamp",
contract->timestamp),
GNUNET_JSON_pack_timestamp ("pay_deadline",
contract->pay_deadline),
GNUNET_JSON_pack_timestamp ("wire_transfer_deadline",
contract->wire_deadline),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_timestamp ("delivery_date",
contract->delivery_date)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("delivery_location",
contract->delivery_location)),
GNUNET_JSON_pack_string ("merchant_base_url",
contract->merchant_base_url),
GNUNET_JSON_pack_object_incref ("merchant",
merchant),
GNUNET_JSON_pack_data_auto ("merchant_pub",
&instance->merchant_pub),
GNUNET_JSON_pack_array_incref ("exchanges",
exchanges),
TALER_JSON_pack_amount ("max_fee",
max_fee),
TALER_JSON_pack_amount ("amount",
&contract->v0.brutto),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("extra",
(json_t *) contract->extra))
);
/* Pack does not work here, because it doesn't set zero-values for timestamps */
GNUNET_assert (0 ==
json_object_set_new (*out,
"refund_deadline",
GNUNET_JSON_from_timestamp (
contract->refund_deadline)));
GNUNET_log (
GNUNET_ERROR_TYPE_INFO,
"Refund deadline for contact is %llu\n",
(unsigned long long) contract->refund_deadline.abs_time.abs_value_us);
GNUNET_log (
GNUNET_ERROR_TYPE_INFO,
"Wallet timestamp for contact is %llu\n",
(unsigned long long) contract->timestamp.abs_time.abs_value_us);
/* Pack does not work here, because it sets zero-values for relative times */
/* auto_refund should only be set if it is not 0 */
if (! GNUNET_TIME_relative_is_zero (contract->auto_refund))
{
GNUNET_assert (0 ==
json_object_set_new (*out,
"auto_refund",
GNUNET_JSON_from_time_rel (
contract->auto_refund)));
}
return GNUNET_OK;
};