Class: Whop_sdk::SetupIntents::Client
- Inherits:
-
Object
- Object
- Whop_sdk::SetupIntents::Client
- Defined in:
- lib/whop_sdk/setup_intents/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Whop_sdk::SetupIntents::Types::CreateSetupIntentsResponse
Save a buyer's payment method for later without charging it.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::SetupIntents::Types::ListSetupIntentsResponse
Returns a paginated list of setup intents for a company, with optional filtering by creation date.
-
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::SetupIntent
Retrieves the details of an existing setup intent.
-
#retrieve_status(request_options: {}, **params) ⇒ Whop_sdk::Types::SetupStatus
Retrieves how far a setup has got and what the buyer must do next, if anything.
-
#update_return_url(request_options: {}, **params) ⇒ Whop_sdk::Types::SetupStatus
Changes where the buyer lands after completing an off-site step, up until they return.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/setup_intents/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Whop_sdk::SetupIntents::Types::CreateSetupIntentsResponse
Save a buyer's payment method for later without charging it. Provide a confirmation token for a method the buyer just supplied, or an existing payment method to re-verify. The buyer may still have a step to complete — 3D Secure, a hosted enrollment, linking a bank account — so poll the setup intent's status endpoint for what to do next.
Required permissions:
payment:chargemember:basic:readmember:email:read
113 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/setup_intents/client.rb', line 113 def create(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "setup_intents", body: Whop_sdk::SetupIntents::Types::CreateSetupIntentsRequest.new(params).to_h, 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::SetupIntents::Types::CreateSetupIntentsResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Whop_sdk::SetupIntents::Types::ListSetupIntentsResponse
Returns a paginated list of setup intents for a company, with optional filtering by creation date. A setup intent securely collects and stores a member's payment method for future use without charging them immediately.
Required permissions:
payment:setup_intent:readmember:basic:readmember:email:read
47 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 |
# File 'lib/whop_sdk/setup_intents/client.rb', line 47 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["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) 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: [:base_url], method: "GET", path: "setup_intents", query: query_params, 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::SetupIntents::Types::ListSetupIntentsResponse.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::SetupIntent
Retrieves the details of an existing setup intent.
Required permissions:
payment:setup_intent:readmember:basic:readmember:email:read
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/whop_sdk/setup_intents/client.rb', line 156 def retrieve(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "setup_intents/#{URI.encode_uri_component(params[:id].to_s)}", 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::SetupIntent.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#retrieve_status(request_options: {}, **params) ⇒ Whop_sdk::Types::SetupStatus
Retrieves how far a setup has got and what the buyer must do next, if anything. Collection runs in the
background, so poll this rather than reading the create response. Accepts either a secret key or the setup's own
client_secret, so the surface collecting the payment method can poll it directly.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/whop_sdk/setup_intents/client.rb', line 241 def retrieve_status(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "setup_intents/#{URI.encode_uri_component(params[:setup_intent_id].to_s)}/status", 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::SetupStatus.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update_return_url(request_options: {}, **params) ⇒ Whop_sdk::Types::SetupStatus
Changes where the buyer lands after completing an off-site step, up until they return. Accepts either a secret
key or the setup's own client_secret, so the surface that knows the final destination can set it.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/whop_sdk/setup_intents/client.rb', line 197 def update_return_url(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::SetupIntents::Types::UpdateReturnURLSetupIntentsRequest.new(params).to_h non_body_param_names = %w[setup_intent_id] body = request_data.except(*non_body_param_names) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "setup_intents/#{URI.encode_uri_component(params[:setup_intent_id].to_s)}/return_url", body: body, 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::SetupStatus.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |