1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
pub mod api_error_code;
use http::Method;
use crate::api_client::api::advanced_commerce_api::api_error_code::ApiErrorCode;
use crate::api_client::api_client::ApiClient;
use crate::api_client::error::ApiServiceError;
use crate::api_client::transport::Transport;
use crate::primitives::advanced_commerce::subscription_cancel_request::SubscriptionCancelRequest;
use crate::primitives::advanced_commerce::subscription_cancel_response::SubscriptionCancelResponse;
use crate::primitives::advanced_commerce::subscription_revoke_request::SubscriptionRevokeRequest;
use crate::primitives::advanced_commerce::subscription_revoke_response::SubscriptionRevokeResponse;
use crate::primitives::advanced_commerce::request_refund_request::RequestRefundRequest;
use crate::primitives::advanced_commerce::request_refund_response::RequestRefundResponse;
use crate::primitives::advanced_commerce::subscription_change_metadata_request::SubscriptionChangeMetadataRequest;
use crate::primitives::advanced_commerce::subscription_change_metadata_response::SubscriptionChangeMetadataResponse;
use crate::primitives::advanced_commerce::subscription_migrate_request::SubscriptionMigrateRequest;
use crate::primitives::advanced_commerce::subscription_migrate_response::SubscriptionMigrateResponse;
use crate::primitives::advanced_commerce::subscription_price_change_request::SubscriptionPriceChangeRequest;
use crate::primitives::advanced_commerce::subscription_price_change_response::SubscriptionPriceChangeResponse;
pub struct AdvancedCommerceApi;
pub type AdvancedCommerceApiClient<T> = ApiClient<T, AdvancedCommerceApi, ApiErrorCode>;
pub type ApiError = ApiServiceError<ApiErrorCode>;
impl<T: Transport> AdvancedCommerceApiClient<T> {
/// Turn off automatic renewal to cancel a customer's auto-renewable subscription.
///
/// [Documentation](https://developer.apple.com/documentation/advancedcommerceapi/cancel-a-subscription)
///
/// # Arguments
///
/// * `transaction_id` - The transaction identifier of the auto-renewable subscription to cancel.
/// * `subscription_cancel_request` - The request body that includes information about the subscription to cancel.
///
/// # Returns
///
/// A response that indicates the subscription was successfully cancelled.
///
/// # Errors
///
/// Returns an `APIError` if the request could not be processed.
pub async fn cancel_subscription(
&self,
transaction_id: &str,
subscription_cancel_request: &SubscriptionCancelRequest,
) -> Result<SubscriptionCancelResponse, ApiError> {
let path = format!("/advancedCommerce/v1/subscription/cancel/{}", transaction_id);
let req = self.build_request(
path.as_str(),
Method::POST,
Some(subscription_cancel_request),
)?;
self.make_request_with_response_body(req).await
}
/// Update the SKU, display name, and description associated with a subscription,
/// without affecting the subscription's billing or its service.
///
/// [Documentation](https://developer.apple.com/documentation/advancedcommerceapi/change-subscription-metadata)
///
/// # Arguments
///
/// * `transaction_id` - The transaction identifier of the auto-renewable subscription to get changes to its metadata.
/// Use the subscription's original transaction ID or any subsequent transaction ID
/// of a transaction related to the subscription.
/// * `subscription_change_metadata_request` - The request body that contains the metadata changes.
///
/// # Returns
///
/// A response that indicates the metadata was successfully changed.
///
/// # Errors
///
/// Returns an `APIError` if the request could not be processed.
pub async fn change_subscription_metadata(
&self,
transaction_id: &str,
subscription_change_metadata_request: &SubscriptionChangeMetadataRequest,
) -> Result<SubscriptionChangeMetadataResponse, ApiError> {
let path = format!("/advancedCommerce/v1/subscription/changeMetadata/{}", transaction_id);
let req = self.build_request(
path.as_str(),
Method::POST,
Some(subscription_change_metadata_request),
)?;
self.make_request_with_response_body(req).await
}
/// Increase or decrease the price of an auto-renewable subscription, a bundle,
/// or individual items within a subscription at the next renewal.
///
/// [Documentation](https://developer.apple.com/documentation/advancedcommerceapi/change-subscription-price)
///
/// # Arguments
///
/// * `transaction_id` - A transaction identifier of the auto-renewable subscription that is subject to the price change.
/// Use the subscription's original transaction ID or any subsequent transaction ID
/// of a transaction related to the subscription.
/// * `subscription_price_change_request` - The request body that contains the details of the price change.
///
/// # Returns
///
/// A response that contains signed JWS renewal and JWS transaction information after a subscription price change request.
///
/// # Errors
///
/// Returns an `APIError` if the request could not be processed.
pub async fn change_subscription_price(
&self,
transaction_id: &str,
subscription_price_change_request: &SubscriptionPriceChangeRequest,
) -> Result<SubscriptionPriceChangeResponse, ApiError> {
let path = format!("/advancedCommerce/v1/subscription/changePrice/{}", transaction_id);
let req = self.build_request(
path.as_str(),
Method::POST,
Some(subscription_price_change_request),
)?;
self.make_request_with_response_body(req).await
}
/// Migrate a subscription that a customer purchased through In-App Purchase
/// to a subscription you manage using the Advanced Commerce API.
///
/// [Documentation](https://developer.apple.com/documentation/advancedcommerceapi/migrate-subscription-to-advanced-commerce-api)
///
/// # Arguments
///
/// * `transaction_id` - The transaction identifier of the auto-renewable subscription to migrate.
/// Use the subscription's original transaction ID or any subsequent transaction ID
/// of a transaction related to the subscription.
/// * `subscription_migrate_request` - The request body that contains the details for the migration.
///
/// # Returns
///
/// A response that indicates the subscription was successfully migrated.
///
/// # Errors
///
/// Returns an `APIError` if the request could not be processed.
pub async fn migrate_subscription(
&self,
transaction_id: &str,
subscription_migrate_request: &SubscriptionMigrateRequest,
) -> Result<SubscriptionMigrateResponse, ApiError> {
let path = format!("/advancedCommerce/v1/subscription/migrate/{}", transaction_id);
let req = self.build_request(
path.as_str(),
Method::POST,
Some(subscription_migrate_request),
)?;
self.make_request_with_response_body(req).await
}
/// Request a refund for a one-time charge or subscription transaction.
///
/// [Documentation](https://developer.apple.com/documentation/advancedcommerceapi/request-transaction-refund)
///
/// # Arguments
///
/// * `transaction_id` - The transaction identifier for which you request a refund.
/// * `request_refund_request` - The request body for the refund.
///
/// # Returns
///
/// A response that indicates the refund request was successfully processed.
///
/// # Errors
///
/// Returns an `APIError` if the request could not be processed.
pub async fn request_transaction_refund(
&self,
transaction_id: &str,
request_refund_request: &RequestRefundRequest,
) -> Result<RequestRefundResponse, ApiError> {
let path = format!("/advancedCommerce/v1/transaction/requestRefund/{}", transaction_id);
let req = self.build_request(
path.as_str(),
Method::POST,
Some(request_refund_request),
)?;
self.make_request_with_response_body(req).await
}
/// Immediately cancel a customer's subscription and all the items that are included in the subscription,
/// and request a full or prorated refund.
///
/// [Documentation](https://developer.apple.com/documentation/advancedcommerceapi/revoke-subscription)
///
/// # Arguments
///
/// * `transaction_id` - The transaction identifier of the auto-renewable subscription to revoke.
/// Use the subscription's original transaction ID or any subsequent transaction ID
/// of a transaction related to the subscription.
/// * `subscription_revoke_request` - The request body for revoking the subscription.
///
/// # Returns
///
/// A response that indicates the subscription was successfully revoked.
///
/// # Errors
///
/// Returns an `APIError` if the request could not be processed.
pub async fn revoke_subscription(
&self,
transaction_id: &str,
subscription_revoke_request: &SubscriptionRevokeRequest,
) -> Result<SubscriptionRevokeResponse, ApiError> {
let path = format!("/advancedCommerce/v1/subscription/revoke/{}", transaction_id);
let req = self.build_request(
path.as_str(),
Method::POST,
Some(subscription_revoke_request),
)?;
self.make_request_with_response_body(req).await
}
}