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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 985dbbc4e62af28fb16d7af3ff829f171dd570f41014b2408eb07e686d3776a3
4
- data.tar.gz: 6605967ad08002c8633f82cef44f3910dbf1c5e66546ad6a2565ec92dd2792f2
3
+ metadata.gz: 43f6940a760136d9ec07fa6996afff0915b9e49833c06684b4385409ea07a3ae
4
+ data.tar.gz: 02d6a26ad6c1020683d185d6204d7d3711a06516bfbd80803ca685ff3d45f2e6
5
5
  SHA512:
6
- metadata.gz: 24b85aa48412e7e55e33f3ed8a8c31536370f6fb8c8f34a0460c39c17b582812752f53f50328729ce09aea05c167a9e7d80b2b4f3825e844dd262530ab89b4df
7
- data.tar.gz: 22092a2f738956cec84167e3dc3d834024e69e1c7d5812049f2a40a1bf7c0409e425fa42b0abae151140c98916a1f15c7112e7586b1ca3e1f54a87a9b254de9d
6
+ metadata.gz: ddbbe449a23f25decf13b4bcdf9d84d2cc86d936d543c4426594c30392f28e61c1f50da4d40e4fcef9008d7079e2413383601e2bad6031048a45e562b325d75e
7
+ data.tar.gz: 9a8a6eae7022ffa666801384f622f44fbc2a7924841171f1993ffe814c64fbe6444a49d83091637046521196c45465612048c986378e5f4dd684b74475697a53
data/.gitignore CHANGED
@@ -6,6 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
9
+ *.gem
10
10
  # rspec failure tracking
11
11
  .rspec_status
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- defra_ruby_govpay (0.1.0)
4
+ defra_ruby_govpay (0.1.2)
5
5
  rest-client (~> 2.1)
6
6
 
7
7
  GEM
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Error < DefraRubyGovpay::Object
4
+ end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyGovpay
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -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.1.2
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-18 00:00:00.000000000 Z
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