vpos 0.1.2 → 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: ff2cd9a72fe1b6d4f15620e7301b5872f535be5892209bdd4eb55cdc66c0e9aa
4
- data.tar.gz: 7ddfa1be6078bf1411d6d8805bdff893aa8c34c93d904616461796aee4d6efb2
3
+ metadata.gz: 89cc2923597e888adbd3b0ed950546c4aa62e91912cceff1406de414452f2b1c
4
+ data.tar.gz: de0949ee1d315d7e8f000320c0b28bfa4dc7b0127fe7fd715a502225e515209d
5
5
  SHA512:
6
- metadata.gz: f8a2b905f9ae393f69a8697f6de8d9de09f11b24ee9eee47f7e1e990e17940a4247a7688f7a1a0af70acd0bf14a05e60d3a5f29045bfed5782a3cc221e8d2a40
7
- data.tar.gz: 7bb873d2b2644f4f0f0074ea98619ba268ebd9120f4807cabb80f86c9e62b4bc18b12985f14c69fff1a4b72dc418782c957f3214aaa70aa1c5a134b1c0fa3ac6
6
+ metadata.gz: 27485c1d09f1f010d6499e081dd39a86c18241dbc9d2c105795f58c636df36f6e550543397be28f4180dcb52f94883f7fc55bf32e9575989983503d4c30ea121
7
+ data.tar.gz: 7199d91f1e2e7421770f2f1f07c692761ed090cec9f84e795ea645348e6647e54dce341ca7f3e66dfed703e8f2049725b7cf57189e952610f191b4d9a18f8294
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vpos (0.1.2)
4
+ vpos (0.1.3)
5
5
  httparty (~> 0.18.1)
6
6
  rspec (~> 3.9.0)
7
7
 
@@ -14,7 +14,7 @@ GEM
14
14
  multi_xml (>= 0.5.2)
15
15
  mime-types (3.3.1)
16
16
  mime-types-data (~> 3.2015)
17
- mime-types-data (3.2020.0512)
17
+ mime-types-data (3.2020.1104)
18
18
  multi_xml (0.6.0)
19
19
  rake (10.5.0)
20
20
  rspec (3.9.0)
@@ -23,13 +23,13 @@ GEM
23
23
  rspec-mocks (~> 3.9.0)
24
24
  rspec-core (3.9.3)
25
25
  rspec-support (~> 3.9.3)
26
- rspec-expectations (3.9.2)
26
+ rspec-expectations (3.9.4)
27
27
  diff-lcs (>= 1.2.0, < 2.0)
28
28
  rspec-support (~> 3.9.0)
29
29
  rspec-mocks (3.9.1)
30
30
  diff-lcs (>= 1.2.0, < 2.0)
31
31
  rspec-support (~> 3.9.0)
32
- rspec-support (3.9.3)
32
+ rspec-support (3.9.4)
33
33
 
34
34
  PLATFORMS
35
35
  ruby
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # vPOS Ruby
2
2
 
3
- ![Azure Build](https://dev.azure.com/next-solutions/vpos/_apis/build/status/vpos%20-%20sdk%20-%20ruby?branchName=main)
3
+ ![Ruby](https://github.com/nextbss/vpos-ruby/workflows/Ruby/badge.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/vpos.svg)](https://badge.fury.io/rb/vpos)
4
5
  [![](https://img.shields.io/badge/nextbss-opensource-blue.svg)](https://www.nextbss.co.ao)
5
6
 
6
7
  This ruby library helps you easily interact with the vPOS API,
@@ -23,27 +24,27 @@ See our documentation on [developer.vpos.ao](https://developer.vpos.ao)
23
24
 
24
25
  ## Installation
25
26
  ```ruby
26
- gem 'vpos'
27
+ gem 'vpos', '~> 0.1.2'
27
28
  ```
28
29
 
29
30
  or
30
31
 
31
32
  ```ruby
32
- gem install `vpos`
33
+ gem install vpos
33
34
  ```
34
35
 
35
36
  ### Configuration
36
37
  This ruby library requires you set up the following environment variables on your machine before
37
38
  interacting with the API using this library:
38
39
 
39
- | Variable | Description
40
- | --- | --- |
41
- | `GPO_POS_ID` | The Point of Sale ID provided by EMIS |
42
- | `GPO_SUPERVISOR_CARD` | The Supervisor card ID provided by EMIS |
43
- | `MERCHANT_VPOS_TOKEN` | The API token provided by vPOS |
44
- | `PAYMENT_CALLBACK_URL` | The URL that will handle payment notifications |
45
- | `REFUND_CALLBACK_URL` | The URL that will handle refund notifications |
46
- | `VPOS_ENVIRONMENT` | The vPOS environment, leave empty for `sandbox` mode and use `"prd"` for `production`. |
40
+ | Variable | Description | Required |
41
+ | --- | --- | --- |
42
+ | `GPO_POS_ID` | The Point of Sale ID provided by EMIS | true |
43
+ | `GPO_SUPERVISOR_CARD` | The Supervisor card ID provided by EMIS | true |
44
+ | `MERCHANT_VPOS_TOKEN` | The API token provided by vPOS | true |
45
+ | `PAYMENT_CALLBACK_URL` | The URL that will handle payment notifications | false |
46
+ | `REFUND_CALLBACK_URL` | The URL that will handle refund notifications | false |
47
+ | `VPOS_ENVIRONMENT` | The vPOS environment, leave empty for `sandbox` mode and use `"prd"` for `production`. | false |
47
48
 
48
49
  Don't have this information? [Talk to us](suporte@vpos.ao)
49
50
 
data/lib/vpos.rb CHANGED
@@ -1,102 +1,5 @@
1
- require "vpos/version"
2
- require "httparty"
3
- require "securerandom"
1
+ require_relative "vpos_module"
4
2
 
5
- module Vpos
6
- class Error < StandardError; end
7
- include HTTParty
8
- follow_redirects false
9
-
10
- def self.new_payment(customer, amount, pos_id: default_pos_id, callback_url: default_payment_callback_url)
11
- content = set_headers
12
- content[:body] = {type:"payment", pos_id: pos_id, mobile: customer, amount: amount, callback_url: callback_url}.to_json
13
- request = post("#{host}/transactions", content)
14
- return_vpos_object(request)
15
- end
16
-
17
- def self.new_refund(transaction_id, supervisor_card: default_supervisor_card, callback_url: default_refund_callback_url)
18
- content = set_headers
19
- content[:body] = {type: "refund", parent_transaction_id: transaction_id, supervisor_card: supervisor_card, callback_url: callback_url}.to_json
20
- request = post("#{host}/transactions", content)
21
- return_vpos_object(request)
22
- end
23
-
24
- def self.get_transaction(transaction_id)
25
- request = get("#{host}/transactions/#{transaction_id}", set_headers)
26
- return_vpos_object(request)
27
- end
28
-
29
- def self.get_transactions
30
- request = get("#{host}/transactions", set_headers)
31
- return_vpos_object(request)
32
- end
33
-
34
- def self.get_request_id(request)
35
- if request[:location].nil?
36
- get("#{host}/references/invalid", set_headers)
37
- else
38
- if request[:status] == 202
39
- request[:location].gsub("/api/v1/requests/", "")
40
- else
41
- request[:location].gsub("/api/v1/transactions/", "")
42
- end
43
- end
44
- end
45
-
46
- def self.get_request(request_id)
47
- request = get("#{host}/requests/#{request_id}", set_headers)
48
- return_vpos_object(request)
49
- end
50
-
51
- private
52
- def self.return_vpos_object(request)
53
- case request.response.code.to_i
54
- when 200, 201
55
- return {status: request.response.code.to_i, message: request.response.message, data: request.parsed_response}
56
- when 202, 303
57
- return {status: request.response.code.to_i, message: request.response.message, location: request.headers["location"]}
58
- else
59
- return {status: request.response.code.to_i, message: request.response.message, details: request.parsed_response["errors"]}
60
- end
61
- end
62
-
63
- def self.set_headers
64
- content = {}
65
- headers = {'Content-Type' => "application/json", 'Accept' => "application/json", 'Authorization' => set_token, 'Idempotency-Key' => SecureRandom.uuid}
66
- content[:headers] = headers
67
- return content
68
- end
69
-
70
- def self.default_pos_id
71
- pos_id = ENV["GPO_POS_ID"]
72
- return "#{pos_id}".to_i
73
- end
74
-
75
- def self.default_supervisor_card
76
- supervisor_card = ENV["GPO_SUPERVISOR_CARD"]
77
- return "#{supervisor_card}"
78
- end
79
-
80
- def self.set_token
81
- token = ENV["MERCHANT_VPOS_TOKEN"]
82
- return "Bearer #{token}"
83
- end
84
-
85
- def self.default_payment_callback_url
86
- url = ENV["PAYMENT_CALLBACK_URL"]
87
- return url
88
- end
89
-
90
- def self.default_refund_callback_url
91
- url = ENV["REFUND_CALLBACK_URL"]
92
- return url
93
- end
94
-
95
- def self.host
96
- if ENV["VPOS_ENVIRONMENT"] == "prd"
97
- return "https://api.vpos.ao/api/v1"
98
- else
99
- return "https://sandbox.vpos.ao/api/v1"
100
- end
101
- end
3
+ class Vpos
4
+ include VposModule
102
5
  end
data/lib/vpos/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Vpos
2
- VERSION = "0.1.2"
1
+ module VposModule
2
+ VERSION = "0.1.3"
3
3
  end
@@ -0,0 +1,102 @@
1
+ require "vpos/version"
2
+ require "httparty"
3
+ require "securerandom"
4
+
5
+ module VposModule
6
+ class Error < StandardError; end
7
+ include HTTParty
8
+ follow_redirects false
9
+
10
+ def new_payment(customer, amount, pos_id: default_pos_id, callback_url: default_payment_callback_url)
11
+ content = set_headers
12
+ content[:body] = {type:"payment", pos_id: pos_id, mobile: customer, amount: amount, callback_url: callback_url}.to_json
13
+ request = HTTParty.post("#{host}/transactions", content)
14
+ return_vpos_object(request)
15
+ end
16
+
17
+ def new_refund(transaction_id, supervisor_card: default_supervisor_card, callback_url: default_refund_callback_url)
18
+ content = set_headers
19
+ content[:body] = {type: "refund", parent_transaction_id: transaction_id, supervisor_card: supervisor_card, callback_url: callback_url}.to_json
20
+ request = HTTParty.post("#{host}/transactions", content)
21
+ return_vpos_object(request)
22
+ end
23
+
24
+ def get_transaction(transaction_id)
25
+ request = HTTParty.get("#{host}/transactions/#{transaction_id}", set_headers)
26
+ return_vpos_object(request)
27
+ end
28
+
29
+ def get_transactions
30
+ request = HTTParty.get("#{host}/transactions", set_headers)
31
+ return_vpos_object(request)
32
+ end
33
+
34
+ def get_request_id(request)
35
+ if request[:location].nil?
36
+ HTTParty.get("#{host}/references/invalid", set_headers)
37
+ else
38
+ if request[:status] == 202
39
+ request[:location].gsub("/api/v1/requests/", "")
40
+ else
41
+ request[:location].gsub("/api/v1/transactions/", "")
42
+ end
43
+ end
44
+ end
45
+
46
+ def get_request(request_id)
47
+ request = HTTParty.get("#{host}/requests/#{request_id}", set_headers)
48
+ return_vpos_object(request)
49
+ end
50
+
51
+ private
52
+ def return_vpos_object(request)
53
+ case request.response.code.to_i
54
+ when 200, 201
55
+ return {status: request.response.code.to_i, message: request.response.message, data: request.parsed_response}
56
+ when 202, 303
57
+ return {status: request.response.code.to_i, message: request.response.message, location: request.headers["location"]}
58
+ else
59
+ return {status: request.response.code.to_i, message: request.response.message, details: request.parsed_response["errors"]}
60
+ end
61
+ end
62
+
63
+ def set_headers
64
+ content = {}
65
+ headers = {'Content-Type' => "application/json", 'Accept' => "application/json", 'Authorization' => set_token, 'Idempotency-Key' => SecureRandom.uuid}
66
+ content[:headers] = headers
67
+ return content
68
+ end
69
+
70
+ def default_pos_id
71
+ pos_id = ENV["GPO_POS_ID"]
72
+ return "#{pos_id}".to_i
73
+ end
74
+
75
+ def default_supervisor_card
76
+ supervisor_card = ENV["GPO_SUPERVISOR_CARD"]
77
+ return "#{supervisor_card}"
78
+ end
79
+
80
+ def set_token
81
+ token = ENV["MERCHANT_VPOS_TOKEN"]
82
+ return "Bearer #{token}"
83
+ end
84
+
85
+ def default_payment_callback_url
86
+ url = ENV["PAYMENT_CALLBACK_URL"]
87
+ return url
88
+ end
89
+
90
+ def default_refund_callback_url
91
+ url = ENV["REFUND_CALLBACK_URL"]
92
+ return url
93
+ end
94
+
95
+ def host
96
+ if ENV["VPOS_ENVIRONMENT"] == "PRD"
97
+ return "https://api.vpos.ao/api/v1"
98
+ else
99
+ return "https://sandbox.vpos.ao/api/v1"
100
+ end
101
+ end
102
+ end
data/vpos.gemspec CHANGED
@@ -4,12 +4,12 @@ require "vpos/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "vpos"
7
- spec.version = Vpos::VERSION
7
+ spec.version = VposModule::VERSION
8
8
  spec.authors = ["Sergio Maziano"]
9
9
  spec.email = ["sergio@nextbss.co.ao"]
10
10
 
11
11
  spec.summary = %q{The one stop shop for online payments in Angola.}
12
- spec.description = %q{The one stop shop for online payments in Angola. This gem allows you process payments requests from EMIS GPO through vPOS.}
12
+ spec.description = %q{The one stop shop for online payments in Angola, allowing you to process payments requests from EMIS GPO through vPOS.}
13
13
  spec.homepage = "https://github.com/nextbss/vpos-ruby"
14
14
  spec.license = "MIT"
15
15
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency "bundler", "~> 2.1.4"
25
+ spec.add_development_dependency "bundler", "~> 2.2.3"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_dependency "httparty", "~> 0.18.1"
28
28
  spec.add_dependency "rspec", "~> 3.9.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vpos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Maziano
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2020-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.4
19
+ version: 2.2.3
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.4
26
+ version: 2.2.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,8 +66,8 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.9.0
69
- description: The one stop shop for online payments in Angola. This gem allows you
70
- process payments requests from EMIS GPO through vPOS.
69
+ description: The one stop shop for online payments in Angola, allowing you to process
70
+ payments requests from EMIS GPO through vPOS.
71
71
  email:
72
72
  - sergio@nextbss.co.ao
73
73
  executables: []
@@ -81,11 +81,11 @@ files:
81
81
  - LICENSE.txt
82
82
  - README.md
83
83
  - Rakefile
84
- - azure-pipelines.yml
85
84
  - bin/console
86
85
  - bin/setup
87
86
  - lib/vpos.rb
88
87
  - lib/vpos/version.rb
88
+ - lib/vpos_module.rb
89
89
  - tags
90
90
  - vpos.gemspec
91
91
  homepage: https://github.com/nextbss/vpos-ruby
data/azure-pipelines.yml DELETED
@@ -1,26 +0,0 @@
1
- # Ruby
2
- # Package your Ruby project.
3
- # Add steps that install rails, analyze code, save build artifacts, deploy, and more:
4
- # https://docs.microsoft.com/azure/devops/pipelines/languages/ruby
5
-
6
- trigger:
7
- - main
8
-
9
- pool:
10
- vmImage: 'ubuntu-latest'
11
-
12
- steps:
13
- - task: UseRubyVersion@0
14
- inputs:
15
- versionSpec: '>= 2.5'
16
-
17
- - script: |
18
- gem install bundler
19
- bundle install --retry=3 --jobs=4
20
- displayName: 'Install Bundler'
21
-
22
- - script: |
23
- gem install rspec
24
-
25
- - script: bundle exec rspec
26
- displayName: 'Run Tests'