mock_braintree 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66a39f78ce84f09223d01929a3703e5b5210f175f0f8b2535db91f42180ddb07
4
- data.tar.gz: 7f628be104f3dc341aea306fa6f28be4d7ad84cf3086d07cd6018b4a6e3161ce
3
+ metadata.gz: aea598969fad5aa0fdf866645af6b3204dca000d59304c4d53faab6f5b0704de
4
+ data.tar.gz: 1b90d38ecd6c5acea7ceed0d851f6990c34412f7a9fe01e858f6aebf87357943
5
5
  SHA512:
6
- metadata.gz: c7544e72412d03e0ac09d0e958a73a9bf96bfa179f71df387d8b2eb60898a8801634664acd1930cd798d3165e0c009154742c6524dc7b0332be99096bd929c37
7
- data.tar.gz: a26d9bf544faec96801c1f3fd5f01aad41cbc7f9fa1c3b117bc857239806b13cd4bec00e420248c6d2dfc58f10697a529f690a35b26bc51ebcbe66bd52a0216a
6
+ metadata.gz: 8cfcf2f6e956d19cb29669d476e57f4338de3250de07aae0d2f6746f693fa3b41ecb20d4e47b4ec0af3852ec54b29bada5163f3159e043bf35290d6d5403b782
7
+ data.tar.gz: f704db440ec0ddac52b1f6d57c5898987721d67e67dc15c14efcdb0a7817150266e82ce847412fdedfb2a7896cb6dd0ba054139c090a3b9e62228971eb8d2b18
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
9
10
  /test.rb
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # 0.2.0
2
+ * BREAKING CHANGE - separated transaction and result object. Depending on success, the result will now be either a `SuccessfulResult` or `UnsuccessfulResult` object that contains a transaction object. This was changed to better match an actual Braintree response.
3
+
4
+ # 0.1.0
5
+ * Add basic `transaction.sale` functionality with result object and `transaction` object
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- First, configure your mock Braintree integration by switching out your real Braintree configuration with `MockBraintree.new`
25
+ First, configure your mock Braintree integration by switching out your real Braintree configuration with `MockBraintree::Gateway.new`
26
26
 
27
27
  example:
28
28
 
@@ -38,9 +38,13 @@ MockBraintree lets you test simple result handling just like Braintree responses
38
38
  result = gateway.transaction.sale(nonce: 'fake-valid-nonce', amount: '10.00', options: { submit_for_settlement: true })
39
39
 
40
40
  puts result.success?
41
+ #=> true
41
42
  puts result.transaction.status
43
+ #=> submitted_for_settlement
42
44
  puts result.transaction.amount
45
+ #=> '10.00'
43
46
  puts result.transaction.id
47
+ #=> 'ej6a32'
44
48
  ```
45
49
 
46
50
  ## Development
@@ -49,9 +53,13 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
49
53
 
50
54
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
55
 
56
+
57
+ ## Disclaimer
58
+ While I work at Braintree, this library was neither built by Braintree, nor is it maintained by Braintree. If there is a feature you are looking for PRs are always welcome, or feel free to fork your own branch and make it your own. If you find a bug please open an issue on this repo and do not contact Braintree directly.
59
+
52
60
  ## Contributing
53
61
 
54
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mock_braintree.
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/buzzamus/mock_braintree.
55
63
 
56
64
  ## License
57
65
 
data/TODO.md ADDED
@@ -0,0 +1,14 @@
1
+ # Todo
2
+
3
+ ##### Add additional `transaction` type calls
4
+ * refund
5
+ * void
6
+ * submit_for_settlement
7
+
8
+ ##### Add more attributes to result and transaction objects to resemble all of, or most of Braintree's attributes
9
+
10
+ ##### Add option to gateway reject (possibly based off of fake nonce value somehow) - revise documentation to list what values to change nonce in `transaction.sale` request to
11
+
12
+ #### Make requests wait several seconds before returning response to match actual request times
13
+
14
+ #### Add ability to create customer and/or payment method in transaction requests, return customer and payment method objects
@@ -1,6 +1,8 @@
1
1
  require "mock_braintree/version"
2
2
  require "mock_braintree/transaction_request"
3
3
  require "mock_braintree/transaction"
4
+ require "mock_braintree/successful_result"
5
+ require "mock_braintree/unsuccessful_result"
4
6
 
5
7
  module MockBraintree
6
8
  class Gateway
@@ -0,0 +1,10 @@
1
+ class SuccessfulResult
2
+ attr_reader :transaction
3
+ def initialize(hash = {})
4
+ @transaction = Transaction.new(hash)
5
+ end
6
+
7
+ def success?
8
+ true
9
+ end
10
+ end
@@ -11,14 +11,6 @@ class Transaction
11
11
  @submit_for_settlement = submit_for_settlement
12
12
  end
13
13
 
14
- def success?
15
- if (status == 'authorized') || (status == 'submitted_for_settlement')
16
- true
17
- else
18
- false
19
- end
20
- end
21
-
22
14
  def status
23
15
  if (amount.to_f < 2000) && (submit_for_settlement == true)
24
16
  'submitted_for_settlement'
@@ -33,9 +25,9 @@ class Transaction
33
25
  end
34
26
  end
35
27
 
36
- def transaction
37
- self
38
- end
28
+ # def transaction
29
+ # self
30
+ # end
39
31
 
40
32
  def id
41
33
  SecureRandom.hex(3)
@@ -1,5 +1,13 @@
1
1
  class TransactionRequest
2
2
  def sale(hash = {})
3
- Transaction.new(hash)
3
+ if hash[:amount].to_f < 2000.00
4
+ SuccessfulResult.new(hash)
5
+ elsif (hash[:amount].to_f >= 2000) && (hash[:amount].to_i < 3000)
6
+ UnsuccessfulResult.new(hash)
7
+ elsif (hash[:amount].to_f >= 3000) && (hash[:amount].to_i <= 3000.99)
8
+ UnsuccessfulResult.new(hash)
9
+ else
10
+ UnsuccessfulResult.new(hash)
11
+ end
4
12
  end
5
13
  end
@@ -0,0 +1,10 @@
1
+ class UnsuccessfulResult
2
+ attr_reader :transaction
3
+ def initialize(hash = {})
4
+ @transaction = Transaction.new(hash)
5
+ end
6
+
7
+ def success?
8
+ false
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module MockBraintree
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_braintree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Busby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-01 00:00:00.000000000 Z
11
+ date: 2019-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -46,16 +46,20 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - CHANGELOG.md
49
50
  - Gemfile
50
51
  - Gemfile.lock
51
52
  - LICENSE.txt
52
53
  - README.md
53
54
  - Rakefile
55
+ - TODO.md
54
56
  - bin/console
55
57
  - bin/setup
56
58
  - lib/mock_braintree.rb
59
+ - lib/mock_braintree/successful_result.rb
57
60
  - lib/mock_braintree/transaction.rb
58
61
  - lib/mock_braintree/transaction_request.rb
62
+ - lib/mock_braintree/unsuccessful_result.rb
59
63
  - lib/mock_braintree/version.rb
60
64
  - mock_braintree.gemspec
61
65
  homepage: https://github.com/buzzamus/mock-braintree