Skip to content

Support bidirectional marshalling/unmarshalling #1198

Open
@nghtstr

Description

When I get a customer, and expand the sources; if the source is of type Source, it does not json.Marshal correctly. Here is some basic code demonstrating that the code should work as expected:

func (h *Handle) getStripeCustomer(user *netauth.User) *stripe.Customer {
	stripe.Key = h.Options.Stripe.Key
	custID := user.Detail.Stripe // Customer ID as stored in the DB

	params := &stripe.CustomerParams{}
	params.AddExpand("sources")
	params.AddExpand("sources.data")
	params.AddExpand("sources.data.source")
	c, _ := customer.Get(custID, params)
	out, _ := json.MarshalIndent(c, "", "  ")
	fmt.Printf("List: ", string(out))

	testSource := "src_1HXWUoDEks681qEQ2rMI3gWJ" // This is a Stripe test card
	s, _ := source.Get(
		testSource,
		nil,
	)
	fmt.Printf("%+v\n", c.Sources)
	for _, src := range c.Sources.Data {
		fmt.Printf("%+v\n", src.SourceObject)
	}
	out, _ = json.MarshalIndent(s, "", "  ")
	fmt.Printf("Source: ", string(out))

	return c
}

The array of customer.Sources.Data does give the appropriate SourceObject but it does not json.Marshal correctly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions