Skip to content

Instantly share code, notes, and snippets.

@shrutiburman
Created January 30, 2023 09:41
Show Gist options
  • Save shrutiburman/9ecec38d6424fc0068d44ed457e43eb0 to your computer and use it in GitHub Desktop.
Save shrutiburman/9ecec38d6424fc0068d44ed457e43eb0 to your computer and use it in GitHub Desktop.
rest/api/v2010/account/call/payment.rb [preview] & /rest/api/v2010/account/incoming_phone_number/assigned_add_on.rb [beta]
##
# This code was generated by
# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
#
# Twilio - Api
# This is the public Twilio REST API.
#
# NOTE: This class is auto generated by OpenAPI Generator.
# https://openapi-generator.tech
# Do not edit the class manually.
#
module Twilio
module REST
class Api < Domain
class V2010 < Version
class AssignedAddOnList < ListResource
##
# Initialize the AssignedAddOnList
# @param [Version] version Version that contains the resource
# @return [AssignedAddOnList] AssignedAddOnList
def initialize(version, account_sid, resource_sid)
super(version)
# Path Solution
@solution = { account_sid: account_sid,resource_sid: resource_sid, }
@uri = "/Accounts/#{@solution[:account_sid]}/IncomingPhoneNumbers/#{@solution[:resource_sid]}/AssignedAddOns.json"
end
##
# Create the AssignedAddOnInstance
# @param [String] installed_add_on_sid The SID that identifies the Add-on installation.
# @return [AssignedAddOnInstance] Created AssignedAddOnInstance
def create(installed_add_on_sid: nil
)
data = Twilio::Values.of(
'InstalledAddOnSid' => installed_add_on_sid,
})
payload = @version.create('POST', @uri, data: data)
AssignedAddOnInstance.new(@version, payload, account_sid: @solution[:account_sid], resource_sid: @solution[:resource_sid],)
end
##
# Lists AssignedAddOnInstance records from the API as a list.
# Unlike stream(), this operation is eager and will load `limit` records into
# memory before returning.
# @param [Integer] limit Upper limit for the number of records to return. stream()
# guarantees to never return more than limit. Default is no limit
# @param [Integer] page_size Number of records to fetch per request, when
# not set will use the default value of 50 records. If no page_size is defined
# but a limit is defined, stream() will attempt to read the limit with the most
# efficient page size, i.e. min(limit, 1000)
# @return [Array] Array of up to limit results
def list( limit: nil, page_size: nil)
self.stream(
limit: limit,
page_size: page_size
).entries
end
##
# Streams Instance records from the API as an Enumerable.
# This operation lazily loads records as efficiently as possible until the limit
# is reached.
# @param [Integer] limit Upper limit for the number of records to return. stream()
# guarantees to never return more than limit. Default is no limit
# @param [Integer] page_size Number of records to fetch per request, when
# not set will use the default value of 50 records. If no page_size is defined
# but a limit is defined, stream() will attempt to read the limit with the most
# efficient page size, i.e. min(limit, 1000)
# @return [Enumerable] Enumerable that will yield up to limit results
def stream( limit: nil, page_size: nil)
limits = @version.read_limits(limit, page_size)
page = self.page(
page_size: limits[:page_size], )
@version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
end
##
# When passed a block, yields AssignedAddOnInstance records from the API.
# This operation lazily loads records as efficiently as possible until the limit
# is reached.
def each
limits = @version.read_limits
page = self.page(page_size: limits[:page_size], )
@version.stream(page,
limit: limits[:limit],
page_limit: limits[:page_limit]).each {|x| yield x}
end
##
# Retrieve a single page of AssignedAddOnInstance records from the API.
# Request is executed immediately.
# @param [String] page_token PageToken provided by the API
# @param [Integer] page_number Page Number, this value is simply for client state
# @param [Integer] page_size Number of records to return, defaults to 50
# @return [Page] Page of AssignedAddOnInstance
def page( page_token: :unset, page_number: :unset, page_size: :unset)
params = Twilio::Values.of({
'PageToken' => page_token,
'Page' => page_number,
'PageSize' => page_size,
})
response = @version.page('GET', @uri, params: params)
AssignedAddOnPage.new(@version, response, @solution)
end
##
# Retrieve a single page of AssignedAddOnInstance records from the API.
# Request is executed immediately.
# @param [String] target_url API-generated URL for the requested results page
# @return [Page] Page of AssignedAddOnInstance
def get_page(target_url)
response = @version.domain.request(
'GET',
target_url
)
AssignedAddOnPage.new(@version, response, @solution)
end
##
# Provide a user friendly representation
def to_s
'#<Twilio.Api.V2010.AssignedAddOnList>'
end
end
##
#PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
class AssignedAddOnContext < InstanceContext
##
# Initialize the AssignedAddOnContext
# @param [Version] version Version that contains the resource
# @param [String] account_sid The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the resource to fetch.
# @param [String] resource_sid The SID of the Phone Number to which the Add-on is assigned.
# @param [String] sid The Twilio-provided string that uniquely identifies the resource to fetch.
# @return [AssignedAddOnContext] AssignedAddOnContext
def initialize(version, account_sid, resource_sid, sid)
super(version)
# Path Solution
@solution = { account_sid: account_sid, resource_sid: resource_sid, sid: sid, }
@uri = "/Accounts/#{@solution[:account_sid]}/IncomingPhoneNumbers/#{@solution[:resource_sid]}/AssignedAddOns/#{@solution[:sid]}.json"
# Dependents
@extensions = nil
end
##
# Delete the AssignedAddOnInstance
# @return [Boolean] True if delete succeeds, false otherwise
def delete
@version.delete('DELETE', @uri, )
end
##
# Fetch the AssignedAddOnInstance
# @return [AssignedAddOnInstance]
Fetched AssignedAddOnInstance
def fetch
payload = @version.fetch('GET',@uri )
AssignedAddOnInstance.new(@version, payload, account_sid: @solution[:account_sid], resource_sid: @solution[:resource_sid],)
end
##
# Access the extensions
# @return [ExtensionsList]
# @return [Assigned_add_on_extensionContext] if sid was passed.
def extensions(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return ExtensionsContext.new(@version, @solution[:account_sid], @solution[:resource_sid],sid )
end
unless @extensions
@extensions = Assigned_add_on_extensionList.new(
@version,
account_sid: @solution[:account_sid],,
resource_sid: @solution[:resource_sid],
)
end
@extensions
end
##
# Provide a user friendly representation
def to_s
context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
"#<Twilio.Api.V2010.AssignedAddOnContext #{context}>"
end
##
# Provide a detailed, user friendly representation
def inspect
context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
"#<Twilio.Api.V2010.AssignedAddOnContext #{context}>"
end
end
class AssignedAddOnPage < Page
##
# Initialize the AssignedAddOnPage
# @param [Version] version Version that contains the resource
# @param [Response] response Response from the API
# @param [Hash] solution Path solution for the resource
# @return [AssignedAddOnPage] AssignedAddOnPage
def initialize(version, response, solution)
super(version, response)
# Path Solution
@solution = solution
end
##
# Build an instance of AssignedAddOnInstance
# @param [Hash] payload Payload response from the API
# @return [AssignedAddOnInstance] AssignedAddOnInstance
def get_instance(payload)
AssignedAddOnInstance.new(@version, payload, account_sid: @solution[:account_sid], resource_sid: @solution[:resource_sid])
end
##
# Provide a user friendly representation
def to_s
'<Twilio.Api.V2010.AssignedAddOnPage>'
end
end
end
end
end
end
##
# This code was generated by
# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
#
# Twilio - Api
# This is the public Twilio REST API.
#
# NOTE: This class is auto generated by OpenAPI Generator.
# https://openapi-generator.tech
# Do not edit the class manually.
#
module Twilio
module REST
class Api < Domain
class V2010 < Version
class PaymentList < ListResource
##
# Initialize the PaymentList
# @param [Version] version Version that contains the resource
# @return [PaymentList] PaymentList
def initialize(version, account_sid, call_sid)
super(version)
# Path Solution
@solution = { account_sid: account_sid,call_sid: call_sid, }
@uri = "/Accounts/#{@solution[:account_sid]}/Calls/#{@solution[:call_sid]}/Payments.json"
end
##
# Create the PaymentInstance
# @param [String] idempotency_key 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.
# @param [String] status_callback 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)
# @param [PaymentsBankAccountType] bank_account_type
# @param [Float] charge_amount A positive decimal value less than 1,000,000 to charge against the credit card or bank account. Default currency can be overwritten with &#x60;currency&#x60; field. Leave blank or set to 0 to tokenize.
# @param [String] currency The currency of the &#x60;charge_amount&#x60;, formatted as [ISO 4127](http://www.iso.org/iso/home/standards/currency_codes.htm) format. The default value is &#x60;USD&#x60; and all values allowed from the Pay Connector are accepted.
# @param [String] description 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.
# @param [String] input A list of inputs that should be accepted. Currently only &#x60;dtmf&#x60; is supported. All digits captured during a pay session are redacted from the logs.
# @param [Integer] min_postal_code_length A positive integer that is used to validate the length of the &#x60;PostalCode&#x60; inputted by the user. User must enter this many digits.
# @param [Object] parameter 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 &lt;Pay&gt; Connector. [Read more](https://www.twilio.com/console/voice/pay-connectors).
# @param [String] payment_connector This is the unique name corresponding to the Pay Connector installed in the Twilio Add-ons. Learn more about [&lt;Pay&gt; Connectors](https://www.twilio.com/console/voice/pay-connectors). The default value is &#x60;Default&#x60;.
# @param [PaymentsPaymentMethod] payment_method
# @param [Boolean] postal_code 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 &#x60;true&#x60;.
# @param [Boolean] security_code Indicates whether the credit card security code is a required piece of payment information that must be provided by the caller. The default is &#x60;true&#x60;.
# @param [Integer] timeout The number of seconds that &lt;Pay&gt; 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 &#x60;5&#x60;, maximum is &#x60;600&#x60;.
# @param [PaymentsTokenType] token_type
# @param [String] valid_card_types Credit card types separated by space that Pay should accept. The default value is &#x60;visa mastercard amex&#x60;
# @return [PaymentInstance] Created PaymentInstance
def create(idempotency_key: nil,
status_callback: nil,
bank_account_type: :unset,
charge_amount: :unset,
currency: :unset,
description: :unset,
input: :unset,
min_postal_code_length: :unset,
parameter: :unset,
payment_connector: :unset,
payment_method: :unset,
postal_code: :unset,
security_code: :unset,
timeout: :unset,
token_type: :unset,
valid_card_types: :unset
)
data = Twilio::Values.of(
'IdempotencyKey' => idempotency_key,
'StatusCallback' => status_callback,
'BankAccountType' => bank_account_type,
'ChargeAmount' => charge_amount,
'Currency' => currency,
'Description' => description,
'Input' => input,
'MinPostalCodeLength' => min_postal_code_length,
'Parameter' => Twilio.serialize_object(parameter) { |e| e },
'PaymentConnector' => payment_connector,
'PaymentMethod' => payment_method,
'PostalCode' => postal_code,
'SecurityCode' => security_code,
'Timeout' => timeout,
'TokenType' => token_type,
'ValidCardTypes' => valid_card_types,
})
payload = @version.create('POST', @uri, data: data)
PaymentInstance.new(@version, payload, account_sid: @solution[:account_sid], call_sid: @solution[:call_sid],)
end
##
# Provide a user friendly representation
def to_s
'#<Twilio.Api.V2010.PaymentList>'
end
end
##
#PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
class PaymentContext < InstanceContext
##
# Initialize the PaymentContext
# @param [Version] version Version that contains the resource
# @param [String] account_sid The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will update the resource.
# @param [String] call_sid The SID of the call that will update the resource. This should be the same call sid that was used to create payments resource.
# @param [String] sid The SID of Payments session that needs to be updated.
# @return [PaymentContext] PaymentContext
def initialize(version, account_sid, call_sid, sid)
super(version)
# Path Solution
@solution = { account_sid: account_sid, call_sid: call_sid, sid: sid, }
@uri = "/Accounts/#{@solution[:account_sid]}/Calls/#{@solution[:call_sid]}/Payments/#{@solution[:sid]}.json"
# Dependents
end
##
# Update the PaymentInstance
# @param [String] idempotency_key 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.
# @param [String] status_callback 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.
# @param [PaymentsCapture] capture
# @param [PaymentsStatus] status
# @return [PaymentInstance]
Updated PaymentInstance
def update(idempotency_key: nil , status_callback: nil , capture: :unset , status: :unset )
data = Twilio::Values.of({
'IdempotencyKey' => idempotency_key,
'StatusCallback' => status_callback,
'Capture' => capture,
'Status' => status,
})
payload = @version.update('POST',@uri, data: data )
PaymentInstance.new(@version, payload, account_sid: @solution[:account_sid], call_sid: @solution[:call_sid],)
end
##
# Provide a user friendly representation
def to_s
context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
"#<Twilio.Api.V2010.PaymentContext #{context}>"
end
##
# Provide a detailed, user friendly representation
def inspect
context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
"#<Twilio.Api.V2010.PaymentContext #{context}>"
end
end
class PaymentPage < Page
##
# Initialize the PaymentPage
# @param [Version] version Version that contains the resource
# @param [Response] response Response from the API
# @param [Hash] solution Path solution for the resource
# @return [PaymentPage] PaymentPage
def initialize(version, response, solution)
super(version, response)
# Path Solution
@solution = solution
end
##
# Build an instance of PaymentInstance
# @param [Hash] payload Payload response from the API
# @return [PaymentInstance] PaymentInstance
def get_instance(payload)
PaymentInstance.new(@version, payload, account_sid: @solution[:account_sid], call_sid: @solution[:call_sid])
end
##
# Provide a user friendly representation
def to_s
'<Twilio.Api.V2010.PaymentPage>'
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment