ecocash 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f0c8ebac975bbc7e9a427c34e38853f829ea0c89c118db4c50494905cd6b60e6
4
+ data.tar.gz: d54e8177603ea06064de132af2589059a00893018d763021d6bbbc457be4883e
5
+ SHA512:
6
+ metadata.gz: 3da1de1ab76cf05ce6f3e9f80d733ec3ffcee1d5c79064491a48c72162500fef590c1a93ddfb1d174b38da4cb43347041bcc45f4cd3d19bb0ebf6a8fd5692389
7
+ data.tar.gz: ece47ab1ac200a3381b01a0ef005735b84e2179de78fc13f8ab6e0dba06c8675c3914b65b2b27015eb96f52770c78b58ba03a6056f94ea9490da8c0af7184782
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ Style/Documentation:
3
+ Enabled: false
4
+
5
+ Metrics/ClassLength:
6
+ Enabled: false
7
+
8
+ Metrics/MethodLength:
9
+ Enabled: false
10
+
11
+ Metrics/ModuleLength:
12
+ Enabled: false
13
+
14
+ Layout/IndentArray:
15
+ EnforcedStyle: consistent
16
+
17
+ Layout/EmptyLinesAroundBlockBody:
18
+ EnforcedStyle: no_empty_lines
19
+ Enabled: true
20
+
21
+ Layout/EmptyLinesAroundClassBody:
22
+ EnforcedStyle: no_empty_lines
23
+ Enabled: true
24
+
25
+ Layout/EmptyLinesAroundModuleBody:
26
+ EnforcedStyle: no_empty_lines
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.6
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ecocash.gemspec
6
+ gemspec
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ecocash (1.0.0)
5
+ httparty (~> 0.16.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ httparty (0.16.2)
11
+ multi_xml (>= 0.5.2)
12
+ minitest (5.11.3)
13
+ multi_xml (0.6.0)
14
+ rake (10.5.0)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.16)
21
+ ecocash!
22
+ minitest (~> 5.0)
23
+ rake (~> 10.0)
24
+
25
+ BUNDLED WITH
26
+ 1.16.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Maxwell Tuso
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ # EcoCash Ruby Library
2
+ This library provides developers with convenient access to the EcoCash Instant Payments(EIP) API from applications written in Ruby.
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ecocash'
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,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ecocash/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ecocash"
8
+ spec.version = Ecocash::VERSION
9
+ spec.authors = ["Kudzai Tuso"]
10
+ spec.email = ["tusomx@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper for EcoCash API}
13
+ spec.description = %q{EcoCash is the easiest way to accept mobile payments online. See https://ecocash.co.zw for more details.}
14
+ spec.homepage = "https://github.com/tusomx/ecocash"
15
+ spec.license = "MIT"
16
+
17
+ if spec.respond_to?(:metadata)
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "httparty", "~> 0.16.2"
34
+ spec.add_development_dependency "bundler", "~> 1.16"
35
+ spec.add_development_dependency "minitest", "~> 5.0"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ end
@@ -0,0 +1,22 @@
1
+ require 'httparty'
2
+ require 'ecocash/configuration'
3
+ require 'ecocash/client'
4
+ require 'ecocash/version'
5
+
6
+ module Ecocash
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def self.reset
16
+ @configuration = Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration)
21
+ end
22
+ end
@@ -0,0 +1,121 @@
1
+ module Ecocash
2
+ class Client
3
+ include HTTParty
4
+
5
+ def charge_subscriber(msisdn, amount)
6
+ url = "#{Ecocash.configuration.api_base_url}/transactions/amount"
7
+ args = {
8
+ clientCorrelator: generated_client_correlator,
9
+ notifyUrl: Ecocash.configuration.notify_url,
10
+ referenceCode: Ecocash.configuration.reference_code,
11
+ tranType: 'MER',
12
+ endUserId: msisdn,
13
+ remarks: Ecocash.configuration.payment_remarks,
14
+ transactionOperationStatus: 'CHARGED',
15
+ paymentAmount: {
16
+ charginginformation: {
17
+ amount: amount,
18
+ currency: Ecocash.configuration.currency_code,
19
+ description: Ecocash.configuration.description
20
+ },
21
+ chargeMetaData: {
22
+ channel: 'WEB',
23
+ purchaseCategoryCode: Ecocash.configuration.purchase_category_code,
24
+ onBeHalfOf: Ecocash.configuration.on_behalf_of
25
+ }
26
+ },
27
+ merchantCode: Ecocash.configuration.merchant_code,
28
+ merchantPin: Ecocash.configuration.merchant_pin,
29
+ merchantNumber: Ecocash.configuration.merchant_number,
30
+ currencyCode: Ecocash.configuration.currency_code,
31
+ countryCode: Ecocash.configuration.country_code,
32
+ terminalID: Ecocash.configuration.terminal_id,
33
+ location: Ecocash.configuration.location,
34
+ superMerchantName: Ecocash.configuration.super_merchant_name,
35
+ merchantName: Ecocash.configuration.merchant_name
36
+ }.to_json
37
+
38
+ options = {
39
+ body: args,
40
+ basic_auth: auth,
41
+ headers: { 'Content-Type' => 'application/json' }
42
+ }
43
+ response = self.class.post(url, options)
44
+ JSON.parse(response.body)
45
+ end
46
+
47
+ def transaction_status(msisdn, client_correlator)
48
+ url = "#{Ecocash.configuration.api_base_url}/#{msisdn}/transactions/amount/#{client_correlator}}"
49
+ options = {
50
+ basic_auth: self.class.auth,
51
+ headers: { 'Content-Type' => 'application/json' }
52
+ }
53
+ response = self.class.get(url, options)
54
+ JSON.parse(response.body)
55
+ end
56
+
57
+ def list_transactions(msisdn)
58
+ url = "#{Ecocash.configuration.api_base_url}/#{msisdn}/transactions"
59
+ options = {
60
+ basic_auth: auth,
61
+ headers: { 'Content-Type' => 'application/json' }
62
+ }
63
+ response = self.class.get(url, options)
64
+ JSON.parse(response.body)
65
+ end
66
+
67
+ def transaction_reversal(msisdn, transaction_id, amount)
68
+ url = "#{Ecocash.configuration.api_base_url}/transactions/refund"
69
+ args = {
70
+ clientCorrelator: generated_client_correlator,
71
+ referenceCode: Ecocash.configuration.reference_code,
72
+ tranType: 'REF',
73
+ endUserId: msisdn,
74
+ originalEcocashReference: transaction_id,
75
+ remark: Ecocash.configuration.refund_remarks,
76
+ paymentAmount: {
77
+ charginginformation: {
78
+ amount: amount,
79
+ currency: Ecocash.configuration.currency_code,
80
+ description: Ecocash.configuration.description
81
+ },
82
+ chargeMetaData: {
83
+ channel: 'SMS',
84
+ purchaseCategoryCode: Ecocash.configuration.purchase_category_code,
85
+ onBeHalfOf: Ecocash.configuration.on_behalf_of
86
+ }
87
+ },
88
+ merchantCode: Ecocash.configuration.merchant_code,
89
+ merchantPin: Ecocash.configuration.merchant_pin,
90
+ merchantNumber: Ecocash.configuration.merchant_number,
91
+ currencyCode: Ecocash.configuration.currency_code,
92
+ countryCode: Ecocash.configuration.country_code,
93
+ terminalID: Ecocash.configuration.terminal_id,
94
+ location: cocash.configuration.location,
95
+ superMerchantName: Ecocash.configuration.super_merchant_name,
96
+ merchantName: Ecocash.configuration.merchant_name
97
+ }.to_json
98
+
99
+ options = {
100
+ body: args,
101
+ basic_auth: auth,
102
+ headers: { 'Content-Type' => 'application/json' }
103
+ }
104
+ response = self.class.post(url, options)
105
+ JSON.parse(response.body)
106
+ end
107
+
108
+ private
109
+
110
+ def generated_client_correlator
111
+ Time.zone.now.strftime('GD%d%m%Y%H%M%S%L%3N')
112
+ end
113
+
114
+ def auth
115
+ {
116
+ username: Ecocash.configuration.username,
117
+ password: Ecocash.configuration.password
118
+ }
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,45 @@
1
+ module Ecocash
2
+ class Configuration
3
+ attr_accessor :username,
4
+ :password,
5
+ :notify_url,
6
+ :payment_remarks,
7
+ :refund_remarks,
8
+ :on_behalf_of,
9
+ :merchant_code,
10
+ :merchant_pin,
11
+ :merchant_number,
12
+ :country_code,
13
+ :api_base_url,
14
+ :currency_code,
15
+ :terminal_id,
16
+ :location,
17
+ :super_merchant_name,
18
+ :merchant_name,
19
+ :purchase_category_code,
20
+ :description,
21
+ :reference_code
22
+
23
+ def initialize
24
+ @username = nil
25
+ @password = nil
26
+ @notify_url = nil
27
+ @refund_remarks = nil
28
+ @payment_remarks = nil
29
+ @on_behalf_of = nil
30
+ @merchant_code = nil
31
+ @merchant_pin = nil
32
+ @merchant_number = nil
33
+ @country_code = nil
34
+ @api_base_url = nil
35
+ @currency_code = nil
36
+ @terminal_id = nil
37
+ @location = nil
38
+ @super_merchant_name = nil
39
+ @merchant_name = nil
40
+ @purchase_category_code = nil
41
+ @description = nil
42
+ @reference_code = nil
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Ecocash
2
+ VERSION = '1.0.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ecocash
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kudzai Tuso
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.16.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.16.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: EcoCash is the easiest way to accept mobile payments online. See https://ecocash.co.zw
70
+ for more details.
71
+ email:
72
+ - tusomx@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - ecocash.gemspec
88
+ - lib/ecocash.rb
89
+ - lib/ecocash/client.rb
90
+ - lib/ecocash/configuration.rb
91
+ - lib/ecocash/version.rb
92
+ homepage: https://github.com/tusomx/ecocash
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ homepage_uri: https://github.com/tusomx/ecocash
97
+ source_code_uri: https://github.com/tusomx/ecocash
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.7.6
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Ruby wrapper for EcoCash API
118
+ test_files: []