orchard-api-client-anm 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.byebug_history +40 -0
- data/.rubocop.yml +5 -1
- data/Gemfile.lock +2 -2
- data/README.md +58 -27
- data/lib/orchard/api/base.rb +20 -3
- data/lib/orchard/api/send_payment_request.rb +2 -6
- data/lib/orchard/api/send_sms.rb +25 -0
- data/lib/orchard/api_client.rb +6 -2
- data/lib/orchard/constants.rb +1 -0
- data/lib/orchard/version.rb +1 -1
- data/lib/orchard.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b3a6c24aa68bebbe5c904d4c2ce159ae7e89ba836a68dc0660107662d2bb381
|
4
|
+
data.tar.gz: 2f6247a62275c2a9bae6123a52450e5b291529101ea01dcfff943b39560a09f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d651c79664926b55f65d5a85d66979aea3008ae7a52383f2242be392c068a4dfca2b35bb31e9ea6c1cf0aa64cf282c8cdc9b416cebfc3afffce15e0fe9d8b223
|
7
|
+
data.tar.gz: 0ca6f77edc0d1e0a11a2cffedfc456a32d988c9ff4fe424725fc083f0a19e0426fe80bcd628f394c2b463806ea9c4f68467830f2978204847f6cac49dee6eb57
|
data/.byebug_history
CHANGED
@@ -1,4 +1,44 @@
|
|
1
1
|
exit
|
2
|
+
"2343333333333333"[-9..]
|
3
|
+
"2343333333333333".[-9..]
|
4
|
+
r
|
5
|
+
exit
|
6
|
+
client.send_sms(sms_payload, {timeout: 5})
|
7
|
+
client.send_sms(sms_payload, {timeout: 10})
|
8
|
+
r
|
9
|
+
exit
|
10
|
+
r
|
11
|
+
exit
|
12
|
+
r
|
13
|
+
exit
|
14
|
+
client
|
15
|
+
exit
|
16
|
+
@connection
|
17
|
+
r
|
18
|
+
exit
|
19
|
+
eit
|
20
|
+
@endpoint
|
21
|
+
r
|
22
|
+
exit
|
23
|
+
r
|
24
|
+
exit
|
25
|
+
r
|
26
|
+
exit
|
27
|
+
r
|
28
|
+
exit
|
29
|
+
r
|
30
|
+
exit
|
31
|
+
continue
|
32
|
+
@timeout
|
33
|
+
exit
|
34
|
+
@timeout
|
35
|
+
exit
|
36
|
+
r
|
37
|
+
exit
|
38
|
+
r
|
39
|
+
exit
|
40
|
+
r
|
41
|
+
exit
|
2
42
|
r.body
|
3
43
|
r.success?
|
4
44
|
r.success
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.6
|
3
3
|
SuggestExtensions: false
|
4
|
+
NewCops: disable
|
4
5
|
|
5
6
|
Style/StringLiterals:
|
6
7
|
Enabled: true
|
@@ -14,4 +15,7 @@ Layout/LineLength:
|
|
14
15
|
Max: 120
|
15
16
|
|
16
17
|
Style/Documentation:
|
17
|
-
Enabled: false
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 15
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
orchard-api-client-anm (0.1.1)
|
5
5
|
byebug
|
6
6
|
faraday (~> 2.6)
|
7
7
|
rspec (~> 3.0)
|
@@ -58,7 +58,7 @@ PLATFORMS
|
|
58
58
|
|
59
59
|
DEPENDENCIES
|
60
60
|
faraday (~> 2.6)
|
61
|
-
|
61
|
+
orchard-api-client-anm!
|
62
62
|
rake (~> 13.0)
|
63
63
|
rspec (~> 3.0)
|
64
64
|
rubocop (~> 1.21)
|
data/README.md
CHANGED
@@ -1,37 +1,68 @@
|
|
1
|
-
# Orchard
|
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/orchard`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
1
|
+
# Orchard API Client
|
2
|
+
This api client integrates into appsNmobiles orchard payment solution
|
6
3
|
|
7
4
|
## Installation
|
8
5
|
|
9
6
|
Install the gem and add to the application's Gemfile by executing:
|
10
7
|
|
11
|
-
$ bundle add orchard
|
8
|
+
$ bundle add orchard-api-client-anm
|
12
9
|
|
13
10
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
11
|
|
15
|
-
$ gem install orchard
|
12
|
+
$ gem install orchard-api-client-anm
|
16
13
|
|
17
14
|
## Usage
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
15
|
+
```ruby
|
16
|
+
#load the gem class
|
17
|
+
require 'orchard'
|
18
|
+
|
19
|
+
#Create a client object with the secret token, client token, and the url
|
20
|
+
params = {
|
21
|
+
secret_token: ENV['SECRET_TOKEN'],
|
22
|
+
client_token: ENV['CLIENT_TOKEN'],
|
23
|
+
url: ENV['ORCHARD_URL']
|
24
|
+
}
|
25
|
+
|
26
|
+
client = Orchard::ApiClient.new(params)
|
27
|
+
|
28
|
+
#Use client object for various api functions
|
29
|
+
|
30
|
+
#optional configuration configurations
|
31
|
+
request_configurations = {
|
32
|
+
timeout: 30
|
33
|
+
}
|
34
|
+
|
35
|
+
#Send payment request
|
36
|
+
|
37
|
+
randval_one = rand(999).to_s.center(3, rand(9).to_s)
|
38
|
+
strtm = Time.new.strftime("%d%H%M%L")
|
39
|
+
processing_id = strtm + randval_one
|
40
|
+
trans_type = allowed_parameters['CTM(client to merchant)' / 'MTC(merchant to client)']
|
41
|
+
nw = allowed_parameters['MTN','VOD','AIR']
|
42
|
+
|
43
|
+
payment_request_payload = {
|
44
|
+
customer_number: '',
|
45
|
+
reference: '',
|
46
|
+
amount: '',
|
47
|
+
exttrid: processing_id,
|
48
|
+
nw: 'MTN',
|
49
|
+
trans_type: 'CTM',
|
50
|
+
callback_url: '/',
|
51
|
+
ts: Time.now.strftime("%Y-%m-%d %H:%M:%S"),
|
52
|
+
client_id: ENV['SERVICE_ID'],
|
53
|
+
voucher_code: ''
|
54
|
+
}
|
55
|
+
|
56
|
+
response = client.send_payment_request(payload, request_configurations)
|
57
|
+
|
58
|
+
#Send Sms
|
59
|
+
sms_payload = {
|
60
|
+
sender_id: '',
|
61
|
+
recipient_number: '',
|
62
|
+
msg_body: '',
|
63
|
+
trans_type: 'SMS',
|
64
|
+
service_id: ENV['SERVICE_ID']
|
65
|
+
}
|
66
|
+
|
67
|
+
response = client.send_sms(payload)
|
68
|
+
```
|
data/lib/orchard/api/base.rb
CHANGED
@@ -3,21 +3,38 @@
|
|
3
3
|
module Orchard
|
4
4
|
module API
|
5
5
|
class Base
|
6
|
-
def initialize(params)
|
6
|
+
def initialize(params, request_configurations)
|
7
7
|
@payload = params[:payload]
|
8
8
|
@client_token = params[:client_token]
|
9
9
|
@secret_token = params[:secret_token]
|
10
10
|
@connection = params[:connection]
|
11
|
+
@timeout = request_configurations[:timeout] || 30
|
11
12
|
end
|
12
13
|
|
13
|
-
def self.call(params)
|
14
|
-
new(params).call
|
14
|
+
def self.call(params, request_configurations)
|
15
|
+
new(params, request_configurations).call
|
15
16
|
end
|
16
17
|
|
17
18
|
def compute_signature
|
18
19
|
digest = OpenSSL::Digest.new("sha256")
|
19
20
|
OpenSSL::HMAC.hexdigest(digest, @secret_token.to_s, @payload.to_json)
|
20
21
|
end
|
22
|
+
|
23
|
+
def make_post_request
|
24
|
+
response = @connection.post do |request|
|
25
|
+
request.url @endpoint
|
26
|
+
request.options.timeout = @timeout
|
27
|
+
request.body = @payload.to_json
|
28
|
+
request["Authorization"] = "#{@client_token}:#{compute_signature}"
|
29
|
+
end
|
30
|
+
|
31
|
+
JSON.parse(response.body)
|
32
|
+
rescue StandardError => e
|
33
|
+
{
|
34
|
+
"res_code" => "999",
|
35
|
+
"res_desc" => e.message
|
36
|
+
}
|
37
|
+
end
|
21
38
|
end
|
22
39
|
end
|
23
40
|
end
|
@@ -4,12 +4,8 @@ module Orchard
|
|
4
4
|
module API
|
5
5
|
class SendPaymentRequest < Orchard::API::Base
|
6
6
|
def call
|
7
|
-
@
|
8
|
-
|
9
|
-
request.options.timeout = 60
|
10
|
-
request.body = @payload.to_json
|
11
|
-
request["Authorization"] = "#{@client_token}:#{compute_signature}"
|
12
|
-
end
|
7
|
+
@endpoint = Orchard::API::Constants::SEND_PAYMENT_REQUEST_ENDPOINT
|
8
|
+
make_post_request
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Orchard
|
4
|
+
module API
|
5
|
+
class SendSMS < Orchard::API::Base
|
6
|
+
def call
|
7
|
+
format_recipients_number
|
8
|
+
generate_unique_id
|
9
|
+
@endpoint = Orchard::API::Constants::SEND_SMS_ENDPOINT
|
10
|
+
make_post_request
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_recipients_number
|
14
|
+
recipient_number = @payload[:recipient_number]
|
15
|
+
return unless recipient_number
|
16
|
+
|
17
|
+
@payload[:recipient_number] = "233#{recipient_number[-9..]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_unique_id
|
21
|
+
@payload[:unique_id] = Time.now.strftime("%y%m%d%L%H%M")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/orchard/api_client.rb
CHANGED
@@ -9,8 +9,12 @@ module Orchard
|
|
9
9
|
@connection = create_connection
|
10
10
|
end
|
11
11
|
|
12
|
-
def send_payment_request(payload)
|
13
|
-
Orchard::API::SendPaymentRequest.call(token_and_payload(payload))
|
12
|
+
def send_payment_request(payload, request_configurations = {})
|
13
|
+
Orchard::API::SendPaymentRequest.call(token_and_payload(payload), request_configurations)
|
14
|
+
end
|
15
|
+
|
16
|
+
def send_sms(payload, request_configurations = {})
|
17
|
+
Orchard::API::SendSMS.call(token_and_payload(payload), request_configurations)
|
14
18
|
end
|
15
19
|
|
16
20
|
private
|
data/lib/orchard/constants.rb
CHANGED
data/lib/orchard/version.rb
CHANGED
data/lib/orchard.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orchard-api-client-anm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sydney Dapilah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/orchard.rb
|
73
73
|
- lib/orchard/api/base.rb
|
74
74
|
- lib/orchard/api/send_payment_request.rb
|
75
|
+
- lib/orchard/api/send_sms.rb
|
75
76
|
- lib/orchard/api_client.rb
|
76
77
|
- lib/orchard/constants.rb
|
77
78
|
- lib/orchard/version.rb
|