iap rs
1.0.0
IAP는 Google Play 스토어 또는 Apple App Store를 통해 구매 한 영수증 정보를 확인하기위한 Rust Library입니다.
UnityPurchaseValidator 만들어 구매가 유효한지 (구독이라면 만료되지 않은 경우) PurchaseResponse 받을 수 있습니다.
use iap :: * ;
const APPLE_SECRET : & str = "<APPLE SECRET>" ;
const GOOGLE_KEY : & str = "<GOOGLE KEY JSON>" ;
# [ tokio :: main ]
pub async fn main ( ) -> Result < ( ) , Box < dyn std :: error :: Error > > {
let validator = UnityPurchaseValidator :: default ( )
. set_apple_secret ( APPLE_SECRET . to_string ( ) )
. set_google_service_account_key ( GOOGLE_KEY . to_string ( ) ) ? ;
// 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 ( ( ) )
}더 많은 세분화 제어와 상점의 종말점의 응답에 대한 액세스를 원한다면 도우미 기능을 제공합니다.
플레이 스토어 용 :
pub async fn validate ( receipt : & UnityPurchaseReceipt ) -> error :: Result < PurchaseResponse > {
let response = fetch_google_receipt_data ( receipt , "<GOOGLE_KEY>" ) . 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 )
}앱 스토어 용 :
pub async fn validate ( receipt : & UnityPurchaseReceipt ) -> error :: Result < PurchaseResponse > {
let response = fetch_apple_receipt_data ( receipt , "<APPLE_SECRET>" ) . await ? ;
// was this purchase made in the production or sandbox environment
println ! ( "Environment: {}" , response . environment . clone ( ) . unwrap ( ) ) ;
Ok ( validate_apple_subscription ( & response ) )
}