Module: FakeBraintree
- Defined in:
- lib/fake_braintree.rb,
lib/fake_braintree/address.rb,
lib/fake_braintree/helpers.rb,
lib/fake_braintree/version.rb,
lib/fake_braintree/customer.rb,
lib/fake_braintree/redirect.rb,
lib/fake_braintree/credit_card.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: Address, CreditCard, Customer, Redirect, Registry, Server, SinatraApp, Subscription
Constant Summary
collapse
- VERSION =
'0.5.0'
- VALID_CREDIT_CARDS =
%w(4111111111111111 4005519200000004
4009348888881881 4012000033330026
4012000077777777 4012888888881881
4217651111111119 4500600000000061
5555555555554444 378282246310005
371449635398431 6011111111111117
3530111333300000)
Class Method Summary
collapse
Class Method Details
.activate! ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/fake_braintree.rb', line 21
def self.activate!
initialize_registry
self.verify_all_cards = false
set_configuration
clear!
boot_server
end
|
.clear! ⇒ Object
33
34
35
36
37
|
# File 'lib/fake_braintree.rb', line 33
def self.clear!
self.registry.clear!
self.decline_all_cards = false
clear_log!
end
|
.clear_log! ⇒ Object
39
40
41
42
|
# File 'lib/fake_braintree.rb', line 39
def self.clear_log!
FileUtils.mkdir_p(File.dirname(log_file_path))
File.new(log_file_path, 'w').close
end
|
.create_failure ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/fake_braintree.rb', line 66
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
|
.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?
decline_all_cards
end
|
.failure?(card_number) ⇒ Boolean
44
45
46
|
# File 'lib/fake_braintree.rb', line 44
def self.failure?(card_number)
registry.failure?(card_number)
end
|
.failure_response(card_number = nil) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/fake_braintree.rb', line 48
def self.failure_response(card_number = nil)
failure = registry.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
|
.generate_transaction(options = {}) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/fake_braintree.rb', line 91
def self.generate_transaction(options = {})
history_item = {
'timestamp' => Time.now,
'amount' => options[:amount],
'status' => options[:status]
}
created_at = options[:created_at] || Time.now
{
'status_history' => [history_item],
'subscription_id' => options[:subscription_id],
'created_at' => created_at,
'amount' => options[:amount]
}
end
|
.log_file_path ⇒ Object
29
30
31
|
# File 'lib/fake_braintree.rb', line 29
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
|