Module: Pay::Paddle::Billable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/pay/paddle/billable.rb
Instance Method Summary collapse
- #create_paddle_charge(amount, options = {}) ⇒ Object
- #create_paddle_subscription(name, plan, options = {}) ⇒ Object
- #paddle_customer ⇒ Object
- #paddle_invoice!(options = {}) ⇒ Object
- #paddle_payment_information(subscription_id) ⇒ Object
- #paddle_subscription(subscription_id, options = {}) ⇒ Object
- #paddle_trial_end_date(subscription) ⇒ Object
- #paddle_upcoming_invoice ⇒ Object
- #sync_payment_information_from_paddle ⇒ Object
- #update_paddle_card(token) ⇒ Object
- #update_paddle_email! ⇒ Object
Instance Method Details
#create_paddle_charge(amount, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pay/paddle/billable.rb', line 14 def create_paddle_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 = PaddlePay::Subscription::Charge.create(subscription.processor_id, amount.to_f / 100, [:charge_name], ) charge = charges.find_or_initialize_by( processor: :paddle, processor_id: response[:invoice_id] ) charge.update( amount: Integer(response[:amount].to_f * 100), card_type: subscription.processor_subscription.payment_information[:payment_method], paddle_receipt_url: response[:receipt_url], created_at: Time.zone.parse(response[:payment_date]) ) charge rescue ::PaddlePay::PaddlePayError => e raise Pay::Paddle::Error, e end |
#create_paddle_subscription(name, plan, options = {}) ⇒ Object
33 34 35 |
# File 'lib/pay/paddle/billable.rb', line 33 def create_paddle_subscription(name, plan, = {}) # pass end |
#paddle_customer ⇒ Object
10 11 12 |
# File 'lib/pay/paddle/billable.rb', line 10 def paddle_customer # pass end |
#paddle_invoice!(options = {}) ⇒ Object
57 58 59 |
# File 'lib/pay/paddle/billable.rb', line 57 def paddle_invoice!( = {}) # pass end |
#paddle_payment_information(subscription_id) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/pay/paddle/billable.rb', line 72 def paddle_payment_information(subscription_id) subscription_user = PaddlePay::Subscription::User.list({subscription_id: subscription_id}).try(:first) payment_information = subscription_user ? subscription_user[:payment_information] : nil return {} if payment_information.nil? case payment_information[:payment_method] when "card" { card_type: payment_information[:card_type], card_last4: payment_information[:last_four_digits], card_exp_month: payment_information[:expiry_date].split("/").first, card_exp_year: payment_information[:expiry_date].split("/").last } when "paypal" { card_type: "PayPal" } else {} end end |
#paddle_subscription(subscription_id, options = {}) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/pay/paddle/billable.rb', line 50 def paddle_subscription(subscription_id, = {}) hash = PaddlePay::Subscription::User.list({subscription_id: subscription_id}, ).try(:first) OpenStruct.new(hash) rescue ::PaddlePay::PaddlePayError => e raise Pay::Paddle::Error, e end |
#paddle_trial_end_date(subscription) ⇒ Object
45 46 47 48 |
# File 'lib/pay/paddle/billable.rb', line 45 def paddle_trial_end_date(subscription) return unless subscription.state == "trialing" Time.zone.parse(subscription.next_payment[:date]).end_of_day end |
#paddle_upcoming_invoice ⇒ Object
61 62 63 |
# File 'lib/pay/paddle/billable.rb', line 61 def paddle_upcoming_invoice # pass end |
#sync_payment_information_from_paddle ⇒ Object
65 66 67 68 69 70 |
# File 'lib/pay/paddle/billable.rb', line 65 def sync_payment_information_from_paddle payment_information = paddle_payment_information(subscription.processor_id) update!(payment_information) unless payment_information.empty? rescue ::PaddlePay::PaddlePayError => e raise Pay::Paddle::Error, e end |
#update_paddle_card(token) ⇒ Object
37 38 39 |
# File 'lib/pay/paddle/billable.rb', line 37 def update_paddle_card(token) sync_payment_information_from_paddle end |
#update_paddle_email! ⇒ Object
41 42 43 |
# File 'lib/pay/paddle/billable.rb', line 41 def update_paddle_email! # pass end |