#alex-billing-testclocks

1 messages · Page 1 of 1 (latest)

hard jackalBOT
heavy oak
#

Hey there

#

Yes you can still retrieve the data from objects that are involved with test clocks

soft shoal
#

I'm not able to do so

#

Would you like the number for the test customer I am using?

charred mural
#

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?

soft shoal
#

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?

charred mural
#

Correct, if that parameter is not provided then Customers that are associated with test clocks are not included in the list results.

soft shoal
#

So if I have a GET request ( url: ${this.#baseURL}/v1/customers?email=${email}), would I add a query parameter for test clock?

charred mural
#

I'll need to double check that.

soft shoal
#

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?

charred mural
#

Can you share the ID of the request that you made to try to pause the Subscription? That should start with a req_ prefix.

soft shoal
#

req_oYNAXhld9Z4P2p

charred mural
soft shoal
#

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}

charred mural
#

What is in request? And what happens if you send that as form-encoded data instead of a JSON string?

soft shoal
#

const request = {
pause_collection: {
behavior: "void",
resumes_at: ${Number(nextBilledAt)},
},
}

charred mural
#

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.

soft shoal
#

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?

hard jackalBOT
charred mural
#

Since you're using fetch I also want to check, are you making these requests from your server-side code?

soft shoal
#

Yes

charred mural
#

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

soft shoal
#

We need the requests in TypeScript

soft shoal
#

I made those changes and I still do not see the request in the log

primal wharf
#

Hello! I'm taking over and catching up...

soft shoal
#

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}`)
    }
primal wharf
#

Can you give me the request ID of the request made as a result of that code?

soft shoal
#

How do you get that?

primal wharf
soft shoal
#

Is that something that should be in the json response?

primal wharf
#

It's in one of the HTTP headers in the response.

#

Or you can get it in the Stripe Dashboard.

soft shoal
#

What if my requests aren't appearing in the logs?

primal wharf
#

Make sure you adjust the filter so it shows GET requests.

soft shoal
#

But the request I'm doing is a POST

primal wharf
#

Can you get the HTTP headers from the response?

soft shoal
#

I can give you the json response. Is that what you want?

primal wharf
#

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.

soft shoal
#

Found it: req_v1O2ZPq75ckYcv

primal wharf
#

Thanks! So this is a GET request, and you're only supply an email as the argument. What are you trying to do here?

soft shoal
#

req_DxignAm1fo7ETH

primal wharf
soft shoal
#

I see, so if there's data in pause_collection then does that mean the request went through successfully?

primal wharf
#

Yes.

#

Those are the properties you passed in.

#

And the update was successful per the 200 HTTP status code.

soft shoal
#

Hooray! What if I wanted to test this with test clocks, is that possible?

primal wharf
#

Wait, let's back up. Does that first request do what you want? What was your intent with req_v1O2ZPq75ckYcv?

soft shoal
#

Yes, because query for customers by email first. When I find the match, then I use customer id when I query for subscriptions.

primal wharf
#

Gotcha, okay, sounds good.

soft shoal
#

Can it be tied to the test customer I have currently?

primal wharf
#

Yes.

soft shoal
#

It looks like you have to add the customer

#

a new customer

primal wharf
#

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.

soft shoal
#

Ok.

#

If I wanted to test with a test clock, can I do that locally with TypeScript?

primal wharf
#

Yes, I suppose so.

hard jackalBOT