od-payments 0.1.8 → 0.2.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 +4 -4
- data/Gemfile.lock +21 -1
- data/README.md +11 -9
- data/lib/od/payments.rb +15 -6
- data/lib/od/payments/resources/charge.rb +31 -8
- data/lib/od/payments/version.rb +1 -1
- data/od-payments.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 757eb2d922170b88687cf60cf366c32f498f7b014858b05da3e00fd75decf32f
|
4
|
+
data.tar.gz: 478e93fcc7314d90fed5d49c5164934a8345ca544fa1c3277de91ddee7d04f71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba9f927f67ff332b93d1555a27d2b496fbb594684c0f3ba390dbf9b5eb505049eb84cf8413a5f8e775d09e61dce6b6321d1a78e474e775ccd497d1f3087153fb
|
7
|
+
data.tar.gz: 1ba2e2df1b737a455c503cae17e207c2544778de634732ade1a120024c8d84aa33ebc5e3098b9a20874f4832a0c99cb03b9a0685e359aaf6a9780948a0149fab
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
od-payments (0.
|
4
|
+
od-payments (0.2.0)
|
5
|
+
square.rb (~> 6.3.0.20200826)
|
5
6
|
stripe (~> 5.22.0)
|
6
7
|
|
7
8
|
GEM
|
@@ -27,23 +28,36 @@ GEM
|
|
27
28
|
tzinfo (~> 1.1)
|
28
29
|
zeitwerk (~> 2.2, >= 2.2.2)
|
29
30
|
builder (3.2.4)
|
31
|
+
certifi (2018.01.18)
|
30
32
|
concurrent-ruby (1.1.6)
|
31
33
|
crass (1.0.6)
|
32
34
|
diff-lcs (1.4.4)
|
33
35
|
erubi (1.9.0)
|
34
36
|
faker (2.13.0)
|
35
37
|
i18n (>= 1.6, < 2)
|
38
|
+
faraday (0.17.3)
|
39
|
+
multipart-post (>= 1.2, < 3)
|
40
|
+
faraday-http-cache (2.2.0)
|
41
|
+
faraday (>= 0.8)
|
42
|
+
faraday_middleware (0.14.0)
|
43
|
+
faraday (>= 0.7.4, < 1.0)
|
36
44
|
generator_spec (0.9.4)
|
37
45
|
activesupport (>= 3.0.0)
|
38
46
|
railties (>= 3.0.0)
|
39
47
|
i18n (1.8.5)
|
40
48
|
concurrent-ruby (~> 1.0)
|
49
|
+
little-plugger (1.1.4)
|
50
|
+
logging (2.3.0)
|
51
|
+
little-plugger (~> 1.1)
|
52
|
+
multi_json (~> 1.14)
|
41
53
|
loofah (2.6.0)
|
42
54
|
crass (~> 1.0.2)
|
43
55
|
nokogiri (>= 1.5.9)
|
44
56
|
method_source (1.0.0)
|
45
57
|
mini_portile2 (2.4.0)
|
46
58
|
minitest (5.14.1)
|
59
|
+
multi_json (1.15.0)
|
60
|
+
multipart-post (2.1.1)
|
47
61
|
nokogiri (1.10.10)
|
48
62
|
mini_portile2 (~> 2.4.0)
|
49
63
|
rack (2.2.3)
|
@@ -74,6 +88,12 @@ GEM
|
|
74
88
|
diff-lcs (>= 1.2.0, < 2.0)
|
75
89
|
rspec-support (~> 3.9.0)
|
76
90
|
rspec-support (3.9.3)
|
91
|
+
square.rb (6.3.0.20200826)
|
92
|
+
certifi (~> 2018.1)
|
93
|
+
faraday (~> 0.15)
|
94
|
+
faraday-http-cache (~> 2.0)
|
95
|
+
faraday_middleware (~> 0.13)
|
96
|
+
logging (~> 2.2)
|
77
97
|
stripe (5.22.0)
|
78
98
|
thor (1.0.1)
|
79
99
|
thread_safe (0.3.6)
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Od::Payments
|
2
2
|
|
3
|
+
stripe version: 5.22.0
|
4
|
+
square version: 6.3.0.20200826
|
3
5
|
## Installation
|
4
6
|
|
5
7
|
### Step 1
|
@@ -15,14 +17,14 @@ gem 'od-payments'
|
|
15
17
|
create `config/initializers/od_payments.rb` with
|
16
18
|
|
17
19
|
```ruby
|
18
|
-
Od::Payments.configure
|
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
|
20
|
+
Od::Payments.configure(:stripe,{api_key_stripe: 'api_key_stripe'})
|
24
21
|
```
|
25
22
|
|
23
|
+
| Prop | Type | Required | Description |
|
24
|
+
| ------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------- |
|
25
|
+
| adapter | Symbol | Yes | :stripe, :square |
|
26
|
+
| options | Hash | No | { api_key_stripe: 'api_key_stripe', access_token_square: 'access_token_square', environment_square: 'environment_square'} |
|
27
|
+
|
26
28
|
## Usage
|
27
29
|
|
28
30
|
### Payment
|
@@ -125,12 +127,12 @@ Od::Payments::Customer.create(
|
|
125
127
|
)
|
126
128
|
```
|
127
129
|
|
128
|
-
| Prop | Type | Required | Description
|
129
|
-
| ------ | ---- | -------- |
|
130
|
+
| Prop | Type | Required | Description |
|
131
|
+
| ------ | ---- | -------- | ----------------------------------------------------------- |
|
130
132
|
| params | Hash | Yes | Show params in https://stripe.com/docs/api/customers/create |
|
131
133
|
|
132
|
-
|
133
134
|
show
|
135
|
+
|
134
136
|
```ruby
|
135
137
|
Od::Payments::Customer.show("customer_id")
|
136
138
|
```
|
data/lib/od/payments.rb
CHANGED
@@ -2,6 +2,7 @@ require 'od/payments/version'
|
|
2
2
|
require 'od/payments/errors'
|
3
3
|
require 'od/payments/resources'
|
4
4
|
require 'stripe'
|
5
|
+
require 'square'
|
5
6
|
module Od
|
6
7
|
module Payments
|
7
8
|
class << self
|
@@ -9,10 +10,15 @@ module Od
|
|
9
10
|
attr_accessor :api_key_stripe
|
10
11
|
attr_accessor :access_token_square
|
11
12
|
attr_accessor :environment_square
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
attr_accessor :client_square
|
14
|
+
attr_accessor :production
|
15
|
+
|
16
|
+
def configure(adapter, options = {})
|
17
|
+
self.adapter = adapter
|
18
|
+
@api_key_stripe = options[:api_key_stripe]
|
19
|
+
@access_token_square = options[:access_token_square]
|
20
|
+
@environment_square = options[:environment_square]
|
21
|
+
@production = options[:production]
|
16
22
|
initializate_stripe if validate_stripe
|
17
23
|
initializate_square if validate_square
|
18
24
|
end
|
@@ -30,7 +36,10 @@ module Od
|
|
30
36
|
end
|
31
37
|
|
32
38
|
def initializate_square
|
33
|
-
|
39
|
+
@client_square = Square::Client.new(
|
40
|
+
access_token: access_token_square,
|
41
|
+
environment: production ? 'production' : 'sandbox'
|
42
|
+
)
|
34
43
|
end
|
35
44
|
|
36
45
|
def adapter
|
@@ -41,7 +50,7 @@ module Od
|
|
41
50
|
end
|
42
51
|
|
43
52
|
def adapter=(adapter)
|
44
|
-
raise Od::Payments::APIError, 'Invalid Adapter' if adapter.class != Symbol
|
53
|
+
raise Od::Payments::APIError, 'Invalid Adapter' if adapter.class != Symbol || !ADAPTERS.include?(adapter)
|
45
54
|
|
46
55
|
@adapter = adapter
|
47
56
|
end
|
@@ -6,14 +6,27 @@ module Od
|
|
6
6
|
when :stripe
|
7
7
|
Stripe::PaymentIntent.create({
|
8
8
|
currency: 'usd',
|
9
|
-
amount: (amount * 100).to_i
|
9
|
+
amount: (amount * 100).to_i
|
10
10
|
}.merge(option))
|
11
|
+
when :square
|
12
|
+
result = Od::Payments.client_square.payments.create_payment(
|
13
|
+
body: {
|
14
|
+
idempotency_key: SecureRandom.uuid,
|
15
|
+
amount_money: {
|
16
|
+
amount: amount,
|
17
|
+
currency: 'USD'
|
18
|
+
}
|
19
|
+
}.merge(option)
|
20
|
+
)
|
21
|
+
|
22
|
+
if result.success?
|
23
|
+
result.data
|
24
|
+
elsif result.error?
|
25
|
+
raise Od::Payments::CardError.new(result.errors, {})
|
26
|
+
end
|
11
27
|
end
|
12
28
|
rescue Stripe::CardError => e
|
13
|
-
|
14
|
-
when :stripe
|
15
|
-
raise Od::Payments::CardError.new(e.error.message, {})
|
16
|
-
end
|
29
|
+
raise Od::Payments::CardError.new(e.error.message, {})
|
17
30
|
rescue Stripe::StripeError => e
|
18
31
|
raise Od::Payments::OdPaymentsError, e.error.message
|
19
32
|
end
|
@@ -40,12 +53,22 @@ module Od
|
|
40
53
|
raise Od::Payments::OdPaymentsError, e.error.message
|
41
54
|
end
|
42
55
|
|
43
|
-
def self.void(payment_intent_id)
|
56
|
+
def self.void(payment_intent_id, option = {})
|
44
57
|
case Od::Payments.adapter
|
45
58
|
when :stripe
|
46
59
|
Stripe::Refund.create({
|
47
|
-
|
48
|
-
|
60
|
+
payment_intent: payment_intent_id
|
61
|
+
}.merge(option))
|
62
|
+
when :square
|
63
|
+
result = Od::Payments.client_square.refunds.refund_payment(body: {
|
64
|
+
payment_id: payment_intent_id,
|
65
|
+
idempotency_key: SecureRandom.uuid
|
66
|
+
}.merge(option))
|
67
|
+
if result.success?
|
68
|
+
result.data
|
69
|
+
elsif result.error?
|
70
|
+
raise Od::Payments::CardError.new(result.errors, {})
|
71
|
+
end
|
49
72
|
end
|
50
73
|
rescue Stripe::CardError => e
|
51
74
|
raise Od::Payments::CardError.new(e.error.message, {})
|
data/lib/od/payments/version.rb
CHANGED
data/od-payments.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'generator_spec'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 4.0.1'
|
31
31
|
# spec.add_dependency 'square.rb', '~> 6.1.0'
|
32
|
+
spec.add_dependency 'square.rb', '~> 6.3.0.20200826'
|
32
33
|
spec.add_dependency 'stripe', '~> 5.22.0'
|
33
34
|
spec.add_development_dependency 'faker'
|
34
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: od-payments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Onward Web Development
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08
|
11
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: generator_spec
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 4.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: square.rb
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 6.3.0.20200826
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 6.3.0.20200826
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: stripe
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|