Sha256: c9ee4362b9d4871eb500583aac49c60e84b1db396fd4df87771dc19c80aabc77
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
# frozen_string_literal: true require 'uri' require 'net/http' require 'json' module Khalti # Khalti verification API wrapper class Verification API_URL = 'https://khalti.com/api/payment/verify/' SECRET_KEY = ENV['KHALTI_SECRET_KEY'] class << self 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 def validate_blank_token(val) return unless val.nil? || val.strip.empty? raise Errors::BlankError, 'Ensure token is not blank.' end def validate_token_length(val) return if val.strip.size >= 22 raise Errors::InvalidTokenError, 'Ensure token has at least ' \ '22 characters.' end def validate_ammount(val) return if Integer(val).positive? raise Errors::InvalidAmountError, 'Ensure amount is ' \ 'greater than 0 paisa.' end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
khalti-0.2.0 | lib/khalti/verification.rb |