Class: Nombaone::Resources::Sandbox

Inherits:
BaseResource show all
Defined in:
lib/nombaone/resources/sandbox.rb,
sig/nombaone/resources.rbs

Overview

Sandbox only. Simulation instruments that make billing outcomes happen on demand — no cron waits, no real cards. These endpoints exist only on the sandbox deployment; calling any of them with a live key raises locally, before any network request.

Instance Method Summary collapse

Methods inherited from BaseResource

#encode, #initialize, #request, #request_page

Constructor Details

This class inherits a constructor from Nombaone::Resources::BaseResource

Instance Method Details

#advance_cycle(subscription_id, request_options: {}) ⇒ NombaObject

Sandbox only. The test clock: run the subscription's next billing cycle right now, through the real engine — invoice, charge, ledger, webhooks and all.

Examples:

result = nombaone.sandbox.advance_cycle(subscription.id)
result.outcome # => "paid"

Parameters:

  • subscription_id (String)

    nbo…sub

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

Returns:

  • (NombaObject)

    the cycle outcome and the invoice it produced.



42
43
44
45
46
# File 'lib/nombaone/resources/sandbox.rb', line 42

def advance_cycle(subscription_id, request_options: {})
  assert_sandbox!
  request(:post, "/sandbox/subscriptions/#{encode(subscription_id)}/advance-cycle",
          body: {}, options: request_options)
end

#assert_sandbox!void

This method returns an undefined value.

Fail locally, before any network call, when constructed with a live key.

Raises:



71
72
73
74
75
76
77
78
# File 'lib/nombaone/resources/sandbox.rb', line 71

def assert_sandbox!
  return unless @client.mode == "live"

  raise Error,
        "nombaone.sandbox.* only works with a sandbox key (nbo_sandbox_…) — the " \
        "/v1/sandbox endpoints do not exist on the live API. Use your sandbox key to " \
        "rehearse, then go live without the sandbox calls."
end

#create_payment_method(customer_id:, behavior: OMIT, kind: OMIT, request_options: {}) ⇒ NombaObject

Sandbox only. Mint a ready, chargeable test payment method whose behavior decides every future charge outcome deterministically.

Examples:

method = nombaone.sandbox.create_payment_method(
  customer_id: customer.id, behavior: "decline_insufficient_funds"
)

Parameters:

  • customer_id (String)

    nbo…cus

  • behavior (String) (defaults to: OMIT)

    "success" (default), "decline_insufficient_funds", "decline_expired_card", "decline_do_not_honor", or "requires_otp".

  • kind (String) (defaults to: OMIT)

    "card" (default) or "mandate".

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

Returns:



24
25
26
27
28
29
# File 'lib/nombaone/resources/sandbox.rb', line 24

def create_payment_method(customer_id:, behavior: OMIT, kind: OMIT, request_options: {})
  assert_sandbox!
  request(:post, "/sandbox/payment-methods",
          body: { customer_id: customer_id, behavior: behavior, kind: kind },
          options: request_options)
end

#simulate_webhook(type:, payload: OMIT, request_options: {}) ⇒ NombaObject

Sandbox only. Emit a real, signed catalog event to your registered endpoints — the genuine pipeline (real secret, real signature, real retries), not a mock. This is how you rehearse your handler.

Examples:

nombaone.sandbox.simulate_webhook(
  type: "invoice.payment_failed",
  payload: { reference: invoice.id, reason: "insufficient_funds" }
)

Parameters:

  • type (String)

    any catalog event type, e.g. "invoice.payment_failed".

  • payload (Hash) (defaults to: OMIT)

    shapes the delivery's data object.

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

Returns:



62
63
64
65
66
# File 'lib/nombaone/resources/sandbox.rb', line 62

def simulate_webhook(type:, payload: OMIT, request_options: {})
  assert_sandbox!
  request(:post, "/sandbox/webhooks/simulate",
          body: { type: type, payload: payload }, options: request_options)
end