Build

iap

iap is a rust library for verifying receipt information for purchases made through the Google Play Store or the Apple App Store.

Current Features

Supported Transaction Types

Coming Features

Usage

For simple validation of Unity IAP receipts

You can receive a PurchaseResponse which will simply tell you if a purchase is valid (and not expired if a subscription) by creating a UnityPurchaseValidator.

```rust use iap::*;

const APPLESECRET: &str = ""; const GOOGLEKEY: &str = "";

[tokio::main]

pub async fn main() -> Result<(), Box> { let validator = UnityPurchaseValidator::default() .setapplesecret(APPLESECRET.tostring()) .setgoogleserviceaccountkey(GOOGLEKEY.tostring())?;

// RECEIPT_INPUT would be the Json string containing the store, transaction id, and payload
// from Unity IAP. ie:
// "{ \"Store\": \"GooglePlay\", \"TransactionID\": \"<Txn ID>\", \"Payload\": \"<Payload>\" }"
let unity_receipt = UnityPurchaseReceipt::from(&std::env::var("RECEIPT_INPUT")?)?;

let response = validator.validate(&unity_receipt).await?;

println!("PurchaseResponse is valid: {}", response.valid);

Ok(())

} ```

If you wanted more granular control and access to the response from the store's endpoint, we provide helper functions to do so.

For the Play Store: ```rust pub async fn validate(receipt: &UnityPurchaseReceipt) -> error::Result { let response = fetchgooglereceipt_data(receipt, "").await?;

// debug or validate on your own with the data in the response
println!("Expiry data: {}", response.expiry_time);

// or just simply validate the response
validate_google_subscription(&response)

} ```

For the App Store: ```rust pub async fn validate(receipt: &UnityPurchaseReceipt) -> error::Result { let response = fetchapplereceipt_data(receipt, "").await?;

// was this purchase made in the production or sandbox environment
println!("Environment: {}", response.environment.clone().unwrap());

Ok(validate_apple_subscription(&response))

} ```