forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ephemeralkey.go
50 lines (42 loc) · 1.58 KB
/
ephemeralkey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package stripe
import "encoding/json"
// EphemeralKeyParams is the set of parameters that can be used when creating
// an ephemeral key.
// For more details see https://stripe.com/docs/api#ephemeral_keys.
type EphemeralKeyParams struct {
Params `form:"*"`
Customer string `form:"customer"`
StripeVersion string `form:"-"` // This goes in the `Stripe-Version` header
}
// EphemeralKey is the resource representing a Stripe ephemeral key.
// For more details see https://stripe.com/docs/api#ephemeral_keys.
type EphemeralKey struct {
AssociatedObjects []struct {
ID string `json:"id"`
Type string `json:"type"`
} `json:"associated_objects"`
Created int64 `json:"created"`
Expires int64 `json:"expires"`
ID string `json:"id"`
Live bool `json:"livemode"`
// RawJSON is provided so that it may be passed back to the frontend
// unchanged. Ephemeral keys are issued on behalf of another client which
// may be running a different version of the bindings and thus expect a
// different JSON structure. This ensures that if the structure differs
// from the version of these bindings, we can still pass back a compatible
// key.
RawJSON []byte `json:"-"`
}
// UnmarshalJSON handles deserialization of an EphemeralKey.
// This custom unmarshaling is needed because we need to store the
// raw JSON on the object so it may be passed back to the frontend.
func (e *EphemeralKey) UnmarshalJSON(data []byte) error {
type ephemeralKey EphemeralKey
var ee ephemeralKey
err := json.Unmarshal(data, &ee)
if err == nil {
*e = EphemeralKey(ee)
}
e.RawJSON = data
return nil
}