#alex-billing-testclocks
1 messages · Page 1 of 1 (latest)
Hey there
Yes you can still retrieve the data from objects that are involved with test clocks
Hi there 👋 jumping in as my teammate needs to step away soon. Can you elaborate a bit on what you're trying to do and what you're seeing? Are you making requests that are encountering errors, or something else?
I'm attempting to look up subscriptions via a REST API. To accomplish this, I first query the list customers endpoint using test customer email address. I am getting null customer at this step.
I see
I have to use the clock id
to get the customer?
Correct, if that parameter is not provided then Customers that are associated with test clocks are not included in the list results.
So if I have a GET request ( url: ${this.#baseURL}/v1/customers?email=${email}), would I add a query parameter for test clock?
I'll need to double check that.
So without test clocks, I tried to pause the subscription by sending the following with a request in test mode, but the subscription object has pause_collection as null.
const request = {
pause_collection: {
behavior: "void",
resumes_at: ${Number(nextBilledAt)},
},
}
I have the billing set as "send_invoice"
Do I need to have an actual payment on file to be able to test pausing a subscription?
Can you share the ID of the request that you made to try to pause the Subscription? That should start with a req_ prefix.
req_oYNAXhld9Z4P2p
I'm not seeing that any body was provided with that request:
https://dashboard.stripe.com/test/logs/req_oYNAXhld9Z4P2p
So it seems expected that no changes would have been made to the specified Subscription. How are you creating these requests?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
TypeScript
newSub = await this.#fetcher
.fetch({
ciid: customerIntegrationID,
method: "POST",
url: uri,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json",
},
body: JSON.stringify(request),
})
This is the uri I am using:
const uri = ${this.#baseURL}/v1/subscriptions/${subscription.id}
What is in request? And what happens if you send that as form-encoded data instead of a JSON string?
const request = {
pause_collection: {
behavior: "void",
resumes_at: ${Number(nextBilledAt)},
},
}
Okay, yeah, so it seems like you're passing a JSON string, but our API is expecting form-encoded data, so the endpoint likely isn't able to parse the data being provided.
How do I fix this?
I did a Google search and it said that x-www-form-encoded is not different than form-encoded. Did you mean form-data?
Those are all the same thing as far as I know, and are not the same as JSON. I searched google for examples of dealing with form encoded data using fetch, which led me to this:
https://gist.github.com/navio/59305c42830581cc07fb566d94276d96
Since you're using fetch I also want to check, are you making these requests from your server-side code?
Yes
Am I correct in inferring that you're using Go for your project? If so, have you considered using our Go library rather than integrating against our endpoints directly?
https://github.com/stripe/stripe-go
We need the requests in TypeScript
I made those changes and I still do not see the request in the log
Hello! I'm taking over and catching up...
const request = {
pause_collection: {
behavior: "void",
resumes_at: ${Number(nextBilledAt)},
},
}
const test = new URLSearchParams()
test.append(
"pause_collection[behavior]",
request.pause_collection.behavior,
)
test.append(
"pause_collection[resumes_at]",
request.pause_collection.resumes_at,
)
try {
newSub = await this.#fetcher
.fetch({
ciid: customerIntegrationID,
method: "POST",
url: uri,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json",
},
body: test.toString(),
})
.then(checkStatus)
.then((resp) => resp.json())
} catch (err) {
throw new Error(`go fetch: ${err}`)
}
Can you give me the request ID of the request made as a result of that code?
How do you get that?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Is that something that should be in the json response?
It's in one of the HTTP headers in the response.
Or you can get it in the Stripe Dashboard.
What if my requests aren't appearing in the logs?
Make sure you adjust the filter so it shows GET requests.
But the request I'm doing is a POST
Can you get the HTTP headers from the response?
I can give you the json response. Is that what you want?
Nope, I want the request ID.
It's in the HTTP headers in the response, or it's in the Dashboard in your request logs.
Found it: req_v1O2ZPq75ckYcv
Thanks! So this is a GET request, and you're only supply an email as the argument. What are you trying to do here?
req_DxignAm1fo7ETH
Also, can you see this request in your Dashboard here? https://dashboard.stripe.com/test/logs/req_v1O2ZPq75ckYcv
That second request modified a Subscription; is that behaving as you expected? https://dashboard.stripe.com/test/logs/req_DxignAm1fo7ETH
I see, so if there's data in pause_collection then does that mean the request went through successfully?
Yes.
Those are the properties you passed in.
And the update was successful per the 200 HTTP status code.
Hooray! What if I wanted to test this with test clocks, is that possible?
Wait, let's back up. Does that first request do what you want? What was your intent with req_v1O2ZPq75ckYcv?
Yes, because query for customers by email first. When I find the match, then I use customer id when I query for subscriptions.
Gotcha, okay, sounds good.
So the answer to your earlier question is yes, you can do this with Test Clocks in general. You need to specify the test_clock you're using though: https://stripe.com/docs/api/customers/list#list_customers-test_clock
Can it be tied to the test customer I have currently?
Yes.
Wait, sorry, I think I misunderstood.
If you have an existing Customer associated with the Test Clock you're using you can use that one. If you mean you want to use an existing Customer not associated with a Test Clock then no, you can't do that.
Yes, I suppose so.