Class: Rubyrave::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rubyrave/client.rb

Constant Summary collapse

RAVE_SANDBOX_URL =
"http://flw-pms-dev.eu-west-1.elasticbeanstalk.com/"
RAVE_LIVE_URL =
"https://api.ravepay.co/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_key, secret_key, pbfpubkey, mode = "test", payment_method = 'sas', http_timeout = 25) ⇒ Client

Returns a new instance of Client.



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

def initialize(public_key, secret_key, pbfpubkey, mode = "test", payment_method = 'sas', http_timeout = 25)
  self.public_key = public_key
  self.secret_key = secret_key
  self.pbfpubkey = pbfpubkey
  self.http_timeout = http_timeout
  self.mode = mode
  if mode == "test"
      self.class.base_uri RAVE_SANDBOX_URL
  else
      self.class.base_uri RAVE_LIVE_URL
  end
end

Instance Attribute Details

#http_timeoutObject

Returns the value of attribute http_timeout.



12
13
14
# File 'lib/rubyrave/client.rb', line 12

def http_timeout
  @http_timeout
end

#modeObject

Returns the value of attribute mode.



12
13
14
# File 'lib/rubyrave/client.rb', line 12

def mode
  @mode
end

#payment_methodObject

Returns the value of attribute payment_method.



12
13
14
# File 'lib/rubyrave/client.rb', line 12

def payment_method
  @payment_method
end

#pbfpubkeyObject

Returns the value of attribute pbfpubkey.



12
13
14
# File 'lib/rubyrave/client.rb', line 12

def pbfpubkey
  @pbfpubkey
end

#public_keyObject

Returns the value of attribute public_key.



12
13
14
# File 'lib/rubyrave/client.rb', line 12

def public_key
  @public_key
end

#secret_keyObject

Returns the value of attribute secret_key.



12
13
14
# File 'lib/rubyrave/client.rb', line 12

def secret_key
  @secret_key
end

Instance Method Details

#checksum(payload) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/rubyrave/client.rb', line 77

def checksum(payload)
  payload.sort_by { |k,v| k.to_s }
  hashed_payload = ''
  family.each { |k,v| 
    hashed_payload << v
  }
  return Digest::SHA256.hexdigest(hashed_payload + self.secret_key)
end

#direct_charge(client_data) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/rubyrave/client.rb', line 90

def direct_charge(client_data)
  payload = {
    "PBFPubKey": self.pbfpubkey,
    "client": client_data,
    "alg": "3DES-24"
  }
  perform_post('flwv3-pug/getpaidx/api/charge', payload)
end

#encrypt(key, data) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/rubyrave/client.rb', line 59

def encrypt(key, data)
  cipher = OpenSSL::Cipher::Cipher.new(“des3”)
  cipher.encrypt # Call this before setting key or iv
  cipher.key = key
  ciphertext = cipher.update(data)
  ciphertext << cipher.final
  return  Base64.encode64(ciphertext)
end

#get_key(stuff) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/rubyrave/client.rb', line 68

def get_key(stuff)
  hash = Digest::MD5.hexdigest("this is a test")
  last_twelve = hash[hash.length-13..hash.length-1]
  private_secret_key = self.secret_key
  private_secret_key['FLWSECK-'] = ''
  first_twelve = private_secret_key[0..11]
  return first_twelve + last_twelve
end

#list_banksObject



86
87
88
# File 'lib/rubyrave/client.rb', line 86

def list_banks()
  perform_get('flwv3-pug/getpaidx/api/flwpbf-banks.js', {:json => 1})
end

#perform_get(endpoint, params = {}) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'lib/rubyrave/client.rb', line 99

def perform_get(endpoint, params = {})
  http_params = {}
  unless params.empty?
    http_params[:query] = params
  end
  unless self.http_timeout.nil?
    http_params[:timeout] = self.http_timeout
  end
  self.class.get("/#{endpoint}", http_params)
end

#perform_post(endpoint, data) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/rubyrave/client.rb', line 110

def perform_post(endpoint, data)
  self.class.post(endpoint,
  { 
    :body => data.to_json,
    :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
  })
end

#set_mode(mode) ⇒ Object

Functions to have

  1. initialize() pass live or test keys to this function. DONE

  2. SetMode() switch between live mode and test mode. DONE

  3. Encrypt3DES() performs 3DES encryption on key and payload DONE

  4. getKey() This generates the key using the secret key DONE

  5. DirectCharge() required param is client, the rest is in the library DONE

  6. ValidateCardCharge() transacionReference and OTP required

  7. ValidateAccountCharge() same as above

  8. VerifyTransaction() flw_ref, seckey, normalize=1 required tx_ref optional

  9. VerifyTransactionXrequery() flw_ref, seckey, tx_ref, last_attemp, only_successful

  10. ListBanks() DONE

  11. ConversionRate() requires seckey origin_currency destination_currency optional amount

  12. StopRecurringPayment() id of recurring payment and seckey

  13. ListRecurringTransactions() seckey only

  14. ListSingleRecurringPayment() seckey tx_id

  15. PreautorizeCard() client seckey alg

  16. CapturePayment() seckey ref

  17. RefundPayment() seckey ref action=refund

  18. VoidPayment() seckey ref action=void

  19. ChargeWithToken() long list of body params

  20. SetPaymentMethod()

  21. CreateIntegrityChecksum() DONE



51
52
53
# File 'lib/rubyrave/client.rb', line 51

def set_mode(mode)
  self.mode = mode
end

#set_payment_method(payment_meethod) ⇒ Object



55
56
57
# File 'lib/rubyrave/client.rb', line 55

def set_payment_method(payment_meethod)
  self.payment_method = payment_method
end