• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperwallet / hyperwallet-ios-ui-sdk / 5360366649

pending completion
5360366649

push

github

web-flow
Rename polaris.yaml to polaris.yml (#345)

2252 of 2341 relevant lines covered (96.2%)

20.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.98
/Receipt/Sources/ReceiptDetailSectionData.swift
1
//
2
// Copyright 2018 - Present Hyperwallet
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5
// and associated documentation files (the "Software"), to deal in the Software without restriction,
6
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
7
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in all copies or
11
// substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18

19
import HyperwalletSDK
20

21
enum ReceiptDetailSectionHeader: String {
22
    case transaction, details, fee, notes
23
}
24

25
struct ReceiptDetailRow {
26
    let title: String
27
    let value: String
28
    let field: String
29
}
30

31
protocol ReceiptDetailSectionData {
32
    var receiptDetailSectionHeader: ReceiptDetailSectionHeader { get }
33
    var rowCount: Int { get }
34
    var title: String { get }
35
    var cellIdentifier: String { get }
36
}
37

38
extension ReceiptDetailSectionData {
39
    var rowCount: Int { return 1 }
2✔
40
}
41

42
struct ReceiptDetailSectionTransactionData: ReceiptDetailSectionData {
43
    var receiptDetailSectionHeader: ReceiptDetailSectionHeader { return .transaction }
1✔
44
    var cellIdentifier: String { return ReceiptTransactionCell.reuseIdentifier }
1✔
45
    var title: String { return "mobileTransactionTypeLabel".localized() }
1✔
46
    let receipt: HyperwalletReceipt
47

48
    init(from receipt: HyperwalletReceipt) {
29✔
49
        self.receipt = receipt
29✔
50
    }
29✔
51
}
52

53
struct ReceiptDetailSectionDetailData: ReceiptDetailSectionData {
54
    var rows = [ReceiptDetailRow]()
29✔
55
    var receiptDetailSectionHeader: ReceiptDetailSectionHeader { return .details }
1✔
56
    var rowCount: Int { return rows.count }
1✔
57
    var cellIdentifier: String { return ReceiptDetailCell.reuseIdentifier }
1✔
58
    var title: String { return "mobileTransactionDetailsLabel".localized() }
1✔
59

60
    init(from receipt: HyperwalletReceipt) {
29✔
61
        if let receiptId = receipt.journalId {
29✔
62
            rows.append(ReceiptDetailRow(title: "mobileJournalNumberLabel".localized(),
29✔
63
                                         value: receiptId,
29✔
64
                                         field: "journalId"))
29✔
65
        }
29✔
66

29✔
67
        if let createdOn = receipt.createdOn,
29✔
68
            let dateTime = ISO8601DateFormatter.ignoreTimeZone.date(from: createdOn)?.format(for: .dateTime) {
29✔
69
            rows.append(ReceiptDetailRow(title: "date".localized(),
29✔
70
                                         value: dateTime,
29✔
71
                                         field: "createdOn"))
29✔
72
        }
29✔
73

29✔
74
        if let charityName = receipt.details?.charityName {
29✔
75
            rows.append(ReceiptDetailRow(title: "mobileCharityName".localized(),
9✔
76
                                         value: charityName,
9✔
77
                                         field: "charityName"))
9✔
78
        }
29✔
79
        if let checkNumber = receipt.details?.checkNumber {
29✔
80
            rows.append(ReceiptDetailRow(title: "mobileCheckNumber".localized(),
9✔
81
                                         value: checkNumber,
9✔
82
                                         field: "checkNumber"))
9✔
83
        }
29✔
84
        if let clientPaymentId = receipt.details?.clientPaymentId {
29✔
85
            rows.append(ReceiptDetailRow(title: "mobileTransactionIdLabel".localized(),
29✔
86
                                         value: clientPaymentId,
29✔
87
                                         field: "clientPaymentId"))
29✔
88
        }
29✔
89
        if let website = receipt.details?.website {
29✔
90
            rows.append(ReceiptDetailRow(title: "mobilePromoWebsite".localized(),
9✔
91
                                         value: website,
9✔
92
                                         field: "website"))
9✔
93
        }
29✔
94
    }
29✔
95
}
96

97
struct ReceiptDetailSectionFeeData: ReceiptDetailSectionData {
98
    var rows = [ReceiptDetailRow]()
31✔
99
    var receiptDetailSectionHeader: ReceiptDetailSectionHeader { return .fee }
3✔
100
    var rowCount: Int { return rows.count }
3✔
101
    var cellIdentifier: String { return ReceiptFeeCell.reuseIdentifier }
3✔
102
    var title: String { return "mobileFeeInfoLabel".localized() }
1✔
103
    init?(from receipt: HyperwalletReceipt) {
31✔
104
        guard
31✔
105
            let stringFee = receipt.fee,
31✔
106
            let fee = Double(stringFee),
31✔
107
            fee != 0.0,
31✔
108
            let amountValue = receipt.amount, let amount = Double(amountValue), let currency = receipt.currency else {
31✔
109
                return nil
2✔
110
        }
29✔
111

29✔
112
        let amountFormat = receipt.entry == HyperwalletReceipt.HyperwalletEntryType.credit ? "%@ %@" : "-%@ %@"
29✔
113
        let valueCurrencyFormat = "%@ %@"
29✔
114

29✔
115
        rows.append(ReceiptDetailRow(title: "amount".localized(),
29✔
116
                                     value: String(format: amountFormat,
29✔
117
                                                   amountValue.formatToCurrency(with: currency),
29✔
118
                                                   currency),
29✔
119
                                     field: "amount"))
29✔
120

29✔
121
        rows.append(ReceiptDetailRow(title: "mobileFeeLabel".localized(),
29✔
122
                                     value: String(format: valueCurrencyFormat,
29✔
123
                                                   stringFee.formatToCurrency(with: currency),
29✔
124
                                                   currency),
29✔
125
                                     field: "fee"))
29✔
126

29✔
127
        let transaction: Double = amount - fee
29✔
128
        rows.append(ReceiptDetailRow(title: "mobileTransactionDetailsTotal".localized(),
29✔
129
                                     value: String(format: valueCurrencyFormat,
29✔
130
                                                   "\(transaction)".formatToCurrency(with: currency),
29✔
131
                                                   currency),
29✔
132
                                     field: "transaction"))
29✔
133
    }
29✔
134
}
135

136
struct ReceiptDetailSectionNotesData: ReceiptDetailSectionData {
137
    let notes: String?
138
    var receiptDetailSectionHeader: ReceiptDetailSectionHeader { return .notes }
1✔
139
    var cellIdentifier: String { return ReceiptNotesCell.reuseIdentifier }
1✔
140
    var title: String { return "mobileConfirmNotesLabel".localized() }
1✔
141

142
    init?(from receipt: HyperwalletReceipt) {
29✔
143
        guard let notes = receipt.details?.notes else {
29✔
144
            return nil
20✔
145
        }
20✔
146
        if receipt.type == .foreignExchange,
9✔
147
           let foreignExchangeRate = receipt.foreignExchangeRate,
9✔
148
           let fixedFX = receipt.foreignExchangeRate?.getFxRateWithFourDecimal() {
9✔
149
            self.notes = notes.replacingOccurrences(of: foreignExchangeRate,
×
150
                                                    with: fixedFX)
×
151
        } else {
9✔
152
            self.notes = notes
9✔
153
        }
9✔
154
    }
9✔
155
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc