From 401853baeab984fd5a6dd4c16170b0da99f1d776 Mon Sep 17 00:00:00 2001 From: garciajordy Date: Thu, 17 Jun 2021 22:22:45 +0300 Subject: [PATCH] Add httparty to dependecies --- README.md | 18 -- .../report_default_change_to_subscriptions.rb | 28 --- .../solidus_subscriptions/subscription.rb | 15 +- .../churn_buster_subscriber.rb | 39 --- config/initializers/subscribers.rb | 8 +- lib/solidus_subscriptions.rb | 15 -- .../churn_buster/client.rb | 48 ---- .../churn_buster/order_serializer.rb | 19 -- .../churn_buster/serializer.rb | 23 -- .../subscription_customer_serializer.rb | 28 --- .../subscription_payment_method_serializer.rb | 37 --- .../churn_buster/subscription_serializer.rb | 17 -- lib/solidus_subscriptions/configuration.rb | 7 +- .../dispatcher/payment_failed_dispatcher.rb | 6 - .../dispatcher/success_dispatcher.rb | 6 - solidus_subscriptions.gemspec | 2 - spec/fixtures/cassettes/churn_buster.yml | 229 ------------------ .../churn_buster/client_spec.rb | 59 ----- .../payment_failed_dispatcher_spec.rb | 15 -- .../dispatcher/success_dispatcher_spec.rb | 15 -- spec/lib/solidus_subscriptions_spec.rb | 30 --- .../subscription_spec.rb | 12 - .../spree/wallet_payment_source_spec.rb | 20 -- .../churn_buster_subscriber_spec.rb | 76 ------ spec/support/vcr.rb | 10 - 25 files changed, 5 insertions(+), 777 deletions(-) delete mode 100644 app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb delete mode 100644 app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb delete mode 100644 lib/solidus_subscriptions/churn_buster/client.rb delete mode 100644 lib/solidus_subscriptions/churn_buster/order_serializer.rb delete mode 100644 lib/solidus_subscriptions/churn_buster/serializer.rb delete mode 100644 lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb delete mode 100644 lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb delete mode 100644 lib/solidus_subscriptions/churn_buster/subscription_serializer.rb delete mode 100644 spec/fixtures/cassettes/churn_buster.yml delete mode 100644 spec/lib/solidus_subscriptions/churn_buster/client_spec.rb delete mode 100644 spec/lib/solidus_subscriptions_spec.rb delete mode 100644 spec/models/spree/wallet_payment_source_spec.rb delete mode 100644 spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb delete mode 100644 spec/support/vcr.rb diff --git a/README.md b/README.md index 0f196bf5..1b728380 100644 --- a/README.md +++ b/README.md @@ -99,24 +99,6 @@ This extensions adds the following [Promotion rules](https://guides.solidus.io/d You can find the API documentation [here](https://stoplight.io/p/docs/gh/solidusio-contrib/solidus_subscriptions?group=master). -### Churn Buster integration - -This extension optionally integrates with [Churn Buster](https://churnbuster.io) for failed payment -recovery. In order to enable the integration, simply add your Churn Buster credentials to your -configuration: - -```ruby -SolidusSubscriptions.configure do |config| - # ... - - config.churn_buster_account_id = 'YOUR_CHURN_BUSTER_ACCOUNT_ID' - config.churn_buster_api_key = 'YOUR_CHURN_BUSTER_API_KEY' -end -``` - -The extension will take care of reporting successful/failed payments and payment method changes -to Churn Buster. - ### Failed installments retries The extension generates an installment for each subscription cycle, however some of them can fail diff --git a/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb b/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb deleted file mode 100644 index 6ee754e7..00000000 --- a/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - module Spree - module WalletPaymentSource - module ReportDefaultChangeToSubscriptions - def self.prepended(base) - base.after_save :report_default_change_to_subscriptions - end - - private - - def report_default_change_to_subscriptions - return if !previous_changes.key?('default') || !default? - - user.subscriptions.with_default_payment_source.each do |subscription| - ::Spree::Event.fire( - 'solidus_subscriptions.subscription_payment_method_changed', - subscription: subscription, - ) - end - end - end - end - end -end - -Spree::WalletPaymentSource.prepend(SolidusSubscriptions::Spree::WalletPaymentSource::ReportDefaultChangeToSubscriptions) diff --git a/app/models/solidus_subscriptions/subscription.rb b/app/models/solidus_subscriptions/subscription.rb index 7e98f827..76f84cc9 100644 --- a/app/models/solidus_subscriptions/subscription.rb +++ b/app/models/solidus_subscriptions/subscription.rb @@ -79,10 +79,6 @@ class Subscription < ApplicationRecord joins(:installments).merge(Installment.unfulfilled) end) - scope :with_default_payment_source, (lambda do - where(payment_method: nil, payment_source: nil) - end) - def self.ransackable_scopes(_auth_object = nil) [:in_processing_state] end @@ -107,7 +103,7 @@ def self.processing_states state_machine :state, initial: :active do event :cancel do transition [:active, :pending_cancellation] => :canceled, - if: ->(subscription) { subscription.can_be_canceled? } + if: ->(subscription) { subscription.can_be_canceled? } transition active: :pending_cancellation end @@ -122,7 +118,7 @@ def self.processing_states event :deactivate do transition active: :inactive, - if: ->(subscription) { subscription.can_be_deactivated? } + if: ->(subscription) { subscription.can_be_deactivated? } end event :activate do @@ -380,13 +376,6 @@ def emit_events_for_update subscription: self, ) end - - if previous_changes.key?('payment_source_id') || previous_changes.key?('payment_source_type') || previous_changes.key?('payment_method_id') - ::Spree::Event.fire( - 'solidus_subscriptions.subscription_payment_method_changed', - subscription: self, - ) - end end end end diff --git a/app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb b/app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb deleted file mode 100644 index 34540038..00000000 --- a/app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - module ChurnBusterSubscriber - include ::Spree::Event::Subscriber - - event_action :report_subscription_cancellation, event_name: 'solidus_subscriptions.subscription_canceled' - event_action :report_subscription_ending, event_name: 'solidus_subscriptions.subscription_ended' - event_action :report_payment_success, event_name: 'solidus_subscriptions.installment_succeeded' - event_action :report_payment_failure, event_name: 'solidus_subscriptions.installment_failed_payment' - event_action :report_payment_method_change, event_name: 'solidus_subscriptions.subscription_payment_method_changed' - - def report_subscription_cancellation(event) - churn_buster&.report_subscription_cancellation(event.payload.fetch(:subscription)) - end - - def report_subscription_ending(event) - churn_buster&.report_subscription_cancellation(event.payload.fetch(:subscription)) - end - - def report_payment_success(event) - churn_buster&.report_successful_payment(event.payload.fetch(:order)) - end - - def report_payment_failure(event) - churn_buster&.report_failed_payment(event.payload.fetch(:order)) - end - - def report_payment_method_change(event) - churn_buster&.report_payment_method_change(event.payload.fetch(:subscription)) - end - - private - - def churn_buster - SolidusSubscriptions.churn_buster - end - end -end diff --git a/config/initializers/subscribers.rb b/config/initializers/subscribers.rb index 486fe72b..fe4c88be 100644 --- a/config/initializers/subscribers.rb +++ b/config/initializers/subscribers.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true -if Spree.solidus_gem_version < Gem::Version.new('2.11.0') - require SolidusSubscriptions::Engine.root.join('app/subscribers/solidus_subscriptions/event_storage_subscriber') - require SolidusSubscriptions::Engine.root.join('app/subscribers/solidus_subscriptions/churn_buster_subscriber') - - SolidusSubscriptions::ChurnBusterSubscriber.subscribe! - SolidusSubscriptions::EventStorageSubscriber.subscribe! +Spree.config do |config| + config.events.subscribers << 'SolidusSubscriptions::EventStorageSubscriber' end diff --git a/lib/solidus_subscriptions.rb b/lib/solidus_subscriptions.rb index 9d6457f0..f2ec3b07 100644 --- a/lib/solidus_subscriptions.rb +++ b/lib/solidus_subscriptions.rb @@ -12,12 +12,6 @@ require 'solidus_subscriptions/permission_sets/subscription_management' require 'solidus_subscriptions/version' require 'solidus_subscriptions/engine' -require 'solidus_subscriptions/churn_buster/client' -require 'solidus_subscriptions/churn_buster/serializer' -require 'solidus_subscriptions/churn_buster/subscription_customer_serializer' -require 'solidus_subscriptions/churn_buster/subscription_payment_method_serializer' -require 'solidus_subscriptions/churn_buster/subscription_serializer' -require 'solidus_subscriptions/churn_buster/order_serializer' require 'solidus_subscriptions/checkout' require 'solidus_subscriptions/subscription_generator' require 'solidus_subscriptions/subscription_line_item_builder' @@ -37,14 +31,5 @@ def configure def configuration @configuration ||= Configuration.new end - - def churn_buster - return unless configuration.churn_buster? - - @churn_buster ||= ChurnBuster::Client.new( - account_id: SolidusSubscriptions.configuration.churn_buster_account_id, - api_key: SolidusSubscriptions.configuration.churn_buster_api_key, - ) - end end end diff --git a/lib/solidus_subscriptions/churn_buster/client.rb b/lib/solidus_subscriptions/churn_buster/client.rb deleted file mode 100644 index 915bb409..00000000 --- a/lib/solidus_subscriptions/churn_buster/client.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - module ChurnBuster - class Client - BASE_API_URL = 'https://api.churnbuster.io/v1' - - attr_reader :account_id, :api_key - - def initialize(account_id:, api_key:) - @account_id = account_id - @api_key = api_key - end - - def report_failed_payment(order) - post('/failed_payments', OrderSerializer.serialize(order)) - end - - def report_successful_payment(order) - post('/successful_payments', OrderSerializer.serialize(order)) - end - - def report_subscription_cancellation(subscription) - post('/cancellations', SubscriptionSerializer.serialize(subscription)) - end - - def report_payment_method_change(subscription) - post('/payment_methods', SubscriptionPaymentMethodSerializer.serialize(subscription)) - end - - private - - def post(path, body) - HTTParty.post( - "#{BASE_API_URL}#{path}", - body: body.to_json, - headers: { - 'Content-Type' => 'application/json', - }, - basic_auth: { - username: account_id, - password: api_key, - }, - ) - end - end - end -end diff --git a/lib/solidus_subscriptions/churn_buster/order_serializer.rb b/lib/solidus_subscriptions/churn_buster/order_serializer.rb deleted file mode 100644 index 5bc5dee7..00000000 --- a/lib/solidus_subscriptions/churn_buster/order_serializer.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - module ChurnBuster - class OrderSerializer < Serializer - def to_h - { - payment: { - source: 'in_house', - source_id: object.number, - amount_in_cents: object.display_total.cents, - currency: object.currency, - }, - customer: SubscriptionCustomerSerializer.serialize(object.subscription), - } - end - end - end -end diff --git a/lib/solidus_subscriptions/churn_buster/serializer.rb b/lib/solidus_subscriptions/churn_buster/serializer.rb deleted file mode 100644 index d8b83bba..00000000 --- a/lib/solidus_subscriptions/churn_buster/serializer.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - module ChurnBuster - class Serializer - attr_reader :object - - class << self - def serialize(object) - new(object).to_h - end - end - - def initialize(object) - @object = object - end - - def to_h - raise NotImplementedError - end - end - end -end diff --git a/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb b/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb deleted file mode 100644 index cd17af3c..00000000 --- a/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - module ChurnBuster - class SubscriptionCustomerSerializer < Serializer - def to_h - { - source: 'in_house', - source_id: object.id, - email: object.user.email, - properties: { - name: name - }, - } - end - - private - - def name - if ::Spree.solidus_gem_version < Gem::Version.new('2.11.0') - "#{object.shipping_address_to_use.first_name} #{object.shipping_address_to_use.last_name}" - else - object.shipping_address_to_use.name - end - end - end - end -end diff --git a/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb b/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb deleted file mode 100644 index 984059da..00000000 --- a/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - module ChurnBuster - class SubscriptionPaymentMethodSerializer < Serializer - def to_h - { - payment_method: { - source: 'in_house', - source_id: [ - object.payment_method_to_use&.id, - object.payment_source_to_use&.id - ].compact.join('-'), - type: 'card', - properties: payment_source_properties, - }, - customer: SubscriptionCustomerSerializer.serialize(object), - } - end - - private - - def payment_source_properties - if object.payment_source.is_a?(::Spree::CreditCard) - { - brand: object.payment_source.cc_type, - last4: object.payment_source.last_digits, - exp_month: object.payment_source.month, - exp_year: object.payment_source.year, - } - else - {} - end - end - end - end -end diff --git a/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb b/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb deleted file mode 100644 index 06c08d16..00000000 --- a/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - module ChurnBuster - class SubscriptionSerializer < Serializer - def to_h - { - subscription: { - source: 'in_house', - source_id: object.id - }, - customer: SubscriptionCustomerSerializer.serialize(object), - } - end - end - end -end diff --git a/lib/solidus_subscriptions/configuration.rb b/lib/solidus_subscriptions/configuration.rb index 9d6c3d2a..adcf41c8 100644 --- a/lib/solidus_subscriptions/configuration.rb +++ b/lib/solidus_subscriptions/configuration.rb @@ -3,8 +3,7 @@ module SolidusSubscriptions class Configuration attr_accessor( - :maximum_total_skips, :maximum_reprocessing_time, :churn_buster_account_id, - :churn_buster_api_key, :clear_past_installments, :processing_error_handler + :maximum_total_skips, :maximum_reprocessing_time, :clear_past_installments, :processing_error_handler ) attr_writer( @@ -78,10 +77,6 @@ def subscribable_class @subscribable_class.constantize end - def churn_buster? - churn_buster_account_id.present? && churn_buster_api_key.present? - end - def order_creator_class @order_creator_class ||= 'SolidusSubscriptions::OrderCreator' @order_creator_class.constantize diff --git a/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb b/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb index a56332ed..16e0b7bc 100644 --- a/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb +++ b/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb @@ -7,12 +7,6 @@ def dispatch order.touch(:completed_at) order.cancel installment.payment_failed!(order) - - ::Spree::Event.fire( - 'solidus_subscriptions.installment_failed_payment', - installment: installment, - order: order, - ) end end end diff --git a/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb b/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb index 0ae71dc7..cf97e892 100644 --- a/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb +++ b/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb @@ -5,12 +5,6 @@ module Dispatcher class SuccessDispatcher < Base def dispatch installment.success!(order) - - ::Spree::Event.fire( - 'solidus_subscriptions.installment_succeeded', - installment: installment, - order: order, - ) end end end diff --git a/solidus_subscriptions.gemspec b/solidus_subscriptions.gemspec index 5831cf18..4f38d050 100644 --- a/solidus_subscriptions.gemspec +++ b/solidus_subscriptions.gemspec @@ -40,8 +40,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'shoulda-matchers', '~> 4.4' spec.add_development_dependency 'solidus_dev_support', '~> 2.0' spec.add_development_dependency 'timecop' - spec.add_development_dependency 'vcr' spec.add_development_dependency 'versioncake' - spec.add_development_dependency 'webmock' spec.add_development_dependency 'yard' end diff --git a/spec/fixtures/cassettes/churn_buster.yml b/spec/fixtures/cassettes/churn_buster.yml deleted file mode 100644 index 0d3803a1..00000000 --- a/spec/fixtures/cassettes/churn_buster.yml +++ /dev/null @@ -1,229 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://api.churnbuster.io/v1/successful_payments - body: - encoding: UTF-8 - string: '{"payment":{"source":"in_house","source_id":"R863897282","amount_in_cents":0,"currency":"USD"},"customer":{"source":"in_house","source_id":1,"email":"email2@example.com","properties":{"first_name":"John","last_name":"John"}}}' - headers: - Content-Type: - - application/json - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Server: - - Cowboy - Date: - - Thu, 01 Oct 2020 13:46:09 GMT - Connection: - - keep-alive - X-Frame-Options: - - SAMEORIGIN - X-Xss-Protection: - - 1; mode=block - X-Content-Type-Options: - - nosniff - X-Download-Options: - - noopen - X-Permitted-Cross-Domain-Policies: - - none - Referrer-Policy: - - strict-origin-when-cross-origin - Content-Type: - - application/json - Cache-Control: - - no-cache - X-Request-Id: - - a664eaa0-2735-4a88-990d-fb9c29766e00 - X-Runtime: - - '0.070480' - Strict-Transport-Security: - - max-age=31536000; includeSubDomains - Transfer-Encoding: - - chunked - Via: - - 1.1 vegur - body: - encoding: UTF-8 - string: '' - recorded_at: Thu, 01 Oct 2020 13:46:09 GMT -- request: - method: post - uri: https://api.churnbuster.io/v1/failed_payments - body: - encoding: UTF-8 - string: '{"payment":{"source":"in_house","source_id":"R276044153","amount_in_cents":0,"currency":"USD"},"customer":{"source":"in_house","source_id":1,"email":"email2@example.com","properties":{"first_name":"John","last_name":"John"}}}' - headers: - Content-Type: - - application/json - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Server: - - Cowboy - Date: - - Thu, 01 Oct 2020 14:24:32 GMT - Connection: - - keep-alive - X-Frame-Options: - - SAMEORIGIN - X-Xss-Protection: - - 1; mode=block - X-Content-Type-Options: - - nosniff - X-Download-Options: - - noopen - X-Permitted-Cross-Domain-Policies: - - none - Referrer-Policy: - - strict-origin-when-cross-origin - Content-Type: - - application/json - Cache-Control: - - no-cache - X-Request-Id: - - bfd0c00b-dafa-4122-95e3-6fae6676bf05 - X-Runtime: - - '0.052157' - Strict-Transport-Security: - - max-age=31536000; includeSubDomains - Transfer-Encoding: - - chunked - Via: - - 1.1 vegur - body: - encoding: UTF-8 - string: '' - recorded_at: Thu, 01 Oct 2020 14:24:32 GMT -- request: - method: post - uri: https://api.churnbuster.io/v1/cancellations - body: - encoding: UTF-8 - string: '{"subscription":{"source":"in_house","source_id":1},"customer":{"source":"in_house","source_id":1,"email":"email5@example.com","properties":{"first_name":"John","last_name":"Von - Doe"}}}' - headers: - Content-Type: - - application/json - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Server: - - Cowboy - Date: - - Thu, 01 Oct 2020 14:24:33 GMT - Connection: - - keep-alive - X-Frame-Options: - - SAMEORIGIN - X-Xss-Protection: - - 1; mode=block - X-Content-Type-Options: - - nosniff - X-Download-Options: - - noopen - X-Permitted-Cross-Domain-Policies: - - none - Referrer-Policy: - - strict-origin-when-cross-origin - Content-Type: - - application/json - Cache-Control: - - no-cache - X-Request-Id: - - aa57bbfb-aa49-4f4c-bad9-a3e9a87335bd - X-Runtime: - - '0.070606' - Strict-Transport-Security: - - max-age=31536000; includeSubDomains - Transfer-Encoding: - - chunked - Via: - - 1.1 vegur - body: - encoding: UTF-8 - string: '' - recorded_at: Thu, 01 Oct 2020 14:24:33 GMT -- request: - method: post - uri: https://api.churnbuster.io/v1/payment_methods - body: - encoding: UTF-8 - string: '{"payment_method":{"source":"in_house","source_id":"1-1","type":"card","properties":{}},"customer":{"source":"in_house","source_id":1,"email":"email6@example.com","properties":{"first_name":"John","last_name":"Von - Doe"}}}' - headers: - Content-Type: - - application/json - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Server: - - Cowboy - Date: - - Mon, 05 Oct 2020 10:55:30 GMT - Connection: - - keep-alive - X-Frame-Options: - - SAMEORIGIN - X-Xss-Protection: - - 1; mode=block - X-Content-Type-Options: - - nosniff - X-Download-Options: - - noopen - X-Permitted-Cross-Domain-Policies: - - none - Referrer-Policy: - - strict-origin-when-cross-origin - Content-Type: - - application/json - Cache-Control: - - no-cache - X-Request-Id: - - 585f1c6a-fb36-4cb4-9127-2f80636d33d9 - X-Runtime: - - '1.184629' - Strict-Transport-Security: - - max-age=31536000; includeSubDomains - Transfer-Encoding: - - chunked - Via: - - 1.1 vegur - body: - encoding: UTF-8 - string: '' - recorded_at: Mon, 05 Oct 2020 10:55:31 GMT -recorded_with: VCR 6.0.0 diff --git a/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb b/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb deleted file mode 100644 index 9efb2e64..00000000 --- a/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe SolidusSubscriptions::ChurnBuster::Client, vcr: { cassette_name: 'churn_buster', record: :new_episodes } do - describe '#report_failed_payment' do - it 'reports the failed payment to Churn Buster' do - client = described_class.new( - account_id: 'test_account_id', - api_key: 'test_api_key', - ) - - order = create(:order, subscription: create(:subscription)) - response = client.report_failed_payment(order) - - expect(response).to be_success - end - end - - describe '#report_successful_payment' do - it 'reports the successful payment to Churn Buster' do - client = described_class.new( - account_id: 'test_account_id', - api_key: 'test_api_key', - ) - - order = create(:order, subscription: create(:subscription)) - response = client.report_successful_payment(order) - - expect(response).to be_success - end - end - - describe '#report_subscription_cancellation' do - it 'reports the failed payment to Churn Buster' do - client = described_class.new( - account_id: 'test_account_id', - api_key: 'test_api_key', - ) - - subscription = create(:subscription) - response = client.report_subscription_cancellation(subscription) - - expect(response).to be_success - end - end - - describe '#report_payment_method_change' do - it 'reports the payment method change to Churn Buster' do - client = described_class.new( - account_id: 'test_account_id', - api_key: 'test_api_key', - ) - - subscription = create(:subscription) - response = client.report_payment_method_change(subscription) - - expect(response).to be_success - end - end -end diff --git a/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb b/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb index 103f176a..47ece4b2 100644 --- a/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb +++ b/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb @@ -25,20 +25,5 @@ expect(order.state).to eq('canceled') end - - it 'fires an installments_failed_payment event' do - stub_const('Spree::Event', class_spy(Spree::Event)) - installment = instance_spy(SolidusSubscriptions::Installment) - order = create(:order_with_line_items) - - dispatcher = described_class.new(installment, order) - dispatcher.dispatch - - expect(Spree::Event).to have_received(:fire).with( - 'solidus_subscriptions.installment_failed_payment', - installment: installment, - order: order, - ) - end end end diff --git a/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb b/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb index 366e1f7c..aa48f4dc 100644 --- a/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb +++ b/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb @@ -11,20 +11,5 @@ expect(installment).to have_received(:success!).with(order) end - - it 'fires an installments_succeeded event' do - stub_const('Spree::Event', class_spy(Spree::Event)) - installment = instance_spy(SolidusSubscriptions::Installment) - order = create(:order_with_line_items) - - dispatcher = described_class.new(installment, order) - dispatcher.dispatch - - expect(Spree::Event).to have_received(:fire).with( - 'solidus_subscriptions.installment_succeeded', - installment: installment, - order: order, - ) - end end end diff --git a/spec/lib/solidus_subscriptions_spec.rb b/spec/lib/solidus_subscriptions_spec.rb deleted file mode 100644 index f99119f5..00000000 --- a/spec/lib/solidus_subscriptions_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe SolidusSubscriptions do - describe '.churn_buster' do - context 'when Churn Buster was configured' do - it 'returns a Churn Buster client instance' do - allow(described_class.configuration).to receive_messages( - churn_buster?: true, - churn_buster_account_id: 'account_id', - churn_buster_api_key: 'api_key', - ) - churn_buster = instance_double(SolidusSubscriptions::ChurnBuster::Client) - allow(SolidusSubscriptions::ChurnBuster::Client).to receive(:new).with( - account_id: 'account_id', - api_key: 'api_key', - ).and_return(churn_buster) - - expect(described_class.churn_buster).to eq(churn_buster) - end - end - - context 'when Churn Buster was not configured' do - it 'returns nil' do - allow(described_class.configuration).to receive_messages(churn_buster?: false) - - expect(described_class.churn_buster).to be_nil - end - end - end -end diff --git a/spec/models/solidus_subscriptions/subscription_spec.rb b/spec/models/solidus_subscriptions/subscription_spec.rb index 6b05cced..49d855aa 100644 --- a/spec/models/solidus_subscriptions/subscription_spec.rb +++ b/spec/models/solidus_subscriptions/subscription_spec.rb @@ -87,18 +87,6 @@ subscription: subscription, ) end - - it 'tracks payment method changes' do - stub_const('Spree::Event', class_spy(Spree::Event)) - - subscription = create(:subscription) - subscription.update!(payment_source: create(:credit_card, user: subscription.user)) - - expect(Spree::Event).to have_received(:fire).with( - 'solidus_subscriptions.subscription_payment_method_changed', - subscription: subscription, - ) - end end describe '#cancel' do diff --git a/spec/models/spree/wallet_payment_source_spec.rb b/spec/models/spree/wallet_payment_source_spec.rb deleted file mode 100644 index ff057f9c..00000000 --- a/spec/models/spree/wallet_payment_source_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Spree::WalletPaymentSource do - describe 'setting it as the default' do - it 'reports a payment method changed event for subscriptions that use the default payment source' do - stub_const('Spree::Event', class_spy(Spree::Event)) - user = create(:user) - subscription = create(:subscription, user: user) - payment_source = create(:credit_card, user: user) - wallet_payment_source = user.wallet.add(payment_source) - - user.wallet.default_wallet_payment_source = wallet_payment_source - - expect(Spree::Event).to have_received(:fire).with( - 'solidus_subscriptions.subscription_payment_method_changed', - subscription: subscription, - ) - end - end -end diff --git a/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb b/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb deleted file mode 100644 index a3e9a23b..00000000 --- a/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb +++ /dev/null @@ -1,76 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe SolidusSubscriptions::ChurnBusterSubscriber do - describe '#report_subscription_cancellation' do - it 'reports the cancellation to Churn Buster' do - churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) - allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) - - subscription = create(:subscription) - Spree::Event.fire('solidus_subscriptions.subscription_canceled', subscription: subscription) - - expect(churn_buster).to have_received(:report_subscription_cancellation).with(subscription) - end - end - - describe '#report_subscription_ending' do - it 'reports the cancellation to Churn Buster' do - churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) - allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) - - subscription = create(:subscription) - Spree::Event.fire('solidus_subscriptions.subscription_ended', subscription: subscription) - - expect(churn_buster).to have_received(:report_subscription_cancellation).with(subscription) - end - end - - describe '#report_payment_success' do - it 'reports the success to Churn Buster' do - churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) - allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) - - order = build_stubbed(:order) - installment = build_stubbed(:installment) - Spree::Event.fire( - 'solidus_subscriptions.installment_succeeded', - installment: installment, - order: order, - ) - - expect(churn_buster).to have_received(:report_successful_payment).with(order) - end - end - - describe '#report_payment_failure' do - it 'reports the failure to Churn Buster' do - churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) - allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) - - order = build_stubbed(:order) - installment = build_stubbed(:installment) - Spree::Event.fire( - 'solidus_subscriptions.installment_failed_payment', - installment: installment, - order: order, - ) - - expect(churn_buster).to have_received(:report_failed_payment).with(order) - end - end - - describe '#report_payment_method_change' do - it 'reports the payment method change to Churn Buster' do - churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) - allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) - - subscription = create(:subscription) - Spree::Event.fire( - 'solidus_subscriptions.subscription_payment_method_changed', - subscription: subscription, - ) - - expect(churn_buster).to have_received(:report_payment_method_change).with(subscription) - end - end -end diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb deleted file mode 100644 index ca8a14a4..00000000 --- a/spec/support/vcr.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'webmock/rspec' -require 'vcr' - -WebMock.disable_net_connect! - -VCR.configure do |config| - config.cassette_library_dir = "spec/fixtures/cassettes" - config.hook_into :webmock - config.configure_rspec_metadata! -end