Skip to content

Commit

Permalink
Merge pull request #46 from namecare/develop
Browse files Browse the repository at this point in the history
chore: Release 1.0.0
  • Loading branch information
tikhop authored Feb 2, 2024
2 parents f4dacbb + fb8055e commit 8bff0dc
Show file tree
Hide file tree
Showing 35 changed files with 1,638 additions and 22 deletions.
16 changes: 14 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "app-store-server-library"
description = "The Rust server library for the App Store Server API and App Store Server Notifications"
version = "0.9.1"
version = "1.0.0"
repository = "https://github.com/namecare/app-store-server-library-rust"
homepage = "https://github.com/namecare/app-store-server-library-rust"
authors = ["tkhp", "namecare"]
Expand Down Expand Up @@ -29,11 +29,23 @@ chrono = { version = "0.4.32", features = ["serde"] }
base64 = "0.21.7"
asn1-rs = { version = "0.5.2", optional = true }

# Networking
reqwest = { version = "0.11.23", features = ["json"], optional = true }

# Utils
thiserror = "1.0.56"

# Tools
regex = { version = "1.10.3", optional = true }
url = "2.5.0"


[dev-dependencies]
http = "1.0.0"
tokio = { version = "1.35.1", features = ["test-util", "macros"] }
jsonwebtoken = { version = "9.2.0", features = ["use_pem"] }

[features]
receipt_utility = ["dep:asn1-rs", "dep:regex"]
api-client = ["dep:reqwest"]
receipt-utility = ["dep:asn1-rs", "dep:regex"]

33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,42 @@ Specify `app-store-server-library` in your project's `Cargo.toml` file, under th

```rust
[dependencies]
app-store-server-library = { version = "0.9.1", features = ["receipt_utility"] }
app-store-server-library = { version = "1.0.0", features = ["receipt-utility", "api-client"] }
```
Check
[crates.io](https://crates.io/crates/app-store-server-library) for the latest version number.

## Usage

### API Usage

```rust
use app_store_server_library::{AppStoreServerApiClient, Environment, AppStoreApiResponse, APIError};

#[tokio::main]
async fn main() {
let issuer_id = "99b16628-15e4-4668-972b-eeff55eeff55";
let key_id = "ABCDEFGHIJ";
let bundle_id = "com.example";
let encoded_key = std::fs::read_to_string("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8").unwrap(); // Adjust the path accordingly
let environment = Environment::Sandbox;

let client = AppStoreServerApiClient::new(encoded_key, key_id, issuer_id, bundle_id, environment);
match client.request_test_notification().await {
Ok(res) => {
println!("{}", response.test_notification_token);
}
Err(err) => {
println!("{}", err.http_status_code);
println!("{:?}", err.raw_api_error);
println!("{:?}", err.api_error);
println!("{}", err.error_message);
}
}
}
```
> Note: To extract transaction id from app/tx receipt, `api-client` feature must be enabled.
### Verification Usage

```rust
Expand All @@ -37,7 +66,7 @@ let decoded_payload = verifier.verify_and_decode_notification(payload).unwrap();
let receipt = "MI..";
let transaction_id = extract_transaction_id_from_app_receipt(receipt);
```
> Note: To extract transaction id from app/tx receipt, `receipt_utility` feature must be enabled.
> Note: To extract transaction id from app/tx receipt, `receipt-utility` feature must be enabled.
### Promotional Offer Signature Creation
```rust
Expand Down
4 changes: 4 additions & 0 deletions assets/models/apiException.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errorCode": 5000000,
"errorMessage": "An unknown error occurred."
}
4 changes: 4 additions & 0 deletions assets/models/apiTooManyRequestsException.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errorCode": 4290000,
"errorMessage": "Rate limit exceeded."
}
4 changes: 4 additions & 0 deletions assets/models/apiUnknownError.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errorCode": 9990000,
"errorMessage": "Testing error."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"requestIdentifier": "758883e8-151b-47b7-abd0-60c4d804c2f5"
}
6 changes: 6 additions & 0 deletions assets/models/extendSubscriptionRenewalDateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"originalTransactionId": "2312412",
"webOrderLineItemId": "9993",
"success": true,
"effectiveDate": 1698148900000
}
35 changes: 35 additions & 0 deletions assets/models/getAllSubscriptionStatusesResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"environment": "LocalTesting",
"bundleId": "com.example",
"appAppleId": 5454545,
"data": [
{
"subscriptionGroupIdentifier": "sub_group_one",
"lastTransactions": [
{
"status": 1,
"originalTransactionId": "3749183",
"signedTransactionInfo": "signed_transaction_one",
"signedRenewalInfo": "signed_renewal_one"
},
{
"status": 5,
"originalTransactionId": "5314314134",
"signedTransactionInfo": "signed_transaction_two",
"signedRenewalInfo": "signed_renewal_two"
}
]
},
{
"subscriptionGroupIdentifier": "sub_group_two",
"lastTransactions": [
{
"status": 2,
"originalTransactionId": "3413453",
"signedTransactionInfo": "signed_transaction_three",
"signedRenewalInfo": "signed_renewal_three"
}
]
}
]
}
27 changes: 27 additions & 0 deletions assets/models/getNotificationHistoryResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"paginationToken": "57715481-805a-4283-8499-1c19b5d6b20a",
"hasMore": true,
"notificationHistory": [
{
"sendAttempts": [
{
"attemptDate": 1698148900000,
"sendAttemptResult": "NO_RESPONSE"
}, {
"attemptDate": 1698148950000,
"sendAttemptResult": "SUCCESS"
}
],
"signedPayload": "signed_payload_one"
},
{
"sendAttempts": [
{
"attemptDate": 1698148800000,
"sendAttemptResult": "CIRCULAR_REDIRECT"
}
],
"signedPayload": "signed_payload_two"
}
]
}
8 changes: 8 additions & 0 deletions assets/models/getRefundHistoryResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"signedTransactions": [
"signed_transaction_one",
"signed_transaction_two"
],
"revision": "revision_output",
"hasMore": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"requestIdentifier": "20fba8a0-2b80-4a7d-a17f-85c1854727f8",
"complete": true,
"completeDate": 1698148900000,
"succeededCount": 30,
"failedCount": 2
}
12 changes: 12 additions & 0 deletions assets/models/getTestNotificationStatusResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"signedPayload": "signed_payload",
"sendAttempts": [
{
"attemptDate": 1698148900000,
"sendAttemptResult": "NO_RESPONSE"
}, {
"attemptDate": 1698148950000,
"sendAttemptResult": "SUCCESS"
}
]
}
7 changes: 7 additions & 0 deletions assets/models/lookupOrderIdResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"status": 1,
"signedTransactions": [
"signed_transaction_one",
"signed_transaction_two"
]
}
3 changes: 3 additions & 0 deletions assets/models/requestTestNotificationResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"testNotificationToken": "ce3af791-365e-4c60-841b-1674b43c1609"
}
11 changes: 11 additions & 0 deletions assets/models/transactionHistoryResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"revision": "revision_output",
"hasMore": true,
"bundleId": "com.example",
"appAppleId": 323232,
"environment": "LocalTesting",
"signedTransactions": [
"signed_transaction_value",
"signed_transaction_value2"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"revision": "revision_output",
"hasMore": 1,
"bundleId": "com.example",
"appAppleId": "hi",
"environment": "LocalTesting",
"signedTransactions": [
"signed_transaction_value",
"signed_transaction_value2"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"revision": "revision_output",
"hasMore": true,
"bundleId": "com.example",
"appAppleId": 323232,
"environment": "LocalTestingxxx",
"signedTransactions": [
"signed_transaction_value",
"signed_transaction_value2"
]
}
3 changes: 3 additions & 0 deletions assets/models/transactionInfoResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"signedTransactionInfo": "signed_transaction_info_value"
}
5 changes: 5 additions & 0 deletions assets/testSigningKey.p8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgSpP55ELdXswj9JRZ
APRwtTfS4CNRqpKIs+28rNHiPAqhRANCAASs8nLES7b+goKslppNVOurf0MonZdw
3pb6TxS8Z/5j+UNY1sWK1ChxpuwNS9I3R50cfdQo/lA9PPhw6XIg8ytd
-----END PRIVATE KEY-----
Loading

0 comments on commit 8bff0dc

Please sign in to comment.