Class: Flutterwave::ACH

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/flutterwave/ach.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#encrypt_data, #post

Constructor Details

#initialize(client) ⇒ ACH

Returns a new instance of ACH.



6
7
8
# File 'lib/flutterwave/ach.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/flutterwave/ach.rb', line 4

def client
  @client
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/flutterwave/ach.rb', line 4

def options
  @options
end

Instance Method Details

#add_user(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/flutterwave/ach.rb', line 34

def add_user(options = {})
  @options = options

  request_params = {
    username: encrypt(:username),
    password: encrypt(:password),
    email: encrypt(:email),
    institution: encrypt(:institution),
    merchantid: client.merchant_key
  }

  request_params[:pin] = encrypt(:pin) if options[:pin]

  response = post(
    Flutterwave::Utils::Constants::ACH[:add_user_url],
    request_params
  )

  Flutterwave::Response.new(response)
end

#charge(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/flutterwave/ach.rb', line 56

def charge(options = {})
  @options = options

  response = post(
    Flutterwave::Utils::Constants::ACH[:charge_url],
    publictoken: encrypt(:publictoken),
    accountid: encrypt(:accountid),
    custid: encrypt(:custid),
    narration: encrypt(:narration),
    trxreference: encrypt(:trxreference),
    amount: encrypt(:amount),
    currency: encrypt(:currency),
    merchantid: client.merchant_key
  )

  Flutterwave::Response.new(response)
end

#encrypt(key) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/flutterwave/ach.rb', line 74

def encrypt(key)
  plain_text = options[key].to_s
  raise Flutterwave::Utils::MissingKeyError.new(
    "#{key.capitalize} key required!"
  ) if plain_text.empty?

  encrypt_data(plain_text, client.api_key)
end

#find_by_id(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flutterwave/ach.rb', line 21

def find_by_id(options = {})
  @options = options

  response = post(
    Flutterwave::Utils::Constants::ACH[:id_url],
    institutionid: encrypt(:id),
    merchantid: client.merchant_key
  )

  Flutterwave::Response.new(response)
end

#listObject



11
12
13
14
15
16
17
18
# File 'lib/flutterwave/ach.rb', line 11

def list
  response = post(
    Flutterwave::Utils::Constants::ACH[:list_url],
    merchantid: client.merchant_key
  )

  Flutterwave::Response.new(response)
end