summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2023-01-23 08:25:49 -0500
committerpriscilla <priscilla.huang@efrei.net>2023-01-23 08:25:49 -0500
commit4ba9ffaaeef83a05964bee764c419d9006a6767d (patch)
tree3f8c3e4936d7391bbdfd99b909bcb9983d1e50f3 /src/backend/taler-merchant-httpd_post-orders-ID-pay.c
parent03ce25438c251820ff556c66f11b22659f7a896f (diff)
downloadmerchant-4ba9ffaaeef83a05964bee764c419d9006a6767d.tar.gz
merchant-4ba9ffaaeef83a05964bee764c419d9006a6767d.tar.bz2
merchant-4ba9ffaaeef83a05964bee764c419d9006a6767d.zip
backend pending webhook
Diffstat (limited to 'src/backend/taler-merchant-httpd_post-orders-ID-pay.c')
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-pay.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
index ee748470..162ee97a 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -251,6 +251,11 @@ struct PayContext
struct MHD_Response *response;
/**
+ * Our contract (or NULL if not available).
+ */
+ json_t *contract_terms;
+
+ /**
* Placeholder for #TALER_MHD_parse_post_json() to keep its internal state.
*/
void *json_parse_context;
@@ -678,6 +683,11 @@ pay_context_cleanup (void *cls)
GNUNET_SCHEDULER_cancel (pc->timeout_task);
pc->timeout_task = NULL;
}
+ if (NULL != pc->contract_terms)
+ {
+ json_decref (pc->contract_terms);
+ pc->contract_terms = NULL;
+ }
abort_active_deposits (pc);
for (unsigned int i = 0; i<pc->coins_cnt; i++)
{
@@ -1035,7 +1045,7 @@ handle_batch_deposit_ok (struct ExchangeGroup *eg,
{
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_SOFT_FAILURE,
+ TALER_EC_GENERIC_DB_SOFT_FAILURE,
"insert_deposit");
return;
}
@@ -1871,7 +1881,7 @@ check_payment_sufficient (struct PayContext *pc)
*
* @param pc context to trigger notification for
*/
-static void
+static enum GNUNET_DB_QueryStatus
trigger_payment_notification (struct PayContext *pc)
{
{
@@ -1916,6 +1926,9 @@ trigger_payment_notification (struct PayContext *pc)
NULL,
0);
}
+ return TMH_trigger_webhook (pc->hc->instance->settings.id,
+ "pay",
+ pc->contract_terms);
}
@@ -2101,7 +2114,26 @@ execute_pay_transaction (struct PayContext *pc)
TMH_OSF_CLAIMED | TMH_OSF_PAID,
pc->timestamp,
pc->order_serial);
-
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = trigger_payment_notification (pc);
+ if (qs < 0)
+ {
+ TMH_db->rollback (TMH_db->cls);
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ {
+ execute_pay_transaction (pc);
+ return;
+ }
+ GNUNET_break (0);
+ resume_pay_with_error (pc,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "failed to trigger webhooks");
+ return;
+ }
+ }
{
enum GNUNET_DB_QueryStatus qs;
@@ -2123,7 +2155,6 @@ execute_pay_transaction (struct PayContext *pc)
NULL);
return;
}
- trigger_payment_notification (pc);
}
generate_success_response (pc);
}
@@ -2509,13 +2540,17 @@ check_contract (struct PayContext *pc)
{
/* obtain contract terms */
enum GNUNET_DB_QueryStatus qs;
- json_t *contract_terms = NULL;
bool paid = false;
+ if (NULL != pc->contract_terms)
+ {
+ json_decref (pc->contract_terms);
+ pc->contract_terms = NULL;
+ }
qs = TMH_db->lookup_contract_terms (TMH_db->cls,
pc->hc->instance->settings.id,
pc->order_id,
- &contract_terms,
+ &pc->contract_terms,
&pc->order_serial,
&paid,
NULL);
@@ -2546,11 +2581,10 @@ check_contract (struct PayContext *pc)
}
/* hash contract (needed later) */
if (GNUNET_OK !=
- TALER_JSON_contract_hash (contract_terms,
+ TALER_JSON_contract_hash (pc->contract_terms,
&pc->h_contract_terms))
{
GNUNET_break (0);
- json_decref (contract_terms);
return (MHD_YES ==
TALER_MHD_reply_with_error (pc->connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
@@ -2572,12 +2606,11 @@ check_contract (struct PayContext *pc)
GNUNET_h2s (&pc->h_contract_terms.hash));
/* basic sanity check on the contract */
- if (NULL == json_object_get (contract_terms,
+ if (NULL == json_object_get (pc->contract_terms,
"merchant"))
{
/* invalid contract */
GNUNET_break (0);
- json_decref (contract_terms);
return (MHD_YES ==
TALER_MHD_reply_with_error (pc->connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
@@ -2626,11 +2659,10 @@ check_contract (struct PayContext *pc)
pc->minimum_age = 0;
res = TALER_MHD_parse_internal_json_data (pc->connection,
- contract_terms,
+ pc->contract_terms,
espec);
if (NULL != fulfillment_url)
pc->fulfillment_url = GNUNET_strdup (fulfillment_url);
- json_decref (contract_terms);
if (GNUNET_YES != res)
{
GNUNET_break (0);