[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-mdb] 26/93: use check payment instead of poll payment
From: |
gnunet |
Subject: |
[taler-taler-mdb] 26/93: use check payment instead of poll payment |
Date: |
Mon, 18 Nov 2019 21:12:49 +0100 |
This is an automated email from the git hooks/post-receive script.
marco-boss pushed a commit to branch master
in repository taler-mdb.
commit 09c898e8f9b645b010366127b44a4ea845a6a391
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Nov 9 13:04:26 2019 +0100
use check payment instead of poll payment
---
src/main.c | 128 +++++++++++++++++++++++--------------------------------------
1 file changed, 49 insertions(+), 79 deletions(-)
diff --git a/src/main.c b/src/main.c
index 6c2099c..22afa34 100644
--- a/src/main.c
+++ b/src/main.c
@@ -70,12 +70,12 @@ struct Product
struct PaymentActivity
{
- struct TALER_MERCHANT_PollPaymentOperation *ppo;
-
struct TALER_MERCHANT_ProposalOperation *po;
struct TALER_MERCHANT_CheckPaymentOperation *cpo;
+ char *order_id;
+
char *taler_pay_uri;
nfc_device *pnd;
@@ -155,8 +155,6 @@ cleanup_payment (struct PaymentActivity *pa)
{
if (NULL != pa->po)
TALER_MERCHANT_proposal_cancel (pa->po);
- if (NULL != pa->ppo)
- TALER_MERCHANT_poll_payment_cancel (pa->ppo);
if (NULL != pa->cpo)
TALER_MERCHANT_check_payment_cancel (pa->cpo);
if (NULL != pa->task)
@@ -167,6 +165,7 @@ cleanup_payment (struct PaymentActivity *pa)
nfc_close (pa->pnd);
}
GNUNET_free_non_null (pa->taler_pay_uri);
+ GNUNET_free_non_null (pa->order_id);
GNUNET_free (pa);
}
@@ -203,52 +202,6 @@ shutdown_task (void *cls)
}
-/**
- * Callback to process a GET /poll-payment request
- *
- * @param cls closure
- * @param http_status HTTP status code for this request
- * @param obj raw response body
- * @param paid #GNUNET_YES if the payment is settled, #GNUNET_NO if not
- * settled, $GNUNET_SYSERR on error
- * (note that refunded payments are returned as paid!)
- * @param refunded #GNUNET_YES if there is at least on refund on this payment,
- * #GNUNET_NO if refunded, #GNUNET_SYSERR or error
- * @param refunded_amount amount that was refunded, NULL if there
- * was no refund
- * @param taler_pay_uri the URI that instructs the wallets to process
- * the payment
- */
-static void
-poll_payment_cb (void *cls,
- unsigned int http_status,
- const json_t *obj,
- int paid,
- int refunded,
- struct TALER_Amount *refund_amount,
- const char *taler_pay_uri)
-{
- struct PaymentActivity *pa = cls;
-
- pa->ppo = NULL;
- // FIXME: handle different http_status codes more nicely
- if (paid)
- {
- fprintf (stderr,
- "FIXME: yield product here!\n");
- cleanup_payment (pa);
- GNUNET_assert (payment_activity == pa);
- payment_activity = NULL;
- }
- else
- {
- cleanup_payment (pa);
- GNUNET_assert (payment_activity == pa);
- payment_activity = NULL;
- }
-}
-
-
static void
connect_target (void *cls);
@@ -414,33 +367,56 @@ check_payment_cb (void *cls,
pa->cpo = NULL;
// FIXME: check http_status, yada yada
- pa->taler_pay_uri = GNUNET_strdup (taler_pay_uri);
- pa->pnd = nfc_open (context, NULL);
- if (NULL != pa->pnd)
+
+ if (paid)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Payment inititation: Unable to open nfc device\n");
+ fprintf (stderr,
+ "FIXME: yield product here!\n");
cleanup_payment (pa);
GNUNET_assert (payment_activity == pa);
payment_activity = NULL;
- return;
}
- if (0 > nfc_initiator_init (pa->pnd))
+ else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to initialize NFC device: %s",
- nfc_strerror (pa->pnd));
- cleanup_payment (pa);
- GNUNET_assert (payment_activity == pa);
- payment_activity = NULL;
- return;
+ pa->cpo = TALER_MERCHANT_check_payment (ctx,
+ backendBaseUrl,
+ pa->order_id,
+ NULL /* snack machine, no Web crap
*/,
+ BACKEND_POLL_TIMEOUT,
+ &check_payment_cb,
+ pa);
+ }
+ if (NULL == pa->taler_pay_uri)
+ {
+ GNUNET_assert (NULL == pa->pnd);
+ pa->taler_pay_uri = GNUNET_strdup (taler_pay_uri);
+ pa->pnd = nfc_open (context, NULL);
+ if (NULL != pa->pnd)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Payment inititation: Unable to open nfc device\n");
+ cleanup_payment (pa);
+ GNUNET_assert (payment_activity == pa);
+ payment_activity = NULL;
+ return;
+ }
+ if (0 > nfc_initiator_init (pa->pnd))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to initialize NFC device: %s",
+ nfc_strerror (pa->pnd));
+ cleanup_payment (pa);
+ GNUNET_assert (payment_activity == pa);
+ payment_activity = NULL;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "NFC in operation %s / %s\n",
+ nfc_device_get_name (pa->pnd),
+ nfc_device_get_connstring (pa->pnd));
+ pa->task = GNUNET_SCHEDULER_add_now (&connect_target,
+ pa);
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "NFC in operation %s / %s\n",
- nfc_device_get_name (pa->pnd),
- nfc_device_get_connstring (pa->pnd));
- pa->task = GNUNET_SCHEDULER_add_now (&connect_target,
- pa);
}
@@ -465,18 +441,12 @@ proposal_cb (void *cls,
payment_activity = NULL;
return;
}
- pa->ppo = TALER_MERCHANT_poll_payment (ctx,
- backendBaseUrl,
- order_id,
- NULL /* &FIXME_h_contract! */,
- NULL /* snack machine, no Web crap */,
- BACKEND_POLL_TIMEOUT,
- &poll_payment_cb,
- pa);
+ pa->order_id = GNUNET_strdup (order_id);
pa->cpo = TALER_MERCHANT_check_payment (ctx,
backendBaseUrl,
- order_id,
+ pa->order_id,
NULL /* snack machine, no Web crap
*/,
+ GNUNET_TIME_UNIT_ZERO,
&check_payment_cb,
pa);
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [taler-taler-mdb] 07/93: first includes of libjansson, (continued)
- [taler-taler-mdb] 07/93: first includes of libjansson, gnunet, 2019/11/18
- [taler-taler-mdb] 11/93: fix nfc and other build issues, gnunet, 2019/11/18
- [taler-taler-mdb] 04/93: initial indenting, gnunet, 2019/11/18
- [taler-taler-mdb] 01/93: revisit build system, except for libnfc should work, gnunet, 2019/11/18
- [taler-taler-mdb] 09/93: revisit build system, except for libnfc should work, gnunet, 2019/11/18
- [taler-taler-mdb] 13/93: reindent code to coding style, gnunet, 2019/11/18
- [taler-taler-mdb] 16/93: merged jsonIntegrity, gnunet, 2019/11/18
- [taler-taler-mdb] 25/93: no curl here, gnunet, 2019/11/18
- [taler-taler-mdb] 21/93: product.h uncrustified, gnunet, 2019/11/18
- [taler-taler-mdb] 22/93: pseudo nonce, gnunet, 2019/11/18
- [taler-taler-mdb] 26/93: use check payment instead of poll payment,
gnunet <=
- [taler-taler-mdb] 10/93: add bootstrap and uncrustify logic, gnunet, 2019/11/18
- [taler-taler-mdb] 17/93: merged jsonIntegrity, gnunet, 2019/11/18
- [taler-taler-mdb] 23/93: chaos monkey, gnunet, 2019/11/18
- [taler-taler-mdb] 15/93: fixes, gnunet, 2019/11/18
- [taler-taler-mdb] 14/93: updated .gitignore, gnunet, 2019/11/18
- [taler-taler-mdb] 20/93: more implementations using GNUNETUtils, gnunet, 2019/11/18
- [taler-taler-mdb] 19/93: GNUnet logs added, -h option added, gnunet, 2019/11/18
- [taler-taler-mdb] 12/93: initial indenting, gnunet, 2019/11/18
- [taler-taler-mdb] 31/93: cleanup, gnunet, 2019/11/18
- [taler-taler-mdb] 33/93: typo, gnunet, 2019/11/18