airtel-pesa 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +57 -0
- data/lib/airtel/pesa/balance_enquiry.rb +58 -0
- data/lib/airtel/pesa/disbursement_payment.rb +92 -0
- data/lib/airtel/pesa/disbursement_transaction_enquiry.rb +59 -0
- data/lib/airtel/pesa/example.rb +68 -0
- data/lib/airtel/pesa/refund_payment.rb +69 -0
- data/lib/airtel/pesa/transaction_enquiry.rb +59 -0
- data/lib/airtel/pesa/user_enquiry.rb +59 -0
- data/lib/airtel/pesa/ussd_push_payment.rb +95 -0
- data/lib/airtel/pesa/version.rb +1 -1
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dedc371bd6300da3b7711ca31c6bf156dd1bacfffba8fe800bed38debd3d586c
|
4
|
+
data.tar.gz: bcdb935588f1622d0daa12a51da58247825d0f88a6b4a3a300d1a5d560973200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d44543437df68897ca3a2a58a2f5eac69b8cfe4ef5e64f31624b4cafc1d455cfe9002fb0312af07e34c08a924f39104ffa846c56a08523854acb8daa359dc0bd
|
7
|
+
data.tar.gz: 72573b45af2b5b7dd37b2be9c7c91da1ecafe992986cf3e1906aaf7e7710fe183798988cd10d4c05498eea0d9764ad0b887be0a289a2e101b4afd0c7e96c19d3
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
airtel-pesa (0.1.1)
|
5
|
+
colorize
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
colorize (0.8.1)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
parallel (1.21.0)
|
14
|
+
parser (3.0.3.1)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
rainbow (3.0.0)
|
17
|
+
rake (13.0.6)
|
18
|
+
regexp_parser (2.2.0)
|
19
|
+
rexml (3.2.5)
|
20
|
+
rspec (3.10.0)
|
21
|
+
rspec-core (~> 3.10.0)
|
22
|
+
rspec-expectations (~> 3.10.0)
|
23
|
+
rspec-mocks (~> 3.10.0)
|
24
|
+
rspec-core (3.10.1)
|
25
|
+
rspec-support (~> 3.10.0)
|
26
|
+
rspec-expectations (3.10.1)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-mocks (3.10.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-support (3.10.3)
|
33
|
+
rubocop (1.23.0)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 3.0.0.0)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml
|
39
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.14.0)
|
43
|
+
parser (>= 3.0.1.1)
|
44
|
+
ruby-progressbar (1.11.0)
|
45
|
+
unicode-display_width (2.1.0)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
x86_64-darwin-21
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
airtel-pesa!
|
52
|
+
rake (~> 13.0)
|
53
|
+
rspec (~> 3.0)
|
54
|
+
rubocop (~> 1.7)
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
2.2.22
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Airtel
|
10
|
+
module Pesa
|
11
|
+
class BalanceEnquiry
|
12
|
+
STAGING_URL = "https://openapiuat.airtel.africa".freeze
|
13
|
+
PRODUCTION_URL = "https://openapi.airtel.africa".freeze
|
14
|
+
|
15
|
+
attr_reader :transaction_country_code, :transaction_currency_code
|
16
|
+
|
17
|
+
def self.call(transaction_country_code:, transaction_currency_code:)
|
18
|
+
new(transaction_country_code, transaction_currency_code).call
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(transaction_country_code, transaction_currency_code)
|
22
|
+
@transaction_country_code = transaction_country_code
|
23
|
+
@transaction_currency_code = transaction_currency_code
|
24
|
+
end
|
25
|
+
|
26
|
+
def call
|
27
|
+
url = URI("#{env_url}/standard/v1/users/balance")
|
28
|
+
|
29
|
+
http = Net::HTTP.new(url.host, url.port)
|
30
|
+
http.use_ssl = true
|
31
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
32
|
+
|
33
|
+
request = Net::HTTP::Get.new(url)
|
34
|
+
request["Authorization"] = "Bearer #{token}"
|
35
|
+
request["X-Country"] = transaction_country_code
|
36
|
+
request["X-Currency"] = transaction_currency_code
|
37
|
+
|
38
|
+
response = http.request(request)
|
39
|
+
parsed_response = JSON.parse(response.read_body)
|
40
|
+
result = Airtel::Pesa.to_recursive_ostruct(parsed_response)
|
41
|
+
OpenStruct.new(result: result, error: nil)
|
42
|
+
rescue JSON::ParserError => error
|
43
|
+
OpenStruct.new(result: nil, error: error)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def env_url
|
49
|
+
return STAGING_URL Airtel::Pesa.configuration.env == 'staging'
|
50
|
+
return PRODUCTION_URL Airtel::Pesa.configuration.env == 'production'
|
51
|
+
end
|
52
|
+
|
53
|
+
def token
|
54
|
+
Airtel::Pesa::Authorization.call.result.access_token
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Airtel
|
10
|
+
module Pesa
|
11
|
+
class UssdPushPayment
|
12
|
+
STAGING_URL = "https://openapiuat.airtel.africa".freeze
|
13
|
+
PRODUCTION_URL = "https://openapi.airtel.africa".freeze
|
14
|
+
|
15
|
+
attr_reader :amount, :phone_number, :reference, :pin,
|
16
|
+
:transaction_country_code, :transaction_currency_code, :unique_random_id
|
17
|
+
|
18
|
+
def self.call(
|
19
|
+
amount:, phone_number:, reference:, pin:,
|
20
|
+
transaction_country_code:, transaction_currency_code:,
|
21
|
+
unique_random_id:
|
22
|
+
)
|
23
|
+
new(
|
24
|
+
amount, phone_number, reference, pin,
|
25
|
+
transaction_country_code, transaction_currency_code,
|
26
|
+
unique_random_id
|
27
|
+
).call
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(
|
31
|
+
amount, phone_number, reference, pin,
|
32
|
+
transaction_country_code, transaction_currency_code,
|
33
|
+
unique_random_id
|
34
|
+
)
|
35
|
+
@amount = amount
|
36
|
+
@phone_number = phone_number
|
37
|
+
@reference = reference
|
38
|
+
@pin = pin
|
39
|
+
@transaction_country_code = transaction_country_code
|
40
|
+
@transaction_currency_code = transaction_currency_code
|
41
|
+
@unique_random_id = unique_random_id
|
42
|
+
end
|
43
|
+
|
44
|
+
def call
|
45
|
+
url = URI("#{env_url}/standard/v1/disbursements")
|
46
|
+
|
47
|
+
http = Net::HTTP.new(url.host, url.port)
|
48
|
+
http.use_ssl = true
|
49
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
50
|
+
|
51
|
+
request = Net::HTTP::Post.new(url)
|
52
|
+
request["Content-Type"] = 'application/json'
|
53
|
+
request["Authorization"] = "Bearer #{token}"
|
54
|
+
request["X-Country"] = transaction_country_code
|
55
|
+
request["X-Currency"] = transaction_currency_code
|
56
|
+
request.body = JSON.dump(body)
|
57
|
+
|
58
|
+
response = http.request(request)
|
59
|
+
parsed_response = JSON.parse(response.read_body)
|
60
|
+
result = Airtel::Pesa.to_recursive_ostruct(parsed_response)
|
61
|
+
OpenStruct.new(result: result, error: nil)
|
62
|
+
rescue JSON::ParserError => error
|
63
|
+
OpenStruct.new(result: nil, error: error)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def env_url
|
69
|
+
return STAGING_URL Airtel::Pesa.configuration.env == 'staging'
|
70
|
+
return PRODUCTION_URL Airtel::Pesa.configuration.env == 'production'
|
71
|
+
end
|
72
|
+
|
73
|
+
def token
|
74
|
+
Airtel::Pesa::Authorization.call.result.access_token
|
75
|
+
end
|
76
|
+
|
77
|
+
def body
|
78
|
+
{
|
79
|
+
"payee": {
|
80
|
+
"msisdn": phone_number
|
81
|
+
},
|
82
|
+
"reference": reference,
|
83
|
+
"pin": pin || Airtel::Pesa::Encryption.call.result,
|
84
|
+
"transaction": {
|
85
|
+
"amount": amount,
|
86
|
+
"id": unique_random_id
|
87
|
+
}
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Airtel
|
10
|
+
module Pesa
|
11
|
+
class DisbursementTransactionEnquiry
|
12
|
+
STAGING_URL = "https://openapiuat.airtel.africa".freeze
|
13
|
+
PRODUCTION_URL = "https://openapi.airtel.africa".freeze
|
14
|
+
|
15
|
+
attr_reader :transaction_id, :transaction_country_code, :transaction_currency_code
|
16
|
+
|
17
|
+
def self.call(transaction_id:, transaction_country_code:, transaction_currency_code:)
|
18
|
+
new(transaction_id, transaction_country_code, transaction_currency_code).call
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(transaction_id, transaction_country_code, transaction_currency_code)
|
22
|
+
@transaction_id = transaction_id
|
23
|
+
@transaction_country_code = transaction_country_code
|
24
|
+
@transaction_currency_code = transaction_currency_code
|
25
|
+
end
|
26
|
+
|
27
|
+
def call
|
28
|
+
url = URI("#{env_url}/standard/v1/disbursements/#{transaction_id}")
|
29
|
+
|
30
|
+
http = Net::HTTP.new(url.host, url.port)
|
31
|
+
http.use_ssl = true
|
32
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
33
|
+
|
34
|
+
request = Net::HTTP::Get.new(url)
|
35
|
+
request["Authorization"] = "Bearer #{token}"
|
36
|
+
request["X-Country"] = transaction_country_code
|
37
|
+
request["X-Currency"] = transaction_currency_code
|
38
|
+
|
39
|
+
response = http.request(request)
|
40
|
+
parsed_response = JSON.parse(response.read_body)
|
41
|
+
result = Airtel::Pesa.to_recursive_ostruct(parsed_response)
|
42
|
+
OpenStruct.new(result: result, error: nil)
|
43
|
+
rescue JSON::ParserError => error
|
44
|
+
OpenStruct.new(result: nil, error: error)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def env_url
|
50
|
+
return STAGING_URL Airtel::Pesa.configuration.env == 'staging'
|
51
|
+
return PRODUCTION_URL Airtel::Pesa.configuration.env == 'production'
|
52
|
+
end
|
53
|
+
|
54
|
+
def token
|
55
|
+
Airtel::Pesa::Authorization.call.result.access_token
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Airtel
|
10
|
+
module Pesa
|
11
|
+
class Example
|
12
|
+
STAGING_URL = "https://openapiuat.airtel.africa".freeze
|
13
|
+
PRODUCTION_URL = "https://openapi.airtel.africa".freeze
|
14
|
+
|
15
|
+
attr_reader :param1, :transaction_country_code, :transaction_currency_code, :param4, :param5, :param6
|
16
|
+
|
17
|
+
def self.call(param1:, transaction_country_code:, transaction_currency_code:, param4:, param5:, param6:)
|
18
|
+
new(param1, transaction_country_code, transaction_currency_code, param4, param5, param6).call
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(param1, transaction_country_code, transaction_currency_code, param4, param5, param6)
|
22
|
+
@param1 = param1
|
23
|
+
@transaction_country_code = transaction_country_code
|
24
|
+
@transaction_currency_code = transaction_currency_code
|
25
|
+
@param4 = param4
|
26
|
+
@param5 = param5
|
27
|
+
@param6 = param6
|
28
|
+
end
|
29
|
+
|
30
|
+
def call
|
31
|
+
url = URI("#{env_url}/merchant/v1/payments/")
|
32
|
+
|
33
|
+
http = Net::HTTP.new(url.host, url.port)
|
34
|
+
http.use_ssl = true
|
35
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
36
|
+
|
37
|
+
request = Net::HTTP::Post.new(url)
|
38
|
+
request["Content-Type"] = 'application/json'
|
39
|
+
request["Authorization"] = "Bearer #{token}"
|
40
|
+
request["X-Country"] = transaction_country_code
|
41
|
+
request["X-Currency"] = transaction_currency_code
|
42
|
+
request.body = JSON.dump(body)
|
43
|
+
|
44
|
+
response = http.request(request)
|
45
|
+
parsed_response = JSON.parse(response.read_body)
|
46
|
+
result = Airtel::Pesa.to_recursive_ostruct(parsed_response)
|
47
|
+
OpenStruct.new(result: result, error: nil)
|
48
|
+
rescue JSON::ParserError => error
|
49
|
+
OpenStruct.new(result: nil, error: error)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def env_url
|
55
|
+
return STAGING_URL Airtel::Pesa.configuration.env == 'staging'
|
56
|
+
return PRODUCTION_URL Airtel::Pesa.configuration.env == 'production'
|
57
|
+
end
|
58
|
+
|
59
|
+
def token
|
60
|
+
Airtel::Pesa::Authorization.call.result.access_token
|
61
|
+
end
|
62
|
+
|
63
|
+
def body
|
64
|
+
{}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Airtel
|
10
|
+
module Pesa
|
11
|
+
class RefundPayment
|
12
|
+
STAGING_URL = "https://openapiuat.airtel.africa".freeze
|
13
|
+
PRODUCTION_URL = "https://openapi.airtel.africa".freeze
|
14
|
+
|
15
|
+
attr_reader :airtel_money_id, :transaction_country_code, :transaction_currency_code
|
16
|
+
|
17
|
+
def self.call(airtel_money_id:, transaction_country_code:, transaction_currency_code:)
|
18
|
+
new(airtel_money_id, transaction_country_code, transaction_currency_code).call
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(airtel_money_id, transaction_country_code, transaction_currency_code)
|
22
|
+
@airtel_money_id = airtel_money_id
|
23
|
+
@transaction_country_code = transaction_country_code
|
24
|
+
@transaction_currency_code = transaction_currency_code
|
25
|
+
end
|
26
|
+
|
27
|
+
def call
|
28
|
+
url = URI("#{env_url}/standard/v1/payments/refund")
|
29
|
+
|
30
|
+
http = Net::HTTP.new(url.host, url.port)
|
31
|
+
http.use_ssl = true
|
32
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
33
|
+
|
34
|
+
request = Net::HTTP::Post.new(url)
|
35
|
+
request["Content-Type"] = 'application/json'
|
36
|
+
request["Authorization"] = "Bearer #{token}"
|
37
|
+
request["X-Country"] = transaction_country_code
|
38
|
+
request["X-Currency"] = transaction_currency_code
|
39
|
+
request.body = JSON.dump(body)
|
40
|
+
|
41
|
+
response = http.request(request)
|
42
|
+
parsed_response = JSON.parse(response.read_body)
|
43
|
+
result = Airtel::Pesa.to_recursive_ostruct(parsed_response)
|
44
|
+
OpenStruct.new(result: result, error: nil)
|
45
|
+
rescue JSON::ParserError => error
|
46
|
+
OpenStruct.new(result: nil, error: error)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def env_url
|
52
|
+
return STAGING_URL Airtel::Pesa.configuration.env == 'staging'
|
53
|
+
return PRODUCTION_URL Airtel::Pesa.configuration.env == 'production'
|
54
|
+
end
|
55
|
+
|
56
|
+
def token
|
57
|
+
Airtel::Pesa::Authorization.call.result.access_token
|
58
|
+
end
|
59
|
+
|
60
|
+
def body
|
61
|
+
{
|
62
|
+
"transaction": {
|
63
|
+
"airtel_money_id": airtel_money_id
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Airtel
|
10
|
+
module Pesa
|
11
|
+
class TransactionEnquiry
|
12
|
+
STAGING_URL = "https://openapiuat.airtel.africa".freeze
|
13
|
+
PRODUCTION_URL = "https://openapi.airtel.africa".freeze
|
14
|
+
|
15
|
+
attr_reader :transaction_id, :transaction_country_code, :transaction_currency_code
|
16
|
+
|
17
|
+
def self.call(transaction_id:, transaction_country_code:, transaction_currency_code:)
|
18
|
+
new(transaction_id, transaction_country_code, transaction_currency_code).call
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(transaction_id, transaction_country_code, transaction_currency_code)
|
22
|
+
@transaction_id = transaction_id
|
23
|
+
@transaction_country_code = transaction_country_code
|
24
|
+
@transaction_currency_code = transaction_currency_code
|
25
|
+
end
|
26
|
+
|
27
|
+
def call
|
28
|
+
url = URI("#{env_url}/standard/v1/payments/#{transaction_id}")
|
29
|
+
|
30
|
+
http = Net::HTTP.new(url.host, url.port)
|
31
|
+
http.use_ssl = true
|
32
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
33
|
+
|
34
|
+
request = Net::HTTP::Get.new(url)
|
35
|
+
request["Authorization"] = "Bearer #{token}"
|
36
|
+
request["X-Country"] = transaction_country_code
|
37
|
+
request["X-Currency"] = transaction_currency_code
|
38
|
+
|
39
|
+
response = http.request(request)
|
40
|
+
parsed_response = JSON.parse(response.read_body)
|
41
|
+
result = Airtel::Pesa.to_recursive_ostruct(parsed_response)
|
42
|
+
OpenStruct.new(result: result, error: nil)
|
43
|
+
rescue JSON::ParserError => error
|
44
|
+
OpenStruct.new(result: nil, error: error)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def env_url
|
50
|
+
return STAGING_URL Airtel::Pesa.configuration.env == 'staging'
|
51
|
+
return PRODUCTION_URL Airtel::Pesa.configuration.env == 'production'
|
52
|
+
end
|
53
|
+
|
54
|
+
def token
|
55
|
+
Airtel::Pesa::Authorization.call.result.access_token
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Airtel
|
10
|
+
module Pesa
|
11
|
+
class TransactionEnquiry
|
12
|
+
STAGING_URL = "https://openapiuat.airtel.africa".freeze
|
13
|
+
PRODUCTION_URL = "https://openapi.airtel.africa".freeze
|
14
|
+
|
15
|
+
attr_reader :phone_number, :transaction_country_code, :transaction_currency_code
|
16
|
+
|
17
|
+
def self.call(phone_number:, transaction_country_code:, transaction_currency_code:)
|
18
|
+
new(phone_number, transaction_country_code, transaction_currency_code).call
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(phone_number, transaction_country_code, transaction_currency_code)
|
22
|
+
@phone_number = phone_number
|
23
|
+
@transaction_country_code = transaction_country_code
|
24
|
+
@transaction_currency_code = transaction_currency_code
|
25
|
+
end
|
26
|
+
|
27
|
+
def call
|
28
|
+
url = URI("#{env_url}/standard/v1/users/#{phone_number}")
|
29
|
+
|
30
|
+
http = Net::HTTP.new(url.host, url.port)
|
31
|
+
http.use_ssl = true
|
32
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
33
|
+
|
34
|
+
request = Net::HTTP::Get.new(url)
|
35
|
+
request["Authorization"] = "Bearer #{token}"
|
36
|
+
request["X-Country"] = transaction_country_code
|
37
|
+
request["X-Currency"] = transaction_currency_code
|
38
|
+
|
39
|
+
response = http.request(request)
|
40
|
+
parsed_response = JSON.parse(response.read_body)
|
41
|
+
result = Airtel::Pesa.to_recursive_ostruct(parsed_response)
|
42
|
+
OpenStruct.new(result: result, error: nil)
|
43
|
+
rescue JSON::ParserError => error
|
44
|
+
OpenStruct.new(result: nil, error: error)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def env_url
|
50
|
+
return STAGING_URL Airtel::Pesa.configuration.env == 'staging'
|
51
|
+
return PRODUCTION_URL Airtel::Pesa.configuration.env == 'production'
|
52
|
+
end
|
53
|
+
|
54
|
+
def token
|
55
|
+
Airtel::Pesa::Authorization.call.result.access_token
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Airtel
|
10
|
+
module Pesa
|
11
|
+
class UssdPushPayment
|
12
|
+
STAGING_URL = "https://openapiuat.airtel.africa".freeze
|
13
|
+
PRODUCTION_URL = "https://openapi.airtel.africa".freeze
|
14
|
+
|
15
|
+
attr_reader :amount, :phone_number, :country_code, :currency_code,
|
16
|
+
:transaction_country_code, :transaction_currency_code, :unique_random_id
|
17
|
+
|
18
|
+
def self.call(
|
19
|
+
amount:, phone_number:, country_code:, currency_code:,
|
20
|
+
transaction_country_code:, transaction_currency_code:,
|
21
|
+
unique_random_id:
|
22
|
+
)
|
23
|
+
new(
|
24
|
+
amount, phone_number, country_code, currency_code,
|
25
|
+
transaction_country_code, transaction_currency_code,
|
26
|
+
unique_random_id
|
27
|
+
).call
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(
|
31
|
+
amount, phone_number, country_code, currency_code,
|
32
|
+
transaction_country_code, transaction_currency_code,
|
33
|
+
unique_random_id
|
34
|
+
)
|
35
|
+
@amount = amount
|
36
|
+
@phone_number = phone_number
|
37
|
+
@country_code = country_code
|
38
|
+
@currency_code = currency_code
|
39
|
+
@transaction_country_code = transaction_country_code
|
40
|
+
@transaction_currency_code = transaction_currency_code
|
41
|
+
@unique_random_id = unique_random_id
|
42
|
+
end
|
43
|
+
|
44
|
+
def call
|
45
|
+
url = URI("#{env_url}/merchant/v1/payments")
|
46
|
+
|
47
|
+
http = Net::HTTP.new(url.host, url.port)
|
48
|
+
http.use_ssl = true
|
49
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
50
|
+
|
51
|
+
request = Net::HTTP::Post.new(url)
|
52
|
+
request["Content-Type"] = 'application/json'
|
53
|
+
request["Authorization"] = "Bearer #{token}"
|
54
|
+
request["X-Country"] = transaction_country_code
|
55
|
+
request["X-Currency"] = transaction_currency_code
|
56
|
+
request.body = JSON.dump(body)
|
57
|
+
|
58
|
+
response = http.request(request)
|
59
|
+
parsed_response = JSON.parse(response.read_body)
|
60
|
+
result = Airtel::Pesa.to_recursive_ostruct(parsed_response)
|
61
|
+
OpenStruct.new(result: result, error: nil)
|
62
|
+
rescue JSON::ParserError => error
|
63
|
+
OpenStruct.new(result: nil, error: error)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def env_url
|
69
|
+
return STAGING_URL Airtel::Pesa.configuration.env == 'staging'
|
70
|
+
return PRODUCTION_URL Airtel::Pesa.configuration.env == 'production'
|
71
|
+
end
|
72
|
+
|
73
|
+
def token
|
74
|
+
Airtel::Pesa::Authorization.call.result.access_token
|
75
|
+
end
|
76
|
+
|
77
|
+
def body
|
78
|
+
{
|
79
|
+
"reference": "airtel-pesa gem transaction",
|
80
|
+
"subscriber": {
|
81
|
+
"country": country_code,
|
82
|
+
"currency": currency_code,
|
83
|
+
"msisdn": phone_number
|
84
|
+
},
|
85
|
+
"transaction": {
|
86
|
+
"amount": amount,
|
87
|
+
"country": transaction_country_code,
|
88
|
+
"currency": transaction_currency_code,
|
89
|
+
"id": unique_random_id
|
90
|
+
}
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/airtel/pesa/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airtel-pesa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvance
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- ".rubocop.yml"
|
38
38
|
- CHANGELOG.md
|
39
39
|
- Gemfile
|
40
|
+
- Gemfile.lock
|
40
41
|
- LICENSE.txt
|
41
42
|
- README.md
|
42
43
|
- Rakefile
|
@@ -45,7 +46,15 @@ files:
|
|
45
46
|
- bin/setup
|
46
47
|
- lib/airtel/pesa.rb
|
47
48
|
- lib/airtel/pesa/authorization.rb
|
49
|
+
- lib/airtel/pesa/balance_enquiry.rb
|
50
|
+
- lib/airtel/pesa/disbursement_payment.rb
|
51
|
+
- lib/airtel/pesa/disbursement_transaction_enquiry.rb
|
48
52
|
- lib/airtel/pesa/encryption.rb
|
53
|
+
- lib/airtel/pesa/example.rb
|
54
|
+
- lib/airtel/pesa/refund_payment.rb
|
55
|
+
- lib/airtel/pesa/transaction_enquiry.rb
|
56
|
+
- lib/airtel/pesa/user_enquiry.rb
|
57
|
+
- lib/airtel/pesa/ussd_push_payment.rb
|
49
58
|
- lib/airtel/pesa/version.rb
|
50
59
|
homepage: https://github.com/Sylvance/airtel-pesa
|
51
60
|
licenses:
|