-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: membership active status check #2
base: main
Are you sure you want to change the base?
Conversation
src/membership_check.rs
Outdated
"expired" | ||
// Parse the expiration date from the MailChimp response | ||
let expires_date = parse_iso_date(&mc_json.merge_fields.expires); | ||
let today = Local::now().with_timezone(&Vancouver).date_naive(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glindstr the signup uses UTC times/dates, not Local. You should not need chrono_tz
since we are using UTC.
See:
squamishaccess-functions/src/ipn_handler.rs
Lines 232 to 233 in 328ea1d
let utc_now: DateTime<Utc> = Utc::now(); | |
let mut utc_expires: DateTime<Utc> = Utc::now() + Duration::days(365); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I suggest we use pacific time for both calculations. A member who expires on January 1st, 2025 and submits a membership check at 9:00pm pacific prevailing time on December 31st, 2024 will receive an email saying their membership has expired but an expiry date of the next day. A similar situation exists when they sign up or renew they would get an extra day at 9pm. The alternative would be to include the browser timezone in the api call but I suggest we stick with Squamish's timezone and not use utc to prevent this confusion.
The Mailchimp field for Expires and Joined is a pure date type. And it appears their system accepts and convert the RFC3339 datetime format into a pure date. I suggest we use dates instead.
Are you onboard to switch from chrono::DateTime to chrono::NaiveDate for these two fields? This would require using chrono_tz.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible I would suggest converting to pacific time (or a localized timezone) when we send the email, to avoid problems with DST. This could be confusing for an admin who looks at mailchimp, I suppose, if they don't know. I think it is still better to store it in UTC in then convert it but if you feel strongly otherwise it can be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using dates is fine but it's less standardized (because timezones), so most storage representations would still be something like RFC 3339.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with UTC always being best when available. In this case I believe the mailchimp system does not store UTC or any time information:
https://mailchimp.com/developer/marketing/docs/merge-fields/#structure
The field type is (naive) date and I believe when we send an RFC 3339 timestamp their system simply ignores all time/timezone information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be recollecting wrong but it may be that you still need to send an ISO date to the API.
Ok well in that case we should probably send pacific time from the ipn handler function and read it as pacific as well, and just ignore the existence of DST
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code does have a comment that there was a requirement for sending datetimes. I believe my other project is sending and receiving naive Dates as strings in json. I'll double check before proceeding. I don't believe we have a DST issue. Let's see what I come back with and discuss.
src/membership_check.rs
Outdated
fn parse_iso_date(iso_date: &str) -> Result<NaiveDate, ParseError> { | ||
NaiveDate::parse_from_str(iso_date, "%Y-%m-%d") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glindstr I see the existing code in the ipn handler does something like this but it probably isn't ideal.
better would be to use DateTime::parse_from_rfc3339
(RFC 3339 is a subset of ISO 8601)
The relevant code in the ipn handler should probably also use DateTime::with_time
as per the example for that, rather than how is is currently adding 365 days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can address this. Depending on our the choice to use NaiveDate type it doesn't have a rfc3338 parsing method.
some deprecations need to be cleaned up on the main branch...
|
I've updated the packages on the main branch and have addressed the deprecations. There are quite a few multiple versions for dependency warnings which seems fine to me but I believe the CI system on the pull request will fail them as errors. |
It looks like there are still some legitimate warnings:
The multiple dependency warning is hard to resolve. I suggest disabling that lint, in the following two spots:
(It would be more ideal to move the lint definitions to the new |
After you make that change, could you please rebase this branch? |
35d068e
to
efc9d70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glindstr good to merge whenever you like but you might want to update the code in the ipn_handler
function to also use local pacific time.
For reference, I believe this is hosted in Azure's Washington datacenter but I would have to double check
errr, you might want to fix the unused imports first though that's what failing checks. I would recommend setting up |
I'll update the PR for standardizing the usage of NaiveDate for your review and feedback. Thanks I'll check out rust-analyzer. I'm slowly fumbling my way through learning the rust tool set. Thank you for your patience. |
If you have a fast laptop/computer you may also want to set |
efc9d70
to
8fce41f
Compare
I've updated the code to use NaiveDate instead of DateTime for Expiry and Joined dates. The IPN function handles live paypal transactions. I don't love making changes to working code on a critical system. Are we setup to push this to a test endpoint and use paypal test events? |
@glindstr sorry life got real over the last part of Dec I think paypal's ipn system was always difficult to test with. I think I ran it locally and pointed their IPN simulator at it |
@Fishrock123 All good. Looking at this again I don't want to modify the IPN handler since it is working and vital to membership operations. I'd like to change this pull request to the membership check only and deploy the change for testing in the near future. What are you thoughts? |
If I recall correct, the IPN has a really long retry period for re-sending unprocessed events in case your handler is malfunctioning, so I don't think it is too big of an issue. |
I think the most annoying thing will be deploy, I always did it from my local windows machine. i would like to move that to GitHub actions... maybe I will have time to take a crack this weekend since I'm stuck sitting around on call ... |
via @glindstr