flowcommerce-activemerchant 0.0.6 → 0.0.7

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
2
  SHA1:
3
- metadata.gz: d29bf5f67b0955bc68f14c89e83523e0ab89c007
4
- data.tar.gz: 25b73be18f38b4c1f86a6c5c8af51415b037c7b3
3
+ metadata.gz: 6a5a5d4dbb7606be2ac9f63c228fd94ed0423f0c
4
+ data.tar.gz: eb6da18efdf964e1ee6bdf5dbc37851515bc8013
5
5
  SHA512:
6
- metadata.gz: 70cb88748bdfc1393182c9e82c6e9c54a89a6281c48d4caf7420bcd5633ce447032b57beb9744c0d6b367ea070d8bb8633e1c3c23151ca910db7ab60c016a1a5
7
- data.tar.gz: 62ca15c0557d47f791f63cd00d9b7612684ce4aeac230b9f8620fb8324e8313a42c7e78bbaf80da698cf17c932fb5ded4208af4278fd02e34f0dde2caaf1db3b
6
+ metadata.gz: 52f6e5e19df430125645ebab00069d664e4d296302ed068b5ba250c55b59764f80767c761e41842737ded97ba0ce0f66913fe5c7948ab31316ec5043b734bca5
7
+ data.tar.gz: 3336fde40352290d319c85c31663343cd87b242ea3666e6a5164cbe84b6078fc15d0216a2dbe6d223cc08621cfa4beed8fe31655d5bfc6a8b09340501e26bcc6
@@ -6,7 +6,7 @@ require 'flow-reference'
6
6
  module ActiveMerchant
7
7
  module Billing
8
8
  class FlowGateway < Gateway
9
- VERSION = '0.0.6' unless defined?(::ActiveMerchant::Billing::FlowGateway::VERSION)
9
+ VERSION = '0.0.7' unless defined?(::ActiveMerchant::Billing::FlowGateway::VERSION)
10
10
 
11
11
  self.display_name = 'Flow.io Pay'
12
12
  self.homepage_url = 'https://www.flow.io/'
@@ -14,7 +14,7 @@ module ActiveMerchant
14
14
  self.supported_countries = Flow::Reference::Countries::ISO_3166_2
15
15
  self.supported_cardtypes = Flow::Reference::PaymentMethods::SUPPORTED_CREDIT_CARDS
16
16
 
17
- def initialize(options = {})
17
+ def initialize options = {}
18
18
  @flow_api_key = options[:api_key] || ENV['FLOW_API_KEY']
19
19
  @flow_organization = options[:organization] || ENV['FLOW_ORGANIZATION']
20
20
 
@@ -25,13 +25,13 @@ module ActiveMerchant
25
25
  end
26
26
 
27
27
  # https://docs.flow.io/module/payment/resource/authorizations#post-organization-authorizations
28
- def authorize(amount, payment_method, options={})
29
- amount = assert_currency(options[:currency], amount)
28
+ def authorize amount, payment_method, options={}
29
+ amount = assert_currency options[:currency], amount
30
30
 
31
- get_flow_cc_token payment_method
31
+ response = get_flow_cc_token payment_method
32
32
 
33
33
  data = {
34
- token: @flow_cc_token,
34
+ token: response.token,
35
35
  amount: amount,
36
36
  currency: options[:currency],
37
37
  cvv: payment_method.verification_value,
@@ -47,59 +47,59 @@ module ActiveMerchant
47
47
  authorization_form = if options[:order_id]
48
48
  # order_number allready present at flow
49
49
  data[:order_number] = options[:order_id]
50
- ::Io::Flow::V0::Models::MerchantOfRecordAuthorizationForm.new(data)
50
+ ::Io::Flow::V0::Models::MerchantOfRecordAuthorizationForm.new data
51
51
  else
52
- ::Io::Flow::V0::Models::DirectAuthorizationForm.new(data)
52
+ ::Io::Flow::V0::Models::DirectAuthorizationForm.new data
53
53
  end
54
- response = flow_instance.authorizations.post(@flow_organization, authorization_form)
54
+ response = flow_instance.authorizations.post @flow_organization, authorization_form
55
55
  rescue => exception
56
- return Response.new(false, exception.message, { exception: exception })
56
+ return Response.new false, exception.message, { exception: exception }
57
57
  end
58
58
 
59
59
  options = { response: response }
60
60
 
61
61
  if response.result.status.value == 'authorized'
62
- store = {}
63
- store[:authorization_id] = response.id
64
- store[:currency] = response.currency
65
- store[:amount] = response.amount
66
- store[:key] = response.key
62
+ store = { key: response.key,
63
+ amount: response.amount,
64
+ currency: response.currency,
65
+ authorization_id: response.id
66
+ }
67
67
 
68
- Response.new(true, 'Flow authorize - Success', options, { authorization: store })
68
+ Response.new true, 'Flow authorize - Success', options, { authorization: store }
69
69
  else
70
- Response.new(false, 'Flow authorize - Error', options)
70
+ Response.new false, 'Flow authorize - Error', options
71
71
  end
72
72
  end
73
73
 
74
74
  # https://docs.flow.io/module/payment/resource/captures#post-organization-captures
75
- def capture(_money, authorization, options={})
75
+ def capture _money, authorization, options={}
76
76
  raise ArgumentError, 'No Authorization authorization, please authorize first' unless authorization
77
77
 
78
78
  begin
79
- capture_form = ::Io::Flow::V0::Models::CaptureForm.new(authorization)
80
- response = flow_instance.captures.post(@flow_organization, capture_form)
79
+ capture_form = ::Io::Flow::V0::Models::CaptureForm.new authorization
80
+ response = flow_instance.captures.post @flow_organization, capture_form
81
81
  rescue => exception
82
- error_response(exception)
82
+ error_response exception
83
83
  end
84
84
 
85
85
  options = { response: response }
86
86
 
87
87
  if response.id
88
- Response.new(true, 'Flow capture - Success', options)
88
+ Response.new true, 'Flow capture - Success', options
89
89
  else
90
- Response.new(false, 'Flow capture - Error', options)
90
+ Response.new false, 'Flow capture - Error', options
91
91
  end
92
92
  end
93
93
 
94
- def purchase(money, credit_card, options={})
94
+ def purchase money, credit_card, options={}
95
95
  response = authorize money, credit_card, options
96
96
  capture money, response.authorization
97
97
  end
98
98
 
99
99
  # https://docs.flow.io/module/payment/resource/authorizations#delete-organization-authorizations-key
100
- def void(money, authorization_key, options={})
101
- response = flow_instance.authorizations.delete_by_key(@flow_organization, authorization_key)
102
- Response.new(true, 'void success', { response: response })
100
+ def void money, authorization_key, options={}
101
+ response = flow_instance.authorizations.delete_by_key @flow_organization, authorization_key
102
+ Response.new true, 'void success', { response: response }
103
103
  rescue Io::Flow::V0::HttpClient::ServerError => exception
104
104
  error_response(exception)
105
105
  end
@@ -112,7 +112,7 @@ module ActiveMerchant
112
112
  # amount - The amount to refund, in the currency of the associated capture. Defaults to the value of the capture minus any prior refunds.
113
113
  # currency - The ISO 4217-3 code for the currency. Required if amount is specified. Case insensitive. Note you will get an error if the currency does not match the related authrization's currency. See https://api.flow.io/reference/currencies
114
114
  # rma_key - The RMA key, if available. If specified, this will udpate the RMA status as refunded.
115
- def refund(amount, capture_id, options={})
115
+ def refund amount, capture_id, options={}
116
116
  refund_form = {}
117
117
  refund_form[:amount] = amount if amount
118
118
  refund_form[:capture_id] = capture_id if capture_id
@@ -123,44 +123,40 @@ module ActiveMerchant
123
123
 
124
124
  if refund_form[:amount]
125
125
  raise ArgumentError, 'Currency is required if amount is provided' unless refund_form[:currency]
126
- refund_form[:amount] = assert_currency(refund_form[:currency], refund_form[:amount])
126
+ refund_form[:amount] = assert_currency refund_form[:currency], refund_form[:amount]
127
127
  end
128
128
 
129
- refund_form = ::Io::Flow::V0::Models::RefundForm.new(refund_form)
130
- flow_instance.refunds.post(@flow_organization, refund_form)
129
+ refund_form = ::Io::Flow::V0::Models::RefundForm.new refund_form
130
+ flow_instance.refunds.post @flow_organization, refund_form
131
131
  end
132
132
 
133
133
  # store credit card with flow and get reference token
134
- def store(credit_card, options={})
135
- token = get_flow_cc_token(credit_card)
136
- Response.new(true, 'Credit card stored', { token: token })
134
+ def store credit_card, options={}
135
+ response = get_flow_cc_token credit_card
136
+ Response.new true, 'Credit card stored', { response: response, token: response.token }
137
137
  rescue Io::Flow::V0::HttpClient::ServerError => exception
138
- error_response(exception)
138
+ error_response exception
139
139
  end
140
140
 
141
141
  private
142
142
 
143
143
  def flow_instance
144
- FlowCommerce.instance(token: @flow_api_key)
144
+ FlowCommerce.instance token: @flow_api_key
145
145
  end
146
146
 
147
- def get_flow_cc_token(credit_card)
148
- return if @flow_cc_token
149
-
150
- data = {}
151
- data[:number] = credit_card.number
152
- data[:name] = '%s %s' % [credit_card.first_name, credit_card.last_name]
153
- data[:cvv] = credit_card.verification_value
154
- data[:expiration_year] = credit_card.year.to_i
155
- data[:expiration_month] = credit_card.month.to_i
156
-
157
- card_form = ::Io::Flow::V0::Models::CardForm.new(data)
158
- result = flow_instance.cards.post(@flow_organization, card_form)
147
+ def get_flow_cc_token credit_card
148
+ data = { number: credit_card.number,
149
+ name: '%s %s' % [credit_card.first_name, credit_card.last_name],
150
+ cvv: credit_card.verification_value,
151
+ expiration_year: credit_card.year.to_i,
152
+ expiration_month: credit_card.month.to_i
153
+ }
159
154
 
160
- @flow_cc_token = result.token
155
+ card_form = ::Io::Flow::V0::Models::CardForm.new data
156
+ flow_instance.cards.post @flow_organization, card_form
161
157
  end
162
158
 
163
- def error_response(exception_object)
159
+ def error_response exception_object
164
160
  message = if exception_object.respond_to?(:body) && exception_object.body.length > 0
165
161
  description = JSON.load(exception_object.body)['messages'].to_sentence
166
162
  '%s: %s (%s)' % [exception_object.details, description, exception_object.code]
@@ -168,12 +164,12 @@ module ActiveMerchant
168
164
  exception_object.message
169
165
  end
170
166
 
171
- Response.new(false, message, exception: exception_object)
167
+ Response.new false, message, exception: exception_object
172
168
  end
173
169
 
174
- def assert_currency(currency, amount)
170
+ def assert_currency currency, amount
175
171
  raise ArgumentError, 'currency not provided' unless currency
176
- currency_model = Flow::Reference::Currencies.find!(currency)
172
+ currency_model = Flow::Reference::Currencies.find! currency
177
173
  currency_model.to_cents(amount).to_f
178
174
  end
179
175
  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.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-26 00:00:00.000000000 Z
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant