Closed lyonbeckers closed 3 years ago
I don't know if apple's response has changed, but the field is named with underscores
"latest_receipt_info": [{ "quantity": "1", "product_id": "com.gameroasters.wr.noads", "transaction_id": "1000000775802959", "original_transaction_id": "1000000767402340", "purchase_date": "2021-02-09 17:22:17 Etc/GMT", "purchase_date_ms": "1612891337000", "purchase_date_pst": "2021-02-09 09:22:17 America/Los_Angeles", "original_purchase_date": "2021-02-09 17:22:21 Etc/GMT", "original_purchase_date_ms": "1612891341000", "original_purchase_date_pst": "2021-02-09 09:22:21 America/Los_Angeles", "expires_date": "2021-02-09 17:25:17 Etc/GMT", "expires_date_ms": "1612891517000", "expires_date_pst": "2021-02-09 09:25:17 America/Los_Angeles", "web_order_line_item_id": "1000000059889086", "is_trial_period": "false", "is_in_intro_offer_period": "false", "subscription_group_identifier": "20729672" },
With the rename to latest-receipt-info, this would map as false because the field is None
let valid = response .latest_receipt_info .as_ref() // <-- this is None .and_then(|receipts| { receipts .iter() .max_by(|a, b| { let a = a.expires_date_ms.parse::<i64>().unwrap_or_default(); let b = b.expires_date_ms.parse::<i64>().unwrap_or_default(); a.partial_cmp(&b).unwrap_or(std::cmp::Ordering::Less) }) .and_then(|receipt| { receipt .expires_date_ms .parse::<i64>() .map(|expiry_time| expiry_time > now) .ok() }) }) .unwrap_or_default(); // <-- therefore false is returned
With the renames removed, this log displays the proper response
let latest_expires_date = response.latest_receipt_info.as_ref().and_then(|receipts| { receipts .iter() .max_by(|a, b| { let a = a.expires_date_ms.parse::<i64>().unwrap_or_default(); let b = b.expires_date_ms.parse::<i64>().unwrap_or_default(); a.partial_cmp(&b).unwrap_or(std::cmp::Ordering::Less) }) .map(|receipt| receipt.expires_date.clone()) }); log::info!( "apple response, status: {}, latest_expires: {:?}", &response.status, latest_expires_date, );
Feb 09 10:38:43.605 INFO apple response, status: 0, latest_expires: Some("2021-02-09 17:25:17 Etc/GMT")
lets use a unittest that feeds us with a correctly formatted response to not regress on this ever again
I don't know if apple's response has changed, but the field is named with underscores
With the rename to latest-receipt-info, this would map as false because the field is None
With the renames removed, this log displays the proper response
Feb 09 10:38:43.605 INFO apple response, status: 0, latest_expires: Some("2021-02-09 17:25:17 Etc/GMT")