moncash_ruby 0.1.0

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/moncash_ruby.rb +78 -0
  3. metadata +43 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 622733f7ff6b6e09e2c110561314dab2b822cd6b61d9d37677d2a552ab8a45b2
4
+ data.tar.gz: c03b175a2f1ad853453c89e32240d23018fc6406db42ddeb2045f19626e4b4d2
5
+ SHA512:
6
+ metadata.gz: 6c07be4a5bc6e31cb871c263db5293d03d75e94226645d673bfa4de22ba628dd82006c4778da8c632e86f996a36bf0c9a8caa21f467bb8ce23fef0ad73e17d1c
7
+ data.tar.gz: 6001379fee91584d2190524696273427ffe43f35ada89f70996ea3e197389935c0ef383da029f58791791eab1ca12ec87ba73112f20251ca9018273e47ef02b6
@@ -0,0 +1,78 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ module Moncash
7
+ class Hit
8
+ attr_accessor :client_id, :secret_id
9
+
10
+ @@token_endpoint = '/Api/oauth/token'
11
+ @@new_payment_endpoint = '/Api/v1/CreatePayment'
12
+ @base_url = ''
13
+ @token = ''
14
+ @payment_repons = ''
15
+
16
+ def initialize(client_id, secret_id)
17
+ @client_id = client_id
18
+ @secret_id = secret_id
19
+ end
20
+
21
+ def create_token(mode)
22
+ if mode == 'sandbox'
23
+ @base_url = 'sandbox.moncashbutton.digicelgroup.com'
24
+ elsif mode == 'live'
25
+ @base_url = 'moncashbutton.digicelgroup.com'
26
+ end
27
+ conn = Faraday.new(url: "https://#{client_id}:#{secret_id}@#{@base_url}") do |faraday|
28
+ faraday.adapter Faraday.default_adapter
29
+ end
30
+
31
+ response = conn.post do |req|
32
+ req.url @@token_endpoint
33
+ req.headers['Content-Type'] = 'application/json'
34
+ req.params = { scope: 'read,write', grant_type: 'client_credentials' }
35
+ end
36
+ repos = JSON.parse response.body
37
+ @token = repos['access_token']
38
+ end
39
+
40
+ def create_payment(amount, order_id, mode = 'sandbox')
41
+ create_token(mode)
42
+ uri = URI.parse("https://#{@base_url}#{@@new_payment_endpoint}")
43
+ request = Net::HTTP::Post.new(uri)
44
+ request.content_type = 'application/json'
45
+ request['Accept'] = 'application/json'
46
+ request['Authorization'] = "Bearer #{@token}"
47
+ request.body = JSON.dump({
48
+ 'amount' => amount,
49
+ 'orderId' => order_id
50
+ })
51
+ req_options = {
52
+ use_ssl: uri.scheme == 'https'
53
+ }
54
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
55
+ http.request(request)
56
+ end
57
+ @payment_repons = JSON.parse response.body
58
+ end
59
+
60
+ def get_payment_detail(order_id, mode = 'sandbox')
61
+ create_token(mode)
62
+ uri = URI.parse("https://#{@base_url}#{@@get_payment_endpoint}")
63
+ request = Net::HTTP::Post.new(uri)
64
+ request.content_type = 'application/json'
65
+ request['Accept'] = 'application/json'
66
+ request['Authorization'] = "Bearer #{@token}"
67
+ request.body = "{ \" transactionId\": #{order_id}}"
68
+ req_options = {
69
+ use_ssl: uri.scheme == 'https'
70
+ }
71
+
72
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
73
+ http.request(request)
74
+ end
75
+ JSON.parse response.body
76
+ end
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moncash_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Certil Remy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: hello@certilremy.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/moncash_ruby.rb
20
+ homepage: https://rubygems.org/gems/moncash_ruby
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.1.2
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Moncash sdk to perform and retieve payment to moncash api
43
+ test_files: []