commit 09c898e8f9b645b010366127b44a4ea845a6a391
parent 4ffdca6c5bcd6190b9b4db056f7724da7bc9ac4a
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 9 Nov 2019 13:04:26 +0100
use check payment instead of poll payment
Diffstat:
| M | src/main.c | | | 128 | ++++++++++++++++++++++++++++++------------------------------------------------- |
1 file changed, 49 insertions(+), 79 deletions(-)
diff --git 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);