Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ueman committed Oct 11, 2024
1 parent 0dc6230 commit 1d36cec
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
2 changes: 2 additions & 0 deletions passkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Unreleased

- No longer mark `PkPass.write()` as experimental
- Add webservice support for orders
- Add image support for orders

## 0.0.10

Expand Down
3 changes: 3 additions & 0 deletions passkit/lib/passkit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export 'src/order/order_return.dart';
export 'src/order/order_return_info.dart';
export 'src/order/order_shipping_fulfillment.dart';
export 'src/order/pk_order.dart';
export 'src/order_webservice/order_identifiers.dart';
export 'src/order_webservice/order_web_client.dart';
export 'src/order_webservice/order_web_client_exceptions.dart';
export 'src/pk_image.dart';
export 'src/pkpass/barcode.dart';
export 'src/pkpass/beacon.dart';
Expand Down
5 changes: 5 additions & 0 deletions passkit/lib/src/order/pk_order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class PkOrder {
// TODO(any): Do proper image loading for orders
// Do a sanity check for paths that already contains @2x/@3x modifier
// What about localized images?
//
// The Apple docs state that
// > Adding an image of the same name to the top-level folder of the order
// > file overrides any localized versions.
// So non-localized images are actually the fallback.
PkImage loadImage(String path, {String? locale}) {
assert(path.isNotEmpty);

Expand Down
62 changes: 31 additions & 31 deletions passkit/lib/src/order_webservice/order_web_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import 'package:passkit/src/order_webservice/order_identifiers.dart';
import 'package:passkit/src/order_webservice/order_web_client_exceptions.dart';
import 'package:passkit/src/utils.dart';

/// This class allows you to update a [Order] the latest version, if the pass
/// This class allows you to update a [PkOrder] the latest version, if the order
/// allows it.
///
/// Docs:
/// [https://developer.apple.com/documentation/walletpasses/send_an_updated_pass]
/// [https://developer.apple.com/documentation/walletorders]
class OrderWebClient {
/// If a [client] is passed to the constructor it will be used, otherwise a
/// default instance will be created. This is useful for testing, or for using
Expand All @@ -21,8 +21,8 @@ class OrderWebClient {

final Client _client;

/// Loads the latest version for the given pass. Throws, if the pass doesn't
/// support being updated. To check whether a pass supports being updated,
/// Loads the latest version for the given order. Throws, if the order doesn't
/// support being updated. To check whether an order supports being updated,
/// check whether [PkOrder.isWebServiceAvailable] returns true.
///
/// Returns null if no new order is available.
Expand Down Expand Up @@ -50,7 +50,7 @@ class OrderWebClient {
headers: {
if (modifiedSince != null)
'If-Modified-Since': formatHttpDate(modifiedSince),
'Authorization': 'ApplePass $authenticationToken',
'Authorization': 'AppleOrder $authenticationToken',
},
);

Expand All @@ -70,7 +70,7 @@ class OrderWebClient {
/// Record a message on the server.
///
/// Docs:
/// [https://developer.apple.com/documentation/walletpasses/log_a_message]
/// [https://developer.apple.com/documentation/walletorders/receive-log-messages]
Future<void> logMessages(PkOrder order, List<String> messages) async {
final webServiceUrl = order.order.webServiceURL;
if (webServiceUrl == null) {
Expand All @@ -82,22 +82,22 @@ class OrderWebClient {
await _client.post(endpoint, body: jsonEncode(messages));
}

/// Set up change notifications for a pass on a device.
/// Set up change notifications for an order on a device.
///
/// [deviceLibraryIdentifier] : A unique identifier you use to identify and
/// [deviceIdentifier] : A unique identifier you use to identify and
/// authenticate the device.
///
/// [pushToken] : A push token the server uses to send update notifications
/// for a registered pass to a device.
///
/// Docs:
/// https://developer.apple.com/documentation/walletpasses/register_a_pass_for_update_notifications
/// https://developer.apple.com/documentation/walletorders/register-a-device-for-update-notifications
Future<void> setupNotifications(
PkOrder order, {
required String deviceLibraryIdentifier,
required String deviceIdentifier,
required String pushToken,
}) async {
// https://yourpasshost.example.com/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}
// https://your-web-service.com/v1/devices/{deviceIdentifier}/registrations/{orderTypeIdentifier}/{orderIdentifier}

final webServiceUrl = order.order.webServiceURL;
if (webServiceUrl == null) {
Expand All @@ -109,7 +109,7 @@ class OrderWebClient {
[
'v1',
'devices',
deviceLibraryIdentifier,
deviceIdentifier,
'registrations',
order.order.orderTypeIdentifier,
order.order.orderIdentifier,
Expand All @@ -119,7 +119,7 @@ class OrderWebClient {
final response = await _client.post(
endpoint,
headers: {
'Authorization': 'ApplePass $authenticationToken',
'Authorization': 'AppleOrder $authenticationToken',
},
body: jsonEncode({
'pushToken': pushToken,
Expand All @@ -141,19 +141,19 @@ class OrderWebClient {
}
}

/// Unregister a Pass for Update Notifications
/// Stop sending update notifications for a pass on a device.
/// Unregister an order for update notifications
/// Stop sending update notifications for an order on a device.
///
/// [deviceLibraryIdentifier] : A unique identifier you use to identify and
/// [deviceIdentifier] : A unique identifier you use to identify and
/// authenticate the device.
///
/// Docs:
/// https://developer.apple.com/documentation/walletpasses/unregister_a_pass_for_update_notifications
/// https://developer.apple.com/documentation/walletorders/unregister-a-device-from-update-notifications
Future<void> stopNotifications(
PkOrder order, {
required String deviceLibraryIdentifier,
required String deviceIdentifier,
}) async {
// https://yourpasshost.example.com/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}
// https://your-web-service.com/v1/devices/{deviceIdentifier}/registrations/{orderTypeIdentifier}/{orderIdentifier}

final webServiceUrl = order.order.webServiceURL;
if (webServiceUrl == null) {
Expand All @@ -165,7 +165,7 @@ class OrderWebClient {
[
'v1',
'devices',
deviceLibraryIdentifier,
deviceIdentifier,
'registrations',
order.order.orderTypeIdentifier,
order.order.orderIdentifier,
Expand All @@ -175,7 +175,7 @@ class OrderWebClient {
final response = await _client.delete(
endpoint,
headers: {
'Authorization': 'ApplePass $authenticationToken',
'Authorization': 'AppleOrder $authenticationToken',
},
);

Expand All @@ -193,21 +193,22 @@ class OrderWebClient {

/// Send the serial numbers for updated passes to a device.
///
/// [deviceLibraryIdentifier] : A unique identifier you use to identify and
/// [deviceIdentifier] : A unique identifier you use to identify and
/// authenticate the device.
///
/// [previousLastUpdated] : The value of the lastUpdated key from the
/// [lastModified] : The value of the lastUpdated key from the
/// SerialNumbers object returned in a previous request. This value limits the
/// results of the current request to the passes updated since that previous
/// request.
///
/// Docs: https://developer.apple.com/documentation/walletpasses/get_the_list_of_updatable_passes
Future<OrderIdentifiers?> getListOfUpdatablePasses(
/// Docs:
/// https://developer.apple.com/documentation/walletorders/retrieve-the-registrations-for-a-device
Future<OrderIdentifiers?> getListOfRegisteredOrders(
PkOrder order, {
required String deviceLibraryIdentifier,
required String? previousLastUpdated,
required String deviceIdentifier,
required String? lastModified,
}) async {
// https://yourpasshost.example.com/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}?passesUpdatedSince={previousLastUpdated}
// https://your-web-service.com/v1/devices/{deviceIdentifier}/registrations/{orderTypeIdentifier}?ordersModifiedSince={lastModified}
final webServiceUrl = order.order.webServiceURL;
if (webServiceUrl == null) {
throw OrderWebServiceUnsupported();
Expand All @@ -216,13 +217,12 @@ class OrderWebClient {
final endpoint = webServiceUrl.appendPathSegments([
'v1',
'devices',
deviceLibraryIdentifier,
deviceIdentifier,
'registrations',
order.order.orderTypeIdentifier,
]).replace(
queryParameters: {
if (previousLastUpdated != null)
'passesUpdatedSince': previousLastUpdated,
if (lastModified != null) 'ordersModifiedSince': lastModified,
},
);

Expand Down

0 comments on commit 1d36cec

Please sign in to comment.