summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-10-31 16:32:26 -0600
committerIván Ávalos <avalos@disroot.org>2023-11-10 23:04:53 -0600
commit48354654282438ab3066bd0f5f43e0264e5bcc55 (patch)
treeab227532192f991b2b6fcb138d1f2effa87df097
parente082595240ff3d82c54eecdd9fa0d6868339e5f9 (diff)
downloadtaler-ios-48354654282438ab3066bd0f5f43e0264e5bcc55.tar.gz
taler-ios-48354654282438ab3066bd0f5f43e0264e5bcc55.tar.bz2
taler-ios-48354654282438ab3066bd0f5f43e0264e5bcc55.zip
Initial refunds implementationdev/ivan-avalos/refunds
-rw-r--r--TalerWallet.xcodeproj/project.pbxproj20
-rw-r--r--TalerWallet1/Backend/WalletBackendRequest.swift25
-rw-r--r--TalerWallet1/Controllers/Controller.swift3
-rw-r--r--TalerWallet1/Model/Model+Refund.swift26
-rw-r--r--TalerWallet1/Views/Sheets/Refund/RefundURIView.swift62
-rw-r--r--TalerWallet1/Views/Sheets/URLSheet.swift2
6 files changed, 138 insertions, 0 deletions
diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj
index 83e73fd..a202d07 100644
--- a/TalerWallet.xcodeproj/project.pbxproj
+++ b/TalerWallet.xcodeproj/project.pbxproj
@@ -254,6 +254,10 @@
4EFA39612AA7946B00742548 /* ToSButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EFA395F2AA7946B00742548 /* ToSButtonView.swift */; };
ABC13AA32859962800D23185 /* taler-swift in Frameworks */ = {isa = PBXBuildFile; productRef = ABC13AA22859962800D23185 /* taler-swift */; };
ABE97B1D286D82BF00580772 /* AnyCodable in Frameworks */ = {isa = PBXBuildFile; productRef = ABE97B1C286D82BF00580772 /* AnyCodable */; };
+ E37AA62A2AF197E5003850CF /* Model+Refund.swift in Sources */ = {isa = PBXBuildFile; fileRef = E37AA6292AF197E5003850CF /* Model+Refund.swift */; };
+ E37AA62B2AF197E5003850CF /* Model+Refund.swift in Sources */ = {isa = PBXBuildFile; fileRef = E37AA6292AF197E5003850CF /* Model+Refund.swift */; };
+ E37AA62E2AF19BE0003850CF /* RefundURIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E37AA62D2AF19BE0003850CF /* RefundURIView.swift */; };
+ E37AA62F2AF19BE0003850CF /* RefundURIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E37AA62D2AF19BE0003850CF /* RefundURIView.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -425,6 +429,8 @@
D14AFD1D24D232B300C51073 /* Taler_Wallet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Taler_Wallet.app; sourceTree = BUILT_PRODUCTS_DIR; };
D14AFD3324D232B500C51073 /* TalerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TalerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D14AFD3E24D232B500C51073 /* TalerUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TalerUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
+ E37AA6292AF197E5003850CF /* Model+Refund.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Model+Refund.swift"; sourceTree = "<group>"; };
+ E37AA62D2AF19BE0003850CF /* RefundURIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundURIView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -623,6 +629,7 @@
4EB095322989CBFE0043A8A1 /* Model+Transactions.swift */,
4EB0953D2989CBFE0043A8A1 /* Model+Withdraw.swift */,
4EB0951E2989CBCB0043A8A1 /* Transaction.swift */,
+ E37AA6292AF197E5003850CF /* Model+Refund.swift */,
);
path = Model;
sourceTree = "<group>";
@@ -783,6 +790,7 @@
4EEC157129F7188B00D46A03 /* Sheets */ = {
isa = PBXGroup;
children = (
+ E37AA62C2AF19BA6003850CF /* Refund */,
4EEC157729F9032900D46A03 /* Sheet.swift */,
4EEC157929F9427F00D46A03 /* QRSheet.swift */,
4E753A072A0B6A5F002D9328 /* ShareSheet.swift */,
@@ -837,6 +845,14 @@
path = TalerUITests;
sourceTree = "<group>";
};
+ E37AA62C2AF19BA6003850CF /* Refund */ = {
+ isa = PBXGroup;
+ children = (
+ E37AA62D2AF19BE0003850CF /* RefundURIView.swift */,
+ );
+ path = Refund;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -1117,6 +1133,7 @@
4E3EAE5C2A990778009F1BE8 /* Model+Pending.swift in Sources */,
4E3EAE5D2A990778009F1BE8 /* ExchangeListView.swift in Sources */,
4E3EAE5E2A990778009F1BE8 /* WithdrawProgressView.swift in Sources */,
+ E37AA62E2AF19BE0003850CF /* RefundURIView.swift in Sources */,
4E3EAE5F2A990778009F1BE8 /* QRSheet.swift in Sources */,
4E3EAE602A990778009F1BE8 /* P2pReceiveURIView.swift in Sources */,
4E3EAE612A990778009F1BE8 /* ListStyle.swift in Sources */,
@@ -1124,6 +1141,7 @@
4E3EAE632A990778009F1BE8 /* WalletCore.swift in Sources */,
4E3EAE642A990778009F1BE8 /* LaunchAnimationView.swift in Sources */,
4E3EAE652A990778009F1BE8 /* SideBarView.swift in Sources */,
+ E37AA62A2AF197E5003850CF /* Model+Refund.swift in Sources */,
4E3EAE662A990778009F1BE8 /* PendingOpView.swift in Sources */,
4E3EAE672A990778009F1BE8 /* PendingOpsListView.swift in Sources */,
4E3EAE682A990778009F1BE8 /* WalletModel.swift in Sources */,
@@ -1226,6 +1244,7 @@
4EB0956E2989CBFE0043A8A1 /* Model+Pending.swift in Sources */,
4EB095522989CBFE0043A8A1 /* ExchangeListView.swift in Sources */,
4EB095642989CBFE0043A8A1 /* WithdrawProgressView.swift in Sources */,
+ E37AA62F2AF19BE0003850CF /* RefundURIView.swift in Sources */,
4EEC157A29F9427F00D46A03 /* QRSheet.swift in Sources */,
4E3B4BC12A41E6C200CC88B8 /* P2pReceiveURIView.swift in Sources */,
4E6EDD872A363D8D0031D520 /* ListStyle.swift in Sources */,
@@ -1233,6 +1252,7 @@
4EB095202989CBCB0043A8A1 /* WalletCore.swift in Sources */,
4EB095672989CBFE0043A8A1 /* LaunchAnimationView.swift in Sources */,
4EB095662989CBFE0043A8A1 /* SideBarView.swift in Sources */,
+ E37AA62B2AF197E5003850CF /* Model+Refund.swift in Sources */,
4EB0956F2989CBFE0043A8A1 /* PendingOpView.swift in Sources */,
4EB095702989CBFE0043A8A1 /* PendingOpsListView.swift in Sources */,
4EB095162989CBB00043A8A1 /* WalletModel.swift in Sources */,
diff --git a/TalerWallet1/Backend/WalletBackendRequest.swift b/TalerWallet1/Backend/WalletBackendRequest.swift
index 293269c..2082796 100644
--- a/TalerWallet1/Backend/WalletBackendRequest.swift
+++ b/TalerWallet1/Backend/WalletBackendRequest.swift
@@ -313,4 +313,29 @@ struct WalletBackendSuspendCoinRequest: WalletBackendFormattedRequest {
}
}
+struct PrepareRefundRequest: WalletBackendFormattedRequest {
+ func operation() -> String { "startRefundQueryForUri" }
+ func args() -> Args { Args(talerRefundUri: talerRefundUri) }
+
+ var talerRefundUri: String
+ struct Args: Encodable {
+ var talerRefundUri: String
+ }
+
+ struct Response: Decodable {
+ var transactionId: String
+ }
+}
+
+struct StartRefundQueryRequest: WalletBackendFormattedRequest {
+ struct Response: Decodable {}
+ func operation() -> String { "startRefundQuery" }
+ func args() -> Args { Args(transactionId: transactionId) }
+
+ var transactionId: String
+
+ struct Args: Encodable {
+ var transactionId: String
+ }
+}
diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift
index fe55625..3e211cd 100644
--- a/TalerWallet1/Controllers/Controller.swift
+++ b/TalerWallet1/Controllers/Controller.swift
@@ -25,6 +25,7 @@ enum UrlCommand {
case payPush
case payTemplate
case reward
+ case refund
}
// MARK: -
@@ -149,6 +150,8 @@ extension Controller {
return UrlCommand.payPush
case "pay-template":
return UrlCommand.payTemplate
+ case "refund":
+ return UrlCommand.refund
default:
symLog.log("unknown command taler://\(command)")
}
diff --git a/TalerWallet1/Model/Model+Refund.swift b/TalerWallet1/Model/Model+Refund.swift
new file mode 100644
index 0000000..dfdd2ff
--- /dev/null
+++ b/TalerWallet1/Model/Model+Refund.swift
@@ -0,0 +1,26 @@
+//
+// Model+Refund.swift
+// TalerWallet
+//
+// Created by Ivan Avalos on 31/10/23.
+// Copyright © 2023 Taler. All rights reserved.
+//
+
+import Foundation
+
+fileprivate let ASYNCDELAY: UInt = 0 //set e.g to 6 or 9 seconds for debugging
+
+extension WalletModel {
+ @MainActor
+ func prepareRefundForUriM(url: String) async throws -> PrepareRefundRequest.Response {
+ let request = PrepareRefundRequest(talerRefundUri: url)
+ let response = try await sendRequest(request, ASYNCDELAY)
+ return response
+ }
+
+ @MainActor
+ func startRefundM(transactionId: String) async throws {
+ let request = StartRefundQueryRequest(transactionId: transactionId)
+ let _ = try await sendRequest(request, ASYNCDELAY)
+ }
+}
diff --git a/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift b/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift
new file mode 100644
index 0000000..7975000
--- /dev/null
+++ b/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift
@@ -0,0 +1,62 @@
+/*
+ * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
+ * See LICENSE.md
+ */
+import SwiftUI
+import SymLog
+import taler_swift
+
+struct RefundURIView: View {
+ private let symLog = SymLogV(0)
+ let stack: CallStack
+ let navTitle = String(localized: "Accept Refund", comment:"receive refund")
+
+ @EnvironmentObject private var controller: Controller
+ @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
+
+ let url: URL
+
+ @EnvironmentObject private var model: WalletModel
+
+ @State var prepareRefundResponse: PrepareRefundRequest.Response? = nil
+
+ var body: some View {
+ if prepareRefundResponse != nil {
+ VStack {
+ Text(String(localized: "Successful refund!"))
+ .accessibilityFont(.title)
+
+ Button("OK") {
+ dismissTop(animated: true)
+ }
+ .padding(.horizontal, 30)
+ .buttonStyle(TalerButtonStyle(type: .prominent,
+ narrow: false,
+ aligned: .center))
+ }
+ } else {
+ let badURL = "Error in Link: \(url)"
+ WithdrawProgressView(message: url.host ?? badURL)
+ .navigationTitle("Find Exchange")
+ .task {
+ do {
+ symLog.log(".task")
+ let result = try await model.prepareRefundForUriM(url: url.absoluteString)
+ prepareRefundResponse = result
+ } catch { // TODO: error
+ symLog.log(error.localizedDescription)
+ }
+ }
+ }
+ }
+}
+
+// MARK: -
+struct RefundURIView_Previews: PreviewProvider {
+ static var previews: some View {
+ let details = PrepareRefundRequest.Response(
+ transactionId: "txn:refund:12345")
+ let url = URL(string: "taler://reward/survey")!
+ RefundURIView(stack: CallStack("Preview"), url: url, prepareRefundResponse: details)
+ }
+}
diff --git a/TalerWallet1/Views/Sheets/URLSheet.swift b/TalerWallet1/Views/Sheets/URLSheet.swift
index 4bb7a10..84c9eb9 100644
--- a/TalerWallet1/Views/Sheets/URLSheet.swift
+++ b/TalerWallet1/Views/Sheets/URLSheet.swift
@@ -31,6 +31,8 @@ struct URLSheet: View {
P2pReceiveURIView(stack: stack.push(), url: urlToOpen)
case .payTemplate:
PayTemplateView(stack: stack.push(), url: urlToOpen)
+ case .refund:
+ RefundURIView(stack: stack.push(), url: urlToOpen)
// case .reward:
// RewardURIView(url: urlToOpen)
default: // Error view