valor_pay_tech 0.1.0
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 +7 -0
- data/lib/valor_pay_tech/client.rb +72 -0
- data/lib/valor_pay_tech/configuration.rb +33 -0
- data/lib/valor_pay_tech/errors.rb +23 -0
- data/lib/valor_pay_tech/resources/payment_links.rb +32 -0
- data/lib/valor_pay_tech/response.rb +16 -0
- data/lib/valor_pay_tech/version.rb +5 -0
- data/lib/valor_pay_tech.rb +28 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6f1db53b0153dd157e88c7446cedf647acdbd9815176f7b432d0a35603ba9531
|
|
4
|
+
data.tar.gz: 7a33faa7126fd52045deb972bb488e6adc5b5ea759e707c9ee9ea1b623a9f699
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1dfbe4b013db7463cb5a0ec0059e8e6b87f2d075e797a9b88d077a69611fbd4b57643a9f91a2d1d13f0abe20a6839c9eafa0f7c9a7faaa4073bbf74cf62bac40
|
|
7
|
+
data.tar.gz: fb28f51bf6f5b32f18467c0a1e865dbc1122fe2265518f2cace0002d5fcd998136032209162878f7706bac10fda4f7fd61458423956732ec3e5981ebe12a2c53
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "json"
|
|
5
|
+
require "uri"
|
|
6
|
+
|
|
7
|
+
module ValorPayTech
|
|
8
|
+
class Client
|
|
9
|
+
attr_reader :configuration
|
|
10
|
+
|
|
11
|
+
def initialize(configuration)
|
|
12
|
+
@configuration = configuration
|
|
13
|
+
configuration.validate!
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def payment_links
|
|
17
|
+
@payment_links ||= Resources::PaymentLinks.new(self)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def post(path, params = {})
|
|
21
|
+
uri = URI("#{configuration.base_url}/#{path}")
|
|
22
|
+
request = Net::HTTP::Post.new(uri)
|
|
23
|
+
request["Content-Type"] = "application/json"
|
|
24
|
+
request.body = build_body(params).to_json
|
|
25
|
+
|
|
26
|
+
response = execute(uri, request)
|
|
27
|
+
handle_response(response)
|
|
28
|
+
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError, Net::OpenTimeout, Net::ReadTimeout => e
|
|
29
|
+
raise ConnectionError, "Connection failed: #{e.message}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def build_body(params)
|
|
35
|
+
{
|
|
36
|
+
appid: configuration.app_id,
|
|
37
|
+
appkey: configuration.app_key,
|
|
38
|
+
epi: configuration.epi
|
|
39
|
+
}.merge(params)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def execute(uri, request)
|
|
43
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
44
|
+
http.use_ssl = uri.scheme == "https"
|
|
45
|
+
http.open_timeout = 10
|
|
46
|
+
http.read_timeout = 30
|
|
47
|
+
http.request(request)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def handle_response(http_response)
|
|
51
|
+
status = http_response.code.to_i
|
|
52
|
+
body = parse_body(http_response.body)
|
|
53
|
+
|
|
54
|
+
case status
|
|
55
|
+
when 200..299
|
|
56
|
+
Response.new(status: status, body: body)
|
|
57
|
+
when 400..499
|
|
58
|
+
raise BadRequestError.new("Bad request: #{http_response.body}", status: status, body: body)
|
|
59
|
+
when 500..599
|
|
60
|
+
raise ServerError.new("Server error: #{http_response.body}", status: status, body: body)
|
|
61
|
+
else
|
|
62
|
+
raise ApiError.new("Unexpected response: #{status}", status: status, body: body)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def parse_body(raw)
|
|
67
|
+
JSON.parse(raw)
|
|
68
|
+
rescue JSON::ParserError
|
|
69
|
+
{ "raw" => raw }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ValorPayTech
|
|
4
|
+
class Configuration
|
|
5
|
+
ENVIRONMENTS = {
|
|
6
|
+
staging: "https://securelink-staging.valorpaytech.com:4430",
|
|
7
|
+
production: "https://securelink.valorpaytech.com"
|
|
8
|
+
}.freeze
|
|
9
|
+
|
|
10
|
+
attr_accessor :app_id, :app_key, :epi, :environment
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@environment = :staging
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def base_url
|
|
17
|
+
ENVIRONMENTS.fetch(environment) do
|
|
18
|
+
raise ConfigurationError, "Unknown environment: #{environment}. Use :staging or :production."
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def validate!
|
|
23
|
+
missing = []
|
|
24
|
+
missing << "app_id" if app_id.nil? || app_id.to_s.strip.empty?
|
|
25
|
+
missing << "app_key" if app_key.nil? || app_key.to_s.strip.empty?
|
|
26
|
+
missing << "epi" if epi.nil? || epi.to_s.strip.empty?
|
|
27
|
+
|
|
28
|
+
return if missing.empty?
|
|
29
|
+
|
|
30
|
+
raise ConfigurationError, "Missing required configuration: #{missing.join(", ")}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ValorPayTech
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
|
|
6
|
+
class ConfigurationError < Error; end
|
|
7
|
+
|
|
8
|
+
class ConnectionError < Error; end
|
|
9
|
+
|
|
10
|
+
class ApiError < Error
|
|
11
|
+
attr_reader :status, :body
|
|
12
|
+
|
|
13
|
+
def initialize(message = nil, status: nil, body: nil)
|
|
14
|
+
@status = status
|
|
15
|
+
@body = body
|
|
16
|
+
super(message)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class BadRequestError < ApiError; end
|
|
21
|
+
|
|
22
|
+
class ServerError < ApiError; end
|
|
23
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ValorPayTech
|
|
4
|
+
module Resources
|
|
5
|
+
class PaymentLinks
|
|
6
|
+
REQUIRED_PARAMS = %i[amount txn_type].freeze
|
|
7
|
+
|
|
8
|
+
DEFAULTS = {
|
|
9
|
+
epage: 1,
|
|
10
|
+
shipping_country: "US"
|
|
11
|
+
}.freeze
|
|
12
|
+
|
|
13
|
+
def initialize(client)
|
|
14
|
+
@client = client
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def create(params = {})
|
|
18
|
+
validate!(params)
|
|
19
|
+
@client.post("?hostedpagesale", DEFAULTS.merge(params))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def validate!(params)
|
|
25
|
+
missing = REQUIRED_PARAMS.select { |key| params[key].nil? }
|
|
26
|
+
return if missing.empty?
|
|
27
|
+
|
|
28
|
+
raise ArgumentError, "Missing required parameters: #{missing.join(", ")}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ValorPayTech
|
|
4
|
+
class Response
|
|
5
|
+
attr_reader :status, :body
|
|
6
|
+
|
|
7
|
+
def initialize(status:, body:)
|
|
8
|
+
@status = status
|
|
9
|
+
@body = body
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def success?
|
|
13
|
+
status == 200 && body.is_a?(Hash) && body["error_no"] == "S00"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "valor_pay_tech/version"
|
|
4
|
+
require_relative "valor_pay_tech/errors"
|
|
5
|
+
require_relative "valor_pay_tech/configuration"
|
|
6
|
+
require_relative "valor_pay_tech/response"
|
|
7
|
+
require_relative "valor_pay_tech/client"
|
|
8
|
+
require_relative "valor_pay_tech/resources/payment_links"
|
|
9
|
+
|
|
10
|
+
module ValorPayTech
|
|
11
|
+
class << self
|
|
12
|
+
def configure
|
|
13
|
+
yield(configuration)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def configuration
|
|
17
|
+
@configuration ||= Configuration.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def client
|
|
21
|
+
Client.new(configuration)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def reset!
|
|
25
|
+
@configuration = Configuration.new
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: valor_pay_tech
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- robzolkos
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-02-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: minitest
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '13.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '13.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: webmock
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
description:
|
|
56
|
+
email:
|
|
57
|
+
executables: []
|
|
58
|
+
extensions: []
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- lib/valor_pay_tech.rb
|
|
62
|
+
- lib/valor_pay_tech/client.rb
|
|
63
|
+
- lib/valor_pay_tech/configuration.rb
|
|
64
|
+
- lib/valor_pay_tech/errors.rb
|
|
65
|
+
- lib/valor_pay_tech/resources/payment_links.rb
|
|
66
|
+
- lib/valor_pay_tech/response.rb
|
|
67
|
+
- lib/valor_pay_tech/version.rb
|
|
68
|
+
homepage:
|
|
69
|
+
licenses: []
|
|
70
|
+
metadata: {}
|
|
71
|
+
post_install_message:
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '3.0'
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubygems_version: 3.5.11
|
|
87
|
+
signing_key:
|
|
88
|
+
specification_version: 4
|
|
89
|
+
summary: Ruby client for the Valor PayTech API
|
|
90
|
+
test_files: []
|