Skip to content
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

Subscription endDate changed from integer to string, no longer works with twig date filter #340

Closed
iamkeir opened this issue Feb 8, 2023 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@iamkeir
Copy link

iamkeir commented Feb 8, 2023

Description

We recently updated the Stripe Payments plugin from a very old version and now the subscription endDate seems to return a string instead of an integer, unlike cancel_at which is still an integer (looks like epoch integer).

As such, if you have a date string such as "22/12/24", date('d/m/Y') fails as it is getting muddled by which part of the string is month and which is day (and 22 is too large for month), and it throws:

DateTime::__construct(): Failed to parse time string (22/12/23) at position 0 (2): Unexpected character

Is this something that could have changed in some updates? Or maybe on the Stripe side? Ideally it would be an integer as strings are unreliable for this reason.

Additional info

  • Craft version: 3.7.17.1
  • PHP version: 7.3
  • Plugin version: 4.0.10
  • Is SCA and Stripe Checkout enabled?: Yes
@iamkeir
Copy link
Author

iamkeir commented Feb 8, 2023

Actually, wait, I think cancel_at is an internal plugin value, whereas endDate (and canceledAt) are coming from Stripe. Perhaps Stripe changed the format of these values?

@iamkeir
Copy link
Author

iamkeir commented Feb 8, 2023

Yep, canceledAt is also a string.

@andrelopez
Copy link
Member

Currently, we're mapping endDate -> current_period_end (from the subscription object) to convert from timestamp (int) to string (human readable)

I will take a look.

@andrelopez andrelopez self-assigned this Feb 8, 2023
@iamkeir
Copy link
Author

iamkeir commented Feb 8, 2023

Ok, let us know. Timestamp (int) is far more useful as it can be manipulated into any date string users require, whereas the string format is prone to error due to dd/mm/yyyy vs mm/dd/yyyy.

@andrelopez andrelopez added bug Something isn't working and removed need more info labels Feb 9, 2023
andrelopez added a commit that referenced this issue Feb 9, 2023
@andrelopez
Copy link
Member

We just released Stripe Payments v4.1.0 (Craft3) and v5.1.0(Craft4) with a fix to this issue. If there is an error it will return the date as comes from Stripe

@andrelopez
Copy link
Member

andrelopez commented Feb 9, 2023

@iamkeir you can access to original stripe's data from: $subscription->data

@andrelopez
Copy link
Member

Sorry I wanted to say $subscription->data, our subscription object it's just a human-readable wrapper of Stripe's subscription object, if you need the data as comes from Stripe you can use:

In PHP

$subscription->data['canceled_at'];

or in Twig:

{{ subscription.data.canceled_at }}
{{ subscription.data.current_period_end }}

You will be able to get the dates as timestamps if you need them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants