Module: Pay

Defined in:
lib/pay/engine.rb,
lib/pay.rb,
lib/pay/env.rb,
lib/pay/errors.rb,
lib/pay/paddle.rb,
lib/pay/stripe.rb,
lib/pay/payment.rb,
lib/pay/version.rb,
lib/pay/billable.rb,
lib/pay/receipts.rb,
lib/pay/braintree.rb,
app/models/pay/charge.rb,
lib/pay/paddle/charge.rb,
lib/pay/stripe/charge.rb,
lib/pay/paddle/billable.rb,
lib/pay/stripe/billable.rb,
lib/pay/braintree/charge.rb,
lib/pay/braintree/billable.rb,
app/jobs/pay/email_sync_job.rb,
app/mailers/pay/user_mailer.rb,
app/models/pay/subscription.rb,
lib/pay/billable/sync_email.rb,
lib/pay/paddle/subscription.rb,
lib/pay/stripe/subscription.rb,
app/jobs/pay/application_job.rb,
lib/generators/pay/orm_helpers.rb,
lib/pay/braintree/subscription.rb,
lib/generators/pay/pay_generator.rb,
app/models/pay/application_record.rb,
app/helpers/pay/application_helper.rb,
app/mailers/pay/application_mailer.rb,
lib/generators/pay/views_generator.rb,
app/controllers/pay/payments_controller.rb,
lib/pay/stripe/webhooks/charge_refunded.rb,
lib/generators/pay/email_views_generator.rb,
lib/pay/stripe/webhooks/charge_succeeded.rb,
lib/pay/stripe/webhooks/customer_deleted.rb,
lib/pay/stripe/webhooks/customer_updated.rb,
app/controllers/pay/application_controller.rb,
lib/pay/paddle/webhooks/signature_verifier.rb,
lib/pay/paddle/webhooks/subscription_created.rb,
lib/pay/paddle/webhooks/subscription_updated.rb,
lib/pay/stripe/webhooks/subscription_created.rb,
lib/pay/stripe/webhooks/subscription_deleted.rb,
lib/pay/stripe/webhooks/subscription_updated.rb,
lib/pay/stripe/webhooks/subscription_renewing.rb,
app/controllers/pay/webhooks/paddle_controller.rb,
lib/pay/paddle/webhooks/subscription_cancelled.rb,
lib/pay/stripe/webhooks/payment_method_updated.rb,
lib/pay/stripe/webhooks/payment_action_required.rb,
app/controllers/pay/webhooks/braintree_controller.rb,
lib/pay/paddle/webhooks/subscription_payment_refunded.rb,
lib/pay/paddle/webhooks/subscription_payment_succeeded.rb

Overview

rubocop:enable Lint/HandleExceptions

Defined Under Namespace

Modules: ApplicationHelper, Billable, Braintree, Env, Generators, Paddle, Receipts, Stripe, Webhooks Classes: ActionRequired, ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, BraintreeAuthorizationError, BraintreeError, Charge, EmailSyncJob, Engine, Error, InvalidPaymentMethod, Payment, PaymentError, PaymentsController, Subscription, UserMailer

Constant Summary collapse

VERSION =
"2.4.2"
@@billable_class =
"User"
@@billable_table =
@@billable_class.tableize
@@model_parent_class =
"ApplicationRecord"
@@chargeable_class =
"Pay::Charge"
@@chargeable_table =
"pay_charges"
@@subscription_class =
"Pay::Subscription"
@@subscription_table =
"pay_subscriptions"
@@send_emails =
true
@@email_receipt_subject =
"Payment receipt"
@@email_refund_subject =
"Payment refunded"
@@email_renewing_subject =
"Your upcoming subscription renewal"
@@email_action_required_subject =
"Confirm your payment"
@@automount_routes =
true
@@default_product_name =
"default"
@@default_plan_name =
"default"
@@routes_path =
"/pay"

Class Method Summary collapse

Class Method Details

.billable_modelsObject



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

def self.billable_models
  Pay::Billable.includers
end

.charge_modelObject



87
88
89
90
91
92
93
# File 'lib/pay.rb', line 87

def self.charge_model
  if Rails.application.config.cache_classes
    @@charge_model ||= chargeable_class.constantize
  else
    chargeable_class.constantize
  end
end

.find_billable(processor:, processor_id:) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/pay.rb', line 67

def self.find_billable(processor:, processor_id:)
  billable_models.each do |model|
    if (record = model.find_by(processor: processor, processor_id: processor_id))
      return record
    end
  end

  nil
end

.receipts_supported?Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
109
# File 'lib/pay.rb', line 103

def self.receipts_supported?
  charge_model.respond_to?(:receipt) &&
    application_name.present? &&
    business_name &&
    business_address &&
    support_email
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Pay)

    the object that the method was called on



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

def self.setup
  yield self
end

.subscription_modelObject



95
96
97
98
99
100
101
# File 'lib/pay.rb', line 95

def self.subscription_model
  if Rails.application.config.cache_classes
    @@subscription_model ||= subscription_class.constantize
  else
    subscription_class.constantize
  end
end

.user_modelObject



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

def self.user_model
  ActiveSupport::Deprecation.warn("Pay.user_model is deprecated and will be removed in v3. Instead, use `Pay.billable_models` now to support more than one billable model.")

  if Rails.application.config.cache_classes
    @@user_model ||= billable_class.constantize
  else
    billable_class.constantize
  end
end