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



25
26
27
28
29
30
31
# File 'lib/pay/paddle_classic.rb', line 25

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

.configure_webhooksObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/pay/paddle_classic.rb', line 71

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)


18
19
20
21
22
23
# File 'lib/pay/paddle_classic.rb', line 18

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



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

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

.owner_from_passthrough(passthrough) ⇒ Object



65
66
67
68
69
# File 'lib/pay/paddle_classic.rb', line 65

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

.parse_passthrough(passthrough) ⇒ Object



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

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

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



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

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

.public_keyObject



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

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

.public_key_base64Object



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

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

.public_key_fileObject



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

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

.vendor_auth_codeObject



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

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

.vendor_idObject



33
34
35
# File 'lib/pay/paddle_classic.rb', line 33

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