Module: Payola
- Defined in:
- lib/payola.rb,
lib/payola/engine.rb,
lib/payola/worker.rb,
lib/payola/version.rb,
app/models/payola/sale.rb,
lib/payola/worker/base.rb,
app/models/payola/coupon.rb,
lib/payola/worker/sidekiq.rb,
app/models/payola/affiliate.rb,
lib/payola/worker/active_job.rb,
app/services/payola/send_mail.rb,
app/models/payola/subscription.rb,
lib/payola/worker/sucker_punch.rb,
app/helpers/payola/price_helper.rb,
app/mailers/payola/admin_mailer.rb,
app/models/concerns/payola/plan.rb,
app/services/payola/charge_card.rb,
app/services/payola/create_card.rb,
app/services/payola/create_plan.rb,
app/services/payola/create_sale.rb,
app/services/payola/update_card.rb,
app/models/payola/stripe_webhook.rb,
app/services/payola/destroy_card.rb,
app/services/payola/invoice_paid.rb,
app/services/payola/process_sale.rb,
app/mailers/payola/receipt_mailer.rb,
app/services/payola/invoice_failed.rb,
app/services/payola/process_refund.rb,
app/models/concerns/payola/sellable.rb,
app/services/payola/update_customer.rb,
app/services/payola/invoice_behavior.rb,
app/helpers/payola/application_helper.rb,
app/services/payola/sync_subscription.rb,
app/services/payola/start_subscription.rb,
app/controllers/payola/cards_controller.rb,
app/services/payola/cancel_subscription.rb,
app/services/payola/create_subscription.rb,
app/services/payola/update_subscription.rb,
lib/generators/payola/install_generator.rb,
app/models/concerns/payola/guid_behavior.rb,
app/services/payola/process_subscription.rb,
app/services/payola/subscription_deleted.rb,
app/controllers/payola/customers_controller.rb,
app/services/payola/change_subscription_plan.rb,
app/controllers/payola/application_controller.rb,
app/controllers/concerns/payola/async_behavior.rb,
app/controllers/payola/transactions_controller.rb,
app/controllers/concerns/payola/status_behavior.rb,
app/controllers/payola/subscriptions_controller.rb,
app/services/payola/change_subscription_quantity.rb,
app/controllers/concerns/payola/affiliate_behavior.rb
Defined Under Namespace
Modules: AffiliateBehavior, ApplicationHelper, AsyncBehavior, GuidBehavior, InvoiceBehavior, Plan, PriceHelper, Sellable, StatusBehavior, Worker Classes: AdminMailer, Affiliate, ApplicationController, CancelSubscription, CardsController, ChangeSubscriptionPlan, ChangeSubscriptionQuantity, ChargeCard, Coupon, CreateCard, CreatePlan, CreateSale, CreateSubscription, CustomersController, DestroyCard, Engine, EnvWrapper, InstallGenerator, InvoiceFailed, InvoicePaid, ProcessRefund, ProcessSale, ProcessSubscription, ReceiptMailer, Retriever, Sale, SendMail, StartSubscription, StripeWebhook, Subscription, SubscriptionDeleted, SubscriptionsController, SyncSubscription, TransactionsController, UpdateCard, UpdateCustomer, UpdateSubscription
Constant Summary collapse
- DEFAULT_EMAILS =
{ receipt: [ 'payola.sale.finished', 'Payola::ReceiptMailer', :receipt ], refund: [ 'charge.refunded', 'Payola::ReceiptMailer', :refund ], admin_receipt: [ 'payola.sale.finished', 'Payola::AdminMailer', :receipt ], admin_dispute: [ 'dispute.created', 'Payola::AdminMailer', :dispute ], admin_refund: [ 'payola.sale.refunded', 'Payola::AdminMailer', :refund ], admin_failure: [ 'payola.sale.failed', 'Payola::AdminMailer', :failure ], }
- VERSION =
"1.5.0"
Class Attribute Summary collapse
-
.additional_charge_attributes ⇒ Object
Returns the value of attribute additional_charge_attributes.
-
.background_worker ⇒ Object
Returns the value of attribute background_worker.
-
.charge_verifier ⇒ Object
Returns the value of attribute charge_verifier.
-
.create_stripe_plans ⇒ Object
Returns the value of attribute create_stripe_plans.
-
.default_currency ⇒ Object
Returns the value of attribute default_currency.
-
.default_tax_percent ⇒ Object
Returns the value of attribute default_tax_percent.
-
.event_filter ⇒ Object
Returns the value of attribute event_filter.
-
.guid_generator ⇒ Object
Returns the value of attribute guid_generator.
-
.pdf_receipt ⇒ Object
Returns the value of attribute pdf_receipt.
-
.publishable_key ⇒ Object
Returns the value of attribute publishable_key.
-
.publishable_key_retriever ⇒ Object
Returns the value of attribute publishable_key_retriever.
-
.secret_key ⇒ Object
Returns the value of attribute secret_key.
-
.secret_key_retriever ⇒ Object
Returns the value of attribute secret_key_retriever.
-
.sellables ⇒ Object
Returns the value of attribute sellables.
-
.subscribables ⇒ Object
Returns the value of attribute subscribables.
-
.support_email ⇒ Object
Returns the value of attribute support_email.
Class Method Summary collapse
- .all(callable = Proc.new) ⇒ Object
- .configure(&block) ⇒ Object
- .instrument(name, object) ⇒ Object
- .publishable_key_for_sale(sale) ⇒ Object
- .queue!(klass, *args) ⇒ Object
- .register_sellable(klass) ⇒ Object
- .register_subscribable(klass) ⇒ Object
- .reset! ⇒ Object
- .secret_key_for_sale(sale) ⇒ Object
- .send_email_for(*emails) ⇒ Object
- .send_mail(mailer, method, *args) ⇒ Object
- .subscribe(name, callable = Proc.new) ⇒ Object
Class Attribute Details
.additional_charge_attributes ⇒ Object
Returns the value of attribute additional_charge_attributes.
19 20 21 |
# File 'lib/payola.rb', line 19 def additional_charge_attributes @additional_charge_attributes end |
.background_worker ⇒ Object
Returns the value of attribute background_worker.
19 20 21 |
# File 'lib/payola.rb', line 19 def background_worker @background_worker end |
.charge_verifier ⇒ Object
Returns the value of attribute charge_verifier.
19 20 21 |
# File 'lib/payola.rb', line 19 def charge_verifier @charge_verifier end |
.create_stripe_plans ⇒ Object
Returns the value of attribute create_stripe_plans.
19 20 21 |
# File 'lib/payola.rb', line 19 def create_stripe_plans @create_stripe_plans end |
.default_currency ⇒ Object
Returns the value of attribute default_currency.
19 20 21 |
# File 'lib/payola.rb', line 19 def default_currency @default_currency end |
.default_tax_percent ⇒ Object
Returns the value of attribute default_tax_percent.
19 20 21 |
# File 'lib/payola.rb', line 19 def default_tax_percent @default_tax_percent end |
.event_filter ⇒ Object
Returns the value of attribute event_filter.
19 20 21 |
# File 'lib/payola.rb', line 19 def event_filter @event_filter end |
.guid_generator ⇒ Object
Returns the value of attribute guid_generator.
19 20 21 |
# File 'lib/payola.rb', line 19 def guid_generator @guid_generator end |
.pdf_receipt ⇒ Object
Returns the value of attribute pdf_receipt.
19 20 21 |
# File 'lib/payola.rb', line 19 def pdf_receipt @pdf_receipt end |
.publishable_key ⇒ Object
Returns the value of attribute publishable_key.
19 20 21 |
# File 'lib/payola.rb', line 19 def publishable_key @publishable_key end |
.publishable_key_retriever ⇒ Object
Returns the value of attribute publishable_key_retriever.
19 20 21 |
# File 'lib/payola.rb', line 19 def publishable_key_retriever @publishable_key_retriever end |
.secret_key ⇒ Object
Returns the value of attribute secret_key.
19 20 21 |
# File 'lib/payola.rb', line 19 def secret_key @secret_key end |
.secret_key_retriever ⇒ Object
Returns the value of attribute secret_key_retriever.
19 20 21 |
# File 'lib/payola.rb', line 19 def secret_key_retriever @secret_key_retriever end |
.sellables ⇒ Object
Returns the value of attribute sellables.
19 20 21 |
# File 'lib/payola.rb', line 19 def sellables @sellables end |
.subscribables ⇒ Object
Returns the value of attribute subscribables.
19 20 21 |
# File 'lib/payola.rb', line 19 def subscribables @subscribables end |
.support_email ⇒ Object
Returns the value of attribute support_email.
19 20 21 |
# File 'lib/payola.rb', line 19 def support_email @support_email end |
Class Method Details
.all(callable = Proc.new) ⇒ Object
57 58 59 |
# File 'lib/payola.rb', line 57 def all(callable = Proc.new) StripeEvent.all(callable) end |
.configure(&block) ⇒ Object
36 37 38 39 |
# File 'lib/payola.rb', line 36 def configure(&block) raise ArgumentError, "must provide a block" unless block_given? block.arity.zero? ? instance_eval(&block) : yield(self) end |
.instrument(name, object) ⇒ Object
53 54 55 |
# File 'lib/payola.rb', line 53 def instrument(name, object) StripeEvent.backend.instrument(StripeEvent.namespace.call(name), object) end |
.publishable_key_for_sale(sale) ⇒ Object
45 46 47 |
# File 'lib/payola.rb', line 45 def publishable_key_for_sale(sale) return publishable_key_retriever.call(sale).to_s end |
.queue!(klass, *args) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/payola.rb', line 61 def queue!(klass, *args) if background_worker.is_a? Symbol Payola::Worker.find(background_worker).call(klass, *args) elsif background_worker.respond_to?(:call) background_worker.call(klass, *args) else Payola::Worker.autofind.call(klass, *args) end end |
.register_sellable(klass) ⇒ Object
97 98 99 |
# File 'lib/payola.rb', line 97 def register_sellable(klass) sellables[klass.product_class] = klass end |
.register_subscribable(klass) ⇒ Object
101 102 103 |
# File 'lib/payola.rb', line 101 def register_subscribable(klass) subscribables[klass.plan_class] = klass end |
.reset! ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/payola.rb', line 75 def reset! StripeEvent.event_retriever = Retriever Stripe.api_version = ENV['STRIPE_API_VERSION'] || '2015-02-18' self.background_worker = nil self.event_filter = lambda { |event| event } self.charge_verifier = lambda { |event| true } self.publishable_key = EnvWrapper.new('STRIPE_PUBLISHABLE_KEY') self.secret_key = EnvWrapper.new('STRIPE_SECRET_KEY') self.secret_key_retriever = lambda { |sale| Payola.secret_key } self.publishable_key_retriever = lambda { |sale| Payola.publishable_key } self.support_email = '[email protected]' self.default_currency = 'usd' self.default_tax_percent = nil self.sellables = {} self.subscribables = {} self.additional_charge_attributes = lambda { |sale, customer| { } } self.pdf_receipt = false self.guid_generator = lambda { SecureRandom.random_number(1_000_000_000).to_s(32) } self.create_stripe_plans = true end |
.secret_key_for_sale(sale) ⇒ Object
41 42 43 |
# File 'lib/payola.rb', line 41 def secret_key_for_sale(sale) return secret_key_retriever.call(sale).to_s end |
.send_email_for(*emails) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/payola.rb', line 105 def send_email_for(*emails) emails.each do |email| spec = DEFAULT_EMAILS[email].dup if spec Payola.subscribe(spec.shift) do |sale| if sale.is_a?(Stripe::Event) sale = Payola::Sale.find_by!(stripe_id: sale.data.object.id) end Payola.send_mail(*(spec + [sale.guid])) end end end end |
.send_mail(mailer, method, *args) ⇒ Object
71 72 73 |
# File 'lib/payola.rb', line 71 def send_mail(mailer, method, *args) Payola.queue!(Payola::SendMail, mailer.to_s, method.to_s, *args) end |
.subscribe(name, callable = Proc.new) ⇒ Object
49 50 51 |
# File 'lib/payola.rb', line 49 def subscribe(name, callable = Proc.new) StripeEvent.subscribe(name, callable) end |