Class: Rubyrave::Client
- Inherits:
-
Object
- Object
- Rubyrave::Client
- 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
-
#http_timeout ⇒ Object
Returns the value of attribute http_timeout.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#payment_method ⇒ Object
Returns the value of attribute payment_method.
-
#pbfpubkey ⇒ Object
Returns the value of attribute pbfpubkey.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #checksum(payload) ⇒ Object
- #direct_charge(client_data) ⇒ Object
- #encrypt(key, data) ⇒ Object
- #get_key(stuff) ⇒ Object
-
#initialize(public_key, secret_key, pbfpubkey, mode = "test", payment_method = 'sas', http_timeout = 25) ⇒ Client
constructor
A new instance of Client.
- #list_banks ⇒ Object
- #perform_get(endpoint, params = {}) ⇒ Object
- #perform_post(endpoint, data) ⇒ Object
-
#set_mode(mode) ⇒ Object
Functions to have 1.
- #set_payment_method(payment_meethod) ⇒ Object
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_timeout ⇒ Object
Returns the value of attribute http_timeout.
12 13 14 |
# File 'lib/rubyrave/client.rb', line 12 def http_timeout @http_timeout end |
#mode ⇒ Object
Returns the value of attribute mode.
12 13 14 |
# File 'lib/rubyrave/client.rb', line 12 def mode @mode end |
#payment_method ⇒ Object
Returns the value of attribute payment_method.
12 13 14 |
# File 'lib/rubyrave/client.rb', line 12 def payment_method @payment_method end |
#pbfpubkey ⇒ Object
Returns the value of attribute pbfpubkey.
12 13 14 |
# File 'lib/rubyrave/client.rb', line 12 def pbfpubkey @pbfpubkey end |
#public_key ⇒ Object
Returns the value of attribute public_key.
12 13 14 |
# File 'lib/rubyrave/client.rb', line 12 def public_key @public_key end |
#secret_key ⇒ Object
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_banks ⇒ Object
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
-
initialize() pass live or test keys to this function. DONE
-
SetMode() switch between live mode and test mode. DONE
-
Encrypt3DES() performs 3DES encryption on key and payload DONE
-
getKey() This generates the key using the secret key DONE
-
DirectCharge() required param is client, the rest is in the library DONE
-
ValidateCardCharge() transacionReference and OTP required
-
ValidateAccountCharge() same as above
-
VerifyTransaction() flw_ref, seckey, normalize=1 required tx_ref optional
-
VerifyTransactionXrequery() flw_ref, seckey, tx_ref, last_attemp, only_successful
-
ListBanks() DONE
-
ConversionRate() requires seckey origin_currency destination_currency optional amount
-
StopRecurringPayment() id of recurring payment and seckey
-
ListRecurringTransactions() seckey only
-
ListSingleRecurringPayment() seckey tx_id
-
PreautorizeCard() client seckey alg
-
CapturePayment() seckey ref
-
RefundPayment() seckey ref action=refund
-
VoidPayment() seckey ref action=void
-
ChargeWithToken() long list of body params
-
SetPaymentMethod()
-
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 |