khalti 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c2ec330bc40f9bacce84aa5ae9800a678a416a87766fb44fc1dcea3c6ba17e7
4
- data.tar.gz: 2e2c29e5cabd33b64bb18176f0a653e0e6cb6d946235e52284c58fc01aafcb21
3
+ metadata.gz: f710f282228b97bc8f188a6f68f296df93174b5a54373d4c78df014c6f26cbee
4
+ data.tar.gz: bfa511624d569ae7dd9d598c2cd9ee0049a525bbf8abbb52eb1e4a2e68ae7c29
5
5
  SHA512:
6
- metadata.gz: a97f5f6ebd63e79072877fc67c84a283a14311e6ae3dd81e369727ce8503e732e5dd7afe3775d8728bfc59bb5ddb64e17ce1654db7b6d7a485befcb311640aeb
7
- data.tar.gz: 42308aff0707789b933be248f521cb6023e4c483e67b67067b3093c606a33c72f72d8c1f5b4c0bd4456bf9f5c25567967c622581752182b1c3e54418478aee18
6
+ metadata.gz: 4b0fecfc8cf7f7885402a7d45452b604846a3d0d3beeeb53941f3bad0a962a7bfd608d6dedcb967042a0844989af81026db6ce1118e4fb067e30c1da81979fce
7
+ data.tar.gz: 3315b174393419596cf382027c18c58e7d48dbd37899a1268cd04e9b6e4368eba50870ade4cf2b05ca0164eab8e9d70fefa08cc14fde02d588826a8046b253fb
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ *.gem
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Khalti
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/khalti`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Welcome to the khalti ruby gem. It is an API wrapper for Khalti payment gateway. For more info visit [Khalti Gateway Docs](http://docs.khalti.com/).
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,18 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Write usage instructions here
23
+ export KHALTI_SECRET_KEY=your_secret_key
24
+
25
+ It supports server side verification and transaction list/ find
26
+
27
+ Verification:
28
+
29
+ Khalti::Verification.verify('token', 'amount')
30
+
31
+ Transaction:
32
+
33
+ Khalti::Transaction.all
34
+ Khalti::Transaction.find(idx)
24
35
 
25
36
  ## Development
26
37
 
@@ -0,0 +1,38 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ API_URL = 'https://khalti.com/api/merchant-transaction'
6
+
7
+ module Khalti
8
+ class Transaction
9
+ def self.find(idx)
10
+ secret_key = ENV['KHALTI_SECRET_KEY'] #test_secret_key_f59e8b7d18b4499ca40f68195a846e9b
11
+ headers = {
12
+ Authorization: "Key #{secret_key}"
13
+ }
14
+ uri = URI.parse("#{API_URL}/#{idx}/")
15
+ puts uri
16
+ https = Net::HTTP.new(uri.host, uri.port)
17
+ https.use_ssl = true
18
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
19
+ response = https.request(request)
20
+
21
+ JSON.parse(response.body) || {}
22
+ end
23
+
24
+ def self.all
25
+ secret_key = ENV['KHALTI_SECRET_KEY'] #test_secret_key_f59e8b7d18b4499ca40f68195a846e9b
26
+ headers = {
27
+ Authorization: "Key #{secret_key}"
28
+ }
29
+ uri = URI.parse("#{API_URL}/")
30
+ https = Net::HTTP.new(uri.host, uri.port)
31
+ https.use_ssl = true
32
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
33
+ response = https.request(request)
34
+
35
+ JSON.parse(response.body) || {}
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ API_URL = "https://khalti.com/api/payment/verify/"
6
+
7
+ module Khalti
8
+ class Verification
9
+ def self.verify(token, amount)
10
+ secret_key = ENV['KHALTI_SECRET_KEY']
11
+ headers = {
12
+ Authorization: "Key #{secret_key}"
13
+ }
14
+ uri = URI.parse("#{API_URL}")
15
+ https = Net::HTTP.new(uri.host, uri.port)
16
+ https.use_ssl = true
17
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
18
+ request.set_form_data('token' => "#{token}", 'amount' => "#{amount}")
19
+ response = https.request(request)
20
+
21
+ JSON.parse(response.body) || {}
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Khalti
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/khalti.rb CHANGED
@@ -1,4 +1,6 @@
1
- require "khalti/version"
1
+ require_relative "khalti/version"
2
+ require_relative "khalti/verification"
3
+ require_relative "khalti/transaction"
2
4
 
3
5
  module Khalti
4
6
  # Your code goes here...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: khalti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Degendra Sivakoti
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2018-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,8 @@ files:
71
71
  - bin/setup
72
72
  - khalti.gemspec
73
73
  - lib/khalti.rb
74
+ - lib/khalti/transaction.rb
75
+ - lib/khalti/verification.rb
74
76
  - lib/khalti/version.rb
75
77
  homepage: https://github.com/bajratech/khalti-ruby
76
78
  licenses: