PaidTransactionDetailV.swift (5083B)
1 /* 2 * This file is part of GNU Taler, ©2022-26 Taler Systems S.A. 3 * See LICENSE.md 4 */ 5 /** 6 * Overview when there's more than 1 currency/exchange 7 * 8 * @author Marc Stibane 9 */ 10 import SwiftUI 11 12 struct PaidTransactionDetailV: View { 13 let stack: CallStack 14 let paymentTx: PaymentTransaction 15 16 #if DEBUG 17 @AppStorage("developerMode") var developerMode: Bool = true 18 #else 19 @AppStorage("developerMode") var developerMode: Bool = false 20 #endif 21 22 var body: some View { 23 let common = paymentTx.common 24 let scope = common.scopes.first 25 let details = paymentTx.details 26 let terms = details.contractTerms 27 let info = details.info 28 Section { 29 if let posConfirmation = details.posConfirmation { 30 Text("Confirmation:", comment: "purchase may have a pos validation / confirmation") 31 .talerFont(.title3) 32 .listRowSeparator(.hidden) 33 let totp = Text(posConfirmation) 34 .talerFont(.title1) 35 let posConfirmationViaNfc = details.posConfirmationViaNfc 36 let isPaying = common.isDialog // We are ALWAYS already finished with the tx 37 if #available(iOS 17.7, *) { 38 BorderWithNFC(totpString: posConfirmation, nfcHint: true, 39 automaticNfc: isPaying ? posConfirmationViaNfc : false, 40 size: 250, scanHints: nil 41 ) { totp } 42 } else { 43 totp 44 } 45 } 46 if let info { 47 // Text(info.merchant.name) TODO: show name & logo here? 48 if common.isDone { 49 VStack(alignment: .leading) { 50 Text("Order-ID:") 51 .talerFont(.title3) 52 HStack { 53 Spacer() 54 Text(info.orderId) 55 .talerFont(.body) 56 } 57 } 58 } 59 } 60 VStack(alignment: .leading) { 61 if let info { 62 Text(info.summary) 63 .talerFont(.title3) 64 } 65 if let choiceIndex = details.choiceIndex { 66 if let contractTerms = details.contractTerms { 67 if let choices = contractTerms.choices, 68 choices.indices.contains(choiceIndex) { 69 let choice = choices[choiceIndex] 70 HStack { 71 if let info { 72 Spacer() 73 } 74 Text(choice.locDescription ?? "Index: \(choiceIndex)") // fallback should never happen 75 .talerFont(.body) 76 } 77 } 78 } 79 } 80 } 81 if let info { 82 if let fulfillmentUrl = info.fulfillmentUrl, common.isDone { 83 // per api-common.rst's WebURL definition, fulfillment_url must be http(s) - 84 // reject any other scheme (tel:, sms:, a third-party app's custom scheme, ...) 85 if let destination = URL(string: fulfillmentUrl), 86 let scheme = destination.scheme?.lowercased(), scheme == "http" || scheme == "https" { 87 let buttonTitle = info.fulfillmentMessage ?? String(localized: "Open merchant website") 88 Link(buttonTitle, destination: destination) 89 .buttonStyle(TalerButtonStyle(type: .prominent)) 90 .accessibilityHint(String(localized: "Will go to the merchant website.", comment: "a11y")) 91 } 92 } else if let fulfillmentMessage = info.fulfillmentMessage { 93 Text(fulfillmentMessage) 94 .talerFont(.body) 95 } 96 } 97 if let failReason = common.failReason { 98 if let hint = failReason.hint { 99 Text(hint) 100 .talerFont(.title3) 101 } 102 } 103 if let abortReason = details.abortReason { 104 if let exchangeResponse = abortReason.exchangeResponse, 105 let hint2 = exchangeResponse.hint { 106 Text(hint2) 107 .talerFont(.body) 108 } 109 if developerMode { 110 if let hint3 = abortReason.hint { 111 Text(hint3) 112 .talerFont(.body) 113 } 114 } 115 } 116 } 117 if let products = terms?.products { 118 ProductsView(stack: stack.push(), 119 scope: scope, 120 products: products) 121 } 122 } 123 } 124 125 // MARK: - 126 //#Preview { 127 // TransactionDetailV() 128 //}