colt 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/colt.gemspec +1 -1
- data/lib/colt.rb +0 -2
- data/lib/colt/subscription.rb +18 -0
- data/lib/colt/version.rb +1 -1
- metadata +7 -10
- data/CHANGELOG.md +0 -4
- data/lib/colt/credential.rb +0 -23
- data/lib/colt/credit_card.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c509e05ca3f0604b1c6726d3ba025b19de7bf7cd
|
4
|
+
data.tar.gz: 98addf173347dcbbabba501ac88025dcbb6e947c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aadae8203559ce61714d601908c624161ec6957c2ab378059112ad5b9df0494fd114672b9e517691ec8f22b4949e2b36b6802ddbc2c8fa466c6a9b67f3a5445e
|
7
|
+
data.tar.gz: 98057ccfb2b431b195b286188f5125aeb95650017996ac4c5607ad92fc49f87a5611ce7600de0e6126bd09abe727557e670950459e91e852e6998567ae47f2ec
|
data/README.md
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
# Colt
|
2
2
|
|
3
|
-
Colt is a micro gem used to subscribe to a given plan using the Stripe API. The plans must already exist in your account.
|
3
|
+
Colt is a micro gem used to subscribe to a given plan using the Stripe API. The plans must already exist in your account. To experiment with the code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
5
|
## Our Sponsor
|
6
6
|
|
7
7
|
This project is sponsored by Zepho Inc. If you are interested in learning TDD in Ruby, you can redeem the coupon here: https://www.udemy.com/learn-test-driven-development-in-ruby/?couponCode=svr
|
8
8
|
|
9
|
+
## Features:
|
10
|
+
|
11
|
+
1. Recurring billing
|
12
|
+
- Subscribe to a plan
|
13
|
+
- Change plan
|
14
|
+
- Cancel subscription
|
15
|
+
2. Process Subscription Payment Failures for Webhooks
|
16
|
+
|
9
17
|
## Version
|
10
18
|
|
11
19
|
Ruby : 2.2.3
|
@@ -38,10 +46,9 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
38
46
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). To run the tests:
|
39
47
|
|
40
48
|
```ruby
|
41
|
-
$ruby -rminitest/pride test/credential_test.rb --verbose
|
42
49
|
$ruby -rminitest/pride test/colt_integration_test.rb --verbose
|
43
50
|
$ruby -rminitest/pride test/subscription_test.rb --verbose
|
44
|
-
$ruby -rminitest/pride test/
|
51
|
+
$ruby -rminitest/pride test/subscription_payment_test.rb --verbose
|
45
52
|
```
|
46
53
|
|
47
54
|
or
|
data/colt.gemspec
CHANGED
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.10"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "minitest", "~> 5.8"
|
27
|
-
spec.add_development_dependency "rubycritic"
|
27
|
+
spec.add_development_dependency "rubycritic", "~> 1.4"
|
28
28
|
end
|
data/lib/colt.rb
CHANGED
data/lib/colt/subscription.rb
CHANGED
@@ -2,6 +2,13 @@ require 'stripe'
|
|
2
2
|
|
3
3
|
module Colt
|
4
4
|
class Subscription
|
5
|
+
|
6
|
+
#
|
7
|
+
# email : The email of the customer
|
8
|
+
# stripe_token : Token representing the credit card
|
9
|
+
#
|
10
|
+
# Returns : Stripe::Customer object
|
11
|
+
#
|
5
12
|
def self.create(email, stripe_token, plan_id, description='none')
|
6
13
|
Stripe::Customer.create(email: email,
|
7
14
|
description: description,
|
@@ -9,11 +16,22 @@ module Colt
|
|
9
16
|
plan: plan_id)
|
10
17
|
end
|
11
18
|
|
19
|
+
#
|
20
|
+
# customer_id : Stripe customer to add a new credit card
|
21
|
+
# plan_id : The plan to subscribe the customer. It is a string like 'gold'.
|
22
|
+
#
|
23
|
+
# Returns : Stripe::Subscription object
|
24
|
+
#
|
12
25
|
def self.update(customer_id, plan_id)
|
13
26
|
customer = Stripe::Customer.retrieve(customer_id)
|
14
27
|
customer.update_subscription(plan: plan_id)
|
15
28
|
end
|
16
29
|
|
30
|
+
#
|
31
|
+
# customer_id : Stripe customer to add a new credit card
|
32
|
+
#
|
33
|
+
# Returns : Stripe::Subscription object
|
34
|
+
#
|
17
35
|
def self.cancel(customer_id)
|
18
36
|
customer = Stripe::Customer.retrieve(customer_id)
|
19
37
|
customer.cancel_subscription
|
data/lib/colt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bala Paranj
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stripe
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rubycritic
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.4'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1.4'
|
83
83
|
description: This gem simplifies subscribing a user to a given recurring plan using
|
84
84
|
Stripe API.
|
85
85
|
email:
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- ".ruby-gemset"
|
93
93
|
- ".ruby-version"
|
94
94
|
- ".travis.yml"
|
95
|
-
- CHANGELOG.md
|
96
95
|
- Gemfile
|
97
96
|
- LICENSE.txt
|
98
97
|
- README.md
|
@@ -101,8 +100,6 @@ files:
|
|
101
100
|
- bin/setup
|
102
101
|
- colt.gemspec
|
103
102
|
- lib/colt.rb
|
104
|
-
- lib/colt/credential.rb
|
105
|
-
- lib/colt/credit_card.rb
|
106
103
|
- lib/colt/subscription.rb
|
107
104
|
- lib/colt/subscription_payment.rb
|
108
105
|
- lib/colt/version.rb
|
@@ -126,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
123
|
version: '0'
|
127
124
|
requirements: []
|
128
125
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.4.7
|
130
127
|
signing_key:
|
131
128
|
specification_version: 4
|
132
129
|
summary: A micro gem to subscribe to a plan using stripe gem.
|
data/CHANGELOG.md
DELETED
data/lib/colt/credential.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Colt
|
2
|
-
class Credential
|
3
|
-
def self.check
|
4
|
-
message = <<ERROR
|
5
|
-
Stripe credentials is not set properly or it is incorrect.
|
6
|
-
Define the following Stripe environment variables.
|
7
|
-
|
8
|
-
export STRIPE_PUBLISHABLE_KEY='pk_test your publishable key'
|
9
|
-
export STRIPE_SECRET_KEY='sk_test your secret key'
|
10
|
-
|
11
|
-
and define:
|
12
|
-
|
13
|
-
Stripe.api_key = 'sk_test your secret key'
|
14
|
-
ERROR
|
15
|
-
begin
|
16
|
-
::Stripe::Account.retrieve
|
17
|
-
rescue ::Stripe::AuthenticationError => exception
|
18
|
-
raise exception
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
data/lib/colt/credit_card.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module Colt
|
2
|
-
|
3
|
-
class CreditCard
|
4
|
-
#
|
5
|
-
# Adds a new credit card as the active default card for an existing customer
|
6
|
-
#
|
7
|
-
# Returns : ?
|
8
|
-
def self.add(stripe_customer_id, stripe_token)
|
9
|
-
customer = Stripe::Customer.retrieve(stripe_customer_id)
|
10
|
-
card = customer.sources.create(source: stripe_token)
|
11
|
-
customer.default_card = card.id
|
12
|
-
customer.save
|
13
|
-
card
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
# Create a new credit card for a customer
|
18
|
-
#
|
19
|
-
# Returns : ?
|
20
|
-
def self.save(stripe_token, description)
|
21
|
-
Stripe::Customer.create(card: stripe_token, description: description)
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# Update expiration date of an existing credit card for a customer
|
26
|
-
#
|
27
|
-
# Returns ?
|
28
|
-
def self.update_expiration_date(stripe_customer_id, card_month, card_year)
|
29
|
-
customer = Stripe::Customer.retrieve(stripe_customer_id)
|
30
|
-
card = customer.sources.first
|
31
|
-
card.exp_month = card_month
|
32
|
-
card.exp_year = card_year
|
33
|
-
card.save
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|