paymentsds-mpesa 0.1.0.pre.alpha.32 → 0.1.0.pre.alpha.33

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/paymentsds/mpesa/errors/{unavailabe_server.rb → unavailable_server.rb} +0 -0
  3. data/lib/paymentsds/mpesa/version.rb +1 -1
  4. data/paymentsds-mpesa-0.1.0.pre.alpha.31/checksums.yaml.gz +0 -0
  5. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data.tar.gz +0 -0
  6. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/.gitignore +13 -0
  7. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/.overcommit.yml +0 -0
  8. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/.rspec +3 -0
  9. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/.rubocop.yml +0 -0
  10. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/.travis.yml +6 -0
  11. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/Gemfile +7 -0
  12. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/LICENSE +201 -0
  13. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/README.md +261 -0
  14. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/Rakefile +6 -0
  15. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/bin/console +14 -0
  16. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/bin/setup +8 -0
  17. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa.rb +17 -0
  18. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/client.rb +29 -0
  19. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/configuration.rb +59 -0
  20. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/constants.rb +164 -0
  21. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/environment.rb +17 -0
  22. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/error_type.rb +8 -0
  23. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/constants.rb +50 -0
  24. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/direct_debt_missing.rb +9 -0
  25. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/duplicate_direct_debt.rb +9 -0
  26. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/errors.rb +26 -0
  27. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/inactive_account.rb +9 -0
  28. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/initiator_authentication.rb +9 -0
  29. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/insuficient_balance.rb +9 -0
  30. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_amount.rb +9 -0
  31. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_initiator_identifier.rb +9 -0
  32. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_language_code.rb +9 -0
  33. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_market.rb +9 -0
  34. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_missing_properties.rb +9 -0
  35. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_msisdn.rb +9 -0
  36. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_receiver.rb +9 -0
  37. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_reference.rb +9 -0
  38. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_security_credential.rb +9 -0
  39. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_shortcode.rb +9 -0
  40. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_thirdparty_reference.rb +9 -0
  41. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_transaction_id.rb +9 -0
  42. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/invalid_transaction_reference.rb +9 -0
  43. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/profile_problems.rb +0 -0
  44. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/request_timeout.rb +9 -0
  45. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/transaction_cancelled.rb +9 -0
  46. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/transaction_failed.rb +9 -0
  47. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/unavailabe_server.rb +9 -0
  48. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/unknown.rb +9 -0
  49. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/unknown_status.rb +9 -0
  50. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/errors/validation.rb +9 -0
  51. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/operation.rb +28 -0
  52. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/patterns.rb +12 -0
  53. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/result.rb +18 -0
  54. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/service.rb +311 -0
  55. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/lib/paymentsds/mpesa/version.rb +7 -0
  56. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/paymentsds-mpesa.gemspec +32 -0
  57. data/paymentsds-mpesa-0.1.0.pre.alpha.31/data/publish.sh +6 -0
  58. data/paymentsds-mpesa-0.1.0.pre.alpha.31/metadata.gz +0 -0
  59. metadata +57 -2
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'paysuite/mpesa'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'mpesa/version'
4
+ require_relative 'mpesa/operation'
5
+ require_relative 'mpesa/constants'
6
+ require_relative 'mpesa/environment'
7
+ require_relative 'mpesa/configuration'
8
+ require_relative 'mpesa/result'
9
+ require_relative 'mpesa/error_type'
10
+ require_relative 'mpesa/service'
11
+ require_relative 'mpesa/client'
12
+
13
+ module Paymentsds
14
+ module MPesa
15
+ class Error < StandardError; end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Paymentsds
4
+ module MPesa
5
+ class Client
6
+ def initialize
7
+ @service = Service.new
8
+ yield(@service.config) if block_given?
9
+ @service.apply
10
+ end
11
+
12
+ def send(intent)
13
+ @service.handle_send(intent)
14
+ end
15
+
16
+ def receive(intent)
17
+ @service.handle_receive(intent)
18
+ end
19
+
20
+ def query(intent)
21
+ @service.handle_query(intent)
22
+ end
23
+
24
+ def revert(intent)
25
+ @service.handle_revert(intent)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+ require 'openssl'
5
+
6
+ module Paymentsds
7
+ module MPesa
8
+ class Configuration
9
+ attr_accessor :access_token
10
+ attr_accessor :api_key
11
+ attr_accessor :public_key
12
+ attr_accessor :user_agent
13
+ attr_accessor :verify_ssl
14
+ attr_accessor :timeout
15
+ attr_accessor :debugging
16
+ attr_accessor :environment
17
+ attr_accessor :initiator_identifier
18
+ attr_accessor :security_credential
19
+ attr_accessor :service_provider_code
20
+ attr_accessor :origin
21
+ attr_reader :auth
22
+
23
+ def initialize
24
+ @user_agent = 'Paymentsds Ruby'
25
+ @origin = "*"
26
+ @verify_ssl = false
27
+ @timeout = 10
28
+
29
+ yield(self) if block_given?
30
+ end
31
+
32
+ def apply
33
+ @environment = if @environment == :production
34
+ Paymentsds::MPesa::Environment.new('https', 'api.vm.co.mz').freeze
35
+ else
36
+ Paymentsds::MPesa::Environment.new('https', 'api.sandbox.vm.co.mz').freeze
37
+ end
38
+ end
39
+
40
+ def generate_access_token
41
+ has_keys = instance_variable_defined?('@api_key') && instance_variable_defined?('@public_key')
42
+ has_access_token = instance_variable_defined?('@access_token')
43
+
44
+ @auth = encrypt(@api_key, @public_key) if has_keys
45
+ @auth = @access_token if has_access_token
46
+ end
47
+
48
+ private
49
+
50
+ def encrypt(api_key, public_key)
51
+ plain_public_key = Base64.decode64 public_key
52
+ key = OpenSSL::PKey::RSA.new plain_public_key
53
+ encrypted_api_key = key.public_encrypt api_key
54
+
55
+ Base64.strict_encode64 encrypted_api_key
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,164 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Paymentsds
4
+ module MPesa
5
+ PATTERNS = {
6
+ PHONE_NUMBER: /^((00|\+)?(258))?8[45][0-9]{7}$/,
7
+ MONEY_AMOUNT: /^[1-9][0-9]*(\.[0-9]+)?$/,
8
+ WORD: /^\w+$/,
9
+ SERVICE_PROVIDER: /^[0-9]{5,6}$/
10
+ }.freeze
11
+
12
+ OPERATIONS = {
13
+ C2B_PAYMENT: {
14
+ method: :post,
15
+ port: '18352',
16
+ path: '/ipg/v1x/c2bPayment/singleStage/',
17
+ mapping: {
18
+ to: 'input_ServiceProviderCode',
19
+ from: 'input_CustomerMSISDN',
20
+ amount: 'input_Amount',
21
+ reference: 'input_ThirdPartyReference',
22
+ transaction: 'input_TransactionReference'
23
+ },
24
+ validation: {
25
+ to: PATTERNS[:SERVICE_PROVIDER],
26
+ from: PATTERNS[:PHONE_NUMBER],
27
+ amount: PATTERNS[:MONEY_AMOUNT],
28
+ reference: PATTERNS[:WORD],
29
+ transaction: PATTERNS[:WORD]
30
+ },
31
+ required: [
32
+ :to,
33
+ :from,
34
+ :amount,
35
+ :reference,
36
+ :transaction
37
+ ],
38
+ optional: [
39
+ :to
40
+ ]
41
+ },
42
+
43
+ B2C_PAYMENT: {
44
+ method: :post,
45
+ port: '18345',
46
+ path: '/ipg/v1x/b2cPayment/',
47
+ mapping: {
48
+ to: 'input_ServiceProviderCode',
49
+ from: 'input_CustomerMSISDN',
50
+ amount: 'input_Amount',
51
+ reference: 'input_ThirdPartyReference',
52
+ transaction: 'input_TransactionReference'
53
+ },
54
+ validation: {
55
+ to: PATTERNS[:SERVICE_PROVIDER],
56
+ from: PATTERNS[:PHONE_NUMBER],
57
+ amount: PATTERNS[:MONEY_AMOUNT],
58
+ reference: PATTERNS[:WORD],
59
+ transaction: PATTERNS[:WORD]
60
+ },
61
+ required: [
62
+ :to,
63
+ :from,
64
+ :amount,
65
+ :reference,
66
+ :transaction
67
+ ],
68
+ optional: [
69
+ :to
70
+ ]
71
+ },
72
+
73
+ B2B_PAYMENT: {
74
+ method: :post,
75
+ port: '18349',
76
+ path: '/ipg/v1x/b2bPayment/',
77
+ mapping: {
78
+ to: 'input_ServiceProviderCode',
79
+ from: 'input_CustomerMSISDN',
80
+ amount: 'input_Amount',
81
+ reference: 'input_ThirdPartyReference',
82
+ transaction: 'input_TransactionReference'
83
+ },
84
+ validation: {
85
+ to: PATTERNS[:SERVICE_PROVIDER],
86
+ from: PATTERNS[:PHONE_NUMBER],
87
+ amount: PATTERNS[:MONEY_AMOUNT],
88
+ reference: PATTERNS[:WORD],
89
+ transaction: PATTERNS[:WORD]
90
+ },
91
+ required: [
92
+ :to,
93
+ :from,
94
+ :amount,
95
+ :reference,
96
+ :transaction
97
+ ],
98
+ optional: [
99
+ :to
100
+ ]
101
+ },
102
+
103
+ REVERSAL: {
104
+ method: :put,
105
+ port: '18354',
106
+ path: '/ipg/v1x/reversal/',
107
+ mapping: {
108
+ to: 'input_ServiceProviderCode',
109
+ from: 'input_CustomerMSISDN',
110
+ amount: 'input_Amount',
111
+ reference: 'input_ThirdPartyReference',
112
+ transaction: 'input_TransactionReference'
113
+ },
114
+ validation: {
115
+ to: PATTERNS[:SERVICE_PROVIDER],
116
+ from: PATTERNS[:PHONE_NUMBER],
117
+ amount: PATTERNS[:MONEY_AMOUNT],
118
+ reference: PATTERNS[:WORD],
119
+ transaction: PATTERNS[:WORD]
120
+ },
121
+ required: [
122
+ :to,
123
+ :from,
124
+ :amount,
125
+ :reference,
126
+ :transaction
127
+ ],
128
+ optional: [
129
+ :to
130
+ ]
131
+ },
132
+
133
+ QUERY_TRANSACTION_STATUS: {
134
+ method: :get,
135
+ port: '18353',
136
+ path: '/ipg/v1x/queryTransactionStatus/',
137
+ mapping: {
138
+ to: 'input_ServiceProviderCode',
139
+ from: 'input_CustomerMSISDN',
140
+ amount: 'input_Amount',
141
+ reference: 'input_ThirdPartyReference',
142
+ transaction: 'input_TransactionReference'
143
+ },
144
+ validation: {
145
+ to: PATTERNS[:SERVICE_PROVIDER],
146
+ from: PATTERNS[:PHONE_NUMBER],
147
+ amount: PATTERNS[:MONEY_AMOUNT],
148
+ reference: PATTERNS[:WORD],
149
+ transaction: PATTERNS[:WORD]
150
+ },
151
+ required: [
152
+ :to,
153
+ :from,
154
+ :amount,
155
+ :reference,
156
+ :transaction
157
+ ],
158
+ optional: [
159
+ :to
160
+ ]
161
+ }
162
+ }.freeze
163
+ end
164
+ end
@@ -0,0 +1,17 @@
1
+ module Paymentsds
2
+ module MPesa
3
+ class Environment
4
+ attr_accessor :scheme
5
+ attr_accessor :domain
6
+
7
+ def initialize(scheme, domain)
8
+ @scheme = scheme
9
+ @domain = domain
10
+ end
11
+
12
+ def to_url
13
+ "#{@scheme}://#{@domain}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module Paymentsds
2
+ module MPesa
3
+ class ErrorType
4
+ MISSING_PROPERTIES = :MISSING_PROPERTIES
5
+ VALIDATION_ERROR = :VALIDATION_ERROR
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,50 @@
1
+ module Paymentsds
2
+ module MPesa
3
+ INS0 = "INS-0"
4
+ INS18 = "INS-18"
5
+ INS19 = "INS-19"
6
+ INS20 = "INS-20"
7
+ INS21 = "INS-21"
8
+ INS22 = "INS-22"
9
+ INS23 = "INS-23"
10
+ INS24 = "INS-24"
11
+ INS25 = "INS-25"
12
+ INS993 = "INS-993"
13
+ INS994 = "INS-994"
14
+ INS995 = "INS-995"
15
+ INS996 = "INS-996"
16
+ INS997 = "INS-997"
17
+ INS998 = "INS-998"
18
+ INS2001 = "INS-2001"
19
+ INS2002 = "INS-2002"
20
+ INS2051 = "INS-2051"
21
+ INS2057 = "INS-2057"
22
+
23
+ DIRECT_DEBT = "DIRECT_DEBT"
24
+ DUPLICATE_TRANSACTION = "DUPLICATE_TRANSACTION"
25
+ INSUFICIENT_BALANCE = "INSUFICIENT_BALANCE"
26
+ INVALID_AMOUNT = "INVALID_AMOUNT"
27
+ INVALID_MISSING_PROPERTIES = "INVALID_MISSING_PROPERTIES"
28
+ INVALID_RECEIVER = "INVALID_RECEIVER"
29
+ INVALID_REFERENCE = "INVALID_REFERENCE"
30
+ INVALID_SECURITY_CREDENTIAL = "INVALID_SECURITY_CREDENTIAL"
31
+ INVALID_SHORTCODE = "INVALID_SHORTCODE"
32
+ INVALID_THIRDPARTY_REFERENCE = "INVALID_THIRDPARTY_REFERENCE"
33
+ INVALID_TRANSACTION_ID = "INVALID_TRANSACTION_ID"
34
+ INVALID_TRANSACTION_REFERENCE = "INVALID_TRANSACTION_INVALID_TRANSACTION_REFERENCE"
35
+ REQUEST_TIMEOUT = "REQUEST_TIMEOUT"
36
+ TRANSACTION_CANCELLED = "TRANSACTION_CANCELLED"
37
+ TRANSACTION_FAILED = "TRANSACTION_FAILED"
38
+ UNAVAILABLE_SERVER = "UNAVAILABLE_SERVER"
39
+ UNKNOWN_STATUS = "UNKNOWN_STATUS"
40
+ UNKNOWN = "UNKNOWN"
41
+ VALIDATION = "VALIDATION"
42
+ INVALID_INITIATOR_IDENTIFIER = "INVALID_INITIATOR_IDENTIFIER"
43
+ INVALID_LANGUAGE_CODE = "INVALID_LANGUAGE_CODE"
44
+ INVALID_MARKET = "INVALID_MARKET"
45
+ INVALID_MSISDN = "INVALID_MSISDN"
46
+ PROFILE_PROBLEMS = "PROFILE_PROBLEMS"
47
+ INACTIVE_ACCOUNT = "INACTIVE_ACCOUNT"
48
+ INITIATOR_AUTHENTICATION = "INITIATOR_AUTHENTICATION"
49
+ end
50
+ end
@@ -0,0 +1,9 @@
1
+ module Paymentsds
2
+ module MPesa
3
+ class DirectDebtMissingError < StandardError
4
+ def initialize(msg=Paymentsds::MPesa::DIRECT_DEBT)
5
+ super(msg)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Paymentsds
2
+ module MPesa
3
+ class DuplicateDirectDebtError < StandardError
4
+ def initialize(msg=Paymentsds::MPesa::DUPLICATE_TRANSACTION)
5
+ super(msg)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ require_relative "constants"
2
+ require_relative "direct_debt_missing"
3
+ require_relative "duplicate_direct_debt"
4
+ require_relative "inactive_account"
5
+ require_relative "initiator_authentication"
6
+ require_relative "insuficient_balance"
7
+ require_relative "invalid_initiator_identifier"
8
+ require_relative "invalid_market"
9
+ require_relative "invalid_language_code"
10
+ require_relative "invalid_msisdn"
11
+ require_relative "profile_problems"
12
+ require_relative "invalid_amount"
13
+ require_relative "invalid_missing_properties"
14
+ require_relative "invalid_receiver"
15
+ require_relative "invalid_reference"
16
+ require_relative "invalid_security_credential"
17
+ require_relative "invalid_shortcode"
18
+ require_relative "invalid_thirdparty_reference"
19
+ require_relative "invalid_transaction_id"
20
+ require_relative "invalid_transaction_reference"
21
+ require_relative "request_timeout"
22
+ require_relative "transaction_cancelled"
23
+ require_relative "transaction_failed"
24
+ require_relative "unavailable_server"
25
+ require_relative "unknown_status"
26
+ require_relative "unknown"
@@ -0,0 +1,9 @@
1
+ module Paymentsds
2
+ module MPesa
3
+ class InactiveAccountError < StandardError
4
+ def initialize(msg=Paymentsds::MPesa::INACTIVE_ACCOUNT)
5
+ super(msg)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Paymentsds
2
+ module MPesa
3
+ class InitiatorAuthenticationError < StandardError
4
+ def initialize(msg=Paymentsds::MPesa::INITIATOR_AUTHENTICATION)
5
+ super(msg)
6
+ end
7
+ end
8
+ end
9
+ end