orchard-api-client-anm 0.1.1 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fe24561d8560f4e72128ed35d5d381fcfa0df5b4102374a1da846e8d68df7dc
4
- data.tar.gz: 79c20d0ae92d8847d57c00db007e21cc9b6d6717abda6ee77d708deae2eb4695
3
+ metadata.gz: c6e66ee039d048dcaeb3323ca7ba1011735941f43dd94d87f58558437b909a6a
4
+ data.tar.gz: 6360df2749da90c401d2e48906c9037d795f75dd00d1c465e7f503f1e83ab3eb
5
5
  SHA512:
6
- metadata.gz: 3abc6c7eaaa9d264666c5f908972b8430c769b7f6ed419fc4d654927fe50c2173e7c7179dce9812b31a156875ec1352a34901b96ebd3c0f7c24f03e60e0a0d8c
7
- data.tar.gz: 2517968d7648e3b6adc0428f7a4b450719b448bd15140ddcd4b0168b8fce5364fe15b320a8f859170acad69737f97e0e7d2db134e3cd95e912d45a384b0993b6
6
+ metadata.gz: e2c5dbeb84b5f2e0653ec185a57b2c2df9e9f6bfdf9733db8e70b18a9c743c1bbe1a8dfee3ace4bfe0d73bc703e37aecd532c3106a37bdbbf3bc7345aa7f0aac
7
+ data.tar.gz: 372f1b1aa0399f425630c1a65579624d191de5a56d7b54f7afd6701cdd006838cec4a34d7a4deb395d1fce814ddbc47185c94d6f92b16e2a846ddae24f9a5b16
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(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(sms_payload, _request_configurations)
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.3"
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"
data/orchard.gemspec CHANGED
@@ -31,9 +31,11 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  # Uncomment to register a new dependency of your gem
34
- spec.add_dependency "byebug"
34
+ spec.add_development_dependency "byebug"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
35
36
  spec.add_dependency "faraday", "~> 2.6"
36
- spec.add_dependency "rspec", "~> 3.0"
37
+
38
+
37
39
  # For more information and examples about making a new gem, check out our
38
40
  # guide at: https://bundler.io/guides/creating_gem.html
39
41
  end
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.3
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
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :runtime
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.6'
34
- type: :runtime
33
+ version: '3.0'
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.6'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: faraday
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '2.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '2.6'
55
55
  description: Orchard API client
56
56
  email:
57
57
  - sydney@appsnmobilesolutions.com
@@ -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