fake_braintree 0.4.3 → 0.5.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
  SHA1:
3
- metadata.gz: add7e06e8924fb857057b26cf5b666c3e4c26e46
4
- data.tar.gz: e29ab9a2d7f8cd055f50136b8665a2ba59a13840
3
+ metadata.gz: 3e1f728169a3ebbadce2b17ce18b02573c62bebb
4
+ data.tar.gz: ae270d791ae918780fc6d73876d1262b767b2d9c
5
5
  SHA512:
6
- metadata.gz: 17bb6bf3ee490082c5a776fb8d8a80f9a076098fe8debeb1eec4ea7dfeff9f942d8eccf3ad4d888bb91fadd2cc4776da7b1e3b937588be8496aa87a928e92301
7
- data.tar.gz: 6bfd5dbfd0bf373283c90a23f05a7269cd0b545a655aa9ab60041e4a0c6ec8d1672b79670cae5fe97a93048642ef1200abd8fd671d12842762c12f073917db4f
6
+ metadata.gz: 8760ad110627da619df7e9d01886f106d43c0e79b820185dce901aabf38c1ca563fc81f9449af1dee11bad69fcc125c3f6cc262314aefd0a24140eab68b1876d
7
+ data.tar.gz: e436d08996cb0b17ef1ab0cd8668dbeb3cd44ef60717b4f69b68fe2f46dddb3d470722b7698b73f6fd7ed25bddef9c17a00312417195272fdcf8edfdba12f87f
@@ -4,6 +4,7 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.0
6
6
  - 2.1.1
7
+ - 2.1.2
7
8
  before_install:
8
9
  - gem update --system
9
10
  branches:
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  # Web servers for different platforms
4
-
5
4
  platform :jruby do
6
5
  gem 'puma'
7
6
  end
@@ -10,12 +9,11 @@ platform :mri do
10
9
  gem 'thin'
11
10
  end
12
11
 
13
- # Specify your gem's dependencies in fake_braintree.gemspec
14
12
  gemspec
15
13
 
16
- # Capybara 2.1.0 requires 1.9.3+ so we install a version that works with
17
- # every Ruby version we test against. This can be removed if we stop testing
18
- # against 1.9.2.
14
+ # Capybara 2.1.0 requires 1.9.3+ so we install a version that works with every
15
+ # Ruby version we test against. This can be removed if we stop testing against
16
+ # 1.9.2.
19
17
  gem 'capybara', '~> 2.0.3'
20
18
 
21
19
  if RUBY_VERSION == '1.9.2'
data/LICENSE CHANGED
@@ -2,7 +2,7 @@ LICENSE
2
2
 
3
3
  The MIT License
4
4
 
5
- Copyright (c) 2011-2013 thoughtbot, inc.
5
+ Copyright (c) 2011-2014 thoughtbot, inc.
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
data/NEWS.md CHANGED
@@ -1,3 +1,12 @@
1
+ # HEAD
2
+
3
+ * Remove unused `i18n` gem dependency (#56).
4
+ * Set `credit_card.card_type`, `credit_card.last_4`, and
5
+ `credit_card.unique_number_identifier`. Ensure `credit_card.bin` is always
6
+ set (#47).
7
+ * Support new Braintree credit card API URLs
8
+ * Requires Braintree ~> 2.32 instead of Braintree ~> 2.5.
9
+
1
10
  # 0.4.3
2
11
 
3
12
  * Add missing quote.
data/README.md CHANGED
@@ -41,6 +41,7 @@ of them (yet).
41
41
  * `Braintree::Transaction.refund`
42
42
  * `Braintree::Transaction.sale`
43
43
  * `Braintree::Transaction.void`
44
+ * `Braintree::Transaction.submit_for_settlement`
44
45
 
45
46
  ### TransparentRedirect
46
47
  * `Braintree::TransparentRedirect.confirm` (only for creating customers)
@@ -74,29 +75,14 @@ If you're using Cucumber, add this too:
74
75
  FakeBraintree.clear!
75
76
  end
76
77
 
77
- ## Spork
78
+ It is advised to run your tests with `js: true` (RSpec) or `@javascript`
79
+ (Cucumber), so that the requests correctly go through `FakeBraintree`. You might
80
+ want to give a look at
81
+ [capybara-webkit](https://github.com/thoughtbot/capybara-webkit).
78
82
 
79
- To use fake\_braintree with Spork, do this:
80
-
81
- # Gemfile
82
- group :test do
83
- gem 'fake_braintree', require: false
84
- end
85
-
86
- # spec/spec_helper.rb
87
- Spork.each_run do
88
- require 'fake_braintree'
89
- # ...other FakeBraintree configuration, for example:
90
- # FakeBraintree.verify_all_cards!
91
- end
92
-
93
- # features/support/env.rb
94
- Spork.each_run do
95
- require 'fake_braintree'
96
- # ...other FakeBraintree configuration, for example:
97
- # FakeBraintree.verify_all_cards!
98
- end
83
+ # Credit Cards
99
84
 
85
+ * `credit_card.card_type` will always be `"FakeBraintree"`.
100
86
 
101
87
  ## Verifying credit cards
102
88
 
@@ -150,10 +136,13 @@ call it with no arguments.
150
136
 
151
137
  Full example:
152
138
 
153
- transaction = FakeBraintree.generate_transaction(amount: '20.00',
154
- status: Braintree::Transaction::Status::Settled,
155
- subscription_id: 'foobar',
156
- created_at: Time.now + 60)
139
+ transaction = FakeBraintree.generate_transaction(
140
+ amount: '20.00',
141
+ status: Braintree::Transaction::Status::Settled,
142
+ subscription_id: 'foobar',
143
+ created_at: Time.now + 60
144
+ )
145
+
157
146
  p transaction
158
147
  # {
159
148
  # "status_history" =>
@@ -166,6 +155,11 @@ Full example:
166
155
  # "subscription_id" => "foobar"
167
156
  # }
168
157
 
158
+ ## Running the tests
159
+
160
+ During tests, debug-level logs will be sent to `tmp/braintree_log`. This is
161
+ useful for seeing which URLs Braintree is actually hitting.
162
+
169
163
  Credits
170
164
  -------
171
165
 
data/Rakefile CHANGED
@@ -5,4 +5,4 @@ require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
7
7
  desc 'Run specs'
8
- task :default => [:spec]
8
+ task default: [:spec]
@@ -17,14 +17,12 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ['lib']
18
18
  s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
19
19
 
20
- s.add_dependency 'capybara'
21
20
  s.add_dependency 'activesupport'
22
- s.add_dependency 'i18n'
21
+ s.add_dependency 'braintree', '~> 2.32'
22
+ s.add_dependency 'capybara'
23
23
  s.add_dependency 'sinatra'
24
- s.add_dependency 'braintree', '~> 2.5'
25
24
 
26
- s.add_development_dependency 'rspec', '~> 2.12.0'
27
- s.add_development_dependency 'bourne', '~> 1.3'
28
- s.add_development_dependency 'timecop', '~> 0.6'
29
25
  s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'rspec', '~> 2.14'
27
+ s.add_development_dependency 'timecop', '~> 0.6'
30
28
  end
@@ -7,33 +7,33 @@ module FakeBraintree
7
7
  end
8
8
 
9
9
  def create
10
- @hash['id'] = generate_id
11
- FakeBraintree.registry.addresses[id] = @hash
12
- customer['addresses'] << @hash
10
+ @address['id'] = generate_id
11
+ FakeBraintree.registry.addresses[id] = @address
12
+ customer['addresses'] << @address
13
13
  response_for_updated_address
14
14
  end
15
15
 
16
16
  def customer
17
- FakeBraintree.registry.customers[@hash['customer_id']]
17
+ FakeBraintree.registry.customers[@address['customer_id']]
18
18
  end
19
19
 
20
20
  def response_for_updated_address
21
- gzipped_response(200, @hash.to_xml(root: 'address'))
21
+ gzipped_response(200, @address.to_xml(root: 'address'))
22
22
  end
23
23
 
24
24
  def set_up_address(address_hash_from_params, options)
25
- @hash = {
25
+ @address = {
26
26
  "merchant_id" => options[:merchant_id],
27
27
  "customer_id" => options[:customer_id],
28
28
  }.merge(address_hash_from_params)
29
29
  end
30
30
 
31
31
  def generate_id
32
- "#{@hash['customer_id']}_#{customer['addresses'].size}"
32
+ "#{@address['customer_id']}_#{customer['addresses'].size}"
33
33
  end
34
34
 
35
35
  def id
36
- @hash['id']
36
+ @address['id']
37
37
  end
38
38
  end
39
39
  end
@@ -5,17 +5,21 @@ module FakeBraintree
5
5
  def initialize(credit_card_hash_from_params, options)
6
6
  set_up_credit_card(credit_card_hash_from_params, options)
7
7
  set_billing_address
8
+ set_bin
9
+ set_card_type
8
10
  set_expiration_month_and_year
11
+ set_last_4
12
+ set_unique_number_identifier
9
13
  end
10
14
 
11
15
  def create
12
16
  if valid_number?
13
17
  if token.nil?
14
- @hash['token'] = generate_token
18
+ @credit_card['token'] = generate_token
15
19
  end
16
- FakeBraintree.registry.credit_cards[token] = @hash
17
- if customer = FakeBraintree.registry.customers[@hash['customer_id']]
18
- customer['credit_cards'] << @hash
20
+ FakeBraintree.registry.credit_cards[token] = @credit_card
21
+ if customer = FakeBraintree.registry.customers[@credit_card['customer_id']]
22
+ customer['credit_cards'] << @credit_card
19
23
  update_default_card
20
24
  end
21
25
  response_for_updated_card
@@ -34,14 +38,14 @@ module FakeBraintree
34
38
  end
35
39
 
36
40
  def to_xml
37
- @hash.to_xml(root: 'credit_card')
41
+ @credit_card.to_xml(root: 'credit_card')
38
42
  end
39
43
 
40
44
  def valid_number?
41
45
  if FakeBraintree.decline_all_cards?
42
46
  false
43
47
  elsif FakeBraintree.verify_all_cards
44
- FakeBraintree::VALID_CREDIT_CARDS.include?(@hash['number'])
48
+ FakeBraintree::VALID_CREDIT_CARDS.include?(@credit_card['number'])
45
49
  else
46
50
  true
47
51
  end
@@ -50,23 +54,23 @@ module FakeBraintree
50
54
  private
51
55
 
52
56
  def update_existing_credit_card
53
- @hash = credit_card_from_registry.merge!(@hash)
57
+ @credit_card = credit_card_from_registry.merge!(@credit_card)
54
58
  update_default_card
55
59
  end
56
60
 
57
- # When updating a card that has 'default' set to true, make sure
58
- # only one card has the flag.
61
+ # When updating a card that has 'default' set to true, make sure only one
62
+ # card has the flag.
59
63
  def update_default_card
60
- if @hash['default']
61
- FakeBraintree.registry.customers[@hash['customer_id']]['credit_cards'].each do |card|
64
+ if @credit_card['default']
65
+ FakeBraintree.registry.customers[@credit_card['customer_id']]['credit_cards'].each do |card|
62
66
  card['default'] = false
63
67
  end
64
- @hash['default'] = true
68
+ @credit_card['default'] = true
65
69
  end
66
70
  end
67
71
 
68
72
  def response_for_updated_card
69
- gzipped_response(200, @hash.to_xml(root: 'credit_card'))
73
+ gzipped_response(200, @credit_card.to_xml(root: 'credit_card'))
70
74
  end
71
75
 
72
76
  def credit_card_exists_in_registry?
@@ -82,10 +86,11 @@ module FakeBraintree
82
86
  end
83
87
 
84
88
  def response_for_invalid_card
85
- gzipped_response(422, FakeBraintree.failure_response.merge(
86
- 'params' => {credit_card: @hash}
87
- ).
88
- to_xml(root: 'api_error_response'))
89
+ body = FakeBraintree.failure_response.merge(
90
+ 'params' => {credit_card: @credit_card}
91
+ ).to_xml(root: 'api_error_response')
92
+
93
+ gzipped_response(422, body)
89
94
  end
90
95
 
91
96
  def expiration_month
@@ -97,7 +102,7 @@ module FakeBraintree
97
102
  end
98
103
 
99
104
  def set_up_credit_card(credit_card_hash_from_params, options)
100
- @hash = {
105
+ @credit_card = {
101
106
  'token' => options[:token],
102
107
  'merchant_id' => options[:merchant_id],
103
108
  'customer_id' => options[:customer_id],
@@ -106,32 +111,52 @@ module FakeBraintree
106
111
  end
107
112
 
108
113
  def set_billing_address
109
- if @hash["billing_address_id"]
110
- @hash["billing_address"] = FakeBraintree.registry.addresses[@hash['billing_address_id']]
114
+ if @credit_card["billing_address_id"]
115
+ @credit_card["billing_address"] = FakeBraintree.registry.addresses[@credit_card['billing_address_id']]
111
116
  end
112
117
  end
113
118
 
119
+ def set_bin
120
+ @credit_card['bin'] = number[0, 6]
121
+ end
122
+
123
+ def set_card_type
124
+ @credit_card['card_type'] = 'FakeBraintree'
125
+ end
126
+
114
127
  def set_expiration_month_and_year
115
128
  if expiration_month
116
- @hash['expiration_month'] = expiration_month
129
+ @credit_card['expiration_month'] = expiration_month
117
130
  end
118
131
 
119
132
  if expiration_year
120
- @hash['expiration_year'] = expiration_year
133
+ @credit_card['expiration_year'] = expiration_year
121
134
  end
122
135
  end
123
136
 
137
+ def set_last_4
138
+ @credit_card['last_4'] = number[-4, 4]
139
+ end
140
+
141
+ def number
142
+ @credit_card['number'].to_s
143
+ end
144
+
145
+ def set_unique_number_identifier
146
+ @credit_card["unique_number_identifier"] = number
147
+ end
148
+
124
149
  def generate_token
125
- md5("#{@hash['number']}#{@hash['merchant_id']}")
150
+ md5("#{@credit_card['number']}#{@credit_card['merchant_id']}")
126
151
  end
127
152
 
128
153
  def token
129
- @hash['token']
154
+ @credit_card['token']
130
155
  end
131
156
 
132
157
  def expiration_date_parts
133
- if @hash.key?('expiration_date')
134
- @hash['expiration_date'].split('/')
158
+ if @credit_card.key?('expiration_date')
159
+ @credit_card['expiration_date'].split('/')
135
160
  else
136
161
  []
137
162
  end
@@ -8,8 +8,8 @@ module FakeBraintree
8
8
  ActiveSupport::Gzip.compress(content)
9
9
  end
10
10
 
11
- def gzipped_response(status_code, uncompressed_content)
12
- [status_code, { 'Content-Encoding' => 'gzip' }, gzip(uncompressed_content)]
11
+ def gzipped_response(status_code, uncompressed_body)
12
+ [status_code, { 'Content-Encoding' => 'gzip' }, gzip(uncompressed_body)]
13
13
  end
14
14
 
15
15
  def md5(content)
@@ -90,7 +90,7 @@ module FakeBraintree
90
90
  end
91
91
 
92
92
  # Braintree::CreditCard.find
93
- get '/merchants/:merchant_id/payment_methods/:credit_card_token' do
93
+ get '/merchants/:merchant_id/payment_methods/credit_card/:credit_card_token' do
94
94
  credit_card = FakeBraintree.registry.credit_cards[params[:credit_card_token]]
95
95
  if credit_card
96
96
  gzipped_response(200, credit_card.to_xml(root: 'credit_card'))
@@ -100,10 +100,11 @@ module FakeBraintree
100
100
  end
101
101
 
102
102
  # Braintree::CreditCard.update
103
- put '/merchants/:merchant_id/payment_methods/:credit_card_token' do
103
+ put '/merchants/:merchant_id/payment_methods/credit_card/:credit_card_token' do
104
104
  credit_card = FakeBraintree.registry.credit_cards[params[:credit_card_token]]
105
105
  updates = hash_from_request_body_with_key('credit_card')
106
106
  options = {token: params[:credit_card_token], merchant_id: params[:merchant_id]}
107
+
107
108
  CreditCard.new(updates, options).update
108
109
  end
109
110
 
@@ -157,7 +158,7 @@ module FakeBraintree
157
158
  gzipped_response(200, transaction_response.to_xml(root: 'transaction'))
158
159
  end
159
160
 
160
-
161
+ # Braintree:Transaction.submit_for_settlement
161
162
  put '/merchants/:merchant_id/transactions/:transaction_id/submit_for_settlement' do
162
163
  transaction = FakeBraintree.registry.transactions[params[:transaction_id]]
163
164
  transaction_response = {'id' => transaction['id'],
@@ -1,3 +1,3 @@
1
1
  module FakeBraintree
2
- VERSION = '0.4.3'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -2,8 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe "Braintree::Address.create" do
4
4
  it "successfully creates address with valid data" do
5
- result = create_customer
6
- result = Braintree::Address.create(customer_id: result.customer.id, postal_code: 30339)
7
- result.should be_success
5
+ customer_response = create_customer
6
+
7
+ address_response = Braintree::Address.create(
8
+ customer_id: customer_response.customer.id,
9
+ postal_code: 30339
10
+ )
11
+
12
+ expect(address_response).to be_success
8
13
  end
9
14
  end
@@ -6,9 +6,12 @@ describe 'Braintree::CreditCard.find' do
6
6
  year = '2016'
7
7
  credit_card = Braintree::CreditCard.find(token_for(month, year))
8
8
 
9
- credit_card.last_4.should == TEST_CC_NUMBER[-4,4]
10
- credit_card.expiration_month.should == month
11
- credit_card.expiration_year.should == year
9
+ expect(credit_card.bin).to eq TEST_CC_NUMBER[0, 6]
10
+ expect(credit_card.card_type).to eq "FakeBraintree"
11
+ expect(credit_card.last_4).to eq TEST_CC_NUMBER[-4,4]
12
+ expect(credit_card.expiration_month).to eq month
13
+ expect(credit_card.expiration_year).to eq year
14
+ expect(credit_card.unique_number_identifier).to eq TEST_CC_NUMBER
12
15
  end
13
16
 
14
17
  def token_for(month, year)
@@ -19,17 +22,18 @@ end
19
22
  describe 'Braintree::CreditCard.sale' do
20
23
  it 'successfully creates a sale' do
21
24
  result = Braintree::CreditCard.sale(cc_token, amount: 10.00)
22
- result.should be_success
23
- Braintree::Transaction.find(result.transaction.id).should be
25
+
26
+ expect(result).to be_success
27
+ expect(Braintree::Transaction.find(result.transaction.id)).to be
24
28
  end
25
29
  end
26
30
 
27
-
28
31
  describe 'Braintree::CreditCard.create' do
29
32
  it 'allows creating a credit card without a customer' do
30
33
  result = Braintree::CreditCard.create(build_credit_card_hash)
31
- result.should be_success
32
- Braintree::CreditCard.find('token').should_not be_nil
34
+
35
+ expect(result).to be_success
36
+ expect(Braintree::CreditCard.find('token')).to_not be_nil
33
37
  end
34
38
 
35
39
  context 'with a customer' do
@@ -39,37 +43,37 @@ describe 'Braintree::CreditCard.create' do
39
43
 
40
44
  it 'fails to create a credit card if decline_all_cards is set' do
41
45
  FakeBraintree.decline_all_cards!
46
+
42
47
  result = Braintree::CreditCard.create(build_credit_card_hash)
43
- result.should_not be_success
48
+
49
+ expect(result).to_not be_success
44
50
  expect { Braintree::CreditCard.find('token') }.to raise_error Braintree::NotFoundError
45
- FakeBraintree.clear!
46
51
  end
47
52
 
48
53
  it 'fails to create a credit card if verify_all_cards is set and card is invalid' do
49
54
  FakeBraintree.verify_all_cards!
50
55
  result = Braintree::CreditCard.create(build_credit_card_hash.merge(number: '12345'))
51
- result.should_not be_success
56
+ expect(result).to_not be_success
52
57
  expect { Braintree::CreditCard.find('token') }.to raise_error Braintree::NotFoundError
53
- FakeBraintree.verify_all_cards = false
54
58
  end
55
59
 
56
60
  it 'successfully creates a credit card' do
57
61
  result = Braintree::CreditCard.create(build_credit_card_hash)
58
- result.should be_success
59
- Braintree::Customer.find(@customer.id).credit_cards.last.token.should == 'token'
60
- Braintree::Customer.find(@customer.id).credit_cards.last.should be_default
61
- Braintree::Customer.find(@customer.id).credit_cards.last.billing_address.postal_code.should == "94110"
62
+ expect(result).to be_success
63
+ expect(Braintree::Customer.find(@customer.id).credit_cards.last.token).to eq 'token'
64
+ expect(Braintree::Customer.find(@customer.id).credit_cards.last).to be_default
65
+ expect(Braintree::Customer.find(@customer.id).credit_cards.last.billing_address.postal_code).to eq "94110"
62
66
  end
63
67
 
64
68
  it 'only allows one credit card to be default' do
65
69
  result = Braintree::CreditCard.create(build_credit_card_hash)
66
- result.should be_success
70
+ expect(result).to be_success
67
71
  result = Braintree::CreditCard.create(build_credit_card_hash)
68
- result.should be_success
72
+ expect(result).to be_success
69
73
  # Reload the customer
70
74
  @customer = Braintree::Customer.find(@customer.id)
71
- @customer.credit_cards.select(&:default?).length.should == 1
72
- @customer.credit_cards.length.should == 2
75
+ expect(@customer.credit_cards.select(&:default?).length).to eq 1
76
+ expect(@customer.credit_cards.length).to eq 2
73
77
  end
74
78
  end
75
79
 
@@ -96,8 +100,8 @@ describe 'Braintree::CreditCard.update' do
96
100
  token = cc_token
97
101
 
98
102
  result = Braintree::CreditCard.update(token, expiration_date: new_expiration_date)
99
- result.should be_success
100
- Braintree::CreditCard.find(token).expiration_date.should == new_expiration_date
103
+ expect(result).to be_success
104
+ expect(Braintree::CreditCard.find(token).expiration_date).to eq new_expiration_date
101
105
  end
102
106
 
103
107
  it 'raises an error for a nonexistent credit card' do