taler-ios

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

Model+Refund.swift (1628B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-25 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     func 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     func 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 refunds was successful
     40     struct Response: Decodable {}
     41 }
     42 // MARK: -
     43 extension WalletModel {
     44     nonisolated func startRefundForUri(url: String, viewHandles: Bool = false) async throws -> String {
     45         let request = StartRefundURIRequest(talerRefundUri: url)
     46         let response = try await sendRequest(request, viewHandles: viewHandles)
     47         return response.transactionId
     48     }
     49 
     50     nonisolated func startRefund4711(transactionId: String, viewHandles: Bool = false) async throws {
     51         let request = StartRefundQueryRequest(transactionId: transactionId)
     52         let _ = try await sendRequest(request, viewHandles: viewHandles)
     53     }
     54 }