Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Sources/AppStoreServerLibrary/AppStoreServerAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public actor AppStoreServerAPIClient: Sendable {
let request: String? = nil
return await makeRequestWithResponseBody(path: "/inApps/v1/notifications/test/" + testNotificationToken, method: .GET, queryParameters: [:], body: request)
}

///See `getTransactionHistory(transactionId: String, revision: String?, transactionHistoryRequest: TransactionHistoryRequest, version: GetTransactionHistoryVersion)`
@available(*, deprecated)
public func getTransactionHistory(transactionId: String, revision: String?, transactionHistoryRequest: TransactionHistoryRequest) async -> APIResult<HistoryResponse> {
Expand Down Expand Up @@ -367,14 +367,25 @@ public actor AppStoreServerAPIClient: Sendable {

///Send consumption information about a consumable in-app purchase to the App Store after your server receives a consumption request notification.
///
///- Parameter transactionId: The transaction identifier for which youre providing consumption information. You receive this identifier in the CONSUMPTION_REQUEST notification the App Store sends to your server.
///- Parameter transactionId: The transaction identifier for which you're providing consumption information. You receive this identifier in the CONSUMPTION_REQUEST notification the App Store sends to your server.
///- Parameter consumptionRequest : The request body containing consumption information.
///- Returns: Success, or information about the failure
///[Send Consumption Information](https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information)
public func sendConsumptionData(transactionId: String, consumptionRequest: ConsumptionRequest) async -> APIResult<Void> {
///[Send Consumption Information](https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information-v1)
@available(*, deprecated, message: "Use sendConsumptionInformation(_:consumptionRequest:) instead")
public func sendConsumptionData(transactionId: String, consumptionRequest: ConsumptionRequestV1) async -> APIResult<Void> {
return await makeRequestWithoutResponseBody(path: "/inApps/v1/transactions/consumption/" + transactionId, method: .PUT, queryParameters: [:], body: consumptionRequest)
}

///Send consumption information about an In-App Purchase to the App Store after your server receives a consumption request notification.
///
///- Parameter transactionId: The transaction identifier for which you're providing consumption information. You receive this identifier in the CONSUMPTION_REQUEST notification the App Store sends to your server's App Store Server Notifications V2 endpoint.
///- Parameter consumptionRequest: The request body containing consumption information.
///- Returns: Success, or information about the failure
///[Send Consumption Information](https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information)
public func sendConsumptionInformation(transactionId: String, consumptionRequest: ConsumptionRequest) async -> APIResult<Void> {
return await makeRequestWithoutResponseBody(path: "/inApps/v2/transactions/consumption/" + transactionId, method: .PUT, queryParameters: [:], body: consumptionRequest)
}

///Sets the app account token value for a purchase the customer makes outside your app, or updates its value in an existing transaction.
///
///- Parameter originalTransactionId: The original transaction identifier of the transaction to receive the app account token update.
Expand Down
76 changes: 76 additions & 0 deletions Sources/AppStoreServerLibrary/Models/AppData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) 2025 Apple Inc. Licensed under MIT License.

import Foundation

///The object that contains the app metadata and signed app transaction information.
///
///[appData](https://developer.apple.com/documentation/appstoreservernotifications/appdata)
public struct AppData: Decodable, Encodable, Hashable, Sendable {

public init(appAppleId: Int64? = nil, bundleId: String? = nil, environment: AppStoreEnvironment? = nil, signedAppTransactionInfo: String? = nil) {
self.appAppleId = appAppleId
self.bundleId = bundleId
self.environment = environment
self.signedAppTransactionInfo = signedAppTransactionInfo
}

public init(appAppleId: Int64? = nil, bundleId: String? = nil, rawEnvironment: String? = nil, signedAppTransactionInfo: String? = nil) {
self.appAppleId = appAppleId
self.bundleId = bundleId
self.rawEnvironment = rawEnvironment
self.signedAppTransactionInfo = signedAppTransactionInfo
}

///The unique identifier of the app that the notification applies to.
///
///[appAppleId](https://developer.apple.com/documentation/appstoreservernotifications/appappleid)
public var appAppleId: Int64?

///The bundle identifier of the app.
///
///[bundleId](https://developer.apple.com/documentation/appstoreservernotifications/bundleid)
public var bundleId: String?

///The server environment that the notification applies to, either sandbox or production.
///
///[environment](https://developer.apple.com/documentation/appstoreservernotifications/environment)
public var environment: AppStoreEnvironment? {
get {
return rawEnvironment.flatMap { AppStoreEnvironment(rawValue: $0) }
}
set {
self.rawEnvironment = newValue.map { $0.rawValue }
}
}

///See ``environment``
public var rawEnvironment: String?

///App transaction information signed by the App Store, in JSON Web Signature (JWS) format.
///
///[JWSAppTransaction](https://developer.apple.com/documentation/appstoreservernotifications/jwsapptransaction)
public var signedAppTransactionInfo: String?

public enum CodingKeys: CodingKey {
case appAppleId
case bundleId
case environment
case signedAppTransactionInfo
}

public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.appAppleId = try container.decodeIfPresent(Int64.self, forKey: .appAppleId)
self.bundleId = try container.decodeIfPresent(String.self, forKey: .bundleId)
self.rawEnvironment = try container.decodeIfPresent(String.self, forKey: .environment)
self.signedAppTransactionInfo = try container.decodeIfPresent(String.self, forKey: .signedAppTransactionInfo)
}

public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(self.appAppleId, forKey: .appAppleId)
try container.encodeIfPresent(self.bundleId, forKey: .bundleId)
try container.encodeIfPresent(self.rawEnvironment, forKey: .environment)
try container.encodeIfPresent(self.signedAppTransactionInfo, forKey: .signedAppTransactionInfo)
}
}
Loading