pay 4.0.4 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pay might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/models/pay/charge.rb +2 -0
- data/app/models/pay/subscription.rb +16 -2
- data/config/locales/en.yml +1 -0
- data/lib/pay/paddle/subscription.rb +2 -2
- data/lib/pay/receipts.rb +17 -4
- data/lib/pay/stripe/charge.rb +5 -2
- data/lib/pay/stripe/subscription.rb +9 -1
- data/lib/pay/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 21dbf64c59853ff5226ba4896f3d25c29625182637cc4ac43f9eaffb60433ec7
         | 
| 4 | 
            +
              data.tar.gz: e0cd4bfa462306aa0ddf15244a2d536c36a97e45b2d4acb2564cee9c8143351b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e3b007b3190cb534dec8953486a21fca0b9fe82d26a1caa80dc27a405f835bbb8424c034508e8adc5f36ce3d9ae526a4334d1a5a315b43ebba472dc60f0772f1
         | 
| 7 | 
            +
              data.tar.gz: 0f0390f51f53fad304ceb5866d1f68a3a5af7272ce33403c27b0362e916d0ad20de756f77a3375f466ec8866d0d2a97e006a15c6dd3f18ac221fb4fc10d3f467
         | 
    
        data/app/models/pay/charge.rb
    CHANGED
    
    | @@ -41,6 +41,8 @@ module Pay | |
| 41 41 | 
             
                store_accessor :data, :discounts # array of discount IDs applied to the Stripe Invoice
         | 
| 42 42 | 
             
                store_accessor :data, :total_discount_amounts # array of discount details
         | 
| 43 43 | 
             
                store_accessor :data, :total_tax_amounts # array of tax details for each jurisdiction
         | 
| 44 | 
            +
                store_accessor :data, :credit_notes # array of credit notes for the Stripe Invoice
         | 
| 45 | 
            +
                store_accessor :data, :refunds # array of refunds
         | 
| 44 46 |  | 
| 45 47 | 
             
                # Helpers for payment processors
         | 
| 46 48 | 
             
                %w[braintree stripe paddle fake_processor].each do |processor_name|
         | 
| @@ -11,7 +11,9 @@ module Pay | |
| 11 11 | 
             
                scope :on_trial, -> { where.not(trial_ends_at: nil).where("#{table_name}.trial_ends_at > ?", Time.zone.now) }
         | 
| 12 12 | 
             
                scope :cancelled, -> { where.not(ends_at: nil) }
         | 
| 13 13 | 
             
                scope :on_grace_period, -> { cancelled.where("#{table_name}.ends_at > ?", Time.zone.now) }
         | 
| 14 | 
            -
                 | 
| 14 | 
            +
                # Stripe considers paused subscriptions to be active, therefore we reflect that in this scope and
         | 
| 15 | 
            +
                # make it consistent across all processors
         | 
| 16 | 
            +
                scope :active, -> { where(status: ["trialing", "active", "paused"], ends_at: nil).or(on_grace_period).or(on_trial) }
         | 
| 15 17 | 
             
                scope :incomplete, -> { where(status: :incomplete) }
         | 
| 16 18 | 
             
                scope :past_due, -> { where(status: :past_due) }
         | 
| 17 19 | 
             
                scope :with_active_customer, -> { joins(:customer).merge(Customer.active) }
         | 
| @@ -49,6 +51,18 @@ module Pay | |
| 49 51 | 
             
                  scope processor_name, -> { joins(:customer).where(pay_customers: {processor: processor_name}) }
         | 
| 50 52 | 
             
                end
         | 
| 51 53 |  | 
| 54 | 
            +
                def self.active_without_paused
         | 
| 55 | 
            +
                  case Pay::Adapter.current_adapter
         | 
| 56 | 
            +
                  when "postgresql", "postgis"
         | 
| 57 | 
            +
                    active.where("data->>'pause_behavior' IS NULL AND status != 'paused'")
         | 
| 58 | 
            +
                  when "mysql2"
         | 
| 59 | 
            +
                    active.where("data->>'$.pause_behavior' IS NULL AND status != 'paused'")
         | 
| 60 | 
            +
                  when "sqlite3"
         | 
| 61 | 
            +
                    # sqlite 3.38 supports ->> syntax, however, sqlite 3.37 is what ships with Ubuntu 22.04.
         | 
| 62 | 
            +
                    active.where("json_extract(data, '$.pause_behavior') IS NULL AND status != 'paused'")
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 52 66 | 
             
                def self.with_metered_items
         | 
| 53 67 | 
             
                  case Pay::Adapter.current_adapter
         | 
| 54 68 | 
             
                  when "sqlite3"
         | 
| @@ -108,7 +122,7 @@ module Pay | |
| 108 122 | 
             
                end
         | 
| 109 123 |  | 
| 110 124 | 
             
                def active?
         | 
| 111 | 
            -
                  ["trialing", "active"].include?(status) && (ends_at.nil? || on_grace_period? || on_trial?)
         | 
| 125 | 
            +
                  ["trialing", "active", "paused"].include?(status) && (ends_at.nil? || on_grace_period? || on_trial?)
         | 
| 112 126 | 
             
                end
         | 
| 113 127 |  | 
| 114 128 | 
             
                def past_due?
         | 
    
        data/config/locales/en.yml
    CHANGED
    
    
| @@ -107,13 +107,13 @@ module Pay | |
| 107 107 | 
             
                  end
         | 
| 108 108 |  | 
| 109 109 | 
             
                  def paused?
         | 
| 110 | 
            -
                     | 
| 110 | 
            +
                    pay_subscription.status == "paused"
         | 
| 111 111 | 
             
                  end
         | 
| 112 112 |  | 
| 113 113 | 
             
                  def pause
         | 
| 114 114 | 
             
                    attributes = {pause: true}
         | 
| 115 115 | 
             
                    response = PaddlePay::Subscription::User.update(processor_id, attributes)
         | 
| 116 | 
            -
                    pay_subscription.update(paddle_paused_from: Time.zone.parse(response.dig(:next_payment, :date)))
         | 
| 116 | 
            +
                    pay_subscription.update(status: :paused, paddle_paused_from: Time.zone.parse(response.dig(:next_payment, :date)))
         | 
| 117 117 | 
             
                  rescue ::PaddlePay::PaddlePayError => e
         | 
| 118 118 | 
             
                    raise Pay::Paddle::Error, e
         | 
| 119 119 | 
             
                  end
         | 
    
        data/lib/pay/receipts.rb
    CHANGED
    
    | @@ -86,16 +86,29 @@ module Pay | |
| 86 86 | 
             
                  "#{tax_rate["display_name"]} - #{tax_rate["jurisdiction"]} (#{percent})"
         | 
| 87 87 | 
             
                end
         | 
| 88 88 |  | 
| 89 | 
            -
                def  | 
| 90 | 
            -
                   | 
| 89 | 
            +
                def receipt_line_items
         | 
| 90 | 
            +
                  line_items = pdf_line_items
         | 
| 91 91 |  | 
| 92 92 | 
             
                  # Include total paid
         | 
| 93 | 
            -
                   | 
| 93 | 
            +
                  line_items << [nil, nil, I18n.t("pay.receipt.amount_paid"), Pay::Currency.format(amount, currency: currency)]
         | 
| 94 94 |  | 
| 95 95 | 
             
                  if refunded?
         | 
| 96 | 
            -
                     | 
| 96 | 
            +
                    # If we have a list of individual refunds, add each entry
         | 
| 97 | 
            +
                    if refunds&.any?
         | 
| 98 | 
            +
                      refunds.each do |refund|
         | 
| 99 | 
            +
                        next unless refund["status"] == "succeeded"
         | 
| 100 | 
            +
                        refunded_at = Time.at(refund["created"]).to_date
         | 
| 101 | 
            +
                        line_items << [nil, nil, I18n.t("pay.receipt.refunded_on", date: I18n.l(refunded_at, format: :long)), Pay::Currency.format(refund["amount"], currency: refund["currency"])]
         | 
| 102 | 
            +
                      end
         | 
| 103 | 
            +
                    else
         | 
| 104 | 
            +
                      line_items << [nil, nil, I18n.t("pay.receipt.refunded"), Pay::Currency.format(amount_refunded, currency: currency)]
         | 
| 105 | 
            +
                    end
         | 
| 97 106 | 
             
                  end
         | 
| 98 107 |  | 
| 108 | 
            +
                  line_items
         | 
| 109 | 
            +
                end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                def receipt_pdf(**options)
         | 
| 99 112 | 
             
                  defaults = {
         | 
| 100 113 | 
             
                    details: receipt_details,
         | 
| 101 114 | 
             
                    recipient: [
         | 
    
        data/lib/pay/stripe/charge.rb
    CHANGED
    
    | @@ -22,6 +22,9 @@ module Pay | |
| 22 22 | 
             
                    pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
         | 
| 23 23 | 
             
                    return unless pay_customer
         | 
| 24 24 |  | 
| 25 | 
            +
                    refunds = []
         | 
| 26 | 
            +
                    object.refunds.auto_paging_each { |refund| refunds << refund }
         | 
| 27 | 
            +
             | 
| 25 28 | 
             
                    payment_method = object.payment_method_details.send(object.payment_method_details.type)
         | 
| 26 29 | 
             
                    attrs = {
         | 
| 27 30 | 
             
                      amount: object.amount,
         | 
| @@ -42,7 +45,8 @@ module Pay | |
| 42 45 | 
             
                      payment_method_type: object.payment_method_details.type,
         | 
| 43 46 | 
             
                      stripe_account: pay_customer.stripe_account,
         | 
| 44 47 | 
             
                      stripe_receipt_url: object.receipt_url,
         | 
| 45 | 
            -
                      total_tax_amounts: []
         | 
| 48 | 
            +
                      total_tax_amounts: [],
         | 
| 49 | 
            +
                      refunds: refunds.sort_by! { |r| r["created"] }
         | 
| 46 50 | 
             
                    }
         | 
| 47 51 |  | 
| 48 52 | 
             
                    # Associate charge with subscription if we can
         | 
| @@ -75,7 +79,6 @@ module Pay | |
| 75 79 | 
             
                          period_end: Time.at(line_item.period.end)
         | 
| 76 80 | 
             
                        }
         | 
| 77 81 | 
             
                      end
         | 
| 78 | 
            -
             | 
| 79 82 | 
             
                    # Charges without invoices
         | 
| 80 83 | 
             
                    else
         | 
| 81 84 | 
             
                      attrs[:period_start] = Time.at(object.created)
         | 
| @@ -100,7 +100,15 @@ module Pay | |
| 100 100 |  | 
| 101 101 | 
             
                  # Common expand options for all requests that create, retrieve, or update a Stripe Subscription
         | 
| 102 102 | 
             
                  def self.expand_options
         | 
| 103 | 
            -
                    { | 
| 103 | 
            +
                    {
         | 
| 104 | 
            +
                      expand: [
         | 
| 105 | 
            +
                        "pending_setup_intent",
         | 
| 106 | 
            +
                        "latest_invoice.payment_intent",
         | 
| 107 | 
            +
                        "latest_invoice.charge",
         | 
| 108 | 
            +
                        "latest_invoice.total_discount_amounts.discount",
         | 
| 109 | 
            +
                        "latest_invoice.total_tax_amounts.tax_rate"
         | 
| 110 | 
            +
                      ]
         | 
| 111 | 
            +
                    }
         | 
| 104 112 | 
             
                  end
         | 
| 105 113 |  | 
| 106 114 | 
             
                  def initialize(pay_subscription)
         | 
    
        data/lib/pay/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: pay
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 4.0 | 
| 4 | 
            +
              version: 4.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jason Charnes
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire:
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2022-07- | 
| 12 | 
            +
            date: 2022-07-29 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: rails
         |