Class: Whop_sdk::Payments::Client
- Inherits:
-
Object
- Object
- Whop_sdk::Payments::Client
- Defined in:
- lib/whop_sdk/payments/client.rb
Instance Method Summary collapse
-
#capture(request_options: {}, **params) ⇒ Whop_sdk::Types::PaymentStatus
Captures the full amount of a card payment created with
capture: false. -
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Charges a buyer for one or more plans.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::Payments::Types::ListPaymentsResponse
Lists payments, newest first.
-
#list_fees(request_options: {}, **params) ⇒ Whop_sdk::Payments::Types::ListFeesPaymentsResponse
Returns the fee breakdown of one payment — Whop's fee, processing, affiliate and other lines — each in the currency it was collected in and converted to the payment's settlement currency.
-
#refund(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Issues a full or partial refund for a payment.
-
#resume(request_options: {}, **params) ⇒ Whop_sdk::Types::PaymentStatus
Starts a fresh on-session attempt with the saved card for a subscription renewal that is waiting on the customer to authenticate; the bank's step then arrives in
next_actionon the following status reads. -
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Returns one payment.
-
#retrieve_status(request_options: {}, **params) ⇒ Whop_sdk::Types::PaymentStatus
Retrieves how far a payment has got and what the buyer must do next, if anything.
-
#retry_(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Retries a failed or pending payment.
-
#update_return_url(request_options: {}, **params) ⇒ Whop_sdk::Types::PaymentStatus
Changes where the buyer lands after completing an off-site step, up until they return.
-
#void(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Voids a payment that has not yet been settled.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/payments/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#capture(request_options: {}, **params) ⇒ Whop_sdk::Types::PaymentStatus
Captures the full amount of a card payment created with capture: false. The payment must still be in
requires_capture before capture_expires_at. Partial capture, multiple captures, capturing more than the
authorized amount, and tips are not supported.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/whop_sdk/payments/client.rb', line 197 def capture(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: "payments/#{URI.encode_uri_component(params[:id].to_s)}/capture", 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::PaymentStatus.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Charges a buyer for one or more plans. Pass a payment method already on file (member_id and
payment_method_id), or a confirmation_token describing a method the buyer just supplied. Collection runs in
the background: the response is the payment as created, not its outcome — poll Retrieve status for how far it
has got and, for a confirmation-token payment, what the buyer must still do. Pass line_items for one or more
plans with quantities, plan_id for an existing plan, or plan to find or create one inline. These inputs are
mutually exclusive.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/whop_sdk/payments/client.rb', line 119 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: "payments", body: Whop_sdk::Payments::Types::CreatePaymentsRequest.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::Types::Payment.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::Payments::Types::ListPaymentsResponse
Lists payments, newest first. Without filters this is every payment the caller can read: a company credential's
own account, or for a user every account they can read payments for. Filters narrow by account, buyer, product,
plan, membership, status, billing reason, currency, and creation window. Filtering by
billing_reason=subscription_cycle also matches renewals recorded as subscription_update.
settlement_time_at is null on list rows — retrieve the payment for it.
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 90 91 92 93 94 95 96 97 98 |
# File 'lib/whop_sdk/payments/client.rb', line 49 def list(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["account_id"] = params[:account_id] if params.key?(:account_id) query_params["status"] = params[:status] if params.key?(:status) query_params["billing_reason"] = params[:billing_reason] if params.key?(:billing_reason) query_params["currency"] = params[:currency] if params.key?(:currency) query_params["user_id"] = params[:user_id] if params.key?(:user_id) query_params["query"] = params[:query] if params.key?(:query) query_params["member_id"] = params[:member_id] if params.key?(:member_id) query_params["membership_id"] = params[:membership_id] if params.key?(:membership_id) query_params["product_id"] = params[:product_id] if params.key?(:product_id) query_params["plan_id"] = params[:plan_id] if params.key?(:plan_id) 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["order"] = params[:order] if params.key?(:order) query_params["direction"] = params[:direction] if params.key?(:direction) query_params["first"] = params[:first] if params.key?(:first) query_params["after"] = params[:after] if params.key?(:after) query_params["last"] = params[:last] if params.key?(:last) query_params["before"] = params[:before] if params.key?(:before) 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: "payments", 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::Payments::Types::ListPaymentsResponse.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 |
#list_fees(request_options: {}, **params) ⇒ Whop_sdk::Payments::Types::ListFeesPaymentsResponse
Returns the fee breakdown of one payment — Whop's fee, processing, affiliate and other lines — each in the currency it was collected in and converted to the payment's settlement currency. The list is complete in one page.
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/whop_sdk/payments/client.rb', line 236 def list_fees(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: "payments/#{URI.encode_uri_component(params[:id].to_s)}/fees", 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::Payments::Types::ListFeesPaymentsResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#refund(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Issues a full or partial refund for a payment. The refund is processed through the original payment processor and the membership status is updated accordingly.
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/whop_sdk/payments/client.rb', line 274 def refund(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::Payments::Types::RefundPaymentsRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "payments/#{URI.encode_uri_component(params[:id].to_s)}/refund", 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::Payment.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#resume(request_options: {}, **params) ⇒ Whop_sdk::Types::PaymentStatus
Starts a fresh on-session attempt with the saved card for a subscription renewal that is waiting on the customer
to authenticate; the bank's step then arrives in next_action on the following status reads. Only the payment's
own customer may call it — with the payment's client_secret or their own session — and it is a no-op for any
payment that is not a parked renewal.
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/whop_sdk/payments/client.rb', line 395 def resume(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: "payments/#{URI.encode_uri_component(params[:payment_id].to_s)}/resume", 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::PaymentStatus.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(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Returns one payment. Related records are ids — resolve a plan, membership, member or shipment on its own
endpoint, and list this payment's refunds, disputes or Resolution Center cases with ?payment_id=.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/whop_sdk/payments/client.rb', line 158 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: "payments/#{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::Payment.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::PaymentStatus
Retrieves how far a payment has got and what the buyer must do next, if anything. A payment is collected in the
background, so poll this rather than reading the create response. Accepts either a secret key or the payment's
own client_secret, so the surface collecting the payment can poll it directly.
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/whop_sdk/payments/client.rb', line 480 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: "payments/#{URI.encode_uri_component(params[:payment_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::PaymentStatus.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#retry_(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Retries a failed or pending payment. This re-attempts the charge using the original payment method and plan details.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/whop_sdk/payments/client.rb', line 317 def retry_(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: "payments/#{URI.encode_uri_component(params[:id].to_s)}/retry", 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::Payment.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::PaymentStatus
Changes where the buyer lands after completing an off-site step, up until they return. Accepts either a secret
key or the payment's own client_secret, so the surface that knows the final destination can set it.
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/whop_sdk/payments/client.rb', line 436 def update_return_url(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::Payments::Types::UpdateReturnURLPaymentsRequest.new(params).to_h non_body_param_names = %w[payment_id] body = request_data.except(*non_body_param_names) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "payments/#{URI.encode_uri_component(params[:payment_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::PaymentStatus.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#void(request_options: {}, **params) ⇒ Whop_sdk::Types::Payment
Voids a payment that has not yet been settled. Voiding cancels the payment before it is captured by the payment processor.
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/whop_sdk/payments/client.rb', line 355 def void(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: "payments/#{URI.encode_uri_component(params[:id].to_s)}/void", 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::Payment.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |