paymentsds-mpesa 0.1.0.pre.alpha.13 → 0.1.0.pre.alpha.18

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: 382655187d79e081000c1ce3b1cd664fa86e8d4d2397958e2add9875cf3b471c
4
- data.tar.gz: 144c2c56e1b236296e931db9dc870ef4fbec7f8727682423a3aa33710239a082
3
+ metadata.gz: 88aa84672598eae578bb28ba63afdc58e6d95a03aebad8de4f04b4135a1075aa
4
+ data.tar.gz: 4567a1ed8243c44b7bc0b091858152a67e65adacbd7757df5191375104f00ab8
5
5
  SHA512:
6
- metadata.gz: 45148c1776339bbe17d8538636b97117f137fc0240a5a369c13351db1a0151d6fde8c3a556acd862c78aeb514a9c42b645ced4ded50ed1c80e2072545c16292f
7
- data.tar.gz: '094269d5f9de88db2c0092cbd1105ad1e3aca770b44ce77d0fc2956cfb30afe136ce1e0a76561edf97cba80c314bf6b00a10b31fa97c5cd8766f748dcd45844f'
6
+ metadata.gz: 9c836c0f1205861cdcdf710ecb85eaca1e8ef22c8db55e0d6a886f17bdfbc6db92c0b751f2416235ce1fce5bc03475f5f4dbbc2f01c298701588a5c369f069bf
7
+ data.tar.gz: 1e4f4bd904bc8319fe0498a2ac01181b51a411dff0996be85e95441ac57159467a062382af2b853f6c39260496dfe715ea01ab506af791331c73eddf6ee22171
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ require 'json'
3
+ require 'faraday'
2
4
 
3
5
  module Paymentsds
4
6
  module MPesa
@@ -131,6 +133,8 @@ module Paymentsds
131
133
  end
132
134
 
133
135
  def perform_request(opcode, intent)
136
+ operation = Paymentsds::MPesa::OPERATIONS[opcode]
137
+
134
138
  generate_access_token
135
139
 
136
140
  request_data = {
@@ -143,27 +147,28 @@ module Paymentsds
143
147
  body: build_request_body(opcode, intent)
144
148
  }
145
149
 
146
- http_client = Faraday::Connection.new do |client|
147
- client.url = "#{request_data[:base_url]}/#{request_data[:path]}"
148
- client.headers = request_data[:headers]
149
- client.options.timeout = request_data.timeout
150
- end
151
-
152
- case operation[:method]
150
+ http_client = Faraday.new(
151
+ url: request_data[:base_url],
152
+ headers: request_data[:headers],
153
+ )
153
154
 
155
+ case operation[:method]
154
156
  when :get
155
- response = http_client.get do |req|
156
- req.params = request_data.body
157
+ response = http_client.get(request_data[:path]) do |req|
158
+ req.params = request_data[:body]
159
+ req.options.timeout = request_data[:timeout]
157
160
  end
158
161
 
159
162
  when :post
160
- response = http_client.post do |req|
161
- req.body = request_data.body
163
+ response = http_client.post(request_data[:path]) do |req|
164
+ req.body = request_data[:body].to_json
165
+ req.options.timeout = request_data[:timeout]
162
166
  end
163
167
 
164
168
  when :put
165
- response = http_client.put do |req|
166
- req.body = request_data.body
169
+ response = http_client.put(request_data[:path]) do |req|
170
+ req.body = request_data[:body].to_json
171
+ req.options.timeout = request_data[:timeout]
167
172
  end
168
173
  end
169
174
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Paymentsds
4
4
  module MPesa
5
- VERSION = '0.1.0.pre.alpha.13'
5
+ VERSION = '0.1.0.pre.alpha.18'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymentsds-mpesa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.alpha.13
4
+ version: 0.1.0.pre.alpha.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edson Michaque