koduc_stripe 1.0.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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +123 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/koduc_stripe.gemspec +39 -0
- data/lib/koduc_stripe.rb +62 -0
- data/lib/koduc_stripe/version.rb +3 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1052eede935a10f12f4ed31582e2aa2dc4f255f5
|
4
|
+
data.tar.gz: fc3c43b3b451d8f9be1def470f6fa88bb63f9d03
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9d8f3037a1245e0390d890551d802f2da5fe6e6486ba611da6c366c433298fbce554bc0b9fdf0570d5ad82c47a250d15857410d186bd4abc219287e624ab591
|
7
|
+
data.tar.gz: 1a250ede7a08b20192f2059e107656303010b38daaa56a3a48fc84f21d54629b8d5c2041a46092bacc6438075cb395a3cfda96a9dc873f396cbef1939efd1e2f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# KoducStripe
|
2
|
+
|
3
|
+
KoducStripe is a lightweight wrapper for Stripe payments API. This ruby gem provides a platform to integrate Stripe payment gateway in Ruby on Rails Application.
|
4
|
+
|
5
|
+
>Currently KoducStripe supports One-time Payment with partially or completely Refund payment with Stripe.
|
6
|
+
|
7
|
+
It is developed for the usage in Ruby on Rails web applications and integrates as a Rails plugin.
|
8
|
+
|
9
|
+
It is developed in November 2015 by [KSolves](http://www.ksolves.com/) team with the help of valuable contributors.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'koduc_stripe'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install koduc_stripe
|
26
|
+
|
27
|
+
# Usage
|
28
|
+
|
29
|
+
Provide the Stripe API Key while initializing the Rails Application by placing the key under `config/initializer`.
|
30
|
+
|
31
|
+
Create a new file in initializer, say `koduc_stripe.rb` and write below piece of code there.
|
32
|
+
```ruby
|
33
|
+
KsStripe::Client.configure do |config|
|
34
|
+
config.stripe_api_key = STRIPE_API_KEY
|
35
|
+
end
|
36
|
+
```
|
37
|
+
** Do not forget to restart the rails server after adding Stripe API Key.
|
38
|
+
|
39
|
+
|
40
|
+
## Charge a user
|
41
|
+
To charge a user, first create an object of `KsStripe::KsBase` class by supplying a hash containing card details. Hash should have below keys:
|
42
|
+
* ``` card_number => Card Number to charged (Required) ```
|
43
|
+
* ``` cvc => Card Verification Code of the card (Required)```
|
44
|
+
* ``` exp_month => Expiration month of the Card (Required)```
|
45
|
+
* ``` exp_year => Expiration Year of the Card (Required)```
|
46
|
+
* ``` name => Name on the Card (Optional)```
|
47
|
+
* ``` card_type => Type of the credit card (Optional)```
|
48
|
+
|
49
|
+
For example:
|
50
|
+
```ruby
|
51
|
+
card_obj = KsStripe::KsBase.new(
|
52
|
+
:card_number=>'4242424242424242',
|
53
|
+
:cvc=>'123',
|
54
|
+
:exp_month => '01',
|
55
|
+
:exp_year => '2020',
|
56
|
+
:card_type => 'visa',
|
57
|
+
:name=>"Atul Khanduri"
|
58
|
+
)
|
59
|
+
```
|
60
|
+
|
61
|
+
Secondly, charge the user by calling `charge method` from `KsStripe::KsBase` object with amount to be charged and optional description of the payment as parameters.
|
62
|
+
|
63
|
+
For example:
|
64
|
+
```ruby
|
65
|
+
charge = card_obj.charge(10, "This is a test payment by KsStripe Gem")
|
66
|
+
```
|
67
|
+
|
68
|
+
##### Please Note:
|
69
|
+
* Amount to be charge must be in cents and supports only US Dollars.
|
70
|
+
* Amount should be a positive integer as Stripe does not supports amount in decimals.
|
71
|
+
* If card_type is provided then only Card is Validated using Regular expression. Although other algorithm's are always applied to validate card number.
|
72
|
+
* Credit Card type can only be american_express, mastercard, visa, jcb, diners_club or discover as Stripe supports only these type of cards.
|
73
|
+
|
74
|
+
|
75
|
+
#### Response of One Time Payment Charge:
|
76
|
+
If the Charge is successful then the response will be the response returned by Stripe.
|
77
|
+
|
78
|
+
If there's any validation or any other error in the payment, then all the errors are returned in below format:
|
79
|
+
```ruby
|
80
|
+
{
|
81
|
+
"error" => {
|
82
|
+
"message" => [<All the Error Messages in Array>]
|
83
|
+
}
|
84
|
+
}
|
85
|
+
```
|
86
|
+
|
87
|
+
### Refund a Payment
|
88
|
+
|
89
|
+
To refund a one-time payment, call `KsStripe::KsBase.refund` method with parameters as charge id, optional amount(in cents) to be refund and optional reason of the refund.
|
90
|
+
```ruby
|
91
|
+
KsStripe::KsBase.refund(<charge_id>, <amount>, <reason>)
|
92
|
+
```
|
93
|
+
|
94
|
+
##### Please Note:
|
95
|
+
* Amount to be charge must be in cents and supports only US Dollars.
|
96
|
+
* Complete payment is refunded if amount is not provided in the parameter else partially amount is refunded as provided in the parameter.
|
97
|
+
* Amount must not be greater than the charge amount.
|
98
|
+
* Refund reason must be one of duplicate, fraudulent or requested_by_customer
|
99
|
+
|
100
|
+
#### Response of Refund:
|
101
|
+
If the refund is successful then the response will be the response returned by Stripe.
|
102
|
+
|
103
|
+
If there's any validation or any other error in payment refund, then all the errors are returned in below format:
|
104
|
+
```ruby
|
105
|
+
{
|
106
|
+
"error" => {
|
107
|
+
"message" => [<All the Error Messages in Array>]
|
108
|
+
}
|
109
|
+
}
|
110
|
+
```
|
111
|
+
|
112
|
+
|
113
|
+
## Contact
|
114
|
+
|
115
|
+
If you found any issue in the Gem then do not forgot to create a issue in Github.
|
116
|
+
|
117
|
+
If you have any query, need support or advice just DROP us a line and we’ll be in touch very soon.
|
118
|
+
|
119
|
+
Email: support@koduc.com
|
120
|
+
|
121
|
+
You can also contact us at +91-120-4540178
|
122
|
+
|
123
|
+
We’d love to hear from you! :) :)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "koduc_stripe"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'koduc_stripe/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "koduc_stripe"
|
8
|
+
spec.version = KsStripe::VERSION
|
9
|
+
spec.authors = ["Koduc"]
|
10
|
+
spec.email = ["ratan@ksolves.com"]
|
11
|
+
|
12
|
+
spec.summary = "KsStripe is a Ruby Gem for Stripe Payment Gateway Integration"
|
13
|
+
spec.description = "KsStripe provides a platform to integrate Stripe payment gateway in Ruby on Rails Application"
|
14
|
+
spec.homepage = "https://github.com/kartiksolves/koduc-stripe"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.required_ruby_version = '>= 1.9.3'
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
20
|
+
# delete this section to allow pushing this gem to any host.
|
21
|
+
# if spec.respond_to?(:metadata)
|
22
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
23
|
+
# else
|
24
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
+
# end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
|
36
|
+
# Rails >=3.2 supports Ruby 1.9.3 (http://edgeguides.rubyonrails.org/3_2_release_notes.html)
|
37
|
+
spec.add_dependency 'activesupport', '>= 3.2'
|
38
|
+
spec.add_dependency "rest-client", '~> 1.4'
|
39
|
+
end
|
data/lib/koduc_stripe.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext"
|
3
|
+
require "rest_client"
|
4
|
+
|
5
|
+
require "koduc_stripe/base"
|
6
|
+
require "koduc_stripe/empty"
|
7
|
+
require "koduc_stripe/error"
|
8
|
+
require "koduc_stripe/luhn"
|
9
|
+
require "koduc_stripe/number_check"
|
10
|
+
require "koduc_stripe/validation"
|
11
|
+
require "koduc_stripe/version"
|
12
|
+
require "koduc_stripe/request"
|
13
|
+
|
14
|
+
module KsStripe
|
15
|
+
# Set the Stripe API key
|
16
|
+
#
|
17
|
+
class Client
|
18
|
+
cattr_reader :stripe_token
|
19
|
+
|
20
|
+
class << self
|
21
|
+
# Set the Stripe API key to a class variable
|
22
|
+
#
|
23
|
+
#
|
24
|
+
# == Parameter: A block of code having Stripe API Key
|
25
|
+
# == Returns: None
|
26
|
+
def configure(&block)
|
27
|
+
config = OpenStruct.new
|
28
|
+
block.call config
|
29
|
+
|
30
|
+
# if config[:stripe_api_key].blank?
|
31
|
+
# raise "No Stripe API key provided."
|
32
|
+
# elsif KsStripe::Empty.empty?(config[:stripe_api_key])
|
33
|
+
if KsStripe::Empty.empty?(config[:stripe_api_key])
|
34
|
+
raise "No Stripe API key provided. Please initialize the App with valid stripe API key."
|
35
|
+
end
|
36
|
+
|
37
|
+
@@stripe_token = config[:stripe_api_key]
|
38
|
+
end
|
39
|
+
|
40
|
+
# Gives the Stripe API Key
|
41
|
+
#
|
42
|
+
# == Parameter: None
|
43
|
+
# == Returns: Stripe API Key
|
44
|
+
def stripe_key
|
45
|
+
return @@stripe_token
|
46
|
+
end
|
47
|
+
|
48
|
+
# Gives Stripe Authorization Header for Stripe API request
|
49
|
+
#
|
50
|
+
# == Parameter: None
|
51
|
+
# == Returns: If stripe key is provided then return Stripe Authorization Header
|
52
|
+
# otherwise Raise exception.
|
53
|
+
def get_key_header
|
54
|
+
if KsStripe::Empty.empty?(self.stripe_key)
|
55
|
+
raise "No Stripe API key provided. Please initialize the App with valid stripe API key."
|
56
|
+
end
|
57
|
+
@@stripe_auth_key = "Bearer #{self.stripe_key}"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: koduc_stripe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Koduc
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
description: KsStripe provides a platform to integrate Stripe payment gateway in Ruby
|
84
|
+
on Rails Application
|
85
|
+
email:
|
86
|
+
- ratan@ksolves.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- koduc_stripe.gemspec
|
100
|
+
- lib/koduc_stripe.rb
|
101
|
+
- lib/koduc_stripe/version.rb
|
102
|
+
homepage: https://github.com/kartiksolves/koduc-stripe
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 1.9.3
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.3
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: KsStripe is a Ruby Gem for Stripe Payment Gateway Integration
|
126
|
+
test_files: []
|
127
|
+
has_rdoc:
|