Class: Spree::PaymentMethod::BogusCreditCard
- Inherits:
-
PaymentMethod::CreditCard
- Object
- PaymentMethod::CreditCard
- Spree::PaymentMethod::BogusCreditCard
- Defined in:
- app/models/spree/payment_method/bogus_credit_card.rb
Constant Summary collapse
- TEST_VISA =
["4111111111111111", "4012888888881881", "4222222222222"]
- TEST_MC =
["5500000000000004", "5555555555554444", "5105105105105100"]
- TEST_AMEX =
["378282246310005", "371449635398431", "378734493671000", "340000000000009"]
- TEST_DISC =
["6011000000000004", "6011111111111117", "6011000990139424"]
- VALID_CCS =
["1", TEST_VISA, TEST_MC, TEST_AMEX, TEST_DISC].flatten
- AUTHORIZATION_CODE =
"12345"- FAILURE_MESSAGE =
"Bogus Gateway: Forced failure"- SUCCESS_MESSAGE =
"Bogus Gateway: Forced success"
Instance Attribute Summary collapse
-
#test ⇒ Object
Returns the value of attribute test.
Instance Method Summary collapse
- #actions ⇒ Object
- #authorize(_money, credit_card, _options = {}) ⇒ Object
- #capture(_money, authorization, _gateway_options) ⇒ Object
- #create_profile(payment) ⇒ Object
- #credit(_money, _credit_card, _response_code, _options = {}) ⇒ Object
- #gateway_class ⇒ Object
- #payment_profiles_supported? ⇒ Boolean
- #purchase(_money, credit_card, _options = {}) ⇒ Object
- #test? ⇒ Boolean
- #void(_response_code, _credit_card, options = {}) ⇒ Object
Instance Attribute Details
#test ⇒ Object
Returns the value of attribute test.
16 17 18 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 16 def test @test end |
Instance Method Details
#actions ⇒ Object
82 83 84 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 82 def actions %w[capture void credit] end |
#authorize(_money, credit_card, _options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 30 def (_money, credit_card, = {}) profile_id = credit_card.gateway_customer_profile_id = " - #{__method__}" if VALID_CCS.include?(credit_card.number) || profile_id&.starts_with?("BGS-") ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + , {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: {code: "D"}) else ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + , {message: FAILURE_MESSAGE + }, test: true) end end |
#capture(_money, authorization, _gateway_options) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 55 def capture(_money, , ) = " - #{__method__}" if == "12345" ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + , {}, test: true) else ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + , error: FAILURE_MESSAGE + , test: true) end end |
#create_profile(payment) ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 22 def create_profile(payment) return if payment.source.has_payment_profile? # simulate the storage of credit card profile using remote service if (success = VALID_CCS.include?(payment.source.number)) payment.source.update(gateway_customer_profile_id: generate_profile_id(success)) end end |
#credit(_money, _credit_card, _response_code, _options = {}) ⇒ Object
50 51 52 53 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 50 def credit(_money, _credit_card, _response_code, = {}) = " - #{__method__}" ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + , {}, test: true, authorization: AUTHORIZATION_CODE) end |
#gateway_class ⇒ Object
18 19 20 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 18 def gateway_class self.class end |
#payment_profiles_supported? ⇒ Boolean
78 79 80 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 78 def payment_profiles_supported? true end |
#purchase(_money, credit_card, _options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 40 def purchase(_money, credit_card, = {}) profile_id = credit_card.gateway_customer_profile_id = " - #{__method__}" if VALID_CCS.include?(credit_card.number) || profile_id&.starts_with?("BGS-") ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + , {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: {code: "M"}) else ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + , message: FAILURE_MESSAGE + , test: true) end end |
#test? ⇒ Boolean
73 74 75 76 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 73 def test? # Test mode is not really relevant with bogus gateway (no such thing as live server) true end |
#void(_response_code, _credit_card, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 64 def void(_response_code, _credit_card, = {}) = " - #{__method__}" if [:originator].completed? ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + , {}, test: true, authorization: AUTHORIZATION_CODE) else ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + , {}, test: true, authorization: AUTHORIZATION_CODE) end end |