github.com/stripe/stripe-go/v76@v76.25.0/ephemeralkey/client.go (about)

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package ephemeralkey provides the /ephemeral_keys APIs
     8  package ephemeralkey
     9  
    10  import (
    11  	"fmt"
    12  	"net/http"
    13  
    14  	stripe "github.com/stripe/stripe-go/v76"
    15  )
    16  
    17  // Client is used to invoke /ephemeral_keys APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // New creates a new ephemeral key.
    24  func New(params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
    25  	return getC().New(params)
    26  }
    27  
    28  // New creates a new ephemeral key.
    29  func (c Client) New(params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
    30  	if params.StripeVersion == nil || len(stripe.StringValue(params.StripeVersion)) == 0 {
    31  		return nil, fmt.Errorf("params.StripeVersion must be specified")
    32  	}
    33  
    34  	if params.Headers == nil {
    35  		params.Headers = make(http.Header)
    36  	}
    37  	params.Headers.Add("Stripe-Version", stripe.StringValue(params.StripeVersion))
    38  
    39  	ephemeralkey := &stripe.EphemeralKey{}
    40  	err := c.B.Call(
    41  		http.MethodPost,
    42  		"/v1/ephemeral_keys",
    43  		c.Key,
    44  		params,
    45  		ephemeralkey,
    46  	)
    47  	return ephemeralkey, err
    48  }
    49  
    50  // Del removes an ephemeral key.
    51  func Del(id string, params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
    52  	return getC().Del(id, params)
    53  }
    54  
    55  // Del removes an ephemeral key.
    56  func (c Client) Del(id string, params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
    57  	path := stripe.FormatURLPath("/v1/ephemeral_keys/%s", id)
    58  	ephemeralkey := &stripe.EphemeralKey{}
    59  	err := c.B.Call(http.MethodDelete, path, c.Key, params, ephemeralkey)
    60  	return ephemeralkey, err
    61  }
    62  
    63  func getC() Client {
    64  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
    65  }