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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package reader provides the /terminal/readers APIs
     8  package reader
     9  
    10  import (
    11  	"net/http"
    12  
    13  	stripe "github.com/stripe/stripe-go/v76"
    14  	"github.com/stripe/stripe-go/v76/form"
    15  )
    16  
    17  // Client is used to invoke /terminal/readers APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // New creates a new terminal reader.
    24  func New(params *stripe.TerminalReaderParams) (*stripe.TerminalReader, error) {
    25  	return getC().New(params)
    26  }
    27  
    28  // New creates a new terminal reader.
    29  func (c Client) New(params *stripe.TerminalReaderParams) (*stripe.TerminalReader, error) {
    30  	reader := &stripe.TerminalReader{}
    31  	err := c.B.Call(
    32  		http.MethodPost,
    33  		"/v1/terminal/readers",
    34  		c.Key,
    35  		params,
    36  		reader,
    37  	)
    38  	return reader, err
    39  }
    40  
    41  // Get returns the details of a terminal reader.
    42  func Get(id string, params *stripe.TerminalReaderParams) (*stripe.TerminalReader, error) {
    43  	return getC().Get(id, params)
    44  }
    45  
    46  // Get returns the details of a terminal reader.
    47  func (c Client) Get(id string, params *stripe.TerminalReaderParams) (*stripe.TerminalReader, error) {
    48  	path := stripe.FormatURLPath("/v1/terminal/readers/%s", id)
    49  	reader := &stripe.TerminalReader{}
    50  	err := c.B.Call(http.MethodGet, path, c.Key, params, reader)
    51  	return reader, err
    52  }
    53  
    54  // Update updates a terminal reader's properties.
    55  func Update(id string, params *stripe.TerminalReaderParams) (*stripe.TerminalReader, error) {
    56  	return getC().Update(id, params)
    57  }
    58  
    59  // Update updates a terminal reader's properties.
    60  func (c Client) Update(id string, params *stripe.TerminalReaderParams) (*stripe.TerminalReader, error) {
    61  	path := stripe.FormatURLPath("/v1/terminal/readers/%s", id)
    62  	reader := &stripe.TerminalReader{}
    63  	err := c.B.Call(http.MethodPost, path, c.Key, params, reader)
    64  	return reader, err
    65  }
    66  
    67  // Del removes a terminal reader.
    68  func Del(id string, params *stripe.TerminalReaderParams) (*stripe.TerminalReader, error) {
    69  	return getC().Del(id, params)
    70  }
    71  
    72  // Del removes a terminal reader.
    73  func (c Client) Del(id string, params *stripe.TerminalReaderParams) (*stripe.TerminalReader, error) {
    74  	path := stripe.FormatURLPath("/v1/terminal/readers/%s", id)
    75  	reader := &stripe.TerminalReader{}
    76  	err := c.B.Call(http.MethodDelete, path, c.Key, params, reader)
    77  	return reader, err
    78  }
    79  
    80  // CancelAction is the method for the `POST /v1/terminal/readers/{reader}/cancel_action` API.
    81  func CancelAction(id string, params *stripe.TerminalReaderCancelActionParams) (*stripe.TerminalReader, error) {
    82  	return getC().CancelAction(id, params)
    83  }
    84  
    85  // CancelAction is the method for the `POST /v1/terminal/readers/{reader}/cancel_action` API.
    86  func (c Client) CancelAction(id string, params *stripe.TerminalReaderCancelActionParams) (*stripe.TerminalReader, error) {
    87  	path := stripe.FormatURLPath("/v1/terminal/readers/%s/cancel_action", id)
    88  	reader := &stripe.TerminalReader{}
    89  	err := c.B.Call(http.MethodPost, path, c.Key, params, reader)
    90  	return reader, err
    91  }
    92  
    93  // ProcessPaymentIntent is the method for the `POST /v1/terminal/readers/{reader}/process_payment_intent` API.
    94  func ProcessPaymentIntent(id string, params *stripe.TerminalReaderProcessPaymentIntentParams) (*stripe.TerminalReader, error) {
    95  	return getC().ProcessPaymentIntent(id, params)
    96  }
    97  
    98  // ProcessPaymentIntent is the method for the `POST /v1/terminal/readers/{reader}/process_payment_intent` API.
    99  func (c Client) ProcessPaymentIntent(id string, params *stripe.TerminalReaderProcessPaymentIntentParams) (*stripe.TerminalReader, error) {
   100  	path := stripe.FormatURLPath(
   101  		"/v1/terminal/readers/%s/process_payment_intent",
   102  		id,
   103  	)
   104  	reader := &stripe.TerminalReader{}
   105  	err := c.B.Call(http.MethodPost, path, c.Key, params, reader)
   106  	return reader, err
   107  }
   108  
   109  // ProcessSetupIntent is the method for the `POST /v1/terminal/readers/{reader}/process_setup_intent` API.
   110  func ProcessSetupIntent(id string, params *stripe.TerminalReaderProcessSetupIntentParams) (*stripe.TerminalReader, error) {
   111  	return getC().ProcessSetupIntent(id, params)
   112  }
   113  
   114  // ProcessSetupIntent is the method for the `POST /v1/terminal/readers/{reader}/process_setup_intent` API.
   115  func (c Client) ProcessSetupIntent(id string, params *stripe.TerminalReaderProcessSetupIntentParams) (*stripe.TerminalReader, error) {
   116  	path := stripe.FormatURLPath(
   117  		"/v1/terminal/readers/%s/process_setup_intent",
   118  		id,
   119  	)
   120  	reader := &stripe.TerminalReader{}
   121  	err := c.B.Call(http.MethodPost, path, c.Key, params, reader)
   122  	return reader, err
   123  }
   124  
   125  // RefundPayment is the method for the `POST /v1/terminal/readers/{reader}/refund_payment` API.
   126  func RefundPayment(id string, params *stripe.TerminalReaderRefundPaymentParams) (*stripe.TerminalReader, error) {
   127  	return getC().RefundPayment(id, params)
   128  }
   129  
   130  // RefundPayment is the method for the `POST /v1/terminal/readers/{reader}/refund_payment` API.
   131  func (c Client) RefundPayment(id string, params *stripe.TerminalReaderRefundPaymentParams) (*stripe.TerminalReader, error) {
   132  	path := stripe.FormatURLPath("/v1/terminal/readers/%s/refund_payment", id)
   133  	reader := &stripe.TerminalReader{}
   134  	err := c.B.Call(http.MethodPost, path, c.Key, params, reader)
   135  	return reader, err
   136  }
   137  
   138  // SetReaderDisplay is the method for the `POST /v1/terminal/readers/{reader}/set_reader_display` API.
   139  func SetReaderDisplay(id string, params *stripe.TerminalReaderSetReaderDisplayParams) (*stripe.TerminalReader, error) {
   140  	return getC().SetReaderDisplay(id, params)
   141  }
   142  
   143  // SetReaderDisplay is the method for the `POST /v1/terminal/readers/{reader}/set_reader_display` API.
   144  func (c Client) SetReaderDisplay(id string, params *stripe.TerminalReaderSetReaderDisplayParams) (*stripe.TerminalReader, error) {
   145  	path := stripe.FormatURLPath("/v1/terminal/readers/%s/set_reader_display", id)
   146  	reader := &stripe.TerminalReader{}
   147  	err := c.B.Call(http.MethodPost, path, c.Key, params, reader)
   148  	return reader, err
   149  }
   150  
   151  // List returns a list of terminal readers.
   152  func List(params *stripe.TerminalReaderListParams) *Iter {
   153  	return getC().List(params)
   154  }
   155  
   156  // List returns a list of terminal readers.
   157  func (c Client) List(listParams *stripe.TerminalReaderListParams) *Iter {
   158  	return &Iter{
   159  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
   160  			list := &stripe.TerminalReaderList{}
   161  			err := c.B.CallRaw(http.MethodGet, "/v1/terminal/readers", c.Key, b, p, list)
   162  
   163  			ret := make([]interface{}, len(list.Data))
   164  			for i, v := range list.Data {
   165  				ret[i] = v
   166  			}
   167  
   168  			return ret, list, err
   169  		}),
   170  	}
   171  }
   172  
   173  // Iter is an iterator for terminal readers.
   174  type Iter struct {
   175  	*stripe.Iter
   176  }
   177  
   178  // TerminalReader returns the terminal reader which the iterator is currently pointing to.
   179  func (i *Iter) TerminalReader() *stripe.TerminalReader {
   180  	return i.Current().(*stripe.TerminalReader)
   181  }
   182  
   183  // TerminalReaderList returns the current list object which the iterator is
   184  // currently using. List objects will change as new API calls are made to
   185  // continue pagination.
   186  func (i *Iter) TerminalReaderList() *stripe.TerminalReaderList {
   187  	return i.List().(*stripe.TerminalReaderList)
   188  }
   189  
   190  func getC() Client {
   191  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
   192  }