You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Make `PersonalizationJSON` a struct instead of a protocol.
- It was missing only a field that we can make optional, now users directly create the struct and we handle the JSON encoding
- Move all the signing information from the delegates to the actual services' classes
- Now users aren't required to use specific `URL`'s initializers, they just pass the path as a String and we create the URL
- The goal is to completely remove the delegates in the future and move the remaining functions to the `PassDataModel` and `OrderDataModel` protocols
- Make the `template` delegate method return a String instead of a URL
- The user provides the path to the directory and we initialize the `URL`
Create a delegate class that implements ``OrdersDelegate``.
114
-
In the ``OrdersDelegate/sslSigningFilesDirectory`` you specify there must be the `WWDR.pem`, `ordercertificate.pem` and `orderkey.pem` files.
115
-
If they are named like that you're good to go, otherwise you have to specify the custom name.
116
-
117
-
> Tip: Obtaining the three certificates files could be a bit tricky. You could get some guidance from [this guide](https://github.com/alexandercerutti/passkit-generator/wiki/Generating-Certificates) and [this video](https://www.youtube.com/watch?v=rJZdPoXHtzI). Those guides are for Wallet passes, but the process is similar for Wallet orders.
118
-
119
-
There are other fields available which have reasonable default values. See ``OrdersDelegate``'s documentation.
120
114
121
115
Because the files for your order's template and the method of encoding might vary by order type, you'll be provided the ``Order`` for those methods.
122
116
In the ``OrdersDelegate/encode(order:db:encoder:)`` method, you'll want to encode a `struct` that conforms to ``OrderJSON``.
@@ -127,12 +121,8 @@ import Fluent
127
121
importOrders
128
122
129
123
finalclassOrderDelegate: OrdersDelegate {
130
-
let sslSigningFilesDirectory =URL(fileURLWithPath: "Certificates/Orders/", isDirectory: true)
131
-
132
-
let pemPrivateKeyPassword: String?= Environment.get("ORDERS_PEM_PRIVATE_KEY_PASSWORD")!
133
-
134
124
funcencode<O: OrderModel>(order: O, db: Database, encoder: JSONEncoder) asyncthrows-> Data {
135
-
// The specific OrderData class you use here may vary based on the `order.orderTypeIdentifier`
125
+
// The specific OrderData class you use here may vary based on the `order.typeIdentifier`
136
126
// if you have multiple different types of orders, and thus multiple types of order data.
> Important: If you have an encrypted PEM private key, you **must** explicitly declare ``OrdersDelegate/pemPrivateKeyPassword`` as a `String?` or Swift will ignore it as it'll think it's a `String` instead.
157
-
158
146
### Initialize the Service
159
147
160
148
Next, initialize the ``OrdersService`` inside the `configure.swift` file.
161
149
This will implement all of the routes that Apple Wallet expects to exist on your server.
150
+
In the `signingFilesDirectory` you specify there must be the `WWDR.pem`, `certificate.pem` and `key.pem` files.
151
+
If they are named like that you're good to go, otherwise you have to specify the custom name.
152
+
153
+
> Tip: Obtaining the three certificates files could be a bit tricky. You could get some guidance from [this guide](https://github.com/alexandercerutti/passkit-generator/wiki/Generating-Certificates) and [this video](https://www.youtube.com/watch?v=rJZdPoXHtzI). Those guides are for Wallet passes, but the process is similar for Wallet orders.
162
154
163
155
```swift
164
156
importFluent
@@ -169,7 +161,11 @@ let orderDelegate = OrderDelegate()
Copy file name to clipboardExpand all lines: Sources/Orders/OrdersDelegate.swift
+5-59
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,10 @@ import Foundation
10
10
11
11
/// The delegate which is responsible for generating the order files.
12
12
publicprotocolOrdersDelegate:AnyObject,Sendable{
13
-
/// Should return a `URL` which points to the template data for the order.
13
+
/// Should return a URL path which points to the template data for the order.
14
14
///
15
-
/// The URL should point to a directory containing all the images and localizations for the generated `.order` archive but should *not* contain any of these items:
15
+
/// The path should point to a directory containing all the images and localizations for the generated `.order` archive
16
+
/// but should *not* contain any of these items:
16
17
/// - `manifest.json`
17
18
/// - `order.json`
18
19
/// - `signature`
@@ -21,10 +22,8 @@ public protocol OrdersDelegate: AnyObject, Sendable {
21
22
/// - order: The order data from the SQL server.
22
23
/// - db: The SQL database to query against.
23
24
///
24
-
/// - Returns: A `URL` which points to the template data for the order.
25
-
///
26
-
/// > Important: Be sure to use the `URL(fileURLWithPath:isDirectory:)` constructor.
Copy file name to clipboardExpand all lines: Sources/Orders/OrdersService.swift
+30-9
Original file line number
Diff line number
Diff line change
@@ -17,14 +17,37 @@ public final class OrdersService: Sendable {
17
17
/// - Parameters:
18
18
/// - app: The `Vapor.Application` to use in route handlers and APNs.
19
19
/// - delegate: The ``OrdersDelegate`` to use for order generation.
20
+
/// - signingFilesDirectory: The path of the directory where the signing files (`wwdrCertificate`, `pemCertificate`, `pemPrivateKey`) are located.
21
+
/// - wwdrCertificate: The name of Apple's WWDR.pem certificate as contained in `signingFilesDirectory` path. Defaults to `WWDR.pem`.
22
+
/// - pemCertificate: The name of the PEM Certificate for signing the pass as contained in `signingFilesDirectory` path. Defaults to `certificate.pem`.
23
+
/// - pemPrivateKey: The name of the PEM Certificate's private key for signing the pass as contained in `signingFilesDirectory` path. Defaults to `key.pem`.
24
+
/// - pemPrivateKeyPassword: The password to the private key file. If the key is not encrypted it must be `nil`. Defaults to `nil`.
25
+
/// - sslBinary: The location of the `openssl` command as a file path.
20
26
/// - pushRoutesMiddleware: The `Middleware` to use for push notification routes. If `nil`, push routes will not be registered.
0 commit comments