Class: Whop_sdk::Refunds::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/whop_sdk/refunds/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/whop_sdk/refunds/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#list(request_options: {}, **params) ⇒ Whop_sdk::Refunds::Types::ListRefundsResponse

Returns a paginated list of refunds, with optional filtering by payment, company, user, and creation date.

Required permissions:

  • payment:basic:read

Examples:

client.refunds.list(
  first: 42,
  last: 42,
  payment_id: "pay_xxxxxxxxxxxxxx",
  company_id: "biz_xxxxxxxxxxxxxx",
  user_id: "user_xxxxxxxxxxxxx",
  created_before: "2023-12-01T05:00:00Z",
  created_after: "2023-12-01T05:00:00Z"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :after (String, nil)
  • :before (String, nil)
  • :first (Integer, nil)
  • :last (Integer, nil)
  • :payment_id (String, nil)
  • :company_id (String, nil)
  • :user_id (String, nil)
  • :direction (Whop_sdk::Types::Direction, nil)
  • :created_before (String, nil)
  • :created_after (String, nil)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/whop_sdk/refunds/client.rb', line 48

def list(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["after"] = params[:after] if params.key?(:after)
  query_params["before"] = params[:before] if params.key?(:before)
  query_params["first"] = params[:first] if params.key?(:first)
  query_params["last"] = params[:last] if params.key?(:last)
  query_params["payment_id"] = params[:payment_id] if params.key?(:payment_id)
  query_params["company_id"] = params[:company_id] if params.key?(:company_id)
  query_params["user_id"] = params[:user_id] if params.key?(:user_id)
  query_params["direction"] = params[:direction] if params.key?(:direction)
  query_params["created_before"] = params[:created_before] if params.key?(:created_before)
  query_params["created_after"] = params[:created_after] if params.key?(:created_after)

  Whop_sdk::Internal::CursorItemIterator.new(
    cursor_field: :end_cursor,
    item_field: :data,
    initial_cursor: query_params["after"]
  ) do |next_cursor|
    query_params["after"] = next_cursor
    request = Whop_sdk::Internal::JSON::Request.new(
      base_url: request_options[:base_url],
      method: "GET",
      path: "refunds",
      query: query_params,
      request_options: request_options
    )
    begin
      response = @client.send(request)
    rescue Net::HTTPRequestTimeout
      raise Whop_sdk::Errors::TimeoutError
    end
    code = response.code.to_i
    if code.between?(200, 299)
      parsed_response = Whop_sdk::Refunds::Types::ListRefundsResponse.load(response.body)
      [parsed_response, response]
    else
      error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
      raise error_class.new(response.body, code: code)
    end
  end
end

#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::Refund

Retrieves the details of an existing refund.

Required permissions:

  • payment:basic:read
  • plan:basic:read
  • access_pass:basic:read
  • member:email:read
  • member:basic:read
  • member:phone:read

Examples:

client.refunds.retrieve(id: "rf_xxxxxxxxxxxxxxx")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (String)

Returns:



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/whop_sdk/refunds/client.rb', line 114

def retrieve(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "refunds/#{URI.encode_uri_component(params[:id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Whop_sdk::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Whop_sdk::Types::Refund.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end