Module: Pay

Defined in:
lib/pay/braintree/webhooks/subscription_expired.rb,
lib/pay.rb,
lib/pay/env.rb,
lib/pay/engine.rb,
lib/pay/errors.rb,
lib/pay/stripe.rb,
lib/pay/adapter.rb,
lib/pay/nano_id.rb,
lib/pay/payment.rb,
lib/pay/version.rb,
lib/pay/currency.rb,
lib/pay/receipts.rb,
lib/pay/webhooks.rb,
lib/pay/braintree.rb,
lib/pay/attributes.rb,
lib/pay/stripe/error.rb,
app/models/pay/charge.rb,
lib/pay/stripe/charge.rb,
app/models/pay/webhook.rb,
lib/pay/fake_processor.rb,
lib/pay/paddle_billing.rb,
lib/pay/paddle_classic.rb,
app/models/pay/customer.rb,
app/models/pay/merchant.rb,
lib/pay/braintree/error.rb,
lib/pay/stripe/billable.rb,
lib/pay/stripe/merchant.rb,
lib/pay/braintree/charge.rb,
lib/pay/braintree/billable.rb,
lib/pay/webhooks/delegator.rb,
app/mailers/pay/user_mailer.rb,
app/models/pay/subscription.rb,
lib/pay/stripe/subscription.rb,
app/jobs/pay/application_job.rb,
lib/pay/fake_processor/error.rb,
lib/pay/paddle_billing/error.rb,
lib/pay/paddle_classic/error.rb,
lib/pay/webhooks/process_job.rb,
app/models/pay/payment_method.rb,
lib/pay/fake_processor/charge.rb,
lib/pay/paddle_billing/charge.rb,
lib/pay/paddle_classic/charge.rb,
lib/pay/stripe/payment_method.rb,
app/jobs/pay/customer_sync_job.rb,
lib/pay/billable/sync_customer.rb,
lib/pay/braintree/subscription.rb,
app/helpers/pay/currency_helper.rb,
lib/pay/fake_processor/billable.rb,
lib/pay/fake_processor/merchant.rb,
lib/pay/paddle_billing/billable.rb,
lib/pay/paddle_classic/billable.rb,
lib/pay/braintree/payment_method.rb,
app/models/pay/application_record.rb,
app/mailers/pay/application_mailer.rb,
lib/generators/pay/views_generator.rb,
lib/pay/fake_processor/subscription.rb,
lib/pay/paddle_billing/subscription.rb,
lib/pay/paddle_classic/subscription.rb,
lib/pay/braintree/authorization_error.rb,
lib/pay/fake_processor/payment_method.rb,
lib/pay/paddle_billing/payment_method.rb,
lib/pay/paddle_classic/payment_method.rb,
lib/pay/stripe/webhooks/payment_failed.rb,
app/controllers/pay/payments_controller.rb,
lib/pay/stripe/webhooks/account_updated.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_billing/webhooks/subscription.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/stripe_controller.rb,
lib/pay/stripe/webhooks/payment_method_updated.rb,
lib/pay/stripe/webhooks/payment_action_required.rb,
lib/pay/stripe/webhooks/payment_method_attached.rb,
lib/pay/stripe/webhooks/payment_method_detached.rb,
lib/pay/braintree/webhooks/subscription_canceled.rb,
lib/pay/stripe/webhooks/payment_intent_succeeded.rb,
app/controllers/pay/webhooks/braintree_controller.rb,
lib/pay/paddle_classic/webhooks/signature_verifier.rb,
lib/pay/stripe/webhooks/checkout_session_completed.rb,
lib/pay/braintree/webhooks/subscription_trial_ended.rb,
lib/pay/braintree/webhooks/subscription_went_active.rb,
lib/pay/stripe/webhooks/subscription_trial_will_end.rb,
lib/pay/paddle_classic/webhooks/subscription_created.rb,
lib/pay/paddle_classic/webhooks/subscription_updated.rb,
lib/pay/braintree/webhooks/subscription_went_past_due.rb,
lib/pay/paddle_billing/webhooks/transaction_completed.rb,
app/controllers/pay/webhooks/paddle_billing_controller.rb,
app/controllers/pay/webhooks/paddle_classic_controller.rb,
lib/pay/paddle_classic/webhooks/subscription_cancelled.rb,
lib/pay/braintree/webhooks/subscription_charged_successfully.rb,
lib/pay/paddle_classic/webhooks/subscription_payment_refunded.rb,
lib/pay/braintree/webhooks/subscription_charged_unsuccessfully.rb,
lib/pay/paddle_classic/webhooks/subscription_payment_succeeded.rb,
lib/pay/stripe/webhooks/checkout_session_async_payment_succeeded.rb

Overview

A subscription successfully moves to the next billing cycle. This will also occur when either a new transaction is created mid-cycle due to proration on an upgrade or a billing cycle is skipped due to the presence of a negative balance that covers the cost of the subscription.

Defined Under Namespace

Modules: Adapter, Attributes, Billable, Braintree, CurrencyHelper, Env, FakeProcessor, Generators, NanoId, PaddleBilling, PaddleClassic, Receipts, Stripe, Webhooks Classes: ActionRequired, ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Charge, Currency, Customer, CustomerSyncJob, Engine, Error, InvalidPaymentMethod, Merchant, Payment, PaymentError, PaymentMethod, PaymentsController, Subscription, UserMailer, Webhook

Constant Summary collapse

VERSION =
"7.1.1"
@@model_parent_class =
"ApplicationRecord"
@@automount_routes =
true
@@default_product_name =
"default"
@@default_plan_name =
"default"
@@routes_path =
"/pay"
@@enabled_processors =
[:stripe, :braintree, :paddle_billing, :paddle_classic]
@@send_emails =
true
@@emails =
ActiveSupport::OrderedOptions.new
@@mailer =
"Pay::UserMailer"
@@parent_mailer =
"Pay::ApplicationMailer"
@@mail_arguments =
-> {
  {
    to: instance_exec(&Pay.mail_to),
    subject: default_i18n_subject(application: Pay.application_name)
  }
}
@@mail_to =
-> {
  if ::ActionMailer::Base.respond_to?(:email_address_with_name)
    ::ActionMailer::Base.email_address_with_name(params[:pay_customer].email, params[:pay_customer].customer_name)
  else
    ::Mail::Address.new.tap do |builder|
      builder.address = params[:pay_customer].email
      builder.display_name = params[:pay_customer].customer_name.presence
    end.to_s
  end
}

Class Method Summary collapse

Class Method Details

.mailerObject



84
85
86
# File 'lib/pay.rb', line 84

def self.mailer
  @@mailer_ref ||= @@mailer&.constantize
end

.mailer=(value) ⇒ Object



79
80
81
82
# File 'lib/pay.rb', line 79

def self.mailer=(value)
  @@mailer = value
  @@mailer_ref = nil
end

.resolve_option(option, *remaining_args) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/pay.rb', line 126

def self.resolve_option(option, *remaining_args)
  if option.respond_to?(:call)
    option.call(*remaining_args)
  else
    option
  end
end

.send_email?(email_option, *remaining_args) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
120
121
122
123
124
# File 'lib/pay.rb', line 117

def self.send_email?(email_option, *remaining_args)
  if resolve_option(send_emails, *remaining_args)
    email_config_option_enabled = emails.send(email_option)
    resolve_option(email_config_option_enabled, *remaining_args)
  else
    false
  end
end

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

Yields:

  • (_self)

Yield Parameters:

  • _self (Pay)

    the object that the method was called on



113
114
115
# File 'lib/pay.rb', line 113

def self.setup
  yield self
end

.support_email=(value) ⇒ Object



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

def self.support_email=(value)
  @@support_email = value.is_a?(::Mail::Address) ? value : ::Mail::Address.new(value)
end