Module: FakeBraintree
- Defined in:
- lib/fake_braintree.rb,
lib/fake_braintree/helpers.rb,
lib/fake_braintree/version.rb,
lib/fake_braintree/customer.rb,
lib/fake_braintree/sinatra_app.rb,
lib/fake_braintree/subscription.rb,
lib/fake_braintree/valid_credit_cards.rb
Defined Under Namespace
Modules: Helpers
Classes: Customer, SinatraApp, Subscription
Constant Summary
collapse
- VERSION =
"0.0.5"
- VALID_CREDIT_CARDS =
%w(4111111111111111 4005519200000004
4009348888881881 4012000033330026
4012000077777777 4012888888881881
4217651111111119 4500600000000061
5555555555554444 378282246310005
371449635398431 6011111111111117
3530111333300000)
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.customers ⇒ Object
Returns the value of attribute customers.
22
23
24
|
# File 'lib/fake_braintree.rb', line 22
def customers
@customers
end
|
.decline_all_cards ⇒ Object
Returns the value of attribute decline_all_cards.
22
23
24
|
# File 'lib/fake_braintree.rb', line 22
def decline_all_cards
@decline_all_cards
end
|
.failures ⇒ Object
Returns the value of attribute failures.
22
23
24
|
# File 'lib/fake_braintree.rb', line 22
def failures
@failures
end
|
.subscriptions ⇒ Object
Returns the value of attribute subscriptions.
22
23
24
|
# File 'lib/fake_braintree.rb', line 22
def subscriptions
@subscriptions
end
|
.transaction ⇒ Object
Returns the value of attribute transaction.
22
23
24
|
# File 'lib/fake_braintree.rb', line 22
def transaction
@transaction
end
|
.verify_all_cards ⇒ Object
Returns the value of attribute verify_all_cards.
22
23
24
|
# File 'lib/fake_braintree.rb', line 22
def verify_all_cards
@verify_all_cards
end
|
Class Method Details
.activate! ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/fake_braintree.rb', line 25
def self.activate!
Braintree::Configuration.environment = :production
Braintree::Configuration.merchant_id = "xxx"
Braintree::Configuration.public_key = "xxx"
Braintree::Configuration.private_key = "xxx"
clear!
ShamRack.mount(FakeBraintree::SinatraApp, "www.braintreegateway.com", 443)
end
|
.clear! ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/fake_braintree.rb', line 38
def self.clear!
self.customers = {}
self.subscriptions = {}
self.failures = {}
self.transaction = {}
self.decline_all_cards = false
clear_log!
end
|
.clear_log! ⇒ Object
47
48
49
50
|
# File 'lib/fake_braintree.rb', line 47
def self.clear_log!
FileUtils.mkdir_p(File.dirname(log_file_path))
File.new(log_file_path, 'w').close
end
|
.create_failure ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/fake_braintree.rb', line 70
def self.create_failure
{ "message" => "Do Not Honor",
"verification" => { "status" => "processor_declined",
"processor_response_text" => "Do Not Honor",
"processor_response_code" => '2000' },
"errors" => { 'errors' => [] },
"params" => {} }
end
|
.credit_card_from_token(token) ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/fake_braintree.rb', line 91
def self.credit_card_from_token(token)
self.customers.values.detect do |customer|
next unless customer.key?("credit_cards")
card = customer["credit_cards"].detect {|card| card["token"] == token }
return card if card
end
end
|
.decline_all_cards! ⇒ Object
79
80
81
|
# File 'lib/fake_braintree.rb', line 79
def self.decline_all_cards!
self.decline_all_cards = true
end
|
.decline_all_cards? ⇒ Boolean
83
84
85
|
# File 'lib/fake_braintree.rb', line 83
def self.decline_all_cards?
self.decline_all_cards
end
|
.failure?(card_number) ⇒ Boolean
52
53
54
|
# File 'lib/fake_braintree.rb', line 52
def self.failure?(card_number)
self.failures.include?(card_number)
end
|
.failure_response(card_number) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/fake_braintree.rb', line 56
def self.failure_response(card_number)
failure = self.failures[card_number] || {}
failure["errors"] ||= { "errors" => [] }
{ "message" => failure["message"],
"verification" => { "status" => failure["status"],
"processor_response_text" => failure["message"],
"processor_response_code" => failure["code"],
"gateway_rejection_reason" => "cvv",
"cvv_response_code" => failure["code"] },
"errors" => failure["errors"],
"params" => {}}
end
|
.log_file_path ⇒ Object
34
35
36
|
# File 'lib/fake_braintree.rb', line 34
def self.log_file_path
'tmp/log'
end
|
.verify_all_cards! ⇒ Object
87
88
89
|
# File 'lib/fake_braintree.rb', line 87
def self.verify_all_cards!
self.verify_all_cards = true
end
|