Class: Whop_sdk::PaymentMethods::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



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

def initialize(client:)
  @client = client
end

Instance Method Details

#delete_payment_method(request_options: {}, **params) ⇒ Boolean

Delete a saved payment method. Cannot delete a payment method attached to an active subscription.

Required permissions:

  • member:payment_methods:manage

Examples:

client.payment_methods.delete_payment_method(
  id: "payt_xxxxxxxxxxxxx",
  company_id: "biz_xxxxxxxxxxxxxx",
  member_id: "mber_xxxxxxxxxxxxx"
)

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)
  • :company_id (String, nil)
  • :member_id (String, nil)

Returns:

  • (Boolean)

Raises:

  • (error_class)


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/whop_sdk/payment_methods/client.rb', line 180

def delete_payment_method(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["company_id"] = params[:company_id] if params.key?(:company_id)
  query_params["member_id"] = params[:member_id] if params.key?(:member_id)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "payment_methods/#{URI.encode_uri_component(params[:id].to_s)}",
    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
  return if code.between?(200, 299)

  error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#list(request_options: {}, **params) ⇒ Whop_sdk::PaymentMethods::Types::ListPaymentMethodsResponse

Returns a paginated list of payment methods for a member or company, or for the authenticated user when neither is given, with optional filtering by creation date. A payment method is a stored representation of how a customer intends to pay, such as a card, bank account, or digital wallet.

Required permissions:

  • member:payment_methods:read

Examples:

client.payment_methods.list(
  first: 42,
  last: 42,
  member_id: "mber_xxxxxxxxxxxxx",
  company_id: "biz_xxxxxxxxxxxxxx",
  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):

Returns:



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
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/whop_sdk/payment_methods/client.rb', line 55

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["member_id"] = params[:member_id] if params.key?(:member_id)
  query_params["company_id"] = params[:company_id] if params.key?(:company_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)
  query_params["future_usage"] = params[:future_usage] if params.key?(:future_usage)
  query_params["payment_method_types"] = params[:payment_method_types] if params.key?(:payment_method_types)
  query_params["card_brands"] = params[:card_brands] if params.key?(:card_brands)
  query_params["card_funding_types"] = params[:card_funding_types] if params.key?(:card_funding_types)
  query_params["has_payer_document"] = params[:has_payer_document] if params.key?(:has_payer_document)
  query_params["expired"] = params[:expired] if params.key?(:expired)
  query_params["broken"] = params[:broken] if params.key?(:broken)

  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: "payment_methods",
      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::PaymentMethods::Types::ListPaymentMethodsResponse.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::PaymentMethod

Retrieves the details of an existing payment method. Addresses a member's wallet when member_id or company_id is given, otherwise your own.

Required permissions:

  • member:payment_methods:read

Examples:

client.payment_methods.retrieve(
  id: "payt_xxxxxxxxxxxxx",
  company_id: "biz_xxxxxxxxxxxxxx",
  member_id: "mber_xxxxxxxxxxxxx"
)

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)
  • :company_id (String, nil)
  • :member_id (String, nil)

Returns:



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/whop_sdk/payment_methods/client.rb', line 129

def retrieve(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["company_id"] = params[:company_id] if params.key?(:company_id)
  query_params["member_id"] = params[:member_id] if params.key?(:member_id)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "payment_methods/#{URI.encode_uri_component(params[:id].to_s)}",
    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)
    Whop_sdk::Types::PaymentMethod.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end