payu_pl 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b782044448418c46fdc1576fc1e2a8b1c3855930e4758dfb692ca5707accc4e2
4
+ data.tar.gz: 18f16cc358d142bd54bd2ed9c696e4ee4300686e47cee7502bf104ca4f0558d5
5
+ SHA512:
6
+ metadata.gz: 93a1fc0a92eb1031ad67cb93aef28f2997a48f500fb4d8d3353bbcb55c2b389b01c67e88cd0612c227ce337e421984921469149f212d1e3b03ea8a2b123750b9
7
+ data.tar.gz: 3e40a0fe16dbbf8e83e5ce7bde53697f1273f34f3c5b1705174d40d9232a365f4466b2feb4667545d4a89ae6e11e37ee417fcdf3f22518d357f5fd1704137d24
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-12-30
4
+
5
+ - Add i18n-backed validation messages (English + Polish) and `PayuPl.configure` locale support
6
+ - DRY up ID validation in operations (`validate_id!` / `validate_ids!` in base)
7
+ - Split specs into multiple focused files and expand coverage
8
+ - Add PayU documentation links to README
9
+ - Consolidate CI workflows (single `ci.yml`)
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Dmytro Koval
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # PayuPl
2
+
3
+ A small Ruby client for the PayU GPO Europe REST API (commonly used for PayU Poland integrations), with:
4
+
5
+ - `Net::HTTP` transport
6
+ - consistent error mapping
7
+ - basic request validation via `dry-validation`
8
+
9
+ This gem focuses on the standard payment flow endpoints:
10
+
11
+ - OAuth token
12
+ - Create / retrieve order
13
+ - Capture / cancel
14
+ - Refunds
15
+ - Transaction retrieve
16
+
17
+ ## Installation
18
+
19
+ Add to your Gemfile:
20
+
21
+ ```ruby
22
+ gem "payu_pl"
23
+ ```
24
+
25
+ Then run:
26
+
27
+ ```bash
28
+ bundle install
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Create a client
34
+
35
+ ```ruby
36
+ client = PayuPl::Client.new(
37
+ client_id: ENV.fetch("PAYU_CLIENT_ID"),
38
+ client_secret: ENV.fetch("PAYU_CLIENT_SECRET"),
39
+ environment: :sandbox # or :production
40
+ )
41
+ ```
42
+
43
+ ### Authenticate (OAuth)
44
+
45
+ ```ruby
46
+ client.oauth_token
47
+ # => {"access_token"=>"...", "token_type"=>"bearer", "expires_in"=>43199, ...}
48
+ ```
49
+
50
+ The token is stored on the client as `client.access_token` and used automatically for subsequent calls.
51
+
52
+ ### Create an order
53
+
54
+ ```ruby
55
+ payload = {
56
+ notifyUrl: "https://example.com/payu/notify",
57
+ customerIp: "127.0.0.1",
58
+ merchantPosId: ENV.fetch("PAYU_POS_ID"),
59
+ description: "RTV market",
60
+ currencyCode: "PLN",
61
+ totalAmount: "21000",
62
+ products: [
63
+ { name: "Wireless Mouse", unitPrice: "21000", quantity: "1" }
64
+ ]
65
+ }
66
+
67
+ response = client.create_order(payload)
68
+ redirect_uri = response["redirectUri"]
69
+ order_id = response["orderId"]
70
+ ```
71
+
72
+ Notes:
73
+
74
+ - `totalAmount` / `unitPrice` are strings in minor units.
75
+ - PayU often responds with HTTP `302` and JSON body; this client does not auto-follow redirects.
76
+
77
+ ### Retrieve an order
78
+
79
+ ```ruby
80
+ client.retrieve_order(order_id)
81
+ ```
82
+
83
+ ### Capture / cancel
84
+
85
+ ```ruby
86
+ client.capture_order(order_id) # full capture (empty JSON body)
87
+
88
+ client.capture_order(order_id, amount: "1000", currency_code: "PLN") # partial capture
89
+
90
+ client.cancel_order(order_id)
91
+ ```
92
+
93
+ ### Refunds
94
+
95
+ ```ruby
96
+ client.create_refund(order_id, description: "Refund")
97
+ client.create_refund(order_id, description: "Partial refund", amount: "1000")
98
+
99
+ client.list_refunds(order_id)
100
+ client.retrieve_refund(order_id, "5000000142")
101
+ ```
102
+
103
+ ### Retrieve transactions
104
+
105
+ ```ruby
106
+ client.retrieve_transactions(order_id)
107
+ ```
108
+
109
+ ## Errors and validation
110
+
111
+ HTTP errors are mapped to Ruby exceptions:
112
+
113
+ - `PayuPl::UnauthorizedError` (401)
114
+ - `PayuPl::ForbiddenError` (403)
115
+ - `PayuPl::NotFoundError` (404)
116
+ - `PayuPl::RateLimitedError` (429)
117
+ - `PayuPl::ClientError` (other 4xx)
118
+ - `PayuPl::ServerError` (5xx)
119
+
120
+ They carry useful fields like `http_status`, `correlation_id`, `raw_body`, and `parsed_body`.
121
+
122
+ Request validation errors raise `PayuPl::ValidationError` and include an `errors` hash.
123
+
124
+ ## PayU documentation
125
+
126
+ Useful official resources:
127
+
128
+ - PayU GPO Europe docs: https://developers.payu.com/europe/docs/
129
+ - REST API reference (OpenAPI): https://developers.payu.com/europe/api/
130
+ - OpenAPI YAML download: https://developers.payu.com/europe/resources/payu-gpo-europe-api-ref.yaml
131
+ - Sandbox testing guide: https://developers.payu.com/europe/docs/testing/sandbox/
132
+ - Sandbox registration: https://registration-merch-prod.snd.payu.com/boarding/#/registerSandbox/
133
+ - Sandbox status page: https://status.snd.payu.com/
134
+
135
+ ## Development
136
+
137
+ Run tests:
138
+
139
+ ```bash
140
+ bundle exec rspec
141
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,10 @@
1
+ en:
2
+ payu_pl:
3
+ validation:
4
+ max_length: "must be at most %{max} characters"
5
+ ip_address: "must be a valid IPv4 or IPv6 address"
6
+ iso_4217: "must be a 3-letter ISO 4217 code"
7
+ numeric_string: "must be a numeric string"
8
+ min_items: "must include at least %{min} item(s)"
9
+ required_with_currency_code: "is required when providing currency_code"
10
+ required_with_amount: "is required when providing amount"
@@ -0,0 +1,10 @@
1
+ pl:
2
+ payu_pl:
3
+ validation:
4
+ max_length: "musi mieć maksymalnie %{max} znaków"
5
+ ip_address: "musi być poprawnym adresem IPv4 lub IPv6"
6
+ iso_4217: "musi być 3-literowym kodem ISO 4217"
7
+ numeric_string: "musi być ciągiem cyfr"
8
+ min_items: "musi zawierać co najmniej %{min} element(y)"
9
+ required_with_currency_code: "jest wymagane, gdy podano currency_code"
10
+ required_with_amount: "jest wymagane, gdy podano amount"
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PayuPl
4
+ module Authorize
5
+ class OAuthToken < Operations::Base
6
+ def call(grant_type: "client_credentials")
7
+ form = {
8
+ grant_type: grant_type,
9
+ client_id: client.client_id,
10
+ client_secret: client.client_secret
11
+ }
12
+
13
+ response = transport.request(
14
+ :post,
15
+ Endpoints::OAUTH_TOKEN,
16
+ headers: { "Content-Type" => "application/x-www-form-urlencoded" },
17
+ form: form,
18
+ authorize: false
19
+ )
20
+
21
+ token = response.fetch("access_token")
22
+ client.access_token = token
23
+ response
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ module PayuPl
6
+ class Client
7
+ DEFAULT_PRODUCTION_BASE_URL = "https://secure.payu.com"
8
+ DEFAULT_SANDBOX_BASE_URL = "https://secure.snd.payu.com"
9
+
10
+ attr_reader :base_url, :client_id, :client_secret, :transport
11
+ attr_accessor :access_token
12
+
13
+ def initialize(
14
+ client_id:,
15
+ client_secret:,
16
+ access_token: nil,
17
+ base_url: nil,
18
+ environment: :production,
19
+ open_timeout: 10,
20
+ read_timeout: 30
21
+ )
22
+ @client_id = client_id
23
+ @client_secret = client_secret
24
+ @access_token = access_token
25
+
26
+ @base_url = base_url || default_base_url_for(environment)
27
+ validate!
28
+
29
+ @transport = Transport.new(
30
+ base_url: @base_url,
31
+ access_token_provider: -> { @access_token },
32
+ open_timeout: open_timeout,
33
+ read_timeout: read_timeout
34
+ )
35
+ end
36
+
37
+ # OAuth
38
+ def oauth_token(grant_type: "client_credentials")
39
+ Authorize::OAuthToken.new(client: self).call(grant_type: grant_type)
40
+ end
41
+
42
+ # Orders
43
+ def create_order(order_create_request)
44
+ Orders::Create.new(client: self).call(order_create_request)
45
+ end
46
+
47
+ def retrieve_order(order_id)
48
+ Orders::Retrieve.new(client: self).call(order_id)
49
+ end
50
+
51
+ def capture_order(order_id, amount: nil, currency_code: nil)
52
+ Orders::Capture.new(client: self).call(order_id, amount: amount, currency_code: currency_code)
53
+ end
54
+
55
+ def cancel_order(order_id)
56
+ Orders::Cancel.new(client: self).call(order_id)
57
+ end
58
+
59
+ def retrieve_transactions(order_id)
60
+ Orders::Transactions.new(client: self).call(order_id)
61
+ end
62
+
63
+ # Refunds
64
+ def create_refund(order_id, description:, amount: nil, ext_refund_id: nil)
65
+ Refunds::Create.new(client: self).call(order_id, description: description, amount: amount, ext_refund_id: ext_refund_id)
66
+ end
67
+
68
+ def list_refunds(order_id)
69
+ Refunds::List.new(client: self).call(order_id)
70
+ end
71
+
72
+ def retrieve_refund(order_id, refund_id)
73
+ Refunds::Retrieve.new(client: self).call(order_id, refund_id)
74
+ end
75
+
76
+ private
77
+
78
+ def validate!
79
+ raise ArgumentError, "client_id is required" if client_id.nil? || client_id.to_s.empty?
80
+ raise ArgumentError, "client_secret is required" if client_secret.nil? || client_secret.to_s.empty?
81
+
82
+ uri = URI.parse(base_url)
83
+ raise ArgumentError, "base_url must be http(s)" unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
84
+ rescue URI::InvalidURIError
85
+ raise ArgumentError, "base_url is invalid"
86
+ end
87
+
88
+ def default_base_url_for(environment)
89
+ case environment&.to_sym
90
+ when :production
91
+ DEFAULT_PRODUCTION_BASE_URL
92
+ when :sandbox
93
+ DEFAULT_SANDBOX_BASE_URL
94
+ else
95
+ raise ArgumentError, "Unknown environment: #{environment.inspect} (use :production or :sandbox)"
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "i18n"
4
+
5
+ module PayuPl
6
+ class Configuration
7
+ attr_accessor :locale
8
+
9
+ def initialize
10
+ @locale = :en
11
+ end
12
+ end
13
+
14
+ def self.config
15
+ @config ||= Configuration.new
16
+ end
17
+
18
+ def self.configure
19
+ yield(config)
20
+ end
21
+
22
+ def self.load_translations!
23
+ locales_glob = File.expand_path("../../config/locales/*.yml", __dir__)
24
+ I18n.load_path |= Dir[locales_glob]
25
+
26
+ # Ensure the backend actually loads newly added paths.
27
+ I18n.backend.load_translations
28
+
29
+ # Do not overwrite user's configuration, only extend.
30
+ I18n.available_locales = (I18n.available_locales | %i[en pl])
31
+ end
32
+
33
+ def self.t(key, **opts)
34
+ I18n.t(key, **opts, scope: %i[payu_pl validation], locale: config.locale)
35
+ end
36
+ end
37
+
38
+ PayuPl.load_translations!
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/validation"
4
+
5
+ module PayuPl
6
+ module Contracts
7
+ class CaptureContract < Dry::Validation::Contract
8
+ params do
9
+ required(:order_id).filled(:string)
10
+ optional(:amount).maybe(:string)
11
+ optional(:currency_code).maybe(:string)
12
+ end
13
+
14
+ rule(:amount, :currency_code) do
15
+ amount_raw = values[:amount]
16
+ currency_raw = values[:currency_code]
17
+
18
+ amount = amount_raw.is_a?(String) ? amount_raw.strip : amount_raw
19
+ currency_code = currency_raw.is_a?(String) ? currency_raw.strip : currency_raw
20
+
21
+ amount_present = !(amount.nil? || (amount.respond_to?(:empty?) && amount.empty?))
22
+ currency_present = !(currency_code.nil? || (currency_code.respond_to?(:empty?) && currency_code.empty?))
23
+
24
+ next if !amount_present && !currency_present
25
+
26
+ key(:amount).failure(PayuPl.t(:required_with_currency_code)) if currency_present && !amount_present
27
+ key(:currency_code).failure(PayuPl.t(:required_with_amount)) if amount_present && !currency_present
28
+
29
+ key(:currency_code).failure(PayuPl.t(:iso_4217)) if currency_present && !currency_code.match?(/\A[A-Z]{3}\z/)
30
+
31
+ key(:amount).failure(PayuPl.t(:numeric_string)) if amount_present && !amount.to_s.match?(/\A\d+\z/)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/validation"
4
+
5
+ module PayuPl
6
+ module Contracts
7
+ class IdContract < Dry::Validation::Contract
8
+ params do
9
+ required(:id).filled(:string)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/validation"
4
+ require "ipaddr"
5
+
6
+ module PayuPl
7
+ module Contracts
8
+ class OrderCreateContract < Dry::Validation::Contract
9
+ IPV4_SEGMENT = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)"
10
+ IPV4_REGEX = /\A#{IPV4_SEGMENT}(?:\.#{IPV4_SEGMENT}){3}\z/.freeze
11
+
12
+ params do
13
+ optional(:continueUrl).filled(:string)
14
+ optional(:notifyUrl).filled(:string)
15
+
16
+ required(:customerIp).filled(:string)
17
+ required(:merchantPosId).filled(:string)
18
+ required(:description).filled(:string)
19
+
20
+ optional(:additionalDescription).filled(:string)
21
+ optional(:visibleDescription).filled(:string)
22
+ optional(:statementDescription).filled(:string)
23
+ optional(:extOrderId).filled(:string)
24
+
25
+ required(:currencyCode).filled(:string)
26
+ required(:totalAmount).filled(:string)
27
+
28
+ required(:products).array(:hash) do
29
+ required(:name).filled(:string)
30
+ required(:unitPrice).filled(:string)
31
+ required(:quantity).filled(:string)
32
+ end
33
+ end
34
+
35
+ rule(:continueUrl) do
36
+ next if value.nil?
37
+
38
+ key.failure(PayuPl.t(:max_length, max: 1024)) if value.length > 1024
39
+ end
40
+
41
+ rule(:notifyUrl) do
42
+ next if value.nil?
43
+
44
+ key.failure(PayuPl.t(:max_length, max: 1024)) if value.length > 1024
45
+ end
46
+
47
+ rule(:customerIp) do
48
+ ip = value.to_s
49
+
50
+ ipv4 = IPV4_REGEX.match?(ip)
51
+ ipv6 = begin
52
+ addr = IPAddr.new(ip)
53
+ addr.ipv6? && ip.include?(":")
54
+ rescue IPAddr::InvalidAddressError
55
+ false
56
+ end
57
+
58
+ key.failure(PayuPl.t(:ip_address)) unless ipv4 || ipv6
59
+ end
60
+
61
+ rule(:description) do
62
+ key.failure(PayuPl.t(:max_length, max: 4000)) if value.length > 4000
63
+ end
64
+
65
+ rule(:additionalDescription) do
66
+ next if value.nil?
67
+
68
+ key.failure(PayuPl.t(:max_length, max: 1024)) if value.length > 1024
69
+ end
70
+
71
+ rule(:visibleDescription) do
72
+ next if value.nil?
73
+
74
+ key.failure(PayuPl.t(:max_length, max: 80)) if value.length > 80
75
+ end
76
+
77
+ rule(:statementDescription) do
78
+ next if value.nil?
79
+
80
+ key.failure(PayuPl.t(:max_length, max: 22)) if value.length > 22
81
+ end
82
+
83
+ rule(:extOrderId) do
84
+ next if value.nil?
85
+
86
+ key.failure(PayuPl.t(:max_length, max: 1024)) if value.length > 1024
87
+ end
88
+
89
+ rule(:currencyCode) do
90
+ code = value
91
+ key.failure(PayuPl.t(:iso_4217)) unless code.match?(/\A[A-Z]{3}\z/)
92
+ end
93
+
94
+ rule(:totalAmount) do
95
+ # API uses a string containing minor units
96
+ key.failure(PayuPl.t(:numeric_string)) unless value.match?(/\A\d+\z/)
97
+ end
98
+
99
+ rule(:products) do
100
+ key.failure(PayuPl.t(:min_items, min: 1)) if value.nil? || value.empty?
101
+ end
102
+
103
+ rule(:products).each do
104
+ unit_price = value[:unitPrice]
105
+ quantity = value[:quantity]
106
+
107
+ key(:unitPrice).failure(PayuPl.t(:numeric_string)) if unit_price && !unit_price.match?(/\A\d+\z/)
108
+
109
+ key(:quantity).failure(PayuPl.t(:numeric_string)) if quantity && !quantity.match?(/\A\d+\z/)
110
+ end
111
+ end
112
+ end
113
+ end