github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_calls_payments.go (about)

     1  /*
     2   * This code was generated by
     3   * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
     4   *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
     5   *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
     6   *
     7   * Twilio - Api
     8   * This is the public Twilio REST API.
     9   *
    10   * NOTE: This class is auto generated by OpenAPI Generator.
    11   * https://openapi-generator.tech
    12   * Do not edit the class manually.
    13   */
    14  
    15  package openapi
    16  
    17  import (
    18  	"encoding/json"
    19  	"fmt"
    20  	"net/url"
    21  	"strings"
    22  )
    23  
    24  // Optional parameters for the method 'CreatePayments'
    25  type CreatePaymentsParams struct {
    26  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will create the resource.
    27  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
    28  	// A unique token that will be used to ensure that multiple API calls with the same information do not result in multiple transactions. This should be a unique string value per API call and can be a randomly generated.
    29  	IdempotencyKey *string `json:"IdempotencyKey,omitempty"`
    30  	// Provide an absolute or relative URL to receive status updates regarding your Pay session. Read more about the [expected StatusCallback values](https://www.twilio.com/docs/voice/api/payment-resource#statuscallback)
    31  	StatusCallback *string `json:"StatusCallback,omitempty"`
    32  	//
    33  	BankAccountType *string `json:"BankAccountType,omitempty"`
    34  	// A positive decimal value less than 1,000,000 to charge against the credit card or bank account. Default currency can be overwritten with `currency` field. Leave blank or set to 0 to tokenize.
    35  	ChargeAmount *float32 `json:"ChargeAmount,omitempty"`
    36  	// The currency of the `charge_amount`, formatted as [ISO 4127](http://www.iso.org/iso/home/standards/currency_codes.htm) format. The default value is `USD` and all values allowed from the Pay Connector are accepted.
    37  	Currency *string `json:"Currency,omitempty"`
    38  	// The description can be used to provide more details regarding the transaction. This information is submitted along with the payment details to the Payment Connector which are then posted on the transactions.
    39  	Description *string `json:"Description,omitempty"`
    40  	// A list of inputs that should be accepted. Currently only `dtmf` is supported. All digits captured during a pay session are redacted from the logs.
    41  	Input *string `json:"Input,omitempty"`
    42  	// A positive integer that is used to validate the length of the `PostalCode` inputted by the user. User must enter this many digits.
    43  	MinPostalCodeLength *int `json:"MinPostalCodeLength,omitempty"`
    44  	// A single-level JSON object used to pass custom parameters to payment processors. (Required for ACH payments). The information that has to be included here depends on the <Pay> Connector. [Read more](https://www.twilio.com/console/voice/pay-connectors).
    45  	Parameter *interface{} `json:"Parameter,omitempty"`
    46  	// This is the unique name corresponding to the Pay Connector installed in the Twilio Add-ons. Learn more about [<Pay> Connectors](https://www.twilio.com/console/voice/pay-connectors). The default value is `Default`.
    47  	PaymentConnector *string `json:"PaymentConnector,omitempty"`
    48  	//
    49  	PaymentMethod *string `json:"PaymentMethod,omitempty"`
    50  	// Indicates whether the credit card postal code (zip code) is a required piece of payment information that must be provided by the caller. The default is `true`.
    51  	PostalCode *bool `json:"PostalCode,omitempty"`
    52  	// Indicates whether the credit card security code is a required piece of payment information that must be provided by the caller. The default is `true`.
    53  	SecurityCode *bool `json:"SecurityCode,omitempty"`
    54  	// The number of seconds that <Pay> should wait for the caller to press a digit between each subsequent digit, after the first one, before moving on to validate the digits captured. The default is `5`, maximum is `600`.
    55  	Timeout *int `json:"Timeout,omitempty"`
    56  	//
    57  	TokenType *string `json:"TokenType,omitempty"`
    58  	// Credit card types separated by space that Pay should accept. The default value is `visa mastercard amex`
    59  	ValidCardTypes *string `json:"ValidCardTypes,omitempty"`
    60  }
    61  
    62  func (params *CreatePaymentsParams) SetPathAccountSid(PathAccountSid string) *CreatePaymentsParams {
    63  	params.PathAccountSid = &PathAccountSid
    64  	return params
    65  }
    66  func (params *CreatePaymentsParams) SetIdempotencyKey(IdempotencyKey string) *CreatePaymentsParams {
    67  	params.IdempotencyKey = &IdempotencyKey
    68  	return params
    69  }
    70  func (params *CreatePaymentsParams) SetStatusCallback(StatusCallback string) *CreatePaymentsParams {
    71  	params.StatusCallback = &StatusCallback
    72  	return params
    73  }
    74  func (params *CreatePaymentsParams) SetBankAccountType(BankAccountType string) *CreatePaymentsParams {
    75  	params.BankAccountType = &BankAccountType
    76  	return params
    77  }
    78  func (params *CreatePaymentsParams) SetChargeAmount(ChargeAmount float32) *CreatePaymentsParams {
    79  	params.ChargeAmount = &ChargeAmount
    80  	return params
    81  }
    82  func (params *CreatePaymentsParams) SetCurrency(Currency string) *CreatePaymentsParams {
    83  	params.Currency = &Currency
    84  	return params
    85  }
    86  func (params *CreatePaymentsParams) SetDescription(Description string) *CreatePaymentsParams {
    87  	params.Description = &Description
    88  	return params
    89  }
    90  func (params *CreatePaymentsParams) SetInput(Input string) *CreatePaymentsParams {
    91  	params.Input = &Input
    92  	return params
    93  }
    94  func (params *CreatePaymentsParams) SetMinPostalCodeLength(MinPostalCodeLength int) *CreatePaymentsParams {
    95  	params.MinPostalCodeLength = &MinPostalCodeLength
    96  	return params
    97  }
    98  func (params *CreatePaymentsParams) SetParameter(Parameter interface{}) *CreatePaymentsParams {
    99  	params.Parameter = &Parameter
   100  	return params
   101  }
   102  func (params *CreatePaymentsParams) SetPaymentConnector(PaymentConnector string) *CreatePaymentsParams {
   103  	params.PaymentConnector = &PaymentConnector
   104  	return params
   105  }
   106  func (params *CreatePaymentsParams) SetPaymentMethod(PaymentMethod string) *CreatePaymentsParams {
   107  	params.PaymentMethod = &PaymentMethod
   108  	return params
   109  }
   110  func (params *CreatePaymentsParams) SetPostalCode(PostalCode bool) *CreatePaymentsParams {
   111  	params.PostalCode = &PostalCode
   112  	return params
   113  }
   114  func (params *CreatePaymentsParams) SetSecurityCode(SecurityCode bool) *CreatePaymentsParams {
   115  	params.SecurityCode = &SecurityCode
   116  	return params
   117  }
   118  func (params *CreatePaymentsParams) SetTimeout(Timeout int) *CreatePaymentsParams {
   119  	params.Timeout = &Timeout
   120  	return params
   121  }
   122  func (params *CreatePaymentsParams) SetTokenType(TokenType string) *CreatePaymentsParams {
   123  	params.TokenType = &TokenType
   124  	return params
   125  }
   126  func (params *CreatePaymentsParams) SetValidCardTypes(ValidCardTypes string) *CreatePaymentsParams {
   127  	params.ValidCardTypes = &ValidCardTypes
   128  	return params
   129  }
   130  
   131  // create an instance of payments. This will start a new payments session
   132  func (c *ApiService) CreatePayments(CallSid string, params *CreatePaymentsParams) (*ApiV2010Payments, error) {
   133  	path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments.json"
   134  	if params != nil && params.PathAccountSid != nil {
   135  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   136  	} else {
   137  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   138  	}
   139  	path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1)
   140  
   141  	data := url.Values{}
   142  	headers := make(map[string]interface{})
   143  
   144  	if params != nil && params.IdempotencyKey != nil {
   145  		data.Set("IdempotencyKey", *params.IdempotencyKey)
   146  	}
   147  	if params != nil && params.StatusCallback != nil {
   148  		data.Set("StatusCallback", *params.StatusCallback)
   149  	}
   150  	if params != nil && params.BankAccountType != nil {
   151  		data.Set("BankAccountType", *params.BankAccountType)
   152  	}
   153  	if params != nil && params.ChargeAmount != nil {
   154  		data.Set("ChargeAmount", fmt.Sprint(*params.ChargeAmount))
   155  	}
   156  	if params != nil && params.Currency != nil {
   157  		data.Set("Currency", *params.Currency)
   158  	}
   159  	if params != nil && params.Description != nil {
   160  		data.Set("Description", *params.Description)
   161  	}
   162  	if params != nil && params.Input != nil {
   163  		data.Set("Input", *params.Input)
   164  	}
   165  	if params != nil && params.MinPostalCodeLength != nil {
   166  		data.Set("MinPostalCodeLength", fmt.Sprint(*params.MinPostalCodeLength))
   167  	}
   168  	if params != nil && params.Parameter != nil {
   169  		v, err := json.Marshal(params.Parameter)
   170  
   171  		if err != nil {
   172  			return nil, err
   173  		}
   174  
   175  		data.Set("Parameter", string(v))
   176  	}
   177  	if params != nil && params.PaymentConnector != nil {
   178  		data.Set("PaymentConnector", *params.PaymentConnector)
   179  	}
   180  	if params != nil && params.PaymentMethod != nil {
   181  		data.Set("PaymentMethod", *params.PaymentMethod)
   182  	}
   183  	if params != nil && params.PostalCode != nil {
   184  		data.Set("PostalCode", fmt.Sprint(*params.PostalCode))
   185  	}
   186  	if params != nil && params.SecurityCode != nil {
   187  		data.Set("SecurityCode", fmt.Sprint(*params.SecurityCode))
   188  	}
   189  	if params != nil && params.Timeout != nil {
   190  		data.Set("Timeout", fmt.Sprint(*params.Timeout))
   191  	}
   192  	if params != nil && params.TokenType != nil {
   193  		data.Set("TokenType", *params.TokenType)
   194  	}
   195  	if params != nil && params.ValidCardTypes != nil {
   196  		data.Set("ValidCardTypes", *params.ValidCardTypes)
   197  	}
   198  
   199  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
   200  	if err != nil {
   201  		return nil, err
   202  	}
   203  
   204  	defer resp.Body.Close()
   205  
   206  	ps := &ApiV2010Payments{}
   207  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   208  		return nil, err
   209  	}
   210  
   211  	return ps, err
   212  }
   213  
   214  // Optional parameters for the method 'UpdatePayments'
   215  type UpdatePaymentsParams struct {
   216  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will update the resource.
   217  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
   218  	// A unique token that will be used to ensure that multiple API calls with the same information do not result in multiple transactions. This should be a unique string value per API call and can be a randomly generated.
   219  	IdempotencyKey *string `json:"IdempotencyKey,omitempty"`
   220  	// Provide an absolute or relative URL to receive status updates regarding your Pay session. Read more about the [Update](https://www.twilio.com/docs/voice/api/payment-resource#statuscallback-update) and [Complete/Cancel](https://www.twilio.com/docs/voice/api/payment-resource#statuscallback-cancelcomplete) POST requests.
   221  	StatusCallback *string `json:"StatusCallback,omitempty"`
   222  	//
   223  	Capture *string `json:"Capture,omitempty"`
   224  	//
   225  	Status *string `json:"Status,omitempty"`
   226  }
   227  
   228  func (params *UpdatePaymentsParams) SetPathAccountSid(PathAccountSid string) *UpdatePaymentsParams {
   229  	params.PathAccountSid = &PathAccountSid
   230  	return params
   231  }
   232  func (params *UpdatePaymentsParams) SetIdempotencyKey(IdempotencyKey string) *UpdatePaymentsParams {
   233  	params.IdempotencyKey = &IdempotencyKey
   234  	return params
   235  }
   236  func (params *UpdatePaymentsParams) SetStatusCallback(StatusCallback string) *UpdatePaymentsParams {
   237  	params.StatusCallback = &StatusCallback
   238  	return params
   239  }
   240  func (params *UpdatePaymentsParams) SetCapture(Capture string) *UpdatePaymentsParams {
   241  	params.Capture = &Capture
   242  	return params
   243  }
   244  func (params *UpdatePaymentsParams) SetStatus(Status string) *UpdatePaymentsParams {
   245  	params.Status = &Status
   246  	return params
   247  }
   248  
   249  // update an instance of payments with different phases of payment flows.
   250  func (c *ApiService) UpdatePayments(CallSid string, Sid string, params *UpdatePaymentsParams) (*ApiV2010Payments, error) {
   251  	path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments/{Sid}.json"
   252  	if params != nil && params.PathAccountSid != nil {
   253  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   254  	} else {
   255  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   256  	}
   257  	path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1)
   258  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
   259  
   260  	data := url.Values{}
   261  	headers := make(map[string]interface{})
   262  
   263  	if params != nil && params.IdempotencyKey != nil {
   264  		data.Set("IdempotencyKey", *params.IdempotencyKey)
   265  	}
   266  	if params != nil && params.StatusCallback != nil {
   267  		data.Set("StatusCallback", *params.StatusCallback)
   268  	}
   269  	if params != nil && params.Capture != nil {
   270  		data.Set("Capture", *params.Capture)
   271  	}
   272  	if params != nil && params.Status != nil {
   273  		data.Set("Status", *params.Status)
   274  	}
   275  
   276  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
   277  	if err != nil {
   278  		return nil, err
   279  	}
   280  
   281  	defer resp.Body.Close()
   282  
   283  	ps := &ApiV2010Payments{}
   284  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   285  		return nil, err
   286  	}
   287  
   288  	return ps, err
   289  }