summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-07-05 21:26:23 +0200
committerChristian Grothoff <christian@grothoff.org>2020-07-05 21:26:23 +0200
commit6dde8e02d3965072a265d9f1d86621bbeb8671b7 (patch)
tree99ea0139f7a3ae8e86579273b7eadf9f0dbca601
parenta808e1d5422ea7818110753e5b4ff7205b984d30 (diff)
downloadtaler-mdb-6dde8e02d3965072a265d9f1d86621bbeb8671b7.tar.gz
taler-mdb-6dde8e02d3965072a265d9f1d86621bbeb8671b7.tar.bz2
taler-mdb-6dde8e02d3965072a265d9f1d86621bbeb8671b7.zip
adapt to merchant v1 API
-rw-r--r--src/main.c130
1 files changed, 60 insertions, 70 deletions
diff --git a/src/main.c b/src/main.c
index 103b101..2f734d9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -330,14 +330,14 @@ struct Product
struct PaymentActivity
{
/**
- * Handle to a PUT /proposal operation
+ * Handle to a POST /orders operation
*/
- struct TALER_MERCHANT_ProposalOperation *po;
+ struct TALER_MERCHANT_PostOrdersOperation *po;
/**
- * Handle for a /check-payment operation.
+ * Handle for a GET /private/orders/$ID operation.
*/
- struct TALER_MERCHANT_CheckPaymentOperation *cpo;
+ struct TALER_MERCHANT_OrderMerchantGetHandle *ogh;
/**
* The product being sold.
@@ -540,7 +540,7 @@ struct Refund
/**
* Handle to the ongoing operation.
*/
- struct TALER_MERCHANT_RefundIncreaseOperation *rio;
+ struct TALER_MERCHANT_OrderRefundHandle *orh;
};
@@ -934,9 +934,9 @@ cleanup_payment (struct PaymentActivity *pa)
cancelbutton_task = NULL;
}
if (NULL != pa->po)
- TALER_MERCHANT_proposal_cancel (pa->po);
- if (NULL != pa->cpo)
- TALER_MERCHANT_check_payment_cancel (pa->cpo);
+ TALER_MERCHANT_orders_post_cancel (pa->po);
+ if (NULL != pa->ogh)
+ TALER_MERCHANT_merchant_order_get_cancel (pa->ogh);
GNUNET_CURL_gnunet_scheduler_reschedule (&rc);
if (NULL != pa->task)
GNUNET_SCHEDULER_cancel (pa->task);
@@ -959,7 +959,7 @@ cleanup_payment (struct PaymentActivity *pa)
#endif
GNUNET_free (pa->taler_pay_uri);
}
- GNUNET_free_non_null (pa->order_id);
+ GNUNET_free (pa->order_id);
GNUNET_free (pa);
}
@@ -1020,7 +1020,7 @@ shutdown_task (void *cls)
GNUNET_CONTAINER_DLL_remove (refund_head,
refund_tail,
r);
- TALER_MERCHANT_refund_increase_cancel (r->rio);
+ TALER_MERCHANT_post_order_refund_cancel (r->orh);
GNUNET_free (r);
}
if (NULL != context)
@@ -1113,8 +1113,8 @@ shutdown_task (void *cls)
for (unsigned int i = 0; i < products_length; i++)
{
GNUNET_free (products[i].description);
- GNUNET_free_non_null (products[i].instance);
- GNUNET_free_non_null (products[i].preview);
+ GNUNET_free (products[i].instance);
+ GNUNET_free (products[i].preview);
}
GNUNET_array_grow (products,
products_length,
@@ -1378,31 +1378,18 @@ start_read_keyboard (void);
*
* @param cls closure
* @param hr HTTP response
- * @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
+ * @param osr order status response details (on success)
*/
static void
check_payment_cb (void *cls,
const struct TALER_MERCHANT_HttpResponse *hr,
- int paid,
- int refunded,
- struct TALER_Amount *refund_amount,
- const char *taler_pay_uri)
+ const struct TALER_MERCHANT_OrderStatusResponse *osr)
{
struct PaymentActivity *pa = cls;
char *uri;
- (void) refunded;
- (void) refund_amount;
GNUNET_assert (payment_activity == pa);
- pa->cpo = NULL;
+ pa->ogh = NULL;
if (MHD_HTTP_OK != hr->http_status)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1417,7 +1404,7 @@ check_payment_cb (void *cls,
return;
}
- if (paid)
+ if (osr->paid)
{
mdb.cmd = &cmd_approve_vend;
payment_activity->paid = GNUNET_YES;
@@ -1434,7 +1421,7 @@ check_payment_cb (void *cls,
we talked successfully to the wallet via NFC because we MAY show the
QR code in the future and in that case the payment may happen
anytime even before the NFC communication succeeds. */
- if ( (NULL == pa->cpo) &&
+ if ( (NULL == pa->ogh) &&
(NULL == pa->delay_pay_task) )
{
pa->delay_pay_task = GNUNET_SCHEDULER_add_delayed (MAX_HTTP_RETRY_FREQ,
@@ -1444,11 +1431,11 @@ check_payment_cb (void *cls,
if (NULL == pa->taler_pay_uri)
{
if (NULL == essid)
- uri = GNUNET_strdup (taler_pay_uri);
+ uri = GNUNET_strdup (osr->details.unpaid.taler_pay_uri);
else
GNUNET_asprintf (&uri,
"%s#%s",
- taler_pay_uri,
+ osr->details.unpaid.taler_pay_uri,
essid);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Trying to talk to wallet to give it pay URI `%s'\n",
@@ -1476,21 +1463,22 @@ check_payment_again (void *cls)
struct Product *p = pa->product;
pa->delay_pay_task = NULL;
- GNUNET_assert (NULL == pa->cpo);
- pa->cpo = TALER_MERCHANT_check_payment (ctx,
- (NULL == p->instance)
- ? backend_base_url
- : p->instance,
- pa->order_id,
- NULL /* snack machine, no Web crap */,
- BACKEND_POLL_TIMEOUT,
- &check_payment_cb,
- pa);
+ GNUNET_assert (NULL == pa->ogh);
+ pa->ogh = TALER_MERCHANT_merchant_order_get (ctx,
+ (NULL == p->instance)
+ ? backend_base_url
+ : p->instance,
+ pa->order_id,
+ NULL /* snack machine, no Web crap */,
+ false,
+ BACKEND_POLL_TIMEOUT,
+ &check_payment_cb,
+ pa);
}
/**
- * @brief Callback for a PUT /order request
+ * @brief Callback for a POST /orders request
*
* @param cls closure
* @param hr HTTP response for this request
@@ -1524,13 +1512,14 @@ proposal_cb (void *cls,
"Backend successfully created order `%s'\n",
order_id);
pa->order_id = GNUNET_strdup (order_id);
- pa->cpo = TALER_MERCHANT_check_payment (ctx,
- backend_base_url,
- pa->order_id,
- NULL /* snack machine, no Web crap */,
- GNUNET_TIME_UNIT_ZERO,
- &check_payment_cb,
- pa);
+ pa->ogh = TALER_MERCHANT_merchant_order_get (ctx,
+ backend_base_url,
+ pa->order_id,
+ NULL /* snack machine, no Web crap */,
+ false,
+ GNUNET_TIME_UNIT_ZERO,
+ &check_payment_cb,
+ pa);
}
@@ -1609,13 +1598,14 @@ launch_payment (struct Product *product)
pa->product = product;
pa->amount = product->price;
/* put the order on the merchant's backend */
- pa->po = TALER_MERCHANT_order_put (ctx,
- (NULL == product->instance)
- ? backend_base_url
- : product->instance,
- orderReq,
- &proposal_cb,
- pa);
+ pa->po = TALER_MERCHANT_orders_post (ctx,
+ (NULL == product->instance)
+ ? backend_base_url
+ : product->instance,
+ orderReq,
+ MAX_REFUND_DELAY,
+ &proposal_cb,
+ pa);
json_decref (orderReq);
if (NULL == pa->po)
{
@@ -1660,7 +1650,7 @@ refund_complete_cb (void *cls,
{
struct Refund *r = cls;
- r->rio = NULL;
+ r->orh = NULL;
if (MHD_HTTP_OK != hr->http_status)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1697,16 +1687,16 @@ vend_failure (void)
mdb.cmd = &endSession;
mdb.session_running = GNUNET_NO;
r = GNUNET_new (struct Refund);
- r->rio = TALER_MERCHANT_refund_increase (ctx,
- (NULL == p->instance)
- ? backend_base_url
- : p->instance,
- payment_activity->order_id,
- &payment_activity->amount,
- "failed to dispense product",
- &refund_complete_cb,
- r);
- if (NULL == r->rio)
+ r->orh = TALER_MERCHANT_post_order_refund (ctx,
+ (NULL == p->instance)
+ ? backend_base_url
+ : p->instance,
+ payment_activity->order_id,
+ &payment_activity->amount,
+ "failed to dispense product",
+ &refund_complete_cb,
+ r);
+ if (NULL == r->orh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to launch refund interaction with the merchant backend!\n");
@@ -2777,8 +2767,8 @@ read_products (void *cls,
section,
"number");
GNUNET_free (tmpProduct.description);
- GNUNET_free_non_null (tmpProduct.instance);
- GNUNET_free_non_null (tmpProduct.preview);
+ GNUNET_free (tmpProduct.instance);
+ GNUNET_free (tmpProduct.preview);
return;
}
/* append the temporary product to the existing products */