effective_orders 4.0.0beta14 → 4.0.0beta15
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.
- checksums.yaml +4 -4
- data/app/controllers/effective/webhooks_controller.rb +2 -2
- data/app/helpers/effective_subscriptions_helper.rb +2 -0
- data/app/models/concerns/acts_as_subscribable_buyer.rb +1 -1
- data/app/models/effective/customer.rb +3 -3
- data/app/models/effective/subscripter.rb +9 -9
- data/lib/effective_orders.rb +1 -5
- data/lib/effective_orders/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9a0e364b3f29eb0d7dedd6924f79f88238e53f4e
         | 
| 4 | 
            +
              data.tar.gz: 565609c4fe438073afae83e024d5293c8c74f573
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0f9da56ad6b265343c14085799645fa2317a0bae30cfd663798ce3e3c51fa12e77c3f5d5febf75b879c9a0d6bd4225895ffba43a70a4d47bd1705b09ed37b1d6
         | 
| 7 | 
            +
              data.tar.gz: baf112b92894922d3dd4ca968430a1e39ec310e1b145990e580d057e55994e87ba640807556bd18c5edb8a720e8a9ce935e315593df77fe9372bb0b75c40ceda
         | 
| @@ -21,7 +21,7 @@ module Effective | |
| 21 21 | 
             
                    (head(:bad_request) and return) if (params[:livemode] == false && Rails.env.production?)
         | 
| 22 22 | 
             
                  end
         | 
| 23 23 |  | 
| 24 | 
            -
                  Rails.logger.info "STRIPE  | 
| 24 | 
            +
                  Rails.logger.info "[STRIPE] webhook received: #{@event.type}"
         | 
| 25 25 |  | 
| 26 26 | 
             
                  Effective::Customer.transaction do
         | 
| 27 27 | 
             
                    case @event.type
         | 
| @@ -56,7 +56,7 @@ module Effective | |
| 56 56 | 
             
                    when 'customer.subscription.updated'
         | 
| 57 57 | 
             
                      send_email(:subscription_updated, customer)
         | 
| 58 58 | 
             
                    else
         | 
| 59 | 
            -
                      Rails.logger.info "[STRIPE | 
| 59 | 
            +
                      Rails.logger.info "[STRIPE] webhook unhandled event type: #{@event.type}"
         | 
| 60 60 | 
             
                    end
         | 
| 61 61 | 
             
                  end
         | 
| 62 62 |  | 
| @@ -19,6 +19,8 @@ module EffectiveSubscriptionsHelper | |
| 19 19 | 
             
                  partial = (
         | 
| 20 20 | 
             
                    if lookup_context.template_exists?("effective/subscriptions/#{plan[:id].downcase}", [], true)
         | 
| 21 21 | 
             
                      "effective/subscriptions/#{plan[:id].downcase}" # Render the app's views/effective/subscriptions/_gold.html.haml
         | 
| 22 | 
            +
                    elsif lookup_context.template_exists?("effective/subscriptions/#{plan[:name].downcase}", [], true)
         | 
| 23 | 
            +
                      "effective/subscriptions/#{plan[:name].downcase}" # Render the app's views/effective/subscriptions/_gold.html.haml
         | 
| 22 24 | 
             
                    else
         | 
| 23 25 | 
             
                      'effective/subscriptions/plan' # Render effective_orders default plan panel
         | 
| 24 26 | 
             
                    end
         | 
| @@ -11,7 +11,7 @@ module ActsAsSubscribableBuyer | |
| 11 11 | 
             
                has_one :customer, class_name: 'Effective::Customer'
         | 
| 12 12 |  | 
| 13 13 | 
             
                before_save(if: -> { persisted? && email_changed? && customer.present? }) do
         | 
| 14 | 
            -
                  Rails.logger.info "STRIPE  | 
| 14 | 
            +
                  Rails.logger.info "[STRIPE] update customer: #{customer.stripe_customer_id}"
         | 
| 15 15 | 
             
                  customer.stripe_customer.email = email
         | 
| 16 16 | 
             
                  customer.stripe_customer.description = to_s
         | 
| 17 17 | 
             
                  throw :abort unless (customer.stripe_customer.save rescue false)
         | 
| @@ -38,21 +38,21 @@ module Effective | |
| 38 38 |  | 
| 39 39 | 
             
                def stripe_customer
         | 
| 40 40 | 
             
                  @stripe_customer ||= if stripe_customer_id.present?
         | 
| 41 | 
            -
                    Rails.logger.info "STRIPE  | 
| 41 | 
            +
                    Rails.logger.info "[STRIPE] get customer: #{stripe_customer_id}"
         | 
| 42 42 | 
             
                    ::Stripe::Customer.retrieve(stripe_customer_id)
         | 
| 43 43 | 
             
                  end
         | 
| 44 44 | 
             
                end
         | 
| 45 45 |  | 
| 46 46 | 
             
                def stripe_subscription
         | 
| 47 47 | 
             
                  @stripe_subscription ||= if stripe_subscription_id.present?
         | 
| 48 | 
            -
                    Rails.logger.info "STRIPE  | 
| 48 | 
            +
                    Rails.logger.info "[STRIPE] get subscription: #{stripe_subscription_id}"
         | 
| 49 49 | 
             
                    ::Stripe::Subscription.retrieve(stripe_subscription_id)
         | 
| 50 50 | 
             
                  end
         | 
| 51 51 | 
             
                end
         | 
| 52 52 |  | 
| 53 53 | 
             
                def upcoming_invoice
         | 
| 54 54 | 
             
                  @upcoming_invoice ||= if stripe_customer_id.present? && stripe_subscription_id.present?
         | 
| 55 | 
            -
                    Rails.logger.info "STRIPE  | 
| 55 | 
            +
                    Rails.logger.info "[STRIPE] get upcoming invoice: #{stripe_customer_id}"
         | 
| 56 56 | 
             
                    ::Stripe::Invoice.upcoming(customer: stripe_customer_id) rescue nil
         | 
| 57 57 | 
             
                  end
         | 
| 58 58 | 
             
                end
         | 
| @@ -75,7 +75,7 @@ module Effective | |
| 75 75 | 
             
                # This should work even if the rest of the form doesn't. Careful with our transactions...
         | 
| 76 76 | 
             
                def create_customer!
         | 
| 77 77 | 
             
                  if customer.stripe_customer.blank?
         | 
| 78 | 
            -
                    Rails.logger.info "STRIPE  | 
| 78 | 
            +
                    Rails.logger.info "[STRIPE] create customer: #{user.email}"
         | 
| 79 79 | 
             
                    customer.stripe_customer = Stripe::Customer.create(email: user.email, description: user.to_s, metadata: { user_id: user.id })
         | 
| 80 80 | 
             
                    customer.stripe_customer_id = customer.stripe_customer.id
         | 
| 81 81 | 
             
                    customer.save!
         | 
| @@ -85,7 +85,7 @@ module Effective | |
| 85 85 | 
             
                # Update stripe customer card
         | 
| 86 86 | 
             
                def create_stripe_token!
         | 
| 87 87 | 
             
                  if stripe_token.present?
         | 
| 88 | 
            -
                    Rails.logger.info "STRIPE  | 
| 88 | 
            +
                    Rails.logger.info "[STRIPE] update source: #{stripe_token}"
         | 
| 89 89 | 
             
                    customer.stripe_customer.source = stripe_token
         | 
| 90 90 | 
             
                    customer.stripe_customer.save
         | 
| 91 91 |  | 
| @@ -113,7 +113,7 @@ module Effective | |
| 113 113 | 
             
                  return unless plan.present?
         | 
| 114 114 | 
             
                  return if customer.stripe_subscription.present?
         | 
| 115 115 |  | 
| 116 | 
            -
                  Rails.logger.info "STRIPE  | 
| 116 | 
            +
                  Rails.logger.info "[STRIPE] create subscription: #{items(metadata: false)}"
         | 
| 117 117 | 
             
                  customer.stripe_subscription = Stripe::Subscription.create(customer: customer.stripe_customer_id, items: items(metadata: false), metadata: metadata)
         | 
| 118 118 | 
             
                  customer.stripe_subscription_id = customer.stripe_subscription.id
         | 
| 119 119 |  | 
| @@ -125,7 +125,7 @@ module Effective | |
| 125 125 | 
             
                  return unless plan.present?
         | 
| 126 126 | 
             
                  return if customer.stripe_subscription.blank?
         | 
| 127 127 |  | 
| 128 | 
            -
                  Rails.logger.info "STRIPE  | 
| 128 | 
            +
                  Rails.logger.info "[STRIPE] update subscription: #{customer.stripe_subscription_id} #{items}"
         | 
| 129 129 |  | 
| 130 130 | 
             
                  if items.length == 0
         | 
| 131 131 | 
             
                    customer.stripe_subscription.delete
         | 
| @@ -147,7 +147,7 @@ module Effective | |
| 147 147 | 
             
                    stripe_item.quantity = item[:quantity]
         | 
| 148 148 | 
             
                    stripe_item.metadata = item[:metadata]
         | 
| 149 149 |  | 
| 150 | 
            -
                    Rails.logger.info " ->  | 
| 150 | 
            +
                    Rails.logger.info " -> [STRIPE] update plan: #{item[:plan]}"
         | 
| 151 151 | 
             
                    stripe_item.save
         | 
| 152 152 | 
             
                  end
         | 
| 153 153 |  | 
| @@ -155,7 +155,7 @@ module Effective | |
| 155 155 | 
             
                  items.each do |item|
         | 
| 156 156 | 
             
                    next if customer.stripe_subscription.items.find { |stripe_item| item[:plan] == stripe_item['plan']['id'] }
         | 
| 157 157 |  | 
| 158 | 
            -
                    Rails.logger.info " ->  | 
| 158 | 
            +
                    Rails.logger.info " -> [STRIPE] create plan: #{item[:plan]}"
         | 
| 159 159 | 
             
                    customer.stripe_subscription.items.create(plan: item[:plan], quantity: item[:quantity], metadata: item[:metadata])
         | 
| 160 160 | 
             
                  end
         | 
| 161 161 |  | 
| @@ -163,20 +163,20 @@ module Effective | |
| 163 163 | 
             
                  customer.stripe_subscription.items.each do |stripe_item|
         | 
| 164 164 | 
             
                    next if items.find { |item| item[:plan] == stripe_item['plan']['id'] }
         | 
| 165 165 |  | 
| 166 | 
            -
                    Rails.logger.info " ->  | 
| 166 | 
            +
                    Rails.logger.info " -> [STRIPE] delete plan: #{stripe_item['plan']['id']}"
         | 
| 167 167 | 
             
                    stripe_item.delete
         | 
| 168 168 | 
             
                  end
         | 
| 169 169 |  | 
| 170 170 | 
             
                  # Update metadata
         | 
| 171 171 | 
             
                  if customer.stripe_subscription.metadata.to_h != metadata
         | 
| 172 | 
            -
                    Rails.logger.info " ->  | 
| 172 | 
            +
                    Rails.logger.info " -> [STRIPE] update metadata: #{metadata}"
         | 
| 173 173 | 
             
                    customer.stripe_subscription.metadata = metadata
         | 
| 174 174 | 
             
                    customer.stripe_subscription.save
         | 
| 175 175 | 
             
                  end
         | 
| 176 176 |  | 
| 177 177 | 
             
                  # When upgrading a plan, invoice immediately.
         | 
| 178 178 | 
             
                  if quantity_increased
         | 
| 179 | 
            -
                    Rails.logger.info " ->  | 
| 179 | 
            +
                    Rails.logger.info " -> [STRIPE] generate invoice"
         | 
| 180 180 | 
             
                    Stripe::Invoice.create(customer: customer.stripe_customer_id).pay
         | 
| 181 181 | 
             
                  end
         | 
| 182 182 |  | 
    
        data/lib/effective_orders.rb
    CHANGED
    
    | @@ -169,11 +169,7 @@ module EffectiveOrders | |
| 169 169 | 
             
                return {} unless (stripe? && subscriptions?)
         | 
| 170 170 |  | 
| 171 171 | 
             
                @stripe_plans ||= (
         | 
| 172 | 
            -
                  Rails.logger.info  | 
| 173 | 
            -
             | 
| 174 | 
            -
                  # {"id":"plan_ChLx90ggbWvB8i","object":"plan","amount":100000,"billing_scheme":"per_unit","created":1523984756,"currency":"usd",
         | 
| 175 | 
            -
                  #{ }"interval":"year","interval_count":1,"livemode":false,"metadata":{},"nickname":"Yearly","product":"prod_ChLwW0XqdykIki",
         | 
| 176 | 
            -
                  #{ }"tiers":null,"tiers_mode":null,"transform_usage":null,"trial_period_days":null,"usage_type":"licensed"},
         | 
| 172 | 
            +
                  Rails.logger.info '[STRIPE] index plans'
         | 
| 177 173 |  | 
| 178 174 | 
             
                  plans = Stripe::Plan.all.inject({}) do |h, plan|
         | 
| 179 175 | 
             
                    h[plan.id] = {
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: effective_orders
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 4.0. | 
| 4 | 
            +
              version: 4.0.0beta15
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Code and Effect
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018- | 
| 11 | 
            +
            date: 2018-07-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |