diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-05-29 16:58:45 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-05-29 16:58:45 +0200 |
commit | d33685e1966d1ae32d76a7d8f682435c5cd6e7af (patch) | |
tree | bac7e5dd2a62bb4bd0ddd71e3d92e9c786cc5df4 | |
parent | 48982ff41c8c7c06e3faccb608f2771538d7ac5a (diff) | |
download | merchant-d33685e1966d1ae32d76a7d8f682435c5cd6e7af.tar.gz merchant-d33685e1966d1ae32d76a7d8f682435c5cd6e7af.tar.bz2 merchant-d33685e1966d1ae32d76a7d8f682435c5cd6e7af.zip |
roll back transaction if payment is insufficient
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index ed2f0cd6..2a91c779 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c @@ -1982,39 +1982,43 @@ begin_transaction (struct PayContext *pc) enum TALER_ErrorCode ec; ec = check_payment_sufficient (pc); - if (TALER_EC_NONE == ec) + if (TALER_EC_NONE != ec) { - /* Payment succeeded, commit! */ - qs = db->mark_proposal_paid (db->cls, - &pc->h_contract_terms, - &pc->mi->pubkey, - pc->session_id); - if (0 <= qs) - qs = db->commit (db->cls); - else - db->rollback (db->cls); - if (0 > qs) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Payment is not sufficient (ec=%u).\n", + (unsigned int) ec); + db->rollback (db->cls); + generate_error_response (pc, + ec); + return; + } + /* Payment succeeded, commit! */ + qs = db->mark_proposal_paid (db->cls, + &pc->h_contract_terms, + &pc->mi->pubkey, + pc->session_id); + if (0 <= qs) + qs = db->commit (db->cls); + else + db->rollback (db->cls); + if (0 > qs) + { + if (GNUNET_DB_STATUS_SOFT_ERROR == qs) { - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - { - begin_transaction (pc); - return; - } - resume_pay_with_error - (pc, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_PAY_DB_STORE_PAYMENTS_ERROR, - "Merchant database error: could not " - "mark proposal as 'paid'"); + begin_transaction (pc); return; } - resume_pay_with_response (pc, - MHD_HTTP_OK, - sign_success_response (pc)); + resume_pay_with_error + (pc, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_PAY_DB_STORE_PAYMENTS_ERROR, + "Merchant database error: could not " + "mark proposal as 'paid'"); return; } - generate_error_response (pc, - ec); + resume_pay_with_response (pc, + MHD_HTTP_OK, + sign_success_response (pc)); return; } |