op_cart 0.5.4 → 0.6.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
  SHA1:
3
- metadata.gz: 6e0c424060ed4b6f0739040d08dd189e67199c5a
4
- data.tar.gz: 86b5699ad0f4ba34a46e1512aa6b20e6444693ce
3
+ metadata.gz: 9b3f63a006094e5d32cc7a4def31e9ebff2ea42b
4
+ data.tar.gz: d16646e931c1e6c3cae3919b46ee9bc4b7204fc0
5
5
  SHA512:
6
- metadata.gz: adcf403857d3529c60dac9c3739004d41d49198cafbe58ff840373eecddd549a6e060eb4a391932304d9d05314a9017035939f66b1bfd2d2b359c9cc3ab12628
7
- data.tar.gz: bbd5e30eb7c5717b346398dfe09ffdc6fc14f3c672e8adbc355c4fe96abe0c7cbc9edb33e764acacee7e650a8fddd90ea9350435adce5bd3eb240e41dd2ac478
6
+ metadata.gz: ec51a4e9afeb2076c0c74fb2b51e5af79441b245a2123fcbcb6c74e30ab43004b1e59f16dac594142a1aef133a0c0cbd177d333632fc60128064d0c0e61cdf4f
7
+ data.tar.gz: 4eccb7a658c896fda9e50e7140f6352ad944ca682f7240af8dc0c74fbd49f16e81300e3a52172954cd926f27330a356a555c4bf2c1f46fac5c828049bdead220
@@ -81,7 +81,12 @@ module OpCart
81
81
  def create_subscriptions
82
82
  line_items.each do |li|
83
83
  if li.sellable.is_a? Plan
84
- subscriptions.new customer: customer, plan: li.sellable, quantity: li.quantity
84
+ es = existing_subscription = customer.subscriptions.where(plan: li.sellable).first
85
+ if existing_subscription.present?
86
+ es.update_attributes quantity: es.quantity + li.quantity
87
+ else
88
+ subscriptions.new customer: customer, plan: li.sellable, quantity: li.quantity
89
+ end
85
90
  end
86
91
  end
87
92
  end
@@ -37,11 +37,11 @@ module OpCart
37
37
  end
38
38
 
39
39
  def update_subscription
40
- subscriptions_attributes = {}
41
- subscriptions_attributes[:quantity] = quantity if quantity_changed?
42
- subscriptions_attributes[:trial_end] = trial_ended_at.to_i if trial_ended_at_changed?
43
- subscriptions_attributes[:plan] = plan.processor_token if plan_id_changed?
44
- update_local_object customer.processor_object.subscriptions.create(subscriptions_attributes)
40
+ subscription = customer.processor_object.subscriptions.retrieve(processor_token)
41
+ subscription.quantity = quantity if quantity_changed?
42
+ subscription.trial_end = trial_ended_at.to_i if trial_ended_at_changed?
43
+ subscription.plan = plan.processor_token if plan_id_changed?
44
+ update_local_object subscription.save
45
45
  rescue Stripe::InvalidRequestError => e
46
46
  if e.param
47
47
  self.errors.add e.param, e.message
@@ -1,3 +1,3 @@
1
1
  module OpCart
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: op_cart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Boehs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails