Class: Flow::SimpleGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/flow/simple_gateway.rb

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ SimpleGateway

Returns a new instance of SimpleGateway.



10
11
12
# File 'lib/flow/simple_gateway.rb', line 10

def initialize(order)
  @order = order
end

Instance Method Details

#cc_authorizationObject

authorises credit card and prepares for capture



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/flow/simple_gateway.rb', line 15

def cc_authorization
  response = FlowcommerceSpree.client.authorizations.post(FlowcommerceSpree::ORGANIZATION, build_authorization_form)
  status_message = response.result.status.value
  status = status_message == ::Io::Flow::V0::Models::AuthorizationStatus.authorized.value

  store = { key: response.key,
            amount: response.amount,
            currency: response.currency,
            authorization_id: response.id }

  @order.flow_data['authorization'] = store
  @order.update_column(:meta, @order.meta.to_json)

  if self.class.clear_zero_amount_payments
    @order.payments.where(amount: 0, state: %w[invalid processing pending]).map(&:destroy)
  end

  ActiveMerchant::Billing::Response.new(status, status_message, { response: response }, authorization: store)
rescue Io::Flow::V0::HttpClient::ServerError => e
  error_response(e)
end