od-payments 0.1.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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +95 -0
- data/LICENSE.txt +21 -0
- data/README.md +146 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/od/payments.rb +50 -0
- data/lib/od/payments/errors.rb +59 -0
- data/lib/od/payments/resources.rb +3 -0
- data/lib/od/payments/resources/charge.rb +79 -0
- data/lib/od/payments/resources/customer.rb +17 -0
- data/lib/od/payments/resources/payment_method.rb +60 -0
- data/lib/od/payments/version.rb +5 -0
- data/od-payments.gemspec +34 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 784fc7fa0cb56d8e29ce155e9944b6a53bda3b78c914193e2b0fb1265518aeda
|
4
|
+
data.tar.gz: 8d20dd3433c2386f29ee326eea35c041743417210b0d17b26e604a4f20b92fbe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '092ad61edd7dc5dc0f627d757c0ac3f67da8fd48cd68934caba96618fb3021062ea84deab33cc85c4fb220c772754ec39cb6e83dbcce0f4077e2bce7c1589ff7'
|
7
|
+
data.tar.gz: baccd488c9e6aecd5e7dcce531e45f7ad6c0b022514a878ccd38026d6b745ef2cee5e5aeac9bb2db1fbef0ca4e9a867d58660b3548dba739deaadd2514395a10
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
od-payments (0.1.0)
|
5
|
+
stripe (~> 5.22.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (6.0.3.2)
|
11
|
+
actionview (= 6.0.3.2)
|
12
|
+
activesupport (= 6.0.3.2)
|
13
|
+
rack (~> 2.0, >= 2.0.8)
|
14
|
+
rack-test (>= 0.6.3)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
+
actionview (6.0.3.2)
|
18
|
+
activesupport (= 6.0.3.2)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubi (~> 1.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
+
activesupport (6.0.3.2)
|
24
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
25
|
+
i18n (>= 0.7, < 2)
|
26
|
+
minitest (~> 5.1)
|
27
|
+
tzinfo (~> 1.1)
|
28
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
29
|
+
builder (3.2.4)
|
30
|
+
concurrent-ruby (1.1.6)
|
31
|
+
crass (1.0.6)
|
32
|
+
diff-lcs (1.4.4)
|
33
|
+
erubi (1.9.0)
|
34
|
+
faker (2.13.0)
|
35
|
+
i18n (>= 1.6, < 2)
|
36
|
+
generator_spec (0.9.4)
|
37
|
+
activesupport (>= 3.0.0)
|
38
|
+
railties (>= 3.0.0)
|
39
|
+
i18n (1.8.5)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
loofah (2.6.0)
|
42
|
+
crass (~> 1.0.2)
|
43
|
+
nokogiri (>= 1.5.9)
|
44
|
+
method_source (1.0.0)
|
45
|
+
mini_portile2 (2.4.0)
|
46
|
+
minitest (5.14.1)
|
47
|
+
nokogiri (1.10.10)
|
48
|
+
mini_portile2 (~> 2.4.0)
|
49
|
+
rack (2.2.3)
|
50
|
+
rack-test (1.1.0)
|
51
|
+
rack (>= 1.0, < 3)
|
52
|
+
rails-dom-testing (2.0.3)
|
53
|
+
activesupport (>= 4.2.0)
|
54
|
+
nokogiri (>= 1.6)
|
55
|
+
rails-html-sanitizer (1.3.0)
|
56
|
+
loofah (~> 2.3)
|
57
|
+
railties (6.0.3.2)
|
58
|
+
actionpack (= 6.0.3.2)
|
59
|
+
activesupport (= 6.0.3.2)
|
60
|
+
method_source
|
61
|
+
rake (>= 0.8.7)
|
62
|
+
thor (>= 0.20.3, < 2.0)
|
63
|
+
rake (12.3.3)
|
64
|
+
rspec (3.9.0)
|
65
|
+
rspec-core (~> 3.9.0)
|
66
|
+
rspec-expectations (~> 3.9.0)
|
67
|
+
rspec-mocks (~> 3.9.0)
|
68
|
+
rspec-core (3.9.2)
|
69
|
+
rspec-support (~> 3.9.3)
|
70
|
+
rspec-expectations (3.9.2)
|
71
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
72
|
+
rspec-support (~> 3.9.0)
|
73
|
+
rspec-mocks (3.9.1)
|
74
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
+
rspec-support (~> 3.9.0)
|
76
|
+
rspec-support (3.9.3)
|
77
|
+
stripe (5.22.0)
|
78
|
+
thor (1.0.1)
|
79
|
+
thread_safe (0.3.6)
|
80
|
+
tzinfo (1.2.7)
|
81
|
+
thread_safe (~> 0.1)
|
82
|
+
zeitwerk (2.4.0)
|
83
|
+
|
84
|
+
PLATFORMS
|
85
|
+
ruby
|
86
|
+
|
87
|
+
DEPENDENCIES
|
88
|
+
faker
|
89
|
+
generator_spec
|
90
|
+
od-payments!
|
91
|
+
rake (~> 12.0)
|
92
|
+
rspec (~> 3.0)
|
93
|
+
|
94
|
+
BUNDLED WITH
|
95
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 William De la Espriella
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Od::Payments
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
### Step 1
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'od-payments'
|
11
|
+
```
|
12
|
+
|
13
|
+
### Step 2
|
14
|
+
|
15
|
+
create `config/initializers/od_payments.rb` with
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Od::Payments.configure do |od_payment|
|
19
|
+
od_payment.api_key_stripe = 'api_key_stripe'
|
20
|
+
od_payment.access_token_square = 'access_token_square'
|
21
|
+
od_payment.environment_square = 'environment_square'
|
22
|
+
od_payment.adapter = :stripe # :stripe or :square, :stripe is adapter for default
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Payment
|
29
|
+
|
30
|
+
create
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
Od::Payments::Charge.create(2000, {
|
34
|
+
token_payment: 'pm_card_visa',
|
35
|
+
capture_method: 'automatic',
|
36
|
+
confirm: true })
|
37
|
+
```
|
38
|
+
|
39
|
+
| Prop | Type | Required | Description |
|
40
|
+
| ------- | ------- | -------- | ------------------------------------------------------------------------ |
|
41
|
+
| amount | Decimal | Yes | Amount |
|
42
|
+
| options | Hash | No | Other options show in https://stripe.com/docs/api/payment_intents/create |
|
43
|
+
|
44
|
+
capture
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
Od::Payments::Charge.capture("charge_id")
|
48
|
+
```
|
49
|
+
|
50
|
+
cancel
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
Od::Payments::Charge.cancel("charge_id")
|
54
|
+
```
|
55
|
+
|
56
|
+
void
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
Od::Payments::Charge.void("charge_id")
|
60
|
+
```
|
61
|
+
|
62
|
+
confirm
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
Od::Payments::Charge.confirm("charge_id")
|
66
|
+
```
|
67
|
+
|
68
|
+
### Payment Method
|
69
|
+
|
70
|
+
create with stripe example
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Od::Payments::PaymentMethod.create(
|
74
|
+
{
|
75
|
+
type: 'card',
|
76
|
+
card: {
|
77
|
+
number: '4000000000000341',
|
78
|
+
exp_month: 8,
|
79
|
+
exp_year: 2021,
|
80
|
+
cvc: '314'
|
81
|
+
}
|
82
|
+
}
|
83
|
+
)
|
84
|
+
```
|
85
|
+
|
86
|
+
| Prop | Type | Required | Description |
|
87
|
+
| ------ | ---- | -------- | ----------------------------------------------------------------- |
|
88
|
+
| params | Hash | Yes | Show params in https://stripe.com/docs/api/payment_methods/create |
|
89
|
+
|
90
|
+
list
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
Od::Payments::PaymentMethod.list "customer_id"
|
94
|
+
```
|
95
|
+
|
96
|
+
delete
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
Od::Payments::PaymentMethod.delete "payment_method_id"
|
100
|
+
```
|
101
|
+
|
102
|
+
show
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
Od::Payments::PaymentMethod.show "payment_method_id"
|
106
|
+
```
|
107
|
+
|
108
|
+
attach
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
Od::Payments::PaymentMethod.attach "payment_method_id"
|
112
|
+
```
|
113
|
+
|
114
|
+
### Customer
|
115
|
+
|
116
|
+
create with stripe example
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
Od::Payments::Customer.create(
|
120
|
+
{
|
121
|
+
email: 'email@example.com',
|
122
|
+
name: "Juan Perez",
|
123
|
+
description: "my description"
|
124
|
+
}
|
125
|
+
)
|
126
|
+
```
|
127
|
+
|
128
|
+
| Prop | Type | Required | Description |
|
129
|
+
| ------ | ---- | -------- | ----------------------------------------------------------------- |
|
130
|
+
| params | Hash | Yes | Show params in https://stripe.com/docs/api/customers/create |
|
131
|
+
|
132
|
+
|
133
|
+
show
|
134
|
+
```ruby
|
135
|
+
Od::Payments::Customer.show("customer_id")
|
136
|
+
```
|
137
|
+
|
138
|
+
## Development
|
139
|
+
|
140
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
141
|
+
|
142
|
+
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).
|
143
|
+
|
144
|
+
## License
|
145
|
+
|
146
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "od/payments"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/od/payments.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'od/payments/version'
|
2
|
+
require 'od/payments/errors'
|
3
|
+
require 'od/payments/resources'
|
4
|
+
require 'stripe'
|
5
|
+
module Od
|
6
|
+
module Payments
|
7
|
+
class << self
|
8
|
+
ADAPTERS = %i[stripe square].freeze
|
9
|
+
attr_accessor :api_key_stripe
|
10
|
+
attr_accessor :access_token_square
|
11
|
+
attr_accessor :environment_square
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield(self) if block_given?
|
15
|
+
|
16
|
+
initializate_stripe if validate_stripe
|
17
|
+
initializate_square if validate_square
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_stripe
|
21
|
+
!api_key_stripe.nil? && !api_key_stripe&.strip&.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate_square
|
25
|
+
!access_token_square.nil? || !access_token_square&.strip&.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def initializate_stripe
|
29
|
+
Stripe.api_key = api_key_stripe
|
30
|
+
end
|
31
|
+
|
32
|
+
def initializate_square
|
33
|
+
'comming soon'
|
34
|
+
end
|
35
|
+
|
36
|
+
def adapter
|
37
|
+
return @adapter if @adapter
|
38
|
+
|
39
|
+
self.adapter = :stripe
|
40
|
+
@adapter
|
41
|
+
end
|
42
|
+
|
43
|
+
def adapter=(adapter)
|
44
|
+
raise Od::Payments::APIError, 'Invalid Adapter' if adapter.class != Symbol && !ADAPTERS.include?(adapter)
|
45
|
+
|
46
|
+
@adapter = adapter
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Od
|
2
|
+
module Payments
|
3
|
+
class OdPaymentsError < StandardError
|
4
|
+
attr_reader :message
|
5
|
+
attr_accessor :response
|
6
|
+
|
7
|
+
attr_reader :code
|
8
|
+
attr_reader :error
|
9
|
+
attr_reader :http_body
|
10
|
+
attr_reader :http_headers
|
11
|
+
attr_reader :http_status
|
12
|
+
attr_reader :json_body # equivalent to #data
|
13
|
+
attr_reader :request_id
|
14
|
+
|
15
|
+
# Initializes a StripeError.
|
16
|
+
def initialize(message = nil, http_status: nil, http_body: nil,
|
17
|
+
json_body: nil, http_headers: nil, code: nil)
|
18
|
+
@message = message
|
19
|
+
@http_status = http_status
|
20
|
+
@http_body = http_body
|
21
|
+
@http_headers = http_headers || {}
|
22
|
+
@idempotent_replayed = @http_headers['idempotent-replayed'] == 'true'
|
23
|
+
@json_body = json_body
|
24
|
+
@code = code
|
25
|
+
@request_id = @http_headers['request-id']
|
26
|
+
@error = construct_error_object
|
27
|
+
end
|
28
|
+
|
29
|
+
def construct_error_object
|
30
|
+
return nil if @json_body.nil? || !@json_body.key?(:error)
|
31
|
+
|
32
|
+
ErrorObject.construct_from(@json_body[:error])
|
33
|
+
end
|
34
|
+
|
35
|
+
def idempotent_replayed?
|
36
|
+
@idempotent_replayed
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
status_string = @http_status.nil? ? '' : "(Status #{@http_status}) "
|
41
|
+
id_string = @request_id.nil? ? '' : "(Request #{@request_id}) "
|
42
|
+
"#{status_string}#{id_string}#{@message}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
class AuthenticationError < StandardError; end
|
46
|
+
class APIError < StandardError; end
|
47
|
+
class CardError < OdPaymentsError
|
48
|
+
attr_reader :param
|
49
|
+
|
50
|
+
def initialize(message, param, code: nil, http_status: nil, http_body: nil,
|
51
|
+
json_body: nil, http_headers: nil)
|
52
|
+
super(message, http_status: http_status, http_body: http_body,
|
53
|
+
json_body: json_body, http_headers: http_headers,
|
54
|
+
code: code)
|
55
|
+
@param = param
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Od
|
2
|
+
module Payments
|
3
|
+
module Charge
|
4
|
+
def self.create(amount, option = {})
|
5
|
+
case Od::Payments.adapter
|
6
|
+
when :stripe
|
7
|
+
Stripe::PaymentIntent.create({
|
8
|
+
amount: amount,
|
9
|
+
currency: 'usd',
|
10
|
+
customer: option[:customer_id],
|
11
|
+
payment_method: option[:token_payment],
|
12
|
+
statement_descriptor: 'Divan Medical',
|
13
|
+
description: option[:description] || '',
|
14
|
+
off_session: option[:off_session] || false,
|
15
|
+
confirm: option[:confirm] || true,
|
16
|
+
capture_method: option[:capture_method] || 'manual',
|
17
|
+
setup_future_usage: option[:setup_future_usage]
|
18
|
+
})
|
19
|
+
end
|
20
|
+
rescue Stripe::CardError => e
|
21
|
+
case Od::Payments.adapter
|
22
|
+
when :stripe
|
23
|
+
raise Od::Payments::CardError.new(e.error.message, {})
|
24
|
+
end
|
25
|
+
rescue Stripe::StripeError => e
|
26
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.capture(payment_intent_id)
|
30
|
+
case Od::Payments.adapter
|
31
|
+
when :stripe
|
32
|
+
Stripe::PaymentIntent.capture(payment_intent_id)
|
33
|
+
end
|
34
|
+
rescue Stripe::CardError => e
|
35
|
+
raise Od::Payments::CardError.new(e.error.message, {})
|
36
|
+
rescue Stripe::StripeError => e
|
37
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.cancel(payment_intent_id)
|
41
|
+
case Od::Payments.adapter
|
42
|
+
when :stripe
|
43
|
+
Stripe::PaymentIntent.cancel payment_intent_id
|
44
|
+
end
|
45
|
+
rescue Stripe::CardError => e
|
46
|
+
raise Od::Payments::CardError.new(e.error.message, {})
|
47
|
+
rescue Stripe::StripeError => e
|
48
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.void(payment_intent_id)
|
52
|
+
case Od::Payments.adapter
|
53
|
+
when :stripe
|
54
|
+
Stripe::Refund.create({
|
55
|
+
payment_intent: payment_intent_id
|
56
|
+
})
|
57
|
+
end
|
58
|
+
rescue Stripe::CardError => e
|
59
|
+
raise Od::Payments::CardError.new(e.error.message, {})
|
60
|
+
rescue Stripe::StripeError => e
|
61
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.confirm(payment_intent_id, payment_method_id)
|
65
|
+
case Od::Payments.adapter
|
66
|
+
when :stripe
|
67
|
+
Stripe::PaymentIntent.confirm(
|
68
|
+
payment_intent_id,
|
69
|
+
{ payment_method: payment_method_id }
|
70
|
+
)
|
71
|
+
end
|
72
|
+
rescue Stripe::CardError => e
|
73
|
+
raise Od::Payments::CardError.new(e.error.message, {})
|
74
|
+
rescue Stripe::StripeError => e
|
75
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Od
|
2
|
+
module Payments
|
3
|
+
module Customer
|
4
|
+
def self.create(params)
|
5
|
+
Stripe::Customer.create(params)
|
6
|
+
rescue Stripe::StripeError => e
|
7
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.show(id)
|
11
|
+
Stripe::Customer.retrieve(id)
|
12
|
+
rescue Stripe::StripeError => e
|
13
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Od
|
2
|
+
module Payments
|
3
|
+
module PaymentMethod
|
4
|
+
|
5
|
+
def self.create(params)
|
6
|
+
case Od::Payments.adapter
|
7
|
+
when :stripe
|
8
|
+
Stripe::PaymentMethod.create params
|
9
|
+
end
|
10
|
+
rescue Stripe::CardError => e
|
11
|
+
raise Od::Payments::CardError.new(e.error.message, {})
|
12
|
+
rescue Stripe::StripeError => e
|
13
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.list(customer_id)
|
17
|
+
case Od::Payments.adapter
|
18
|
+
when :stripe
|
19
|
+
Stripe::PaymentMethod.list({
|
20
|
+
customer: customer_id,
|
21
|
+
type: 'card'
|
22
|
+
})
|
23
|
+
end
|
24
|
+
rescue Stripe::StripeError => e
|
25
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.delete(payment_method_id)
|
29
|
+
case Od::Payments.adapter
|
30
|
+
when :stripe
|
31
|
+
Stripe::PaymentMethod.detach(
|
32
|
+
payment_method_id
|
33
|
+
)
|
34
|
+
end
|
35
|
+
rescue Stripe::StripeError => e
|
36
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.show(payment_method_id)
|
40
|
+
case Od::Payments.adapter
|
41
|
+
when :stripe
|
42
|
+
Stripe::PaymentIntent.retrieve payment_method_id
|
43
|
+
end
|
44
|
+
rescue Stripe::StripeError => e
|
45
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.attach(payment_method_id, customer_id)
|
49
|
+
Stripe::PaymentMethod.attach(
|
50
|
+
payment_method_id,
|
51
|
+
{ customer: customer_id }
|
52
|
+
)
|
53
|
+
rescue Stripe::CardError => e
|
54
|
+
raise Od::Payments::CardError.new(e.error.message, {})
|
55
|
+
rescue Stripe::StripeError => e
|
56
|
+
raise Od::Payments::OdPaymentsError, e.error.message
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/od-payments.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'lib/od/payments/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'od-payments'
|
5
|
+
spec.version = Od::Payments::VERSION
|
6
|
+
spec.author = 'Onward Web Development'
|
7
|
+
spec.email = ['hello@onwarddev.com']
|
8
|
+
|
9
|
+
spec.summary = 'od Payment'
|
10
|
+
spec.description = 'Adapter to apply multiple payment methods to rails.'
|
11
|
+
spec.homepage = 'https://github.com/onwarddev/od-payments'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/onwarddev/od-payments'
|
19
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
spec.add_development_dependency 'generator_spec'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 4.0.1'
|
31
|
+
# spec.add_dependency 'square.rb', '~> 6.1.0'
|
32
|
+
spec.add_dependency 'stripe', '~> 5.22.0'
|
33
|
+
spec.add_development_dependency 'faker'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: od-payments
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Onward Web Development
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: generator_spec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: stripe
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.22.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.22.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faker
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Adapter to apply multiple payment methods to rails.
|
70
|
+
email:
|
71
|
+
- hello@onwarddev.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/od/payments.rb
|
87
|
+
- lib/od/payments/errors.rb
|
88
|
+
- lib/od/payments/resources.rb
|
89
|
+
- lib/od/payments/resources/charge.rb
|
90
|
+
- lib/od/payments/resources/customer.rb
|
91
|
+
- lib/od/payments/resources/payment_method.rb
|
92
|
+
- lib/od/payments/version.rb
|
93
|
+
- od-payments.gemspec
|
94
|
+
homepage: https://github.com/onwarddev/od-payments
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata:
|
98
|
+
homepage_uri: https://github.com/onwarddev/od-payments
|
99
|
+
source_code_uri: https://github.com/onwarddev/od-payments
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.3.0
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubygems_version: 3.0.3
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: od Payment
|
119
|
+
test_files: []
|