flowcommerce-activemerchant 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fd3cd7c71165eb856d2df8a62f381c4a345216c2
4
- data.tar.gz: 2da46342bd287ac1400862e00ab21d61d43b62e7
2
+ SHA256:
3
+ metadata.gz: 863d0652e20731cf27b0aece10bef3a84f30591c2795edf5a5e4cff849e6113c
4
+ data.tar.gz: c43210cb05f3edb2a374f23c84a1a1019a45fddc2b31a95961644b27f077ad94
5
5
  SHA512:
6
- metadata.gz: 3531b26248d5a5015dc02786d73176b7e80b1e7ebac09a786a8ff4198fb22f0f478eb61080b643e8c38d16d794a3fd66cacc44477bb1775504731fa913cd7429
7
- data.tar.gz: b9c3740fc926e3060403e9adfd64610d45a2534bf1d4ca0fcf19fa833a45fce930a8e8d2af43a477ee7a34dcb2296e823392949700bfee6c75b0f4936b10badc
6
+ metadata.gz: fc9e5cc9e1c7833032104308bb743fd7a01b65f6b30745f325e54502b037d703d134ec608ee7a2e18cafec488000782da97da7d028f40216e288843b0b5dfb09
7
+ data.tar.gz: c6655876fc5a3efd3b950b4aa89cd41e64fe49ff7469fd4274f46e8f3e6b580fedd6fd4eabc9f61999b0a007793db524836248862347ca9a56e87861a4f7f42e
@@ -1,4 +1,4 @@
1
- # @Flow.io (2017)
1
+ # @Flow.io (2017)
2
2
  # Active Merchant adapter for Flow api
3
3
 
4
4
  require 'flowcommerce-reference'
@@ -6,15 +6,7 @@ require 'flowcommerce-reference'
6
6
  module ActiveMerchant
7
7
  module Billing
8
8
  class FlowGateway < Gateway
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
9
+ VERSION = '0.2.0' unless defined?(::ActiveMerchant::Billing::FlowGateway::VERSION)
18
10
 
19
11
  self.display_name = 'Flow.io Pay'
20
12
  self.homepage_url = 'https://www.flow.io/'
@@ -22,7 +14,6 @@ module ActiveMerchant
22
14
  self.supported_countries = FlowCommerce::Reference::Countries::ISO_3166_2
23
15
  self.supported_cardtypes = FlowCommerce::Reference::PaymentMethods::SUPPORTED_CREDIT_CARDS
24
16
 
25
-
26
17
  def initialize options = {}
27
18
  @flow_api_key = options[:api_key] || ENV['FLOW_API_KEY']
28
19
  @flow_organization = options[:organization] || ENV['FLOW_ORGANIZATION']
@@ -36,29 +27,25 @@ module ActiveMerchant
36
27
  # Create a new authorization.
37
28
  # https://docs.flow.io/module/payment/resource/authorizations#post-organization-authorizations
38
29
  def authorize cc_or_token, order_number, opts={}
39
- unless opts[:currency]
40
- return error_response('Currency is a required option')
41
- end
42
-
43
- unless opts[:discriminator]
44
- return error_response 'Discriminator is not defined, please choose one [%s]' % FORM_TYPES.join(', ')
45
- end
30
+ return error_response('Currency is a required option') unless opts[:currency]
46
31
 
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
32
+ opts[:discriminator] ||= 'merchant_of_record'
50
33
 
51
34
  body = {
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
35
+ amount: opts[:amount] || 0.0,
36
+ currency: opts[:currency],
37
+ token: store(cc_or_token),
38
+ order_number: order_number
57
39
  }
58
40
 
59
- response = flow_instance.authorizations.post @flow_organization, body
41
+ authorization_form = if opts[:discriminator].to_s.include?('merchant')
42
+ ::Io::Flow::V0::Models::MerchantOfRecordAuthorizationForm.new body
43
+ else
44
+ ::Io::Flow::V0::Models::DirectAuthorizationForm.new body
45
+ end
60
46
 
61
- Response.new true, 'Flow authorize - Success', { response: response }, { authorization: response.id }
47
+ response = flow_instance.authorizations.post @flow_organization, authorization_form
48
+ Response.new true, 'Flow authorize - Success', { response: response }
62
49
  rescue => exception
63
50
  error_response exception
64
51
  end
@@ -67,13 +54,11 @@ module ActiveMerchant
67
54
  def flow_get_authorization order_number:
68
55
  response = flow_instance.authorizations.get @flow_organization, order_number: order_number
69
56
  response.last
70
- rescue => exception
71
- error_response exception
72
57
  end
73
58
 
74
59
  # https://docs.flow.io/module/payment/resource/captures#post-organization-captures
75
60
  def capture amount, authorization_key, options={}
76
- return error_response('Currency is a required option') unless options[:currency]
61
+ options[:currency] ||= 'USD'
77
62
 
78
63
  body = {
79
64
  authorization_id: authorization_key,
@@ -97,10 +82,10 @@ module ActiveMerchant
97
82
  error_response exception
98
83
  end
99
84
 
100
- def purchase credit_card, order_number, options={}
101
- response = authorize credit_card, order_number, options
102
- capture options[:amount], response.authorization, options
103
- end
85
+ # def purchase money, credit_card, options={}
86
+ # response = authorize money, credit_card, options
87
+ # capture money, response.authorization
88
+ # end
104
89
 
105
90
  # https://docs.flow.io/module/payment/resource/reversals#post-organization-reversals
106
91
  # if amount is not provided, reverse the full or remaining amount
@@ -143,6 +128,14 @@ module ActiveMerchant
143
128
  error_response exception
144
129
  end
145
130
 
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
+
146
139
  # stores credit card and returns credit card Flow token String id
147
140
  def store input
148
141
  credit_card =
@@ -162,35 +155,10 @@ module ActiveMerchant
162
155
  cvv: credit_card.verification_value,
163
156
  expiration_year: credit_card.year.to_i,
164
157
  expiration_month: credit_card.month.to_i
165
- address: credit_card.address
166
158
  }
167
159
 
168
160
  response = flow_instance.cards.post @flow_organization, data
169
-
170
- if response.respond_to?(:token)
171
- Response.new true, 'Flow refund - Success', { response: response }
172
- else
173
- Response.new false, 'Flow POST /:organization/cards - Failure', { response: response }
174
- end
175
- rescue Io::Flow::V0::HttpClient::ServerError => exception
176
- error_response exception
177
- end
178
-
179
- # Creates and order
180
- # https://docs.flow.io/module/localization/resource/orders#post-organization-orders
181
- def flow_create_order body, query_string={}
182
- flow_instance.orders.post @flow_organization, body, query_string
183
- rescue => exception
184
- error_response exception
185
- end
186
-
187
- # Submits an order and
188
- # pushes all subsequent authorizations from status "review" to "authorized"
189
- # takes ~ 60 seconds
190
- def flow_submission_by_number order_number
191
- flow_instance.orders.put_submissions_by_number @flow_organization, order_number
192
- rescue => exception
193
- error_response exception
161
+ response.token
194
162
  end
195
163
 
196
164
  private
@@ -221,6 +189,10 @@ module ActiveMerchant
221
189
  end
222
190
 
223
191
  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
+
224
196
  FlowCommerce::Reference::Currencies.find! currency
225
197
  amount.to_f
226
198
  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.1.4
4
+ version: 0.2.0
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-11-14 00:00:00.000000000 Z
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -59,8 +59,6 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - "./.version"
63
- - "./LICENSE"
64
62
  - "./lib/active_merchant/billing/gateways/flow.rb"
65
63
  - "./lib/flowcommerce-activemerchant.rb"
66
64
  homepage: https://www.flow.io
@@ -83,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
81
  version: '0'
84
82
  requirements: []
85
83
  rubyforge_project:
86
- rubygems_version: 2.5.2.3
84
+ rubygems_version: 2.7.5
87
85
  signing_key:
88
86
  specification_version: 4
89
87
  summary: Adapter for Flow.io global payment gateway
data/.version DELETED
@@ -1 +0,0 @@
1
- 0.1.4
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 - 2018 Flow Commerce Inc.
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 all
13
- 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 THE
21
- SOFTWARE.