Class: Pay::PaddleClassic::Customer
- Inherits:
-
Customer
- Object
- Customer
- Pay::PaddleClassic::Customer
- Defined in:
- app/models/pay/paddle_classic/customer.rb
Instance Method Summary collapse
-
#add_payment_method(token = nil, default: true) ⇒ Object
Paddle does not use payment method tokens.
- #api_record ⇒ Object
- #charge(amount, options = {}) ⇒ Object
- #subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
- #update_api_record ⇒ Object
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.
43 44 45 |
# File 'app/models/pay/paddle_classic/customer.rb', line 43 def add_payment_method(token = nil, default: true) Pay::PaddleClassic::PaymentMethod.sync(pay_customer: self) end |
#api_record ⇒ Object
9 10 |
# File 'app/models/pay/paddle_classic/customer.rb', line 9 def api_record end |
#charge(amount, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/pay/paddle_classic/customer.rb', line 15 def charge(amount, = {}) 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 = charges.find_or_initialize_by(processor_id: response[:invoice_id]) charge.update(attributes) charge rescue ::Paddle::Error => e raise Pay::PaddleClassic::Error, e end |
#subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
37 38 39 |
# File 'app/models/pay/paddle_classic/customer.rb', line 37 def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **) # pass end |
#update_api_record ⇒ Object
12 13 |
# File 'app/models/pay/paddle_classic/customer.rb', line 12 def update_api_record end |