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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fe24561d8560f4e72128ed35d5d381fcfa0df5b4102374a1da846e8d68df7dc
4
- data.tar.gz: 79c20d0ae92d8847d57c00db007e21cc9b6d6717abda6ee77d708deae2eb4695
3
+ metadata.gz: 8b3a6c24aa68bebbe5c904d4c2ce159ae7e89ba836a68dc0660107662d2bb381
4
+ data.tar.gz: 2f6247a62275c2a9bae6123a52450e5b291529101ea01dcfff943b39560a09f8
5
5
  SHA512:
6
- metadata.gz: 3abc6c7eaaa9d264666c5f908972b8430c769b7f6ed419fc4d654927fe50c2173e7c7179dce9812b31a156875ec1352a34901b96ebd3c0f7c24f03e60e0a0d8c
7
- data.tar.gz: 2517968d7648e3b6adc0428f7a4b450719b448bd15140ddcd4b0168b8fce5364fe15b320a8f859170acad69737f97e0e7d2db134e3cd95e912d45a384b0993b6
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
- orchard_anm (0.1.0)
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
- orchard_anm!
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
- TODO: Write usage instructions here
20
-
21
- ## Development
22
-
23
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
-
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
-
27
- ## Contributing
28
-
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/orchard. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/orchard/blob/master/CODE_OF_CONDUCT.md).
30
-
31
- ## License
32
-
33
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
-
35
- ## Code of Conduct
36
-
37
- Everyone interacting in the Orchard project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/orchard/blob/master/CODE_OF_CONDUCT.md).
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
+ ```
@@ -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
- @connection.post do |request|
8
- request.url Orchard::API::Constants::SEND_PAYMENT_REQUEST_ENDPOINT
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
@@ -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
@@ -4,6 +4,7 @@ module Orchard
4
4
  module API
5
5
  module Constants
6
6
  SEND_PAYMENT_REQUEST_ENDPOINT = "/sendRequest"
7
+ SEND_SMS_ENDPOINT = "/sendSms"
7
8
  end
8
9
  end
9
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orchard
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/orchard.rb CHANGED
@@ -6,5 +6,6 @@ require_relative "orchard/version"
6
6
  require_relative "orchard/constants"
7
7
  require_relative "orchard/api/base"
8
8
  require_relative "orchard/api/send_payment_request"
9
+ require_relative "orchard/api/send_sms"
9
10
 
10
11
  require_relative "orchard/api_client"
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.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-19 00:00:00.000000000 Z
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