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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package token provides the /tokens APIs
     8  package token
     9  
    10  import (
    11  	"net/http"
    12  
    13  	stripe "github.com/stripe/stripe-go/v76"
    14  )
    15  
    16  // Client is used to invoke /tokens APIs.
    17  type Client struct {
    18  	B   stripe.Backend
    19  	Key string
    20  }
    21  
    22  // New creates a new token.
    23  func New(params *stripe.TokenParams) (*stripe.Token, error) {
    24  	return getC().New(params)
    25  }
    26  
    27  // New creates a new token.
    28  func (c Client) New(params *stripe.TokenParams) (*stripe.Token, error) {
    29  	token := &stripe.Token{}
    30  	err := c.B.Call(http.MethodPost, "/v1/tokens", c.Key, params, token)
    31  	return token, err
    32  }
    33  
    34  // Get returns the details of a token.
    35  func Get(id string, params *stripe.TokenParams) (*stripe.Token, error) {
    36  	return getC().Get(id, params)
    37  }
    38  
    39  // Get returns the details of a token.
    40  func (c Client) Get(id string, params *stripe.TokenParams) (*stripe.Token, error) {
    41  	path := stripe.FormatURLPath("/v1/tokens/%s", id)
    42  	token := &stripe.Token{}
    43  	err := c.B.Call(http.MethodGet, path, c.Key, params, token)
    44  	return token, err
    45  }
    46  
    47  func getC() Client {
    48  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
    49  }