#x001w - subscriptions

1 messages ยท Page 1 of 1 (latest)

undone kiln
#

Hi there!

turbid hatch
#

hi friend, pls

undone kiln
#

Are you trying to set items.metadata for a subscription? If so, what is the issue?

turbid hatch
#

I had tried to create a sub

#

but the Items.metadata didn't set

#

according my above code

undone kiln
turbid hatch
#

req_FLewZbOizqeQJa

undone kiln
#

It looks like that request worked, and I do see the metadata on the items. Why do you think it's not working?

turbid hatch
#

because it doesn't have metadata

#

so it didn't work.

undone kiln
turbid hatch
turbid hatch
#

sent

#

the code about the Items, I give two params, one is sub_id another is Metadata

#

the code can create the sub, but it seem wrong that doesn't create the Metadata at the same time

#

maybe you should check the event

#

"evt_1LEx4TD5BdSHt7NMylAD4MEh"

#

the webhook back didn't attach the metadata

undone kiln
#

Where do you want to create the metadata? On the subscription? On the subscription.item? On the invoice?
Each of these is different.

turbid hatch
#

I want to create the sub with the metadata at the same time.

undone kiln
#

Then it should be something like this:

var options = new SubscriptionCreateOptions
{
  Customer = "cus_xxx",
  Items = new List<SubscriptionItemOptions>
  {
    new SubscriptionItemOptions
    {
      Price = "price_xxx",
    },
  },
  Metadata: # add the metadata here, directly on the subscription object
};
turbid hatch
#

metadata object is in Items, it's no problem.

undone kiln
#

I'm sorry I'm a bit lost.
The code you shared at the very beginning is correct and works, I can see the metadata stored in the subscription.item on your account.
Earlier you said you want the metadata directly on the subscription object, so I showed you how to do that.
And now you want it in subscription.item?

turbid hatch
#

it did't store in the subscription.item. Didn't work. I want to know why?

#

pls check the req_FLewZbOizqeQJa and event evt_1LEx4TD5BdSHt7NMylAD4MEh

#

or you should try the way I have done subscription with the metadata created

undone kiln
#

it did't store in the subscription.item. Didn't work. I want to know why?
Why do you say it didn't work? Is it because you don't see it in the invoice.paid event?

turbid hatch
#

more than that invoice.paid event and the picture didn't have

turbid hatch
#

it's normal like this picture.

#

so I'm very confused

undone kiln
#

The invoice.paid event doesn't have subscription.item in it, so it's expected to not see the metadata. If you want to see it here, you could:

  • add the metadata directly to the price ID
  • or add the metadata to the subscription itself, and when you receive the event invoice.paid retrieve the subscription associated with the invoice.
turbid hatch
#

you mean I should do that for two steps? one step is just create the sub, or the another step is attach metadata associated the sub_id?

undone kiln
#

No I didn't say that.

#

so I'm very confused
Is this a screenshot of the subscription in the dashboard? If so, you need to add the metadata directly to the subscription (as I showed you earlier) to see the metadata there.

turbid hatch
#

If you're not quite sure why, I can show the problem again. I think this is a bug. Or your documentation doesn't write clearly about some situations, which makes it impossible to create Metadata when creating subscriptions at the same time.

undone kiln
#

Can you try my suggestion:

var options = new SubscriptionCreateOptions
{
  Customer = "cus_xxx",
  Items = new List<SubscriptionItemOptions>
  {
    new SubscriptionItemOptions
    {
      Price = "price_xxx",
    },
  },
  Metadata: # add the metadata here, directly on the subscription object
};

This will add metadata directly to the subscription, and you will be able to see it in the dashboard.
And when you get invoice.paid event, find the subscription ID in the invoice.subscription property, then retrieve the subscription object, and you will see the metadata.

#

Would that solve your issue? If not, please let me know exactly what is the issue.

turbid hatch
#

you code dosen't include DefaultPaymentMethod

#

that's important

undone kiln
#

Yes this is just an example, feel free to add DefaultPaymentMethod or anything else

#

Just make sure to keep the Metadata directly on the subscription object (and not on the item object)

turbid hatch
#

is it Ok? my code

undone kiln
#

Your code looks okay, but you didn't change the metadata. You need to move it from the items and put it on the subscription directly (see my example above)

#

Can you copy-paste your code directly here? I'll show you.

turbid hatch
#

params := &stripe.SubscriptionParams{
Customer: stripe.String("cus_xxx"),
DefaultPaymentMethod: stripe.String("pm_xxx"),
Items: []*stripe.SubscriptionItemsParams{
{
Price: stripe.String("price_xxx"),
Metadata: map[string]string{
"subscriber": "whmtest",
"streamer": "philgodlewski",
"period": "monthly",
},
},
},
TrialEnd: stripe.Int64(1657505820),
BillingCycleAnchor: stripe.Int64(1657505820),
}

#

it's golang code

undone kiln
#

Can you try something like this? This will add the metadata directly to the subscription:

params := &stripe.SubscriptionParams{
        Customer:             stripe.String("cus_xxx"),
        DefaultPaymentMethod: stripe.String("pm_xxx"),
        Items: []*stripe.SubscriptionItemsParams{
            {
                Price: stripe.String("price_xxx"),
            },
        },
        TrialEnd:           stripe.Int64(1657505820),
        BillingCycleAnchor: stripe.Int64(1657505820),
        Metadata: map[string]string{
            "subscriber": "whmtest",
            "streamer":   "philgodlewski",
            "period":     "monthly",
        },
    }
turbid hatch
#

sorry it's wrong

#

metadata must in Items

#

SubscriptionParams dosen't have the Metadata object

#

SubscriptionParams just has the Items

wintry junco
#

๐Ÿ‘‹ , I'm stepping in for my colleague @undone kiln

turbid hatch
#

Hi, pls help me to solve the problem.

wintry junco
#

a couple of things

#

2- as my colleague explained, you are putting the metadata in the Items Object instead of the Subscription

#

so you need to move it from the SubscriptionItemParams to the SubscriptionParams object itself

turbid hatch
turbid hatch
#

the SubscriptionParams didn't have the Metadata Object

wintry junco
#

what version of the Stripe golang library are you using?

turbid hatch
wintry junco
#

In go you can't add Metadata in this way

#

instead use this params.AddMetadata("order_id", "6735")

#

on your SubscriptionParams object