github.com/stripe/stripe-go/v76@v76.25.0/ephemeralkey.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 package stripe 8 9 import "encoding/json" 10 11 // Invalidates a short-lived API key for a given resource. 12 type EphemeralKeyParams struct { 13 Params `form:"*"` 14 // The ID of the Customer you'd like to modify using the resulting ephemeral key. 15 Customer *string `form:"customer"` 16 // Specifies which fields in the response should be expanded. 17 Expand []*string `form:"expand"` 18 // The ID of the Issuing Card you'd like to access using the resulting ephemeral key. 19 IssuingCard *string `form:"issuing_card"` 20 // A single-use token, created by Stripe.js, used for creating ephemeral keys for Issuing Cards without exchanging sensitive information. 21 Nonce *string `form:"nonce"` 22 // The ID of the Identity VerificationSession you'd like to access using the resulting ephemeral key 23 VerificationSession *string `form:"verification_session"` 24 StripeVersion *string `form:"-"` // This goes in the `Stripe-Version` header 25 } 26 27 // AddExpand appends a new field to expand. 28 func (p *EphemeralKeyParams) AddExpand(f string) { 29 p.Expand = append(p.Expand, &f) 30 } 31 32 type EphemeralKey struct { 33 APIResource 34 // Time at which the object was created. Measured in seconds since the Unix epoch. 35 Created int64 `json:"created"` 36 // Time at which the key will expire. Measured in seconds since the Unix epoch. 37 Expires int64 `json:"expires"` 38 // Unique identifier for the object. 39 ID string `json:"id"` 40 // Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. 41 Livemode bool `json:"livemode"` 42 // String representing the object's type. Objects of the same type share the same value. 43 Object string `json:"object"` 44 // The key's secret. You can use this value to make authorized requests to the Stripe API. 45 Secret string `json:"secret"` 46 // RawJSON is provided so that it may be passed back to the frontend 47 // unchanged. Ephemeral keys are issued on behalf of another client which 48 // may be running a different version of the bindings and thus expect a 49 // different JSON structure. This ensures that if the structure differs 50 // from the version of these bindings, we can still pass back a compatible 51 // key. 52 RawJSON []byte `json:"-"` 53 } 54 55 // UnmarshalJSON handles deserialization of an EphemeralKey. 56 // This custom unmarshaling is needed because we need to store the 57 // raw JSON on the object so it may be passed back to the frontend. 58 59 func (e *EphemeralKey) UnmarshalJSON(data []byte) error { 60 type ephemeralKey EphemeralKey 61 var ee ephemeralKey 62 err := json.Unmarshal(data, &ee) 63 if err == nil { 64 *e = EphemeralKey(ee) 65 } 66 67 // Go does guarantee the longevity of `data`, so copy when assigning `RawJSON` 68 // See https://golang.org/pkg/encoding/json/#Unmarshaler 69 // and https://github.com/stripe/stripe-go/pull/1142 70 e.RawJSON = append(e.RawJSON[:0], data...) 71 72 return nil 73 }