defra_ruby_govpay 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile.lock +1 -1
- data/lib/defra_ruby_govpay/error.rb +4 -0
- data/lib/defra_ruby_govpay/object.rb +45 -0
- data/lib/defra_ruby_govpay/payment.rb +17 -0
- data/lib/defra_ruby_govpay/refund.rb +15 -0
- data/lib/defra_ruby_govpay/version.rb +1 -1
- data/lib/defra_ruby_govpay.rb +4 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43f6940a760136d9ec07fa6996afff0915b9e49833c06684b4385409ea07a3ae
|
4
|
+
data.tar.gz: 02d6a26ad6c1020683d185d6204d7d3711a06516bfbd80803ca685ff3d45f2e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddbbe449a23f25decf13b4bcdf9d84d2cc86d936d543c4426594c30392f28e61c1f50da4d40e4fcef9008d7079e2413383601e2bad6031048a45e562b325d75e
|
7
|
+
data.tar.gz: 9a8a6eae7022ffa666801384f622f44fbc2a7924841171f1993ffe814c64fbe6444a49d83091637046521196c45465612048c986378e5f4dd684b74475697a53
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module DefraRubyGovpay
|
6
|
+
# Generic Object. Takes the hash/Json returned from the Govpay API
|
7
|
+
# and gives us openstruct objects for easier reading/consuming
|
8
|
+
class Object < OpenStruct
|
9
|
+
def initialize(attributes)
|
10
|
+
super to_ostruct(attributes)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_ostruct(obj)
|
14
|
+
case obj
|
15
|
+
when Hash
|
16
|
+
OpenStruct.new(obj.transform_values { |v| to_ostruct(v) })
|
17
|
+
when Array
|
18
|
+
obj.map { |o| to_ostruct(o) }
|
19
|
+
when String
|
20
|
+
string_reader(obj)&.strip
|
21
|
+
else # Likely a primative value
|
22
|
+
obj
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def string_reader(value)
|
27
|
+
return if nil_value?(value)
|
28
|
+
|
29
|
+
value = value.to_s
|
30
|
+
value = yield value if block_given?
|
31
|
+
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
def nil_value?(value)
|
36
|
+
value.nil? ||
|
37
|
+
%w[nil null].any?(
|
38
|
+
value
|
39
|
+
.to_s
|
40
|
+
.strip
|
41
|
+
.downcase
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DefraRubyGovpay
|
4
|
+
# The Payment class represents a payment object in the Govpay Integration.
|
5
|
+
# It contains methods to check refund status and details about the payment.
|
6
|
+
class Payment < Object
|
7
|
+
def refundable?(amount_requested = 0)
|
8
|
+
refund.status == "available" &&
|
9
|
+
refund.amount_available > refund.amount_submitted &&
|
10
|
+
amount_requested <= refund.amount_available
|
11
|
+
end
|
12
|
+
|
13
|
+
def refund
|
14
|
+
refund_summary
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DefraRubyGovpay
|
4
|
+
# The Refund class represents a refund object in the Govpay Integration.
|
5
|
+
# It provides methods to check the status of a refund.
|
6
|
+
class Refund < Object
|
7
|
+
def success?
|
8
|
+
status == "success"
|
9
|
+
end
|
10
|
+
|
11
|
+
def submitted?
|
12
|
+
status == "submitted"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/defra_ruby_govpay.rb
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
require "json"
|
4
4
|
require_relative "defra_ruby_govpay/version"
|
5
5
|
require_relative "defra_ruby_govpay/configuration"
|
6
|
+
require_relative "defra_ruby_govpay/object"
|
7
|
+
require_relative "defra_ruby_govpay/payment"
|
8
|
+
require_relative "defra_ruby_govpay/refund"
|
9
|
+
require_relative "defra_ruby_govpay/error"
|
6
10
|
require_relative "defra_ruby_govpay/api"
|
7
11
|
|
8
12
|
# The DefraRubyGovpay module facilitates integration with Govpay services.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defra_ruby_govpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerome Pratt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -46,6 +46,10 @@ files:
|
|
46
46
|
- lib/defra_ruby_govpay.rb
|
47
47
|
- lib/defra_ruby_govpay/api.rb
|
48
48
|
- lib/defra_ruby_govpay/configuration.rb
|
49
|
+
- lib/defra_ruby_govpay/error.rb
|
50
|
+
- lib/defra_ruby_govpay/object.rb
|
51
|
+
- lib/defra_ruby_govpay/payment.rb
|
52
|
+
- lib/defra_ruby_govpay/refund.rb
|
49
53
|
- lib/defra_ruby_govpay/version.rb
|
50
54
|
- sig/defra_ruby_govpay.rbs
|
51
55
|
homepage: https://github.com/DEFRA/defra-ruby-govpay
|