affirm-ruby-v1 1.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.
@@ -0,0 +1,71 @@
1
+ require "helper"
2
+
3
+ RSpec.describe Affirm::FailureResult do
4
+ let(:body) do
5
+ {
6
+ "status_code" => 400,
7
+ "type" => "invalid_request",
8
+ "code" => "invalid_field",
9
+ "message" => "An input field resulted in invalid request.",
10
+ "field" => "foo"
11
+ }
12
+ end
13
+
14
+ let(:response) do
15
+ double(:response, status: 400, success?: false, body: body)
16
+ end
17
+
18
+ subject { described_class.new(response) }
19
+
20
+ context "response" do
21
+ it "should have status" do
22
+ expect(subject.status).to eq(response.status)
23
+ end
24
+
25
+ it "should not be successful" do
26
+ expect(subject).not_to be_success
27
+ end
28
+ end
29
+
30
+ context "error object" do
31
+ %w(
32
+ status_code
33
+ type
34
+ code
35
+ message
36
+ field
37
+ ).each do |method|
38
+ it method do
39
+ expect(subject.error.public_send(method)).to eq(body[method])
40
+ end
41
+ end
42
+ end
43
+
44
+ context "with non-Hash body" do
45
+ let(:response) do
46
+ double(:response, status: 502, success?: false, body: "Bad Gateway")
47
+ end
48
+
49
+ subject { described_class.new(response) }
50
+
51
+ it "wraps the body string in the error message" do
52
+ expect(subject.error.message).to eq("Bad Gateway")
53
+ end
54
+
55
+ it "is not successful" do
56
+ expect(subject).not_to be_success
57
+ end
58
+ end
59
+
60
+ context "with nil body" do
61
+ let(:response) do
62
+ double(:response, status: 500, success?: false, body: nil)
63
+ end
64
+
65
+ subject { described_class.new(response) }
66
+
67
+ it "stringifies nil into the error message" do
68
+ expect(subject.error.message).to eq("")
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,22 @@
1
+ {
2
+ "status": "authorized",
3
+ "amount_refunded": 0,
4
+ "provider_id": 1,
5
+ "created": "2021-06-23T23:25:55Z",
6
+ "order_id": "ABC123",
7
+ "checkout_id": "7WYDR0M83CGE47GJ",
8
+ "currency": "USD",
9
+ "amount": 49999,
10
+ "events": [
11
+ {
12
+ "currency": "USD",
13
+ "amount": 49999,
14
+ "type": "auth",
15
+ "id": "7WYDR0M83CGE47GJ",
16
+ "created": "2021-06-23T23:26:28Z"
17
+ }
18
+ ],
19
+ "remove_tax": false,
20
+ "authorization_expiration": "2021-07-23T23:26:28Z",
21
+ "id": "AMLC-5X0W"
22
+ }
data/spec/helper.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "affirm"
2
+ require "byebug"
3
+ require "json"
4
+
5
+ def to_seconds(datetime)
6
+ Time.parse(datetime.to_s).to_i
7
+ end
@@ -0,0 +1,61 @@
1
+ require "helper"
2
+
3
+ # Integration specs hit the live Affirm sandbox. Excluded from the default
4
+ # rspec run; invoke with `bundle exec rspec --tag integration`.
5
+ #
6
+ # Required env vars:
7
+ # AFFIRM_PUBLIC_API_KEY
8
+ # AFFIRM_PRIVATE_API_KEY
9
+ RSpec.describe "Affirm sandbox", :integration do
10
+ before(:all) do
11
+ public_key = ENV.fetch("AFFIRM_PUBLIC_API_KEY")
12
+ private_key = ENV.fetch("AFFIRM_PRIVATE_API_KEY")
13
+
14
+ Affirm.configuration = nil
15
+ Affirm.configure do |config|
16
+ config.public_api_key = public_key
17
+ config.private_api_key = private_key
18
+ config.environment = :sandbox
19
+ end
20
+ end
21
+
22
+ after(:all) do
23
+ Affirm.configuration = nil
24
+ end
25
+
26
+ it "configures the sandbox endpoint" do
27
+ expect(Affirm.configuration.endpoint).to eq("https://sandbox.affirm.com")
28
+ end
29
+
30
+ describe "Affirm::Charge.find with an unknown id" do
31
+ subject(:result) { Affirm::Charge.find("DOES-NOT-EXIST-#{Time.now.to_i}") }
32
+
33
+ it "returns a FailureResult" do
34
+ expect(result).to be_an_instance_of(Affirm::FailureResult)
35
+ end
36
+
37
+ it "returns a non-success HTTP status" do
38
+ expect(result.status).to be >= 400
39
+ end
40
+
41
+ it "exposes a parsed error message" do
42
+ expect(result.error.message.to_s).not_to be_empty
43
+ end
44
+ end
45
+
46
+ describe "Affirm::Charge.authorize with a bogus checkout token" do
47
+ subject(:result) { Affirm::Charge.authorize("not-a-real-token", "ORDER-INTEGRATION-#{Time.now.to_i}") }
48
+
49
+ it "returns a FailureResult" do
50
+ expect(result).to be_an_instance_of(Affirm::FailureResult)
51
+ end
52
+
53
+ it "returns a non-success HTTP status" do
54
+ expect(result.status).to be >= 400
55
+ end
56
+
57
+ it "exposes a parsed error message" do
58
+ expect(result.error.message.to_s).not_to be_empty
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ # These two settings work together to allow you to limit a spec run
44
+ # to individual examples or groups you care about by tagging them with
45
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
46
+ # get run.
47
+ config.filter_run :focus
48
+ config.run_all_when_everything_filtered = true
49
+
50
+ # Integration specs hit the live Affirm sandbox and require credentials.
51
+ # Run them with `bundle exec rspec --tag integration`.
52
+ config.filter_run_excluding :integration unless config.inclusion_filter[:integration]
53
+
54
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
55
+ # For more details, see:
56
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
57
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
59
+ config.disable_monkey_patching!
60
+
61
+ # This setting enables warnings. It's recommended, but in some cases may
62
+ # be too noisy due to issues in dependencies.
63
+ config.warnings = true
64
+
65
+ # Many RSpec users commonly either run the entire suite or an individual
66
+ # file, and it's useful to allow more verbose output when running an
67
+ # individual spec file.
68
+ if config.files_to_run.one?
69
+ # Use the documentation formatter for detailed output,
70
+ # unless a formatter has already been configured
71
+ # (e.g. via a command-line flag).
72
+ config.default_formatter = 'doc'
73
+ end
74
+
75
+ # Print the 10 slowest examples and example groups at the
76
+ # end of the spec run, to help surface which specs are running
77
+ # particularly slow.
78
+ config.profile_examples = 10
79
+
80
+ # Run specs in random order to surface order dependencies. If you find an
81
+ # order dependency and want to debug it, you can fix the order by providing
82
+ # the seed, which is printed after each run.
83
+ # --seed 1234
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+ end
@@ -0,0 +1,31 @@
1
+ require "helper"
2
+
3
+ RSpec.describe Affirm::SuccessResult do
4
+ let(:object) { double(:object, id: 1, amount: 500, void: false) }
5
+
6
+ subject { described_class.new(object) }
7
+
8
+ it "should be successful" do
9
+ expect(subject).to be_success
10
+ end
11
+
12
+ it "should have id" do
13
+ expect(subject.id).to eq(object.id)
14
+ end
15
+
16
+ it "should have amount" do
17
+ expect(subject.amount).to eq(object.amount)
18
+ end
19
+
20
+ it "should not be voided" do
21
+ expect(subject.void).to be_falsey
22
+ end
23
+
24
+ it "should raise no method error on missing method" do
25
+ expect { subject.does_not_exist }.to raise_error(NoMethodError)
26
+ end
27
+
28
+ it "should not respond to missing method" do
29
+ expect(subject).not_to respond_to(:does_not_exist)
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: affirm-ruby-v1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yury Velikanau
8
+ - Igor Pstyga
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bigdecimal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: logger
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.4'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.4'
47
+ - !ruby/object:Gem::Dependency
48
+ name: ostruct
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.5'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.5'
61
+ - !ruby/object:Gem::Dependency
62
+ name: faraday
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '2.10'
68
+ - - "<"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '2.10'
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: '3.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: virtus
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '1.0'
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 1.0.0
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.0'
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.0.0
101
+ - !ruby/object:Gem::Dependency
102
+ name: bundler
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '2.0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '2.0'
115
+ - !ruby/object:Gem::Dependency
116
+ name: rake
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '13.0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '13.0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: rspec
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '3.0'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '3.0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: byebug
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '11.0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '11.0'
157
+ description: Ruby client for Affirm.com /api/v1/transactions with compatibility helpers
158
+ for legacy affirm-ruby call sites.
159
+ email:
160
+ - yury.velikanau@gmail.com
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - ".rspec"
166
+ - CHANGELOG.md
167
+ - Gemfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - lib/affirm.rb
172
+ - lib/affirm/charge.rb
173
+ - lib/affirm/client.rb
174
+ - lib/affirm/configuration.rb
175
+ - lib/affirm/failure_result.rb
176
+ - lib/affirm/objects/event.rb
177
+ - lib/affirm/responses/auth.rb
178
+ - lib/affirm/responses/capture.rb
179
+ - lib/affirm/responses/error.rb
180
+ - lib/affirm/responses/refund.rb
181
+ - lib/affirm/responses/update.rb
182
+ - lib/affirm/responses/void.rb
183
+ - lib/affirm/success_result.rb
184
+ - lib/affirm/version.rb
185
+ - spec/charge_object_interface.rb
186
+ - spec/charge_spec.rb
187
+ - spec/client_spec.rb
188
+ - spec/configuration_spec.rb
189
+ - spec/failure_result_spec.rb
190
+ - spec/fixtures/auth.json
191
+ - spec/helper.rb
192
+ - spec/integration/sandbox_spec.rb
193
+ - spec/spec_helper.rb
194
+ - spec/success_result_spec.rb
195
+ homepage: https://github.com/hknaksu/affirm-ruby-v1
196
+ licenses:
197
+ - MIT
198
+ metadata: {}
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '3.3'
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
212
+ requirements: []
213
+ rubygems_version: 3.6.9
214
+ specification_version: 4
215
+ summary: Ruby wrapper for the Affirm v1 Transactions API
216
+ test_files: []