stripe-rails 1.3.0 → 1.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a48f7cd53408976274d19e00765d59c76aa0e4ae69e7accaf4b0e58de6737db
4
- data.tar.gz: 0cdb70b8481b375c043ed622082376da4342712ed1a389170eccbc944a668713
3
+ metadata.gz: 4b35454f34ad04d0060f9ffc0bfc0f768717c75a5feaf000b5d5dd55850aecbf
4
+ data.tar.gz: 0000ba8f4f607ed56108fa6da955f7e03f3fc1ba092a6a8ad9f203c600ba189f
5
5
  SHA512:
6
- metadata.gz: fe441c8ddb0f65fea0b8ae401609c8dc9ea3f24b8426168fc2b93f830fa895911e2f1649ef570d73b48f6f73dd80eb6b3fbd68f687561d5fd613424c97e558a9
7
- data.tar.gz: e8451147cfcb761affc302a442da37ad0311ce09201a515d4c29205724463e301d9c63e5998df2af7481d9c38e33955fd24654837b88e7fda7a53e2878eebade
6
+ metadata.gz: dd48273cf821b7af2c5515aed2321fed95d0ed93496cf9c090698d9d2c231544b9264d676fbcbd58a4262d6e1f6621d7744b4e3638b09a46c834e5a9b398bb92
7
+ data.tar.gz: defdc32f8c2a558283324ed0f5164c7140cb03d9daecd4c8b24acd20f26837e090ed7a4655ad5abc46747980fedb0834c7ea461be418af049859e1f3f95b50f5
@@ -1,3 +1,7 @@
1
+ ## 1.4.0 (2018-07-30)
2
+
3
+ * Spanking new products builder for Stripe Billing (#117) - Thanks to @renchap for suggesting this and to @henryaj for reviewing it.
4
+
1
5
  ## 1.3.0 (2018-07-23)
2
6
 
3
7
  * do not create new product when product id is provided (#115) - Thanks to @renchap for reporting this
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Build Status](https://travis-ci.org/tansengming/stripe-rails.png?branch=master)](https://travis-ci.org/tansengming/stripe-rails)
4
4
  [![Code Climate](https://codeclimate.com/github/tansengming/stripe-rails/badges/gpa.svg)](https://codeclimate.com/github/tansengming/stripe-rails)
5
5
  [![Test Coverage](https://codeclimate.com/github/tansengming/stripe-rails/badges/coverage.svg)](https://codeclimate.com/github/tansengming/stripe-rails/coverage)
6
- [![Dependency Status](https://gemnasium.com/tansengming/stripe-rails.png)](https://gemnasium.com/tansengming/stripe-rails)
7
6
 
8
7
 
9
8
  This gem can help your rails application integrate with Stripe in the following ways
@@ -125,6 +124,7 @@ rails generate stripe:install
125
124
  this will generate the configuration files containing your plan and coupon definitions:
126
125
 
127
126
  ```console
127
+ create config/stripe/products.rb
128
128
  create config/stripe/plans.rb
129
129
  create config/stripe/coupons.rb
130
130
  ```
@@ -173,6 +173,16 @@ Stripe.coupon :super_elite_free_vip do |coupon|
173
173
  end
174
174
  ```
175
175
 
176
+
177
+ As are Products:
178
+
179
+ ```ruby
180
+ Stripe.products :primo do |products|
181
+ products.name = 'PRIMO as a service'
182
+ products.type = 'service'
183
+ end
184
+ ```
185
+
176
186
  To upload your plans and coupons onto stripe.com, run:
177
187
 
178
188
  ```sh
@@ -4,6 +4,7 @@ module Stripe
4
4
 
5
5
  desc "copy plans.rb"
6
6
  def copy_plans_file
7
+ copy_file "products.rb", "config/stripe/products.rb"
7
8
  copy_file "plans.rb", "config/stripe/plans.rb"
8
9
  copy_file "coupons.rb", "config/stripe/coupons.rb"
9
10
  end
@@ -0,0 +1,19 @@
1
+ # This file contains descriptions of all your stripe products
2
+
3
+ # Example
4
+ # Stripe::Products::PRIMO #=> 'primo'
5
+
6
+ # Stripe.products :primo do |products|
7
+ # # products name as it will appear on credit card statements
8
+ # products.name = 'Acme as a service PRIMO'
9
+ #
10
+ # # Product, either 'service' or 'good'
11
+ # products.type = 'service'
12
+ # end
13
+
14
+ # Once you have your productss defined, you can run
15
+ #
16
+ # rake stripe:prepare
17
+ #
18
+ # This will export any new plans to stripe.com so that you can
19
+ # begin using them in your API calls.
@@ -0,0 +1,12 @@
1
+ class CurrentApiVersion
2
+ def self.call
3
+ Stripe.api_version || begin
4
+ resp, _ = Stripe::Plan.request(:get, Stripe::Plan.resource_url)
5
+ resp.http_headers['stripe-version']
6
+ end
7
+ end
8
+
9
+ def self.after_switch_to_products_in_plans?
10
+ Date.parse(call) >= Date.parse('2018-02-05')
11
+ end
12
+ end
@@ -63,7 +63,7 @@ environment file directly.
63
63
  end
64
64
 
65
65
  initializer 'stripe.plans_and_coupons' do |app|
66
- for configuration in %w(plans coupons)
66
+ for configuration in %w(products plans coupons)
67
67
  path = app.root.join("config/stripe/#{configuration}.rb")
68
68
  load path if path.exist?
69
69
  end
@@ -36,24 +36,13 @@ module Stripe
36
36
  end
37
37
 
38
38
  def create_options
39
- if api_version_after_switch_to_products_in_plans
39
+ if CurrentApiVersion.after_switch_to_products_in_plans?
40
40
  default_create_options
41
41
  else
42
42
  create_options_without_products
43
43
  end
44
44
  end
45
45
 
46
- def api_version_after_switch_to_products_in_plans
47
- Date.parse(current_api_version) >= Date.parse('2018-02-05')
48
- end
49
-
50
- def current_api_version
51
- Stripe.api_version || begin
52
- resp, _ = @stripe_class.request(:get, @stripe_class.resource_url)
53
- resp.http_headers['stripe-version']
54
- end
55
- end
56
-
57
46
  def default_create_options
58
47
  {
59
48
  :currency => @currency,
@@ -0,0 +1,42 @@
1
+ module Stripe
2
+ module Products
3
+ include ConfigurationBuilder
4
+
5
+ configuration_for :product do
6
+ attr_accessor :name,
7
+ :type,
8
+ :active,
9
+ :attributes,
10
+ :description,
11
+ :caption,
12
+ :metadata,
13
+ :shippable,
14
+ :url
15
+
16
+ validates_presence_of :name, :type
17
+
18
+ validates :active, :shippable, inclusion: { in: [true, false] }, allow_nil: true
19
+ validates :type, inclusion: { in: %w(service good) }
20
+ validates :caption, :description, :shippable, :url, absence: true, unless: :good?
21
+
22
+ private
23
+ def good?
24
+ type == 'good'
25
+ end
26
+
27
+ def create_options
28
+ {
29
+ name: name,
30
+ type: type,
31
+ active: active,
32
+ attributes: attributes,
33
+ description: description,
34
+ caption: caption,
35
+ metadata: metadata,
36
+ shippable: shippable,
37
+ url: url,
38
+ }.delete_if{|_, v| v.nil? }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,6 +2,8 @@ require 'responders'
2
2
  require "stripe/rails/version"
3
3
  require 'stripe/engine'
4
4
  require 'stripe/configuration_builder'
5
+ require 'stripe/current_api_version'
5
6
  require 'stripe/plans'
6
7
  require 'stripe/coupons'
7
- require 'stripe/callbacks'
8
+ require 'stripe/products'
9
+ require 'stripe/callbacks'
@@ -1,6 +1,4 @@
1
-
2
1
  namespace :stripe do
3
-
4
2
  desc 'verify your stripe.com authentication configuration'
5
3
  task 'verify' => :environment do
6
4
  begin
@@ -11,6 +9,14 @@ namespace :stripe do
11
9
  end
12
10
  end
13
11
 
12
+ task 'products:prepare' => 'environment' do
13
+ if CurrentApiVersion.after_switch_to_products_in_plans?
14
+ Stripe::Products.put!
15
+ else
16
+ puts '[SKIPPED] Current API version does not support Products'
17
+ end
18
+ end
19
+
14
20
  task 'plans:prepare' => 'environment' do
15
21
  Stripe::Plans.put!
16
22
  end
@@ -24,6 +30,6 @@ namespace :stripe do
24
30
  Stripe::Coupons.reset!
25
31
  end
26
32
 
27
- desc "create all plans and coupons defined in config/stripe/{plans|coupons}.rb"
28
- task 'prepare' => ['plans:prepare', 'coupons:prepare']
33
+ desc "create all plans and coupons defined in config/stripe/{products|plans|coupons}.rb"
34
+ task 'prepare' => ['products:prepare', 'plans:prepare', 'coupons:prepare']
29
35
  end
@@ -1,5 +1,5 @@
1
1
  module Stripe
2
2
  module Rails
3
- VERSION = '1.3.0'
3
+ VERSION = '1.4.0'
4
4
  end
5
5
  end
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'building coupons' do
4
- parallelize_me!
5
-
6
4
  before do
7
5
  Stripe::Coupons.configurations.clear
8
6
  end
@@ -1,4 +1,5 @@
1
1
  Dummy::Application.configure do
2
+ config.eager_load = false
2
3
  # Settings specified here will take precedence over those in config/application.rb
3
4
 
4
5
  # In the development environment your application's code is reloaded on
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'building products' do
4
+ before do
5
+ Stripe.product :primo do |product|
6
+ product.name = 'Acme as a service PRIMO'
7
+ product.type = 'service'
8
+ product.active = true
9
+ product.attributes = ['size', 'gender']
10
+ product.metadata = {:number_of_awesome_things => 5}
11
+ end
12
+ end
13
+
14
+ after { Stripe::Products.send(:remove_const, :PRIMO) }
15
+
16
+ it 'is accessible via id' do
17
+ Stripe::Products::PRIMO.wont_be_nil
18
+ end
19
+
20
+ it 'is accessible via collection' do
21
+ Stripe::Products.all.must_include Stripe::Products::PRIMO
22
+ end
23
+
24
+ it 'is accessible via hash lookup (symbol/string agnostic)' do
25
+ Stripe::Products[:primo].must_equal Stripe::Products::PRIMO
26
+ Stripe::Products['primo'].must_equal Stripe::Products::PRIMO
27
+ end
28
+
29
+ describe '.put!' do
30
+ describe 'when none exists on stripe.com' do
31
+ before { Stripe::Product.stubs(:retrieve).raises(Stripe::InvalidRequestError.new("not found", "id")) }
32
+
33
+ it 'creates the plan online' do
34
+ Stripe::Product.expects(:create).with(
35
+ :id => :primo,
36
+ :name => 'Acme as a service PRIMO',
37
+ :type => 'service',
38
+ :active => true,
39
+ :attributes => ['size', 'gender'],
40
+ :metadata => {:number_of_awesome_things => 5},
41
+ )
42
+ Stripe::Products::PRIMO.put!
43
+ end
44
+ end
45
+
46
+ describe 'when it is already present on stripe.com' do
47
+ before do
48
+ Stripe::Product.stubs(:retrieve).returns(Stripe::Product.construct_from({
49
+ :id => :primo,
50
+ :name => 'Acme as a service PRIMO',
51
+ }))
52
+ end
53
+
54
+ it 'is a no-op' do
55
+ Stripe::Product.expects(:create).never
56
+ Stripe::Products::PRIMO.put!
57
+ end
58
+ end
59
+ end
60
+
61
+ describe 'validations' do
62
+ describe 'with missing mandatory values' do
63
+ it 'raises an exception after configuring it' do
64
+ lambda { Stripe.product(:bad){} }.must_raise Stripe::InvalidConfigurationError
65
+ end
66
+ end
67
+
68
+ describe 'invalid type' do
69
+ it 'raises an exception during configuration' do
70
+ lambda {
71
+ Stripe.product :broken do |product|
72
+ product.name = 'Acme as a service BROKEN'
73
+ product.type = 'anything'
74
+ end
75
+ }.must_raise Stripe::InvalidConfigurationError
76
+ end
77
+ end
78
+
79
+ describe 'when using an attribute only for goods' do
80
+ it 'raises an exception during configuration' do
81
+ lambda {
82
+ Stripe.product :broken do |product|
83
+ product.name = 'Broken Service'
84
+ product.type = 'service'
85
+ product.caption = 'So good it is Primo'
86
+ end
87
+ }.must_raise Stripe::InvalidConfigurationError
88
+ end
89
+ end
90
+ end
91
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-07-23 00:00:00.000000000 Z
13
+ date: 2018-07-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -62,7 +62,6 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - ".codeclimate.yml"
65
- - ".github/release-drafter.yml"
66
65
  - ".gitignore"
67
66
  - ".rubocop.yml"
68
67
  - ".travis.yml"
@@ -84,13 +83,16 @@ files:
84
83
  - lib/generators/stripe/install_generator.rb
85
84
  - lib/generators/templates/coupons.rb
86
85
  - lib/generators/templates/plans.rb
86
+ - lib/generators/templates/products.rb
87
87
  - lib/stripe-rails.rb
88
88
  - lib/stripe/callbacks.rb
89
89
  - lib/stripe/callbacks/builder.rb
90
90
  - lib/stripe/configuration_builder.rb
91
91
  - lib/stripe/coupons.rb
92
+ - lib/stripe/current_api_version.rb
92
93
  - lib/stripe/engine.rb
93
94
  - lib/stripe/plans.rb
95
+ - lib/stripe/products.rb
94
96
  - lib/stripe/rails.rb
95
97
  - lib/stripe/rails/tasks.rake
96
98
  - lib/stripe/rails/testing.rb
@@ -147,6 +149,7 @@ files:
147
149
  - test/javascript_helper_spec.rb
148
150
  - test/pings_controller_spec.rb
149
151
  - test/plan_builder_spec.rb
152
+ - test/product_builder_spec.rb
150
153
  - test/spec_helper.rb
151
154
  - test/stripe_initializers_spec.rb
152
155
  - test/support/application_system_test_case.rb
@@ -230,6 +233,7 @@ test_files:
230
233
  - test/javascript_helper_spec.rb
231
234
  - test/pings_controller_spec.rb
232
235
  - test/plan_builder_spec.rb
236
+ - test/product_builder_spec.rb
233
237
  - test/spec_helper.rb
234
238
  - test/stripe_initializers_spec.rb
235
239
  - test/support/application_system_test_case.rb
@@ -1,4 +0,0 @@
1
- template: |
2
- ## What's Changed
3
-
4
- $CHANGES