#nsgrantham
1 messages · Page 1 of 1 (latest)
hello! will those payments be for subscriptions?
Not necessarily, I would like to include one-time payments too, but subscriptions are probably the most important thing to support.
For some additional context, here's what I have tried so far:
- Custom
createdvalue. At first I assumed this would be straightforward to do, I could simply supply my owncreatedvalue when creating a new object. For example,stripe.Subscription.create(..., created=int(now()) - 31536000)(Python pseudocode) would retroactively create a subscription approximately one year (31,536,000 seconds) in the past. Unfortunately, this does not appear to be supported, as I received the following error:stripe.error.InvalidRequestError: Request req_xxx: Received unknown parameter: created. I also tried this withstripe.Customer.create()andstripe.Product.create(), but no luck. - Prorated subscription. Next, I learned that a Subscription could be created and supplied a start date in the past. In this case, the subscription would be prorated over the period from the start date to the present. Great! However, this proration is charged as a lump sum at the present time, rather than appearing as a series of monthly charges between the start date and the present.
- Test Clocks. Finally, I discovered Test Clocks. At last, this is what I've been looking for! I created a test clock set at a frozen time 1 year in the past. I then created 3 customers associated with this test clock and created a subscription for each customer tied to an existing product. So far so good. Then I advanced the clock forward in time and observed that each of the customers was charged their monthly subscriptions over the test clock's passage of time. However, similar to the case with the prorated subscription, the charges are incurred at the present time when I advanced the clock rather than appearing to have been charged in the period between the start of the test clock and its new time following the advancement.
One method to achieve this that I have not yet tried is to import data into Stripe, something like the Importing external transactions and Correcting imported data examples, but it's not clear to me if this would result in the same "past charges appear at the present time" problem.
hrm, based off what you've tried, i don't think it's possible then. You're probably going to have to mock the dates of those "past" data
How would I go about mocking the dates? Is this something I can do via the API?
no, it's not something you can do via the API. You can retrieve the relevant data then save those somewhere locally, update the dates, and then run your tests against those saved data instead
ah okay, I see, using something like https://github.com/stripe/stripe-mock ?
I don't know if stripe-mock will work for your scenario, but you can try. Ultimately, you just have to pretend you're making a call to Stripe but return those mock data instead. There're various ways to go about it