Module: FakeBraintree
- Defined in:
- lib/fake_braintree.rb,
lib/fake_braintree/version.rb,
lib/fake_braintree/sinatra_app.rb
Defined Under Namespace
Classes: SinatraApp
Constant Summary collapse
- VERSION =
"0.0.2"
Class Attribute Summary collapse
-
.customers ⇒ Object
Returns the value of attribute customers.
-
.decline_all_cards ⇒ Object
Returns the value of attribute decline_all_cards.
-
.failures ⇒ Object
Returns the value of attribute failures.
-
.subscriptions ⇒ Object
Returns the value of attribute subscriptions.
-
.transaction ⇒ Object
Returns the value of attribute transaction.
Class Method Summary collapse
- .activate! ⇒ Object
- .clear! ⇒ Object
- .create_failure ⇒ Object
- .credit_card_from_token(token) ⇒ Object
- .decline_all_cards! ⇒ Object
- .decline_all_cards? ⇒ Boolean
- .failure?(card_number) ⇒ Boolean
- .failure_response(card_number) ⇒ Object
- .generated_transaction ⇒ Object
Class Attribute Details
.customers ⇒ Object
Returns the value of attribute customers.
17 18 19 |
# File 'lib/fake_braintree.rb', line 17 def customers @customers end |
.decline_all_cards ⇒ Object
Returns the value of attribute decline_all_cards.
17 18 19 |
# File 'lib/fake_braintree.rb', line 17 def decline_all_cards @decline_all_cards end |
.failures ⇒ Object
Returns the value of attribute failures.
17 18 19 |
# File 'lib/fake_braintree.rb', line 17 def failures @failures end |
.subscriptions ⇒ Object
Returns the value of attribute subscriptions.
17 18 19 |
# File 'lib/fake_braintree.rb', line 17 def subscriptions @subscriptions end |
.transaction ⇒ Object
Returns the value of attribute transaction.
17 18 19 |
# File 'lib/fake_braintree.rb', line 17 def transaction @transaction end |
Class Method Details
.activate! ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/fake_braintree.rb', line 20 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
29 30 31 32 33 34 35 |
# File 'lib/fake_braintree.rb', line 29 def self.clear! self.customers = {} self.subscriptions = {} self.failures = {} self.transaction = {} self.decline_all_cards = false end |
.create_failure ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/fake_braintree.rb', line 55 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
72 73 74 75 76 77 78 79 |
# File 'lib/fake_braintree.rb', line 72 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
64 65 66 |
# File 'lib/fake_braintree.rb', line 64 def self.decline_all_cards! self.decline_all_cards = true end |
.decline_all_cards? ⇒ Boolean
68 69 70 |
# File 'lib/fake_braintree.rb', line 68 def self.decline_all_cards? self.decline_all_cards end |
.failure?(card_number) ⇒ Boolean
37 38 39 |
# File 'lib/fake_braintree.rb', line 37 def self.failure?(card_number) self.failures.include?(card_number) end |
.failure_response(card_number) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fake_braintree.rb', line 41 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 |
.generated_transaction ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/fake_braintree.rb', line 81 def self.generated_transaction {"status_history"=>[{"timestamp"=>Time.now, "amount"=>FakeBraintree.transaction[:amount], "transaction_source"=>"CP", "user"=>"copycopter", "status"=>"authorized"}, {"timestamp"=>Time.now, "amount"=>FakeBraintree.transaction[:amount], "transaction_source"=>"CP", "user"=>"copycopter", "status"=>FakeBraintree.transaction[:status]}], "created_at"=>(FakeBraintree.transaction[:created_at] || Time.now), "currency_iso_code"=>"USD", "settlement_batch_id"=>nil, "processor_authorization_code"=>"ZKB4VJ", "avs_postal_code_response_code"=>"I", "order_id"=>nil, "updated_at"=>Time.now, "refunded_transaction_id"=>nil, "amount"=>FakeBraintree.transaction[:amount], "credit_card"=>{"last_4"=>"1111", "card_type"=>"Visa", "token"=>"8yq7", "customer_location"=>"US", "expiration_year"=>"2013", "expiration_month"=>"02", "bin"=>"411111", "cardholder_name"=>"Chad Lee Pytel" }, "refund_id"=>nil, "add_ons"=>[], "shipping"=>{"region"=>nil, "company"=>nil, "country_name"=>nil, "extended_address"=>nil, "postal_code"=>nil, "id"=>nil, "street_address"=>nil, "country_code_numeric"=>nil, "last_name"=>nil, "locality"=>nil, "country_code_alpha2"=>nil, "country_code_alpha3"=>nil, "first_name"=>nil}, "id"=>"49sbx6", "merchant_account_id"=>"Thoughtbot", "type"=>"sale", "cvv_response_code"=>"I", "subscription_id"=>FakeBraintree.transaction[:subscription_id], "custom_fields"=>"\n", "discounts"=>[], "billing"=>{"region"=>nil, "company"=>nil, "country_name"=>nil, "extended_address"=>nil, "postal_code"=>nil, "id"=>nil, "street_address"=>nil, "country_code_numeric"=>nil, "last_name"=>nil, "locality"=>nil, "country_code_alpha2"=>nil, "country_code_alpha3"=>nil, "first_name"=>nil}, "processor_response_code"=>"1000", "refund_ids"=>[], "customer"=>{"company"=>nil, "id"=>"108427", "last_name"=>nil, "fax"=>nil, "phone"=>nil, "website"=>nil, "first_name"=>nil, "email"=>"[email protected]" }, "avs_error_response_code"=>nil, "processor_response_text"=>"Approved", "avs_street_address_response_code"=>"I", "status"=>FakeBraintree.transaction[:status], "gateway_rejection_reason"=>nil} end |