summaryrefslogtreecommitdiff
path: root/src/headless/merchant.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-11-30 00:36:20 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-11-30 00:36:20 +0100
commitaaf7e1338d6cdb1b4e01ad318938b3eaea2f922b (patch)
tree594129ccdf20757aeb86d434dd62c0c1e8259ed5 /src/headless/merchant.ts
parent809fa186448dbd924f258f89920b9336f1979bb0 (diff)
downloadwallet-core-aaf7e1338d6cdb1b4e01ad318938b3eaea2f922b.tar.gz
wallet-core-aaf7e1338d6cdb1b4e01ad318938b3eaea2f922b.tar.bz2
wallet-core-aaf7e1338d6cdb1b4e01ad318938b3eaea2f922b.zip
wallet robustness WIP
Diffstat (limited to 'src/headless/merchant.ts')
-rw-r--r--src/headless/merchant.ts64
1 files changed, 57 insertions, 7 deletions
diff --git a/src/headless/merchant.ts b/src/headless/merchant.ts
index 889eb2d6a..423e3d09e 100644
--- a/src/headless/merchant.ts
+++ b/src/headless/merchant.ts
@@ -19,9 +19,9 @@
* Used mostly for integration tests.
*/
- /**
- * Imports.
- */
+/**
+ * Imports.
+ */
import axios from "axios";
import { CheckPaymentResponse } from "../talerTypes";
import URI = require("urijs");
@@ -30,10 +30,60 @@ import URI = require("urijs");
* Connection to the *internal* merchant backend.
*/
export class MerchantBackendConnection {
- constructor(
- public merchantBaseUrl: string,
- public apiKey: string,
- ) {}
+ async refund(
+ orderId: string,
+ reason: string,
+ refundAmount: string,
+ ): Promise<void> {
+ const reqUrl = new URI("refund").absoluteTo(this.merchantBaseUrl).href();
+ const refundReq = {
+ order_id: orderId,
+ reason,
+ refund: refundAmount,
+ };
+ const resp = await axios({
+ method: "post",
+ url: reqUrl,
+ data: refundReq,
+ responseType: "json",
+ headers: {
+ Authorization: `ApiKey ${this.apiKey}`,
+ },
+ });
+ if (resp.status != 200) {
+ throw Error("failed to do refund");
+ }
+ console.log("response", resp.data);
+ const refundUri = resp.data.taler_refund_uri;
+ if (!refundUri) {
+ throw Error("no refund URI in response");
+ }
+ return refundUri;
+ }
+
+ constructor(public merchantBaseUrl: string, public apiKey: string) {}
+
+ async authorizeTip(amount: string, justification: string) {
+ const reqUrl = new URI("tip-authorize").absoluteTo(this.merchantBaseUrl).href();
+ const tipReq = {
+ amount,
+ justification,
+ };
+ const resp = await axios({
+ method: "post",
+ url: reqUrl,
+ data: tipReq,
+ responseType: "json",
+ headers: {
+ Authorization: `ApiKey ${this.apiKey}`,
+ },
+ });
+ const tipUri = resp.data.taler_tip_uri;
+ if (!tipUri) {
+ throw Error("response does not contain tip URI");
+ }
+ return tipUri;
+ }
async createOrder(
amount: string,