class Rubyrave::Client

Constants

RAVE_LIVE_URL
RAVE_SANDBOX_URL

Attributes

http_timeout[RW]
mode[RW]
payment_method[RW]
pbfpubkey[RW]
public_key[RW]
secret_key[RW]

Public Class Methods

new(public_key, secret_key, pbfpubkey, mode = "test", payment_method = 'sas', http_timeout = 25) click to toggle source
# 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

Public Instance Methods

checksum(payload) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_banks() click to toggle source
# 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 = {}) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

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

# File lib/rubyrave/client.rb, line 51
def set_mode(mode)
  self.mode = mode
end
set_payment_method(payment_meethod) click to toggle source
# File lib/rubyrave/client.rb, line 55
def set_payment_method(payment_meethod)
  self.payment_method = payment_method
end