flowcommerce-activemerchant 0.2.0 → 0.2.2
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/lib/active_merchant/billing/gateways/flow.rb +46 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12d618c04585fcb8b16b30a3f616e0244cea8a07fccb85c949c901417b912a5b
|
4
|
+
data.tar.gz: 7b3622aa3affacf4a4154288107409681edce9f18da5684885d48df49f01ac77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e056b9217ddff93241d438b553d3a340bd3bddb039f5d99d502e5aff9f15521dc4c5a41af3742f0b3448241be5dcf4d120f7e21a5e4a610ad09724604c75055b
|
7
|
+
data.tar.gz: ccc956a2df1ffd950e419899d8f42f2254c32026912eb2c25fc7173b66d9374221e4824c2dde4bc0f47682818c4ad56121319ef1f372b1ddea6581f94815ee2c
|
@@ -6,7 +6,15 @@ require 'flowcommerce-reference'
|
|
6
6
|
module ActiveMerchant
|
7
7
|
module Billing
|
8
8
|
class FlowGateway < Gateway
|
9
|
-
|
9
|
+
unless defined?(::ActiveMerchant::Billing::FlowGateway::VERSION)
|
10
|
+
VERSION = File.read(File.expand_path("../../../../.version", File.dirname(__FILE__))).chomp
|
11
|
+
|
12
|
+
FORM_TYPES = [
|
13
|
+
:authorization_copy_form, :direct_authorization_form, :merchant_of_record_authorization_form,
|
14
|
+
:paypal_authorization_form, :redirect_authorization_form, :inline_authorization_form,
|
15
|
+
:card_authorization_form, :ach_authorization_form
|
16
|
+
]
|
17
|
+
end
|
10
18
|
|
11
19
|
self.display_name = 'Flow.io Pay'
|
12
20
|
self.homepage_url = 'https://www.flow.io/'
|
@@ -14,6 +22,7 @@ module ActiveMerchant
|
|
14
22
|
self.supported_countries = FlowCommerce::Reference::Countries::ISO_3166_2
|
15
23
|
self.supported_cardtypes = FlowCommerce::Reference::PaymentMethods::SUPPORTED_CREDIT_CARDS
|
16
24
|
|
25
|
+
|
17
26
|
def initialize options = {}
|
18
27
|
@flow_api_key = options[:api_key] || ENV['FLOW_API_KEY']
|
19
28
|
@flow_organization = options[:organization] || ENV['FLOW_ORGANIZATION']
|
@@ -27,24 +36,28 @@ module ActiveMerchant
|
|
27
36
|
# Create a new authorization.
|
28
37
|
# https://docs.flow.io/module/payment/resource/authorizations#post-organization-authorizations
|
29
38
|
def authorize cc_or_token, order_number, opts={}
|
30
|
-
|
39
|
+
unless opts[:currency]
|
40
|
+
return error_response('Currency is a required option')
|
41
|
+
end
|
31
42
|
|
32
|
-
opts[:discriminator]
|
43
|
+
unless opts[:discriminator]
|
44
|
+
return error_response 'Discriminator is not defined, please choose one [%s]' % FORM_TYPES.join(', ')
|
45
|
+
end
|
46
|
+
|
47
|
+
unless FORM_TYPES.include?(opts[:discriminator].to_sym)
|
48
|
+
return error_response 'Discriminator [%s] not found, please choose one [%s]' % [opts[:discriminator], FORM_TYPES.join(', ')]
|
49
|
+
end
|
33
50
|
|
34
51
|
body = {
|
35
|
-
amount:
|
36
|
-
currency:
|
37
|
-
|
38
|
-
|
52
|
+
amount: opts[:amount] || 0.0,
|
53
|
+
currency: opts[:currency],
|
54
|
+
discriminator: opts[:discriminator],
|
55
|
+
token: store(cc_or_token),
|
56
|
+
order_number: order_number
|
39
57
|
}
|
40
58
|
|
41
|
-
|
42
|
-
::Io::Flow::V0::Models::MerchantOfRecordAuthorizationForm.new body
|
43
|
-
else
|
44
|
-
::Io::Flow::V0::Models::DirectAuthorizationForm.new body
|
45
|
-
end
|
59
|
+
response = flow_instance.authorizations.post @flow_organization, body
|
46
60
|
|
47
|
-
response = flow_instance.authorizations.post @flow_organization, authorization_form
|
48
61
|
Response.new true, 'Flow authorize - Success', { response: response }
|
49
62
|
rescue => exception
|
50
63
|
error_response exception
|
@@ -54,11 +67,13 @@ module ActiveMerchant
|
|
54
67
|
def flow_get_authorization order_number:
|
55
68
|
response = flow_instance.authorizations.get @flow_organization, order_number: order_number
|
56
69
|
response.last
|
70
|
+
rescue => exception
|
71
|
+
error_response exception
|
57
72
|
end
|
58
73
|
|
59
74
|
# https://docs.flow.io/module/payment/resource/captures#post-organization-captures
|
60
75
|
def capture amount, authorization_key, options={}
|
61
|
-
options[:currency]
|
76
|
+
return error_response('Currency is a required option') unless options[:currency]
|
62
77
|
|
63
78
|
body = {
|
64
79
|
authorization_id: authorization_key,
|
@@ -128,14 +143,6 @@ module ActiveMerchant
|
|
128
143
|
error_response exception
|
129
144
|
end
|
130
145
|
|
131
|
-
# store credit card with flow and get reference token
|
132
|
-
def store credit_card, options={}
|
133
|
-
response = cc_with_token credit_card
|
134
|
-
Response.new true, 'Credit card stored', { response: response, token: response.token }
|
135
|
-
rescue Io::Flow::V0::HttpClient::ServerError => exception
|
136
|
-
error_response exception
|
137
|
-
end
|
138
|
-
|
139
146
|
# stores credit card and returns credit card Flow token String id
|
140
147
|
def store input
|
141
148
|
credit_card =
|
@@ -161,6 +168,23 @@ module ActiveMerchant
|
|
161
168
|
response.token
|
162
169
|
end
|
163
170
|
|
171
|
+
# Creates and order
|
172
|
+
# https://docs.flow.io/module/localization/resource/orders#post-organization-orders
|
173
|
+
def flow_create_order body, query_string={}
|
174
|
+
flow_instance.orders.post @flow_organization, body, query_string
|
175
|
+
rescue => exception
|
176
|
+
error_response exception
|
177
|
+
end
|
178
|
+
|
179
|
+
# Submits an order and
|
180
|
+
# pushes all subsequent authorizations from status "review" to "authorized"
|
181
|
+
# takes ~ 60 seconds
|
182
|
+
def flow_submission_by_number order_number
|
183
|
+
flow_instance.orders.put_submissions_by_number @flow_organization, order_number
|
184
|
+
rescue => exception
|
185
|
+
error_response exception
|
186
|
+
end
|
187
|
+
|
164
188
|
private
|
165
189
|
|
166
190
|
def flow_instance
|
@@ -189,10 +213,6 @@ module ActiveMerchant
|
|
189
213
|
end
|
190
214
|
|
191
215
|
def assert_currency currency, amount
|
192
|
-
unless currency.to_s.length == 3
|
193
|
-
raise ArgumentError.new('Currency is required if amount is provided')
|
194
|
-
end
|
195
|
-
|
196
216
|
FlowCommerce::Reference::Currencies.find! currency
|
197
217
|
amount.to_f
|
198
218
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flowcommerce-activemerchant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dino Reic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemerchant
|