aboutsummaryrefslogtreecommitdiff
path: root/src/exchange-lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange-lib')
-rw-r--r--src/exchange-lib/exchange_api_deposit.c2
-rw-r--r--src/exchange-lib/exchange_api_refund.c73
-rw-r--r--src/exchange-lib/test_exchange_api.c59
3 files changed, 125 insertions, 9 deletions
diff --git a/src/exchange-lib/exchange_api_deposit.c b/src/exchange-lib/exchange_api_deposit.c
index d90b1aa75..76e3e4da9 100644
--- a/src/exchange-lib/exchange_api_deposit.c
+++ b/src/exchange-lib/exchange_api_deposit.c
@@ -454,7 +454,7 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,
" s:o," /* merchant_pub */
" s:o, s:o," /* refund_deadline, wire_deadline */
" s:o}", /* coin_sig */
- "f", TALER_JSON_from_amount (amount),
+ "contribution", TALER_JSON_from_amount (amount),
"wire", wire_details,
"H_wire", GNUNET_JSON_from_data_auto (&h_wire),
"h_contract_terms", GNUNET_JSON_from_data_auto (h_contract_terms),
diff --git a/src/exchange-lib/exchange_api_refund.c b/src/exchange-lib/exchange_api_refund.c
index a39dd23a8..ef1d66b90 100644
--- a/src/exchange-lib/exchange_api_refund.c
+++ b/src/exchange-lib/exchange_api_refund.c
@@ -243,12 +243,8 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange,
TALER_EXCHANGE_RefundResultCallback cb,
void *cb_cls)
{
- struct TALER_EXCHANGE_RefundHandle *rh;
- struct GNUNET_CURL_Context *ctx;
struct TALER_RefundRequestPS rr;
struct TALER_MerchantSignatureP merchant_sig;
- json_t *refund_obj;
- CURL *eh;
GNUNET_assert (GNUNET_YES ==
MAH_handle_is_ready (exchange));
@@ -267,7 +263,68 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_CRYPTO_eddsa_sign (&merchant_priv->eddsa_priv,
&rr.purpose,
&merchant_sig.eddsa_sig));
- refund_obj = json_pack ("{s:o, s:o," /* amount/fee */
+ return TALER_EXCHANGE_refund2 (exchange,
+ amount,
+ refund_fee,
+ h_contract_terms,
+ coin_pub,
+ rtransaction_id,
+ &rr.merchant,
+ &merchant_sig,
+ cb,
+ cb_cls);
+}
+
+
+/**
+ * Submit a refund request to the exchange and get the exchange's
+ * response. This API is used by a merchant. Note that
+ * while we return the response verbatim to the caller for further
+ * processing, we do already verify that the response is well-formed
+ * (i.e. that signatures included in the response are all valid). If
+ * the exchange's reply is not well-formed, we return an HTTP status code
+ * of zero to @a cb.
+ *
+ * The @a exchange must be ready to operate (i.e. have
+ * finished processing the /keys reply). If this check fails, we do
+ * NOT initiate the transaction with the exchange and instead return NULL.
+ *
+ * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param amount the amount to be refunded; must be larger than the refund fee
+ * (as that fee is still being subtracted), and smaller than the amount
+ * (with deposit fee) of the original deposit contribution of this coin
+ * @param refund_fee fee applicable to this coin for the refund
+ * @param h_contract_terms hash of the contact of the merchant with the customer that is being refunded
+ * @param coin_pub coin’s public key of the coin from the original deposit operation
+ * @param rtransaction_id transaction id for the transaction between merchant and customer (of refunding operation);
+ * this is needed as we may first do a partial refund and later a full refund. If both
+ * refunds are also over the same amount, we need the @a rtransaction_id to make the disjoint
+ * refund requests different (as requests are idempotent and otherwise the 2nd refund might not work).
+ * @param merchant_pub public key of the merchant
+ * @param merchant_sig signature affirming the refund from the merchant
+ * @param cb the callback to call when a reply for this request is available
+ * @param cb_cls closure for the above callback
+ * @return a handle for this request; NULL if the inputs are invalid (i.e.
+ * signatures fail to verify). In this case, the callback is not called.
+ */
+struct TALER_EXCHANGE_RefundHandle *
+TALER_EXCHANGE_refund2 (struct TALER_EXCHANGE_Handle *exchange,
+ const struct TALER_Amount *amount,
+ const struct TALER_Amount *refund_fee,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t rtransaction_id,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_MerchantSignatureP *merchant_sig,
+ TALER_EXCHANGE_RefundResultCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_RefundHandle *rh;
+ struct GNUNET_CURL_Context *ctx;
+ json_t *refund_obj;
+ CURL *eh;
+
+refund_obj = json_pack ("{s:o, s:o," /* amount/fee */
" s:o, s:o," /* h_contract_terms, coin_pub */
" s:I," /* rtransaction id */
" s:o, s:o}", /* merchant_pub, merchant_sig */
@@ -276,8 +333,8 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange,
"h_contract_terms", GNUNET_JSON_from_data_auto (h_contract_terms),
"coin_pub", GNUNET_JSON_from_data_auto (coin_pub),
"rtransaction_id", (json_int_t) rtransaction_id,
- "merchant_pub", GNUNET_JSON_from_data_auto (&rr.merchant),
- "merchant_sig", GNUNET_JSON_from_data_auto (&merchant_sig)
+ "merchant_pub", GNUNET_JSON_from_data_auto (merchant_pub),
+ "merchant_sig", GNUNET_JSON_from_data_auto (merchant_sig)
);
if (NULL == refund_obj)
{
@@ -294,7 +351,7 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange,
rh->depconf.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_REFUND);
rh->depconf.h_contract_terms = *h_contract_terms;
rh->depconf.coin_pub = *coin_pub;
- rh->depconf.merchant = rr.merchant;
+ rh->depconf.merchant = *merchant_pub;
rh->depconf.rtransaction_id = GNUNET_htonll (rtransaction_id);
TALER_amount_hton (&rh->depconf.refund_amount,
amount);
diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c
index 6fd9ad693..bccd4f99c 100644
--- a/src/exchange-lib/test_exchange_api.c
+++ b/src/exchange-lib/test_exchange_api.c
@@ -3562,7 +3562,66 @@ run (void *cls)
.details.refund.fee = "EUR:0.01",
.details.refund.deposit_ref = "deposit-refund-2",
},
+ { .oc = OC_CHECK_BANK_TRANSFERS_EMPTY,
+ .label = "check-empty-after-refund" },
+
+
+ /* Test refunded coins are never executed, even past
+ refund deadline */
+ { .oc = OC_ADMIN_ADD_INCOMING,
+ .label = "create-reserve-rb",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.admin_add_incoming.debit_account_no = 42,
+ .details.admin_add_incoming.credit_account_no = EXCHANGE_ACCOUNT_NO,
+ .details.admin_add_incoming.auth_username = "user42",
+ .details.admin_add_incoming.auth_password = "pass42",
+ .details.admin_add_incoming.amount = "EUR:5.01" },
+ /* Run wirewatch to observe /admin/add/incoming */
+ { .oc = OC_RUN_WIREWATCH,
+ .label = "wirewatch-3b" },
+ /* Withdraw a 5 EUR coin, at fee of 1 ct */
+ { .oc = OC_WITHDRAW_SIGN,
+ .label = "withdraw-coin-rb",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.reserve_withdraw.reserve_reference = "create-reserve-rb",
+ .details.reserve_withdraw.amount = "EUR:5" },
+ /* Spend 5 EUR of the 5 EUR coin (in full)
+ (merchant would receive EUR:4.99 due to 1 ct deposit fee) */
+ { .oc = OC_DEPOSIT,
+ .label = "deposit-refund-1b",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.deposit.amount = "EUR:5",
+ .details.deposit.coin_ref = "withdraw-coin-rb",
+ .details.deposit.wire_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42 }",
+ .details.deposit.contract_terms = "{ \"items\" : [ { \"name\":\"ice cream\", \"value\":\"EUR:5\" } ] }",
+ .details.deposit.refund_deadline = { 0 },
+ },
+ { .oc = OC_CHECK_BANK_TRANSFER,
+ .label = "check_bank_transfer-aai-3b",
+ .details.check_bank_transfer.exchange_base_url = "https://exchange.com/",
+ .details.check_bank_transfer.amount = "EUR:5.01",
+ .details.check_bank_transfer.account_debit = 42,
+ .details.check_bank_transfer.account_credit = 2
+ },
+ /* Trigger refund (before aggregator had a chance to execute
+ deposit, even though refund deadline was zero) */
+ { .oc = OC_REFUND,
+ .label = "refund-ok-fast",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.refund.amount = "EUR:5",
+ .details.refund.fee = "EUR:0.01",
+ .details.refund.deposit_ref = "deposit-refund-1b",
+ },
+ /* Run transfers. This will do the transfer as refund deadline
+ was 0, except of course because the refund succeeded, the
+ transfer should no longer be done. */
+ { .oc = OC_RUN_AGGREGATOR,
+ .label = "run-aggregator-3b" },
+ /* check that aggregator didn't do anything, as expected */
+ { .oc = OC_CHECK_BANK_TRANSFERS_EMPTY,
+ .label = "check-refund-fast-not-run" },
+
/* ************** End of refund API testing************* */
/* ************** Test /payback API ************* */