Exception: Poodle::PaymentError

Inherits:
Error
  • Object
show all
Defined in:
lib/poodle/errors/payment_error.rb

Overview

Exception raised when payment is required (402 Payment Required)

Examples:

Handling payment errors

begin
  client.send_email(email)
rescue Poodle::PaymentError => e
  puts "Payment required: #{e.message}"
  puts "Upgrade URL: #{e.upgrade_url}" if e.upgrade_url
end

Instance Attribute Summary collapse

Attributes inherited from Error

#context, #status_code

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#message, #to_s

Constructor Details

#initialize(message = "Payment required", upgrade_url: nil, context: {}) ⇒ PaymentError

Initialize a new PaymentError

Parameters:

  • message (String) (defaults to: "Payment required")

    the error message

  • upgrade_url (String, nil) (defaults to: nil)

    URL to upgrade subscription

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

    additional context information



24
25
26
27
# File 'lib/poodle/errors/payment_error.rb', line 24

def initialize(message = "Payment required", upgrade_url: nil, context: {})
  @upgrade_url = upgrade_url
  super(message, context: context.merge(upgrade_url: upgrade_url), status_code: 402)
end

Instance Attribute Details

#upgrade_urlString? (readonly)

Returns URL to upgrade subscription.

Returns:

  • (String, nil)

    URL to upgrade subscription



17
18
19
# File 'lib/poodle/errors/payment_error.rb', line 17

def upgrade_url
  @upgrade_url
end

Class Method Details

.monthly_limit_exceededPaymentError

Create a PaymentError for monthly limit exceeded (alias for monthly_limit_reached)

Returns:



65
66
67
68
69
70
71
# File 'lib/poodle/errors/payment_error.rb', line 65

def self.monthly_limit_exceeded
  new(
    "Monthly email limit exceeded. Please upgrade your plan to send more emails.",
    upgrade_url: "https://app.usepoodle.com/upgrade",
    context: { error_type: "monthly_limit_exceeded" }
  )
end

.monthly_limit_reachedPaymentError

Create a PaymentError for monthly limit reached

Returns:



54
55
56
57
58
59
60
# File 'lib/poodle/errors/payment_error.rb', line 54

def self.monthly_limit_reached
  new(
    "Monthly email limit reached. Please upgrade your plan to send more emails.",
    upgrade_url: "https://app.usepoodle.com/upgrade",
    context: { error_type: "monthly_limit_reached" }
  )
end

.subscription_expiredPaymentError

Create a PaymentError for subscription expired

Returns:



32
33
34
35
36
37
38
# File 'lib/poodle/errors/payment_error.rb', line 32

def self.subscription_expired
  new(
    "Subscription expired. Please renew your subscription to continue sending emails.",
    upgrade_url: "https://app.usepoodle.com/upgrade",
    context: { error_type: "subscription_expired" }
  )
end

.trial_limit_reachedPaymentError

Create a PaymentError for trial limit reached

Returns:



43
44
45
46
47
48
49
# File 'lib/poodle/errors/payment_error.rb', line 43

def self.trial_limit_reached
  new(
    "Trial limit reached. Please upgrade to a paid plan to continue sending emails.",
    upgrade_url: "https://app.usepoodle.com/upgrade",
    context: { error_type: "trial_limit_reached" }
  )
end