Class: Flutterwave::Pay

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#encrypt_data, #post

Constructor Details

#initialize(client) ⇒ Pay

Returns a new instance of Pay.



9
10
11
# File 'lib/flutterwave/pay.rb', line 9

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/flutterwave/pay.rb', line 7

def client
  @client
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/flutterwave/pay.rb', line 7

def options
  @options
end

Instance Method Details

#encrypt(key) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/flutterwave/pay.rb', line 112

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


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/flutterwave/pay.rb', line 14

def link(options = {})
  @options = options
  options[:country] ||= 'NG'

  response = post(
    Flutterwave::Utils::Constants::PAY[:link_url],
    merchantid: client.merchant_key,
    accountnumber: encrypt(:accountnumber),
    country: encrypt(:country)
  )

  Flutterwave::Response.new(response)
end

#linked_accounts(options = {}) ⇒ Object

www.flutterwave.com/documentation/pay/ - Get Linked Accounts



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/flutterwave/pay.rb', line 69

def linked_accounts(options = {})
  @options = options
  options[:country] ||= 'NG'

  response = post(
    Flutterwave::Utils::Constants::PAY[:linked_accounts_url],
    merchantid: client.merchant_key,
    country: encrypt(:country)
  )

  Flutterwave::Response.new(response)
end

#send(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/flutterwave/pay.rb', line 46

def send(options = {})
  @options = options
  options[:country] ||= 'NG'

  response = post(
    Flutterwave::Utils::Constants::PAY[:send_url],
    merchantid: client.merchant_key,
    accounttoken: encrypt(:accounttoken),
    destbankcode: encrypt(:destbankcode),
    currency: encrypt(:currency),
    country: encrypt(:country),
    transferamount: encrypt(:transferamount),
    uniquereference: encrypt(:uniquereference),
    narration: encrypt(:narration),
    recipientname: encrypt(:recipientname),
    sendername: encrypt(:sendername),
    recipientaccount: encrypt(:recipientaccount)
  )

  Flutterwave::Response.new(response)
end

#status(options = {}) ⇒ Object

www.flutterwave.com/documentation/pay/ - Get Transaction Status



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/flutterwave/pay.rb', line 98

def status(options = {})
  @options = options
  options[:country] ||= 'NG'

  response = post(
    Flutterwave::Utils::Constants::PAY[:status_url],
    merchantid: client.merchant_key,
    uniquereference: encrypt(:uniquereference),
    country: encrypt(:country)
  )

  Flutterwave::Response.new(response)
end


83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/flutterwave/pay.rb', line 83

def unlink(options = {})
  @options = options
  options[:country] ||= 'NG'

  response = post(
    Flutterwave::Utils::Constants::PAY[:unlink_url],
    merchantid: client.merchant_key,
    accountnumber: encrypt(:accountnumber),
    country: encrypt(:country)
  )

  Flutterwave::Response.new(response)
end

#validate(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/flutterwave/pay.rb', line 29

def validate(options = {})
  @options = options
  options[:country] ||= 'NG'

  response = post(
    Flutterwave::Utils::Constants::PAY[:validate_url],
    merchantid: client.merchant_key,
    otp: encrypt(:otp),
    relatedreference: encrypt(:relatedreference),
    otptype: encrypt(:otptype),
    country: encrypt(:country)
  )

  Flutterwave::Response.new(response)
end