Class: Nimbleshop::PaymentTransactionRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/nimbleshop/nimbleshop/payment_transaction_recorder.rb

Overview

This class is responsible for recording the payment transaction.

Note that even the unsuccessful transactions are recorded for reporting and analysis purpose.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PaymentTransactionRecorder

Returns a new instance of PaymentTransactionRecorder.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nimbleshop/nimbleshop/payment_transaction_recorder.rb', line 10

def initialize(options = {})
  options.symbolize_keys!
  options.assert_valid_keys :order, :response, :operation, :transaction_gid, :metadata, :params
  options.reverse_merge! metadata: {}

  @order     = options.fetch :order
  @response  = options.fetch :response
  @operation = options.fetch :operation
  @metadata  = options.fetch :metadata
  @transaction_gid = options.fetch :transaction_gid
end

Instance Method Details

#recordObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nimbleshop/nimbleshop/payment_transaction_recorder.rb', line 22

def record

  h = { operation: @operation.to_s,
        params: @response.params,
        amount: @order.total_amount_in_cents,
        metadata: @metadata,
        transaction_gid: @transaction_gid }

  @order.payment_transactions.create!(h)

end