@@ -3,9 +3,7 @@ import UIKit
33/// Renders a receipt in an AirPrint enabled printer.
44///
55public final class ReceiptRenderer : UIPrintPageRenderer {
6- private let lines : [ ReceiptLineItem ]
7- private let parameters : CardPresentReceiptParameters
8- private let cartTotals : [ ReceiptTotalLine ]
6+ private let content : ReceiptContent
97
108 private let dateFormatter : DateFormatter = {
119 let formatter = DateFormatter ( )
@@ -17,9 +15,7 @@ public final class ReceiptRenderer: UIPrintPageRenderer {
1715 } ( )
1816
1917 public init ( content: ReceiptContent ) {
20- self . lines = content. lineItems
21- self . parameters = content. parameters
22- self . cartTotals = content. cartTotals
18+ self . content = content
2319
2420 super. init ( )
2521
@@ -49,7 +45,7 @@ public extension ReceiptRenderer {
4945 background-color:#F5F5F5;
5046 width:100%;
5147 color: #707070;
52- margin: \( Constants . margin / 2 ) pt 0 0 0 ;
48+ margin: \( Constants . margin / 2 ) pt 0;
5349 padding: \( Constants . margin / 2 ) pt;
5450 }
5551 table td:last-child { width: 30%; text-align: right; }
@@ -77,19 +73,20 @@ public extension ReceiptRenderer {
7773 <h1> \( receiptTitle) </h1>
7874 <h3> \( Localization . amountPaidSectionTitle. uppercased ( ) ) </h3>
7975 <p>
80- \( parameters. formattedAmount) \( parameters. currency. uppercased ( ) )
76+ \( content . parameters. formattedAmount) \( content . parameters. currency. uppercased ( ) )
8177 </p>
8278 <h3> \( Localization . datePaidSectionTitle. uppercased ( ) ) </h3>
8379 <p>
84- \( dateFormatter. string ( from: parameters. date) )
80+ \( dateFormatter. string ( from: content . parameters. date) )
8581 </p>
8682 <h3> \( Localization . paymentMethodSectionTitle. uppercased ( ) ) </h3>
8783 <p>
88- <span class= " card-icon \( parameters. cardDetails. brand. iconName) -icon " ></span> - \( parameters. cardDetails. last4)
84+ <span class= " card-icon \( content . parameters. cardDetails. brand. iconName) -icon " ></span> - \( content . parameters. cardDetails. last4)
8985 </p>
9086 </header>
9187 <h3> \( summarySectionTitle. uppercased ( ) ) </h3>
9288 \( summaryTable ( ) )
89+ \( orderNoteSection ( ) )
9390 <footer>
9491 <p>
9592 \( requiredItems ( ) )
@@ -112,8 +109,8 @@ private extension ReceiptRenderer {
112109
113110 private func summaryTable( ) -> String {
114111 var summaryContent = " <table> "
115- for line in lines {
116- summaryContent += " <tr><td> \( line. title) × \( line. quantity) </td><td> \( line. amount) \( parameters. currency. uppercased ( ) ) </td></tr> "
112+ for line in content . lineItems {
113+ summaryContent += " <tr><td> \( line. title) × \( line. quantity) </td><td> \( line. amount) \( content . parameters. currency. uppercased ( ) ) </td></tr> "
117114 }
118115 summaryContent += totalRows ( )
119116 summaryContent += " </table> "
@@ -123,7 +120,7 @@ private extension ReceiptRenderer {
123120
124121 private func totalRows( ) -> String {
125122 var rows = " "
126- for total in cartTotals {
123+ for total in content . cartTotals {
127124 rows += summaryRow ( title: total. description, amount: total. amount)
128125 }
129126 return rows
@@ -136,14 +133,24 @@ private extension ReceiptRenderer {
136133 \( title)
137134 </td>
138135 <td>
139- \( amount) \( parameters. currency. uppercased ( ) )
136+ \( amount) \( content . parameters. currency. uppercased ( ) )
140137 </td>
141138 </tr>
142139 """
143140 }
144141
142+ private func orderNoteSection( ) -> String {
143+ guard let orderNote = content. orderNote else {
144+ return " "
145+ }
146+ return """
147+ <h3> \( Localization . orderNoteSectionTitle. uppercased ( ) ) </h3>
148+ <p> \( orderNote) </p>
149+ """
150+ }
151+
145152 private func requiredItems( ) -> String {
146- guard let emv = parameters. cardDetails. receipt else {
153+ guard let emv = content . parameters. cardDetails. receipt else {
147154 return " <br/> "
148155 }
149156
@@ -163,15 +170,15 @@ private extension ReceiptRenderer {
163170 }
164171
165172 private var receiptTitle : String {
166- guard let storeName = parameters. storeName else {
173+ guard let storeName = content . parameters. storeName else {
167174 return Localization . receiptTitle
168175 }
169176
170177 return . localizedStringWithFormat( Localization . receiptFromFormat, storeName)
171178 }
172179
173180 private var summarySectionTitle : String {
174- guard let orderID = parameters. orderID else {
181+ guard let orderID = content . parameters. orderID else {
175182 return Localization . summarySectionTitle
176183 }
177184 return String ( format: Localization . summarySectionTitleWithOrderFormat, String ( orderID) )
@@ -218,6 +225,10 @@ private extension ReceiptRenderer {
218225 comment: " Title of 'Summary' section in the receipt when the order number is unknown "
219226 )
220227
228+ static let orderNoteSectionTitle = NSLocalizedString (
229+ " Notes " ,
230+ comment: " Title of order note section in the receipt, commonly used for Quick Orders. " )
231+
221232 static let summarySectionTitleWithOrderFormat = NSLocalizedString (
222233 " Summary: Order #%1$@ " ,
223234 comment: " Title of 'Summary' section in the receipt. %1$@ is the order number, e.g. 4920 "
0 commit comments