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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/moncash_ruby.rb +19 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 622733f7ff6b6e09e2c110561314dab2b822cd6b61d9d37677d2a552ab8a45b2
4
- data.tar.gz: c03b175a2f1ad853453c89e32240d23018fc6406db42ddeb2045f19626e4b4d2
3
+ metadata.gz: f686bdc5281444f9ca18133361845af6a86b75ebee89fa84ffe05659bd2c3ae4
4
+ data.tar.gz: 9389ce6c01f4e2d0a775c0694c7116e1269dd99059fca3378dcef792cfaa6a9b
5
5
  SHA512:
6
- metadata.gz: 6c07be4a5bc6e31cb871c263db5293d03d75e94226645d673bfa4de22ba628dd82006c4778da8c632e86f996a36bf0c9a8caa21f467bb8ce23fef0ad73e17d1c
7
- data.tar.gz: 6001379fee91584d2190524696273427ffe43f35ada89f70996ea3e197389935c0ef383da029f58791791eab1ca12ec87ba73112f20251ca9018273e47ef02b6
6
+ metadata.gz: 7a02f8b45db9a48d4e34ef334938907a017938654f93460079d564edb4aac3a4ecf4ea8110449b3317debe45055a99bcc817dedb77b039a89223301a1e4268c5
7
+ data.tar.gz: 21e7c488b202d2a8d8f9e78b626be07f1cdcd736766a4f91ec78e2c87c0fb50e9100bf5c65caee5a250aa5279510b89ea2bb56a454453b11cdbcabac6e17ce8b
@@ -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 create_token(mode)
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
- @payment_repons = JSON.parse response.body
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(order_id, mode = 'sandbox')
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 = "{ \" transactionId\": #{order_id}}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moncash_ruby
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
  - Certil Remy