Class: Pay::PaddleClassic::Billable
- Inherits:
-
Object
- Object
- Pay::PaddleClassic::Billable
- Defined in:
- lib/pay/paddle_classic/billable.rb
Instance Attribute Summary collapse
-
#pay_customer ⇒ Object
readonly
Returns the value of attribute pay_customer.
Instance Method Summary collapse
-
#add_payment_method(token = nil, default: true) ⇒ Object
Paddle does not use payment method tokens.
- #charge(amount, options = {}) ⇒ Object
- #customer ⇒ Object
-
#initialize(pay_customer) ⇒ Billable
constructor
A new instance of Billable.
- #processor_subscription(subscription_id, options = {}) ⇒ Object
- #subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
- #trial_end_date(subscription) ⇒ Object
- #update_customer! ⇒ Object
Constructor Details
#initialize(pay_customer) ⇒ Billable
Returns a new instance of Billable.
13 14 15 |
# File 'lib/pay/paddle_classic/billable.rb', line 13 def initialize(pay_customer) @pay_customer = pay_customer end |
Instance Attribute Details
#pay_customer ⇒ Object (readonly)
Returns the value of attribute pay_customer.
4 5 6 |
# File 'lib/pay/paddle_classic/billable.rb', line 4 def pay_customer @pay_customer end |
Instance Method Details
#add_payment_method(token = nil, default: true) ⇒ Object
Paddle does not use payment method tokens. The method signature has it here to have a uniform API with the other payment processors.
54 55 56 |
# File 'lib/pay/paddle_classic/billable.rb', line 54 def add_payment_method(token = nil, default: true) Pay::PaddleClassic::PaymentMethod.sync(pay_customer: pay_customer) end |
#charge(amount, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pay/paddle_classic/billable.rb', line 25 def charge(amount, = {}) subscription = pay_customer.subscription return unless subscription.processor_id raise Pay::Error, "A charge_name is required to create a one-time charge" if [:charge_name].nil? response = PaddleClassic.client.charges.create(subscription_id: subscription.processor_id, amount: amount.to_f / 100, charge_name: [:charge_name]) attributes = { amount: (response[:amount].to_f * 100).to_i, paddle_receipt_url: response[:receipt_url], created_at: Time.zone.parse(response[:payment_date]) } # Lookup subscription payment method details attributes.merge! Pay::PaddleClassic::PaymentMethod.payment_method_details_for(subscription_id: subscription.processor_id) charge = pay_customer.charges.find_or_initialize_by(processor_id: response[:invoice_id]) charge.update(attributes) charge rescue ::Paddle::Error => e raise Pay::PaddleClassic::Error, e end |
#customer ⇒ Object
17 18 19 |
# File 'lib/pay/paddle_classic/billable.rb', line 17 def customer # pass end |
#processor_subscription(subscription_id, options = {}) ⇒ Object
63 64 65 66 67 |
# File 'lib/pay/paddle_classic/billable.rb', line 63 def processor_subscription(subscription_id, = {}) PaddleClassic.client.users.list(subscription_id: subscription_id).data.try(:first) rescue ::Paddle::Error => e raise Pay::PaddleClassic::Error, e end |
#subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
48 49 50 |
# File 'lib/pay/paddle_classic/billable.rb', line 48 def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **) # pass end |
#trial_end_date(subscription) ⇒ Object
58 59 60 61 |
# File 'lib/pay/paddle_classic/billable.rb', line 58 def trial_end_date(subscription) return unless subscription.state == "trialing" Time.zone.parse(subscription.next_payment[:date]).end_of_day end |
#update_customer! ⇒ Object
21 22 23 |
# File 'lib/pay/paddle_classic/billable.rb', line 21 def update_customer! # pass end |