#FireCoder-dotnet-subscription

1 messages ยท Page 1 of 1 (latest)

bold vesselBOT
winged estuary
#

You should be able to do that as long as the product names are within four levels of expansion. The expand parameter is an array of strings and you can pass as many parameters to expand as you want as long as none of them are further than four levels

#

Or are you already trying that and product names are deeper than that?

unreal iris
#

So customer would be 1 level deep. Then we have items.data.price.data.product

#

so, beyond 4 levels

#

Unless I'm not understanding

winged estuary
#

Have you already tried expanding with that?

unreal iris
#

But I also need to get the full customer object

#

Or can we do .AddExpand[] more than once?

winged estuary
#

So you can pass expand=["customer", items.data.price.product"]

#

Yes I think so

#

That is the java library right?

unreal iris
#

C#

#

Hmm, doesn't seem to be correct syntax

#

I am able to use .AddExpand more than once though. At least at the moment. I won't know for sure until I run the app.

#

Uff that didn't work.

winged estuary
#

Did you get an error?

unreal iris
#

Cannot convert from Stripe.SubscriptionListOptions to string

winged estuary
#

Can you paste your C# code for this call so I can take a look?

unreal iris
#

Would you like a snip or code?

winged estuary
#

Code, the text of the code will be best to look at

unreal iris
#

public async Task<List<SubscriptionModel>> GetSubscriptions()
{
var subscriptionOptions = new SubscriptionGetOptions()
{
Expand = { "customer", "items.data.price.product" }
};

        var service = new SubscriptionService();
        await service.GetAsync(subscriptionOptions);
    }
#

Yeah I know I should use SubscriptionListOptions, I changed and forgot to change back. Still same message though.

#

Ahh 1 sec. Maybe I need to use ListAsync

#

Ok, that cleared things up.

winged estuary
#

Oh nice! So you are getting all the info back that you want now?

unreal iris
#

I'm not sure just yet. I just know that the errors went away in VS. I'm working on the rest of the method and then I'll be able to test.

winged estuary
#

Sounds good, just let me know

unreal iris
#

Ok, so I'm unable to access Price or Product from x. I'll paste code.

#

return results.GetRange(0, results.Count() >= maxrecords ? maxrecords : results.Count())
.Select(x => new SubscriptionModel(x.Id)
{

                Id = _guidGenerator.Create(),
               SubscriptionId = x.Id,
               CustomerName = x.Customer.Name,
               Product = x.Items.Data.
            }).ToList();
winged estuary
#

Do you have the ID of a subscription that you got back from that call that you didn't see that data for?

unreal iris
#

Nope. This is strictly in code. I haven't even gotten that far due to not being able to assign values.

winged estuary
#

Oh gotcha. Misunderstood the question. I'm not that familiar with our .NET library, is SubscriptionModel a class from our stripe-dotnet library?

unreal iris
#

No. it's a custom model that I made.

#

However, all the other items are being assigned values unless they are contained within Items.Data

winged estuary
#

Oh I see, I mixed up some of the code here. So x should be a Subscription object then? Is VS recognizing it as just a generic object or does it know that it will be a Subscription here?

unreal iris
#

Ok, so I have to use an indexer to get Price and Product. Like data[0].Price etc. Hmm

#

Yes, x is a Subscription object and yes, VS is recognizing x as a Subscription object.

winged estuary
#

Gotcha, I see now, yes the Items property on a Subscription object is a list so you need to access the Product property on a specific item in the list.

unreal iris
#

Cool. Thanks again for your help and patience.

winged estuary
#

Of course, and I am actually stepping out right now but my colleague two-shoes will be able to help if you have any followups

unreal iris
#

Great, thanks again.

unreal iris
#

@cobalt hollow hello. Pompey stated I could contact you if I ran into further issues.

cobalt hollow
#

Hi ๐Ÿ‘‹ how can I assist?

unreal iris
#

I'm having some issues expanding subscriptions out. I'm trying to get the full customer, product and price.
I'd like to display: Customer.Name, Product.Name and Price.UnitPrice.

#

I'm hitting a null ref error no matter what I do. I"m probably not using correct syntax.

#

VS Studio

cobalt hollow
#

That's C# yeah?

unreal iris
#

Yes

cobalt hollow
#

Which object is null? It's hard to tell from the screenshot. Can you mouse over each of them?

unreal iris
#

sure

cobalt hollow
#

One of them is not being instantiated properly, I'm just not sure which one

unreal iris
#

If I remove Expand = {"customer"} I do get results back

#

initialPageOptions, when hovering over it says it's null. Which I'm not sure how that is...

cobalt hollow
#

interesting, okay. That's fine, it's probably null up until runtime.

Can you try this syntax in place of the line where you have Expand?
['expand' => ['customer']]

unreal iris
#

Expand = ["expand" => ["customer"]]

#

If that's what you meant, it does not like the syntax.

cobalt hollow
unreal iris
#

LOL. I didn't think that looked correct.

cobalt hollow
#

Yeah, it took me a second

#

Okay, so the example looks like this:

var service = new ChargeService();
var options = new ChargeGetOptions();
options.AddExpand("customer");
options.AddExpand("invoice.subscription");

var charge = service.Get("ch_1EOeV7ILwdSSnvJbIahCycKI", options);

#

But that's for charges

unreal iris
#

Yeah, but should be able to be modified for other stuff I'd imagine.

cobalt hollow
#

Yup, exactly. So let me peek at the library

#

I'll circle back in a couple of minutes

unreal iris
#

Ok

#

Expand = new List<string> { "data.customer" }

#

Since Expand is a List<string>. I got what I needed, I believe. Hopefully I can expand more.

cobalt hollow
#

That worked for you? Apologies. I got caught up between getting the standard example to work and trying to adapt it to what you already have

unreal iris
#

It's ok. Yes, that did work. Now I just need to get product name and price.

cobalt hollow
#

Well, if you got Customer already, then those shouldn't be too far off. They're nested under data.price and data.price.product on the Subscription object

unreal iris
#

so I don't need to use data.items.data.price....?

#

I should just be able to use data.price?

cobalt hollow
#

I'm not sure. I think in your code you already have subscription.data, since you were able to get data.customer right?

unreal iris
#

yes

cobalt hollow
#

So you have subscription.data.customer, then I think you're right. You just need to get subscription.data.items.data.price and subscription.data.items.data.price.product

unreal iris
#

But then that's more than 4 levels deep.

#

Uff

hallow tangle
#

Hi ๐Ÿ‘‹ I'm stepping in because @cobalt hollow needs to go.

unreal iris
#

Ok

hallow tangle
#

The price and product info is actually exactly at 4 levels deep (you don't include the subscription when passing in the Expand parameters

unreal iris
#

Right now I have data.items.data.price

hallow tangle
#

Yup, 4 levels

unreal iris
#

But the product name isn't in there, at least from what I can see.

#

I get the product id, but I need to display the product name.

hallow tangle
#

Yeah, that may require a 2nd API call

unreal iris
#

Hmm

#

Ok. That's what I was thinking. Thanks to you both for your help. I'll give this a try and let ya know.

hallow tangle
#

I hope it works out for you but we'll be here for any additional questions you might have.

unreal iris
#

thanks