moncash_ruby 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/moncash_ruby.rb +19 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f686bdc5281444f9ca18133361845af6a86b75ebee89fa84ffe05659bd2c3ae4
|
4
|
+
data.tar.gz: 9389ce6c01f4e2d0a775c0694c7116e1269dd99059fca3378dcef792cfaa6a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a02f8b45db9a48d4e34ef334938907a017938654f93460079d564edb4aac3a4ecf4ea8110449b3317debe45055a99bcc817dedb77b039a89223301a1e4268c5
|
7
|
+
data.tar.gz: 21e7c488b202d2a8d8f9e78b626be07f1cdcd736766a4f91ec78e2c87c0fb50e9100bf5c65caee5a250aa5279510b89ea2bb56a454453b11cdbcabac6e17ce8b
|
data/lib/moncash_ruby.rb
CHANGED
@@ -12,18 +12,24 @@ module Moncash
|
|
12
12
|
@base_url = ''
|
13
13
|
@token = ''
|
14
14
|
@payment_repons = ''
|
15
|
+
@gateway_base_url = ''
|
16
|
+
@@get_payment_endpoint = '/Api/v1/RetrieveTransactionPayment'
|
15
17
|
|
16
18
|
def initialize(client_id, secret_id)
|
17
19
|
@client_id = client_id
|
18
20
|
@secret_id = secret_id
|
19
21
|
end
|
20
22
|
|
21
|
-
def
|
23
|
+
def setup_mode(mode)
|
22
24
|
if mode == 'sandbox'
|
23
25
|
@base_url = 'sandbox.moncashbutton.digicelgroup.com'
|
24
26
|
elsif mode == 'live'
|
25
27
|
@base_url = 'moncashbutton.digicelgroup.com'
|
26
28
|
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_token(mode)
|
32
|
+
setup_mode(mode)
|
27
33
|
conn = Faraday.new(url: "https://#{client_id}:#{secret_id}@#{@base_url}") do |faraday|
|
28
34
|
faraday.adapter Faraday.default_adapter
|
29
35
|
end
|
@@ -39,6 +45,11 @@ module Moncash
|
|
39
45
|
|
40
46
|
def create_payment(amount, order_id, mode = 'sandbox')
|
41
47
|
create_token(mode)
|
48
|
+
if mode == 'sandbox'
|
49
|
+
@gateway_base_url = 'https://sandbox.moncashbutton.digicelgroup.com/Moncash-middleware'
|
50
|
+
elsif mode == 'live'
|
51
|
+
@gateway_base_url = 'https://moncashbutton.digicelgroup.com/Moncash-middleware'
|
52
|
+
end
|
42
53
|
uri = URI.parse("https://#{@base_url}#{@@new_payment_endpoint}")
|
43
54
|
request = Net::HTTP::Post.new(uri)
|
44
55
|
request.content_type = 'application/json'
|
@@ -54,21 +65,24 @@ module Moncash
|
|
54
65
|
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
55
66
|
http.request(request)
|
56
67
|
end
|
57
|
-
|
68
|
+
hash_repos = JSON.parse response.body
|
69
|
+
@payment_repons = "#{@gateway_base_url}/Payment/Redirect?token=#{hash_repos['payment_token']['token']}"
|
58
70
|
end
|
59
71
|
|
60
|
-
def get_payment_detail(
|
72
|
+
def get_payment_detail(transaction_id, mode = 'sandbox')
|
61
73
|
create_token(mode)
|
74
|
+
setup_mode(mode)
|
62
75
|
uri = URI.parse("https://#{@base_url}#{@@get_payment_endpoint}")
|
63
76
|
request = Net::HTTP::Post.new(uri)
|
64
77
|
request.content_type = 'application/json'
|
65
78
|
request['Accept'] = 'application/json'
|
66
79
|
request['Authorization'] = "Bearer #{@token}"
|
67
|
-
request.body =
|
80
|
+
request.body = JSON.dump({
|
81
|
+
'transactionId' => transaction_id
|
82
|
+
})
|
68
83
|
req_options = {
|
69
84
|
use_ssl: uri.scheme == 'https'
|
70
85
|
}
|
71
|
-
|
72
86
|
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
73
87
|
http.request(request)
|
74
88
|
end
|