stripe_wrapper 0.1.5 → 0.1.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 608895732525b9ea768c68e4e6a2abd91d5b5cd2
|
4
|
+
data.tar.gz: 1642287f1f67a297ec72ca68e5398c299f2a994c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 235468ffcff1e8e40b28e2cb21a0ef9b82cf894994da7b2b38a167b1d7e14dc09bb6b207d66091174d51ed1e903d0b9620edc2aae40111b77bbd38f0fd35c8f2
|
7
|
+
data.tar.gz: 65326c20b042d0f0650a8db42724b4561b117123c2c0d5e6a2e2a67545bd9b1d664cb8eca456d6dc702e83ff9caf941a3ae91e49dede5e47a5906e3d69ae4ba8
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# StripeWrapper
|
2
|
-
|
2
|
+
StripeWrapper is a Wrapper around the Stripe Gem, simplifying the amount of work you need to do in order to generate charges and customers using [Stripe](https://www.stripe.com). The main purpose of this gem is to allow you to implement an easy solution using [Stripe](https://www.stripe.com) in just a few lines of code.
|
3
3
|
|
4
|
-
## Usage
|
5
|
-
How to use my plugin.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
Add this line to your application's Gemfile:
|
@@ -16,13 +14,89 @@ And then execute:
|
|
16
14
|
$ bundle
|
17
15
|
```
|
18
16
|
|
17
|
+
|
19
18
|
Or install it yourself as:
|
20
19
|
```bash
|
21
20
|
$ gem install stripe_wrapper
|
22
21
|
```
|
23
22
|
|
23
|
+
Then execute the installer in order to generate the migrations and mount the engine
|
24
|
+
```bash
|
25
|
+
$ rails generate stripe_wrapper:install
|
26
|
+
```
|
27
|
+
|
28
|
+
This will copy the two core models of the Wrapper:
|
29
|
+
|
30
|
+
1. Charges (`StripeWrapper::Charge`)
|
31
|
+
|
32
|
+
2. Customers (`StripeWrapper::Customer`)
|
33
|
+
|
34
|
+
You can also copy all the controllers, views and models by running in order to customize the views and scaffolds as you like
|
35
|
+
```
|
36
|
+
$ rails generate stripe_wrapper:copy_files
|
37
|
+
```
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
After installing the gem and running the generators, using this gem is very easy. These are the steps you must follow in order to use it.
|
41
|
+
|
42
|
+
1. You must add the main helper to your main_app's ApplicationController, as follows:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class ApplicationController < ActionController::Base
|
46
|
+
include StripeWrapper::StripeWrapperHelper
|
47
|
+
#More Code
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
2. Go to an action where you decide to charge the customer. Here you must set the amount you're charging your customer. You can do this easily by using the following method:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
def my_cool_action
|
55
|
+
stripe_set_amount(@amount)
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
3. In the corresponding view, render stripe_wrapper's partial, passing as argument the URL you desire to be redirected to after the charge is processed.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
= render partial: 'stripe_wrapper/charges/pay',locals:{redirect_url: your_cool_path}
|
63
|
+
```
|
64
|
+
|
65
|
+
4. After the payment is processed, you will be redirected to the path you specified, with the charge_id param as response. Let's say you were redirected to the action payment_processed, you'd get the Charge ID like this
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
def payment_processed
|
69
|
+
charge_id = params[:charge_id]
|
70
|
+
redirect_to root_path, notice: "Payment with ID #{charge_id} was created"
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
5. You can access stripe_wrapper's dashboard by going to the engine's route (by default `/stripe_wrapper`). You'll be able to see the scaffolds of both Charges and Customers.
|
75
|
+
|
24
76
|
## Contributing
|
25
77
|
Contribution directions go here.
|
26
78
|
|
79
|
+
## TODO
|
80
|
+
|
81
|
+
Tests are missing, and ideally charts are needed in both scaffolds
|
82
|
+
|
83
|
+
## Development
|
84
|
+
|
85
|
+
To be more clear - this is the for when you are working on this gem. Not for when you are implementing it into your Rails app.
|
86
|
+
|
87
|
+
First, to get started, migrate and seed the database (SQLite by default):
|
88
|
+
|
89
|
+
```bash
|
90
|
+
bundle
|
91
|
+
# Create, migrate, and seed the development database with fake forum users, topics, and posts:
|
92
|
+
rake db:create db:migrate db:seed
|
93
|
+
```
|
94
|
+
|
95
|
+
Then, start the dummy app server:
|
96
|
+
|
97
|
+
```bash
|
98
|
+
rake dev:server
|
99
|
+
```
|
100
|
+
|
27
101
|
## License
|
28
102
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module StripeWrapper
|
3
|
+
class FileCopyGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def copy_files
|
7
|
+
# controllers
|
8
|
+
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "app", "controllers", "stripe_wrapper")
|
9
|
+
target = File.join(Rails.root, "app", "controllers", "stripe_wrapper")
|
10
|
+
FileUtils.cp_r source, target
|
11
|
+
# models
|
12
|
+
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "app", "models", "stripe_wrapper")
|
13
|
+
target = File.join(Rails.root, "app", "models", "stripe_wrapper")
|
14
|
+
FileUtils.cp_r source, target
|
15
|
+
# views
|
16
|
+
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "app", "views", "stripe_wrapper")
|
17
|
+
target = File.join(Rails.root, "app", "views", "stripe_wrapper")
|
18
|
+
FileUtils.cp_r source, target
|
19
|
+
# locales
|
20
|
+
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "config", "locales", "en.yml")
|
21
|
+
target = File.join(Rails.root, "config", "locales", "stripe_wrapper.en.yml")
|
22
|
+
FileUtils.cp source, target
|
23
|
+
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "config", "locales", "es.yml")
|
24
|
+
target = File.join(Rails.root, "config", "locales", "stripe_wrapper.es.yml")
|
25
|
+
FileUtils.cp source, target
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -10,27 +10,5 @@ module StripeWrapper
|
|
10
10
|
def mount_engine
|
11
11
|
route 'mount StripeWrapper::Engine => "/stripe_wrapper", as: "stripe_wrapper"'
|
12
12
|
end
|
13
|
-
|
14
|
-
def copy_files
|
15
|
-
# controllers
|
16
|
-
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "app", "controllers", "stripe_wrapper")
|
17
|
-
target = File.join(Rails.root, "app", "controllers", "stripe_wrapper")
|
18
|
-
FileUtils.cp_r source, target
|
19
|
-
# models
|
20
|
-
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "app", "models", "stripe_wrapper")
|
21
|
-
target = File.join(Rails.root, "app", "models", "stripe_wrapper")
|
22
|
-
FileUtils.cp_r source, target
|
23
|
-
# views
|
24
|
-
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "app", "views", "stripe_wrapper")
|
25
|
-
target = File.join(Rails.root, "app", "views", "stripe_wrapper")
|
26
|
-
FileUtils.cp_r source, target
|
27
|
-
# locales
|
28
|
-
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "config", "locales", "en.yml")
|
29
|
-
target = File.join(Rails.root, "config", "locales", "stripe_wrapper.en.yml")
|
30
|
-
FileUtils.cp source, target
|
31
|
-
source = File.join(Gem.loaded_specs["stripe_wrapper"].full_gem_path, "config", "locales", "es.yml")
|
32
|
-
target = File.join(Rails.root, "config", "locales", "stripe_wrapper.es.yml")
|
33
|
-
FileUtils.cp source, target
|
34
|
-
end
|
35
13
|
end
|
36
14
|
end
|
data/lib/stripe_wrapper.rb
CHANGED
@@ -5,8 +5,9 @@ module StripeWrapper
|
|
5
5
|
Stripe.api_key = ENV["STRIPE_KEY"]
|
6
6
|
|
7
7
|
# Source is either a customer or a token
|
8
|
-
def self.create_charge(customer=nil,source=nil,amount=
|
8
|
+
def self.create_charge(customer=nil,source=nil,amount=nil,currency='clp',metadata={},description='')
|
9
9
|
#Metadata must be a hash. Example: :metadata => {'order_id' => '6735'}
|
10
|
+
return false if amount.blank?()
|
10
11
|
Stripe::Charge.create({
|
11
12
|
amount: amount,
|
12
13
|
currency: currency,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Peebles | @waclock
|
@@ -378,6 +378,7 @@ files:
|
|
378
378
|
- config/routes.rb
|
379
379
|
- db/migrate/20161215195603_create_stripe_wrapper_customers.rb
|
380
380
|
- db/migrate/20161215195608_create_stripe_wrapper_charges.rb
|
381
|
+
- lib/generators/stripe_wrapper/file_copy/file_copy_generator.rb
|
381
382
|
- lib/generators/stripe_wrapper/install/USAGE
|
382
383
|
- lib/generators/stripe_wrapper/install/install_generator.rb
|
383
384
|
- lib/stripe_wrapper.rb
|