Module: Pay::Paddle

Extended by:
Env
Defined in:
lib/pay/paddle.rb,
lib/pay/paddle/error.rb,
lib/pay/paddle/charge.rb,
lib/pay/paddle/billable.rb,
lib/pay/paddle/subscription.rb,
lib/pay/paddle/payment_method.rb,
lib/pay/paddle/webhooks/signature_verifier.rb,
lib/pay/paddle/webhooks/subscription_created.rb,
lib/pay/paddle/webhooks/subscription_updated.rb,
lib/pay/paddle/webhooks/subscription_cancelled.rb,
lib/pay/paddle/webhooks/subscription_payment_refunded.rb,
lib/pay/paddle/webhooks/subscription_payment_succeeded.rb

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.configure_webhooksObject


70
71
72
73
74
75
76
77
78
# File 'lib/pay/paddle.rb', line 70

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

.enabled?Boolean

Returns:

  • (Boolean)

20
21
22
23
24
# File 'lib/pay/paddle.rb', line 20

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

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

.environmentObject


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

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

.owner_from_passthrough(passthrough) ⇒ Object


64
65
66
67
68
# File 'lib/pay/paddle.rb', line 64

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

.parse_passthrough(passthrough) ⇒ Object


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

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

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


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

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

.public_keyObject


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

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

.public_key_base64Object


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

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

.public_key_fileObject


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

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

.setupObject


26
27
28
29
30
# File 'lib/pay/paddle.rb', line 26

def self.setup
  ::PaddlePay.config.vendor_id = vendor_id
  ::PaddlePay.config.vendor_auth_code = vendor_auth_code
  ::PaddlePay.config.environment = environment
end

.vendor_auth_codeObject


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

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

.vendor_idObject


32
33
34
# File 'lib/pay/paddle.rb', line 32

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