Class: Khalti::Verification

Inherits:
Object
  • Object
show all
Defined in:
lib/khalti/verification.rb

Overview

Khalti verification API wrapper

Constant Summary collapse

API_URL =
'https://khalti.com/api/payment/verify/'
SECRET_KEY =
ENV['KHALTI_SECRET_KEY']

Class Method Summary collapse

Class Method Details

.validate_ammount(val) ⇒ Object



31
32
33
34
# File 'lib/khalti/verification.rb', line 31

def validate_ammount(val)
  return if Integer(val).positive?
  raise Errors::InvalidAmountError, 'Ensure amount is greater than 0 paisa.'
end

.validate_blank_token(val) ⇒ Object

Raises:



21
22
23
24
# File 'lib/khalti/verification.rb', line 21

def validate_blank_token(val)
  return unless val.nil? || val.strip.empty?
  raise Errors::BlankError, 'Ensure token is not blank.'
end

.validate_token_length(val) ⇒ Object



26
27
28
29
# File 'lib/khalti/verification.rb', line 26

def validate_token_length(val)
  return if val.strip.size >= 22
  raise Errors::InvalidTokenError, 'Ensure token has at least 22 characters.'
end

.verify(token, amount) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/khalti/verification.rb', line 13

def verify(token, amount)
  validate_blank_token(token)
  validate_token_length(token)
  validate_ammount(amount)
  params = { 'token': token, 'amount': amount.to_i }
  RequestHelper.post(API_URL, params)
end