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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package paymentintent provides the /payment_intents APIs
     8  package paymentintent
     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 /payment_intents APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // New creates a new payment intent.
    24  func New(params *stripe.PaymentIntentParams) (*stripe.PaymentIntent, error) {
    25  	return getC().New(params)
    26  }
    27  
    28  // New creates a new payment intent.
    29  func (c Client) New(params *stripe.PaymentIntentParams) (*stripe.PaymentIntent, error) {
    30  	paymentintent := &stripe.PaymentIntent{}
    31  	err := c.B.Call(
    32  		http.MethodPost,
    33  		"/v1/payment_intents",
    34  		c.Key,
    35  		params,
    36  		paymentintent,
    37  	)
    38  	return paymentintent, err
    39  }
    40  
    41  // Get returns the details of a payment intent.
    42  func Get(id string, params *stripe.PaymentIntentParams) (*stripe.PaymentIntent, error) {
    43  	return getC().Get(id, params)
    44  }
    45  
    46  // Get returns the details of a payment intent.
    47  func (c Client) Get(id string, params *stripe.PaymentIntentParams) (*stripe.PaymentIntent, error) {
    48  	path := stripe.FormatURLPath("/v1/payment_intents/%s", id)
    49  	paymentintent := &stripe.PaymentIntent{}
    50  	err := c.B.Call(http.MethodGet, path, c.Key, params, paymentintent)
    51  	return paymentintent, err
    52  }
    53  
    54  // Update updates a payment intent's properties.
    55  func Update(id string, params *stripe.PaymentIntentParams) (*stripe.PaymentIntent, error) {
    56  	return getC().Update(id, params)
    57  }
    58  
    59  // Update updates a payment intent's properties.
    60  func (c Client) Update(id string, params *stripe.PaymentIntentParams) (*stripe.PaymentIntent, error) {
    61  	path := stripe.FormatURLPath("/v1/payment_intents/%s", id)
    62  	paymentintent := &stripe.PaymentIntent{}
    63  	err := c.B.Call(http.MethodPost, path, c.Key, params, paymentintent)
    64  	return paymentintent, err
    65  }
    66  
    67  // ApplyCustomerBalance is the method for the `POST /v1/payment_intents/{intent}/apply_customer_balance` API.
    68  func ApplyCustomerBalance(id string, params *stripe.PaymentIntentApplyCustomerBalanceParams) (*stripe.PaymentIntent, error) {
    69  	return getC().ApplyCustomerBalance(id, params)
    70  }
    71  
    72  // ApplyCustomerBalance is the method for the `POST /v1/payment_intents/{intent}/apply_customer_balance` API.
    73  func (c Client) ApplyCustomerBalance(id string, params *stripe.PaymentIntentApplyCustomerBalanceParams) (*stripe.PaymentIntent, error) {
    74  	path := stripe.FormatURLPath(
    75  		"/v1/payment_intents/%s/apply_customer_balance",
    76  		id,
    77  	)
    78  	paymentintent := &stripe.PaymentIntent{}
    79  	err := c.B.Call(http.MethodPost, path, c.Key, params, paymentintent)
    80  	return paymentintent, err
    81  }
    82  
    83  // Cancel is the method for the `POST /v1/payment_intents/{intent}/cancel` API.
    84  func Cancel(id string, params *stripe.PaymentIntentCancelParams) (*stripe.PaymentIntent, error) {
    85  	return getC().Cancel(id, params)
    86  }
    87  
    88  // Cancel is the method for the `POST /v1/payment_intents/{intent}/cancel` API.
    89  func (c Client) Cancel(id string, params *stripe.PaymentIntentCancelParams) (*stripe.PaymentIntent, error) {
    90  	path := stripe.FormatURLPath("/v1/payment_intents/%s/cancel", id)
    91  	paymentintent := &stripe.PaymentIntent{}
    92  	err := c.B.Call(http.MethodPost, path, c.Key, params, paymentintent)
    93  	return paymentintent, err
    94  }
    95  
    96  // Capture is the method for the `POST /v1/payment_intents/{intent}/capture` API.
    97  func Capture(id string, params *stripe.PaymentIntentCaptureParams) (*stripe.PaymentIntent, error) {
    98  	return getC().Capture(id, params)
    99  }
   100  
   101  // Capture is the method for the `POST /v1/payment_intents/{intent}/capture` API.
   102  func (c Client) Capture(id string, params *stripe.PaymentIntentCaptureParams) (*stripe.PaymentIntent, error) {
   103  	path := stripe.FormatURLPath("/v1/payment_intents/%s/capture", id)
   104  	paymentintent := &stripe.PaymentIntent{}
   105  	err := c.B.Call(http.MethodPost, path, c.Key, params, paymentintent)
   106  	return paymentintent, err
   107  }
   108  
   109  // Confirm is the method for the `POST /v1/payment_intents/{intent}/confirm` API.
   110  func Confirm(id string, params *stripe.PaymentIntentConfirmParams) (*stripe.PaymentIntent, error) {
   111  	return getC().Confirm(id, params)
   112  }
   113  
   114  // Confirm is the method for the `POST /v1/payment_intents/{intent}/confirm` API.
   115  func (c Client) Confirm(id string, params *stripe.PaymentIntentConfirmParams) (*stripe.PaymentIntent, error) {
   116  	path := stripe.FormatURLPath("/v1/payment_intents/%s/confirm", id)
   117  	paymentintent := &stripe.PaymentIntent{}
   118  	err := c.B.Call(http.MethodPost, path, c.Key, params, paymentintent)
   119  	return paymentintent, err
   120  }
   121  
   122  // IncrementAuthorization is the method for the `POST /v1/payment_intents/{intent}/increment_authorization` API.
   123  func IncrementAuthorization(id string, params *stripe.PaymentIntentIncrementAuthorizationParams) (*stripe.PaymentIntent, error) {
   124  	return getC().IncrementAuthorization(id, params)
   125  }
   126  
   127  // IncrementAuthorization is the method for the `POST /v1/payment_intents/{intent}/increment_authorization` API.
   128  func (c Client) IncrementAuthorization(id string, params *stripe.PaymentIntentIncrementAuthorizationParams) (*stripe.PaymentIntent, error) {
   129  	path := stripe.FormatURLPath(
   130  		"/v1/payment_intents/%s/increment_authorization",
   131  		id,
   132  	)
   133  	paymentintent := &stripe.PaymentIntent{}
   134  	err := c.B.Call(http.MethodPost, path, c.Key, params, paymentintent)
   135  	return paymentintent, err
   136  }
   137  
   138  // VerifyMicrodeposits is the method for the `POST /v1/payment_intents/{intent}/verify_microdeposits` API.
   139  func VerifyMicrodeposits(id string, params *stripe.PaymentIntentVerifyMicrodepositsParams) (*stripe.PaymentIntent, error) {
   140  	return getC().VerifyMicrodeposits(id, params)
   141  }
   142  
   143  // VerifyMicrodeposits is the method for the `POST /v1/payment_intents/{intent}/verify_microdeposits` API.
   144  func (c Client) VerifyMicrodeposits(id string, params *stripe.PaymentIntentVerifyMicrodepositsParams) (*stripe.PaymentIntent, error) {
   145  	path := stripe.FormatURLPath(
   146  		"/v1/payment_intents/%s/verify_microdeposits",
   147  		id,
   148  	)
   149  	paymentintent := &stripe.PaymentIntent{}
   150  	err := c.B.Call(http.MethodPost, path, c.Key, params, paymentintent)
   151  	return paymentintent, err
   152  }
   153  
   154  // List returns a list of payment intents.
   155  func List(params *stripe.PaymentIntentListParams) *Iter {
   156  	return getC().List(params)
   157  }
   158  
   159  // List returns a list of payment intents.
   160  func (c Client) List(listParams *stripe.PaymentIntentListParams) *Iter {
   161  	return &Iter{
   162  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
   163  			list := &stripe.PaymentIntentList{}
   164  			err := c.B.CallRaw(http.MethodGet, "/v1/payment_intents", c.Key, b, p, list)
   165  
   166  			ret := make([]interface{}, len(list.Data))
   167  			for i, v := range list.Data {
   168  				ret[i] = v
   169  			}
   170  
   171  			return ret, list, err
   172  		}),
   173  	}
   174  }
   175  
   176  // Iter is an iterator for payment intents.
   177  type Iter struct {
   178  	*stripe.Iter
   179  }
   180  
   181  // PaymentIntent returns the payment intent which the iterator is currently pointing to.
   182  func (i *Iter) PaymentIntent() *stripe.PaymentIntent {
   183  	return i.Current().(*stripe.PaymentIntent)
   184  }
   185  
   186  // PaymentIntentList returns the current list object which the iterator is
   187  // currently using. List objects will change as new API calls are made to
   188  // continue pagination.
   189  func (i *Iter) PaymentIntentList() *stripe.PaymentIntentList {
   190  	return i.List().(*stripe.PaymentIntentList)
   191  }
   192  
   193  // Search returns a search result containing payment intents.
   194  func Search(params *stripe.PaymentIntentSearchParams) *SearchIter {
   195  	return getC().Search(params)
   196  }
   197  
   198  // Search returns a search result containing payment intents.
   199  func (c Client) Search(params *stripe.PaymentIntentSearchParams) *SearchIter {
   200  	return &SearchIter{
   201  		SearchIter: stripe.GetSearchIter(params, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.SearchContainer, error) {
   202  			list := &stripe.PaymentIntentSearchResult{}
   203  			err := c.B.CallRaw(http.MethodGet, "/v1/payment_intents/search", c.Key, b, p, list)
   204  
   205  			ret := make([]interface{}, len(list.Data))
   206  			for i, v := range list.Data {
   207  				ret[i] = v
   208  			}
   209  
   210  			return ret, list, err
   211  		}),
   212  	}
   213  }
   214  
   215  // SearchIter is an iterator for payment intents.
   216  type SearchIter struct {
   217  	*stripe.SearchIter
   218  }
   219  
   220  // PaymentIntent returns the payment intent which the iterator is currently pointing to.
   221  func (i *SearchIter) PaymentIntent() *stripe.PaymentIntent {
   222  	return i.Current().(*stripe.PaymentIntent)
   223  }
   224  
   225  // PaymentIntentSearchResult returns the current list object which the iterator is
   226  // currently using. List objects will change as new API calls are made to
   227  // continue pagination.
   228  func (i *SearchIter) PaymentIntentSearchResult() *stripe.PaymentIntentSearchResult {
   229  	return i.SearchResult().(*stripe.PaymentIntentSearchResult)
   230  }
   231  
   232  func getC() Client {
   233  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
   234  }