Module: Pay::PaddleBilling

Extended by:
Env
Defined in:
lib/pay/paddle_billing.rb,
app/models/pay/paddle_billing/charge.rb,
app/models/pay/paddle_billing/customer.rb,
app/models/pay/paddle_billing/subscription.rb,
app/models/pay/paddle_billing/payment_method.rb,
lib/pay/paddle_billing/webhooks/subscription.rb,
lib/pay/paddle_billing/webhooks/transaction_completed.rb

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.api_keyObject



34
35
36
# File 'lib/pay/paddle_billing.rb', line 34

def self.api_key
  find_value_by_name(:paddle_billing, :api_key)
end

.client_tokenObject



30
31
32
# File 'lib/pay/paddle_billing.rb', line 30

def self.client_token
  find_value_by_name(:paddle_billing, :client_token)
end

.configure_webhooksObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pay/paddle_billing.rb', line 42

def self.configure_webhooks
  Pay::Webhooks.configure do |events|
    events.subscribe "paddle_billing.subscription.activated", Pay::PaddleBilling::Webhooks::Subscription.new
    events.subscribe "paddle_billing.subscription.canceled", Pay::PaddleBilling::Webhooks::Subscription.new
    events.subscribe "paddle_billing.subscription.created", Pay::PaddleBilling::Webhooks::Subscription.new
    events.subscribe "paddle_billing.subscription.imported", Pay::PaddleBilling::Webhooks::Subscription.new
    events.subscribe "paddle_billing.subscription.past_due", Pay::PaddleBilling::Webhooks::Subscription.new
    events.subscribe "paddle_billing.subscription.paused", Pay::PaddleBilling::Webhooks::Subscription.new
    events.subscribe "paddle_billing.subscription.resumed", Pay::PaddleBilling::Webhooks::Subscription.new
    events.subscribe "paddle_billing.subscription.trialing", Pay::PaddleBilling::Webhooks::Subscription.new
    events.subscribe "paddle_billing.subscription.updated", Pay::PaddleBilling::Webhooks::Subscription.new
    events.subscribe "paddle_billing.transaction.completed", Pay::PaddleBilling::Webhooks::TransactionCompleted.new
  end
end

.enabled?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/pay/paddle_billing.rb', line 14

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

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

.environmentObject



26
27
28
# File 'lib/pay/paddle_billing.rb', line 26

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

.setupObject



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

def self.setup
  ::Paddle.config.environment = environment
  ::Paddle.config.api_key = api_key
end

.signing_secretObject



38
39
40
# File 'lib/pay/paddle_billing.rb', line 38

def self.signing_secret
  find_value_by_name(:paddle_billing, :signing_secret)
end

.sync_transaction(transaction_id) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/pay/paddle_billing.rb', line 57

def self.sync_transaction(transaction_id)
  transaction = ::Paddle::Transaction.retrieve(id: transaction_id)

  if transaction.subscription_id.present?
    Pay::PaddleBilling::Subscription.sync(transaction.subscription_id)
  else
    Pay::PaddleBilling::Charge.sync(transaction_id, object: transaction)
  end
end