taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

Model+Refund.swift (1689B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-26 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  */
      8 import Foundation
      9 
     10 // MARK: -
     11 /// A request to prepare a refund with an obtained URI
     12 struct StartRefundURIRequest: WalletBackendFormattedRequest {
     13     var operation: String { "startRefundQueryForUri" }
     14     func args() -> Args { Args(talerRefundUri: talerRefundUri) }
     15 
     16     var talerRefundUri: String
     17 
     18     struct Args: Encodable {
     19         var talerRefundUri: String
     20     }
     21 
     22     /// returns the txID of the new refund
     23     struct Response: Decodable {
     24         var transactionId: String
     25     }
     26 }
     27 
     28 /// A request to prepare a refund with a transactionID
     29 struct StartRefundQueryRequest: WalletBackendFormattedRequest {
     30     var operation: String { "startRefundQuery" }
     31     func args() -> Args { Args(transactionId: transactionId) }
     32 
     33     var transactionId: String
     34 
     35     struct Args: Encodable {
     36         var transactionId: String
     37     }
     38 
     39     /// No error means the background refund query was started
     40     /// the actual outcome arrives later via notification
     41     struct Response: Decodable {}
     42 }
     43 // MARK: -
     44 extension WalletModel {
     45     nonisolated func startRefundForUri(url: String, viewHandles: Bool = false) async throws -> String {
     46         let request = StartRefundURIRequest(talerRefundUri: url)
     47         let response = try await sendRequest(request, viewHandles: viewHandles)
     48         return response.transactionId
     49     }
     50 
     51     nonisolated func startRefund4711(transactionId: String, viewHandles: Bool = false) async throws {
     52         let request = StartRefundQueryRequest(transactionId: transactionId)
     53         let _ = try await sendRequest(request, viewHandles: viewHandles)
     54     }
     55 }