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_plan.rb,
app/services/payola/create_sale.rb,
app/services/payola/update_card.rb,
app/models/payola/stripe_webhook.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/models/concerns/payola/sellable.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/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/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, ChangeSubscriptionPlan, ChangeSubscriptionQuantity, ChargeCard, Coupon, CreatePlan, CreateSale, CreateSubscription, Engine, EnvWrapper, InstallGenerator, InvoiceFailed, InvoicePaid, ProcessSale, ProcessSubscription, ReceiptMailer, Retriever, Sale, SendMail, StartSubscription, StripeWebhook, Subscription, SubscriptionsController, SyncSubscription, TransactionsController, UpdateCard, 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.3.2"
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.
-
.default_currency ⇒ Object
Returns the value of attribute default_currency.
-
.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 |
.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 |
.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
55 56 57 |
# File 'lib/payola.rb', line 55 def all(callable = Proc.new) StripeEvent.all(callable) end |
.configure(&block) ⇒ Object
34 35 36 37 |
# File 'lib/payola.rb', line 34 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
51 52 53 |
# File 'lib/payola.rb', line 51 def instrument(name, object) StripeEvent.backend.instrument(StripeEvent.namespace.call(name), object) end |
.publishable_key_for_sale(sale) ⇒ Object
43 44 45 |
# File 'lib/payola.rb', line 43 def publishable_key_for_sale(sale) return publishable_key_retriever.call(sale).to_s end |
.queue!(klass, *args) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/payola.rb', line 59 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
93 94 95 |
# File 'lib/payola.rb', line 93 def register_sellable(klass) sellables[klass.product_class] = klass end |
.register_subscribable(klass) ⇒ Object
97 98 99 |
# File 'lib/payola.rb', line 97 def register_subscribable(klass) subscribables[klass.plan_class] = klass end |
.reset! ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/payola.rb', line 73 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.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) } end |
.secret_key_for_sale(sale) ⇒ Object
39 40 41 |
# File 'lib/payola.rb', line 39 def secret_key_for_sale(sale) return secret_key_retriever.call(sale).to_s end |
.send_email_for(*emails) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/payola.rb', line 101 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
69 70 71 |
# File 'lib/payola.rb', line 69 def send_mail(mailer, method, *args) Payola.queue!(Payola::SendMail, mailer.to_s, method.to_s, *args) end |
.subscribe(name, callable = Proc.new) ⇒ Object
47 48 49 |
# File 'lib/payola.rb', line 47 def subscribe(name, callable = Proc.new) StripeEvent.subscribe(name, callable) end |