Module: Pay::PaddleClassic

Extended by:
Env
Defined in:
lib/pay/paddle_classic.rb,
app/models/pay/paddle_classic/charge.rb,
app/models/pay/paddle_classic/customer.rb,
app/models/pay/paddle_classic/subscription.rb,
app/models/pay/paddle_classic/payment_method.rb,
lib/pay/paddle_classic/webhooks/signature_verifier.rb,
lib/pay/paddle_classic/webhooks/subscription_created.rb,
lib/pay/paddle_classic/webhooks/subscription_updated.rb,
lib/pay/paddle_classic/webhooks/subscription_cancelled.rb,
lib/pay/paddle_classic/webhooks/subscription_payment_refunded.rb,
lib/pay/paddle_classic/webhooks/subscription_payment_succeeded.rb

Defined Under Namespace

Modules: Webhooks Classes: Charge, Customer, Error, PaymentMethod, Subscription

Class Method Summary collapse

Class Method Details

.clientObject



28
29
30
31
32
33
34
# File 'lib/pay/paddle_classic.rb', line 28

def self.client
  @client ||= Paddle::Classic::Client.new(
    vendor_id: vendor_id,
    vendor_auth_code: vendor_auth_code,
    sandbox: environment != "production"
  )
end

.configure_webhooksObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/pay/paddle_classic.rb', line 74

def self.configure_webhooks
  Pay::Webhooks.configure do |events|
    events.subscribe "paddle_classic.subscription_created", Pay::PaddleClassic::Webhooks::SubscriptionCreated.new
    events.subscribe "paddle_classic.subscription_updated", Pay::PaddleClassic::Webhooks::SubscriptionUpdated.new
    events.subscribe "paddle_classic.subscription_cancelled",
      Pay::PaddleClassic::Webhooks::SubscriptionCancelled.new
    events.subscribe "paddle_classic.subscription_payment_succeeded",
      Pay::PaddleClassic::Webhooks::SubscriptionPaymentSucceeded.new
    events.subscribe "paddle_classic.subscription_payment_refunded",
      Pay::PaddleClassic::Webhooks::SubscriptionPaymentRefunded.new
  end
end

.enabled?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/pay/paddle_classic.rb', line 21

def self.enabled?
  return false unless Pay.enabled_processors.include?(:paddle_classic) && defined?(::Paddle)

  Pay::Engine.version_matches?(required: "~> 2.5",
    current: ::Paddle::VERSION) || (raise "[Pay] paddle gem must be version ~> 2.5")
end

.environmentObject



44
45
46
# File 'lib/pay/paddle_classic.rb', line 44

def self.environment
  find_value_by_name(:paddle_classic, :environment) || "production"
end

.owner_from_passthrough(passthrough) ⇒ Object



68
69
70
71
72
# File 'lib/pay/paddle_classic.rb', line 68

def self.owner_from_passthrough(passthrough)
  GlobalID::Locator.locate_signed parse_passthrough(passthrough)["owner_sgid"]
rescue JSON::ParserError
  nil
end

.parse_passthrough(passthrough) ⇒ Object



64
65
66
# File 'lib/pay/paddle_classic.rb', line 64

def self.parse_passthrough(passthrough)
  JSON.parse(passthrough)
end

.passthrough(owner:, **options) ⇒ Object



60
61
62
# File 'lib/pay/paddle_classic.rb', line 60

def self.passthrough(owner:, **options)
  options.merge(owner_sgid: owner.to_sgid.to_s).to_json
end

.public_keyObject



48
49
50
# File 'lib/pay/paddle_classic.rb', line 48

def self.public_key
  find_value_by_name(:paddle_classic, :public_key)
end

.public_key_base64Object



56
57
58
# File 'lib/pay/paddle_classic.rb', line 56

def self.public_key_base64
  find_value_by_name(:paddle_classic, :public_key_base64)
end

.public_key_fileObject



52
53
54
# File 'lib/pay/paddle_classic.rb', line 52

def self.public_key_file
  find_value_by_name(:paddle_classic, :public_key_file)
end

.vendor_auth_codeObject



40
41
42
# File 'lib/pay/paddle_classic.rb', line 40

def self.vendor_auth_code
  find_value_by_name(:paddle_classic, :vendor_auth_code)
end

.vendor_idObject



36
37
38
# File 'lib/pay/paddle_classic.rb', line 36

def self.vendor_id
  find_value_by_name(:paddle_classic, :vendor_id)
end