Class: Spree::PaymentMethod::StripeCreditCard

Inherits:
CreditCard
  • Object
show all
Defined in:
app/models/spree/payment_method/stripe_credit_card.rb

Constant Summary collapse

CARD_TYPE_MAPPING =
{
  'American Express' => 'american_express',
  'Diners Club' => 'diners_club',
  'Visa' => 'visa'
}

Instance Method Summary collapse

Instance Method Details

#authorize(money, creditcard, transaction_options) ⇒ Object



36
37
38
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 36

def authorize(money, creditcard, transaction_options)
  gateway.authorize(*options_for_purchase_or_auth(money, creditcard, transaction_options))
end

#cancel(response_code) ⇒ Object



52
53
54
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 52

def cancel(response_code)
  gateway.void(response_code, {})
end

#capture(money, response_code, transaction_options) ⇒ Object



40
41
42
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 40

def capture(money, response_code, transaction_options)
  gateway.capture(money, response_code, transaction_options)
end

#create_profile(payment) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 56

def create_profile(payment)
  return unless payment.source.gateway_customer_profile_id.nil?

  options = {
    email: payment.order.email,
    login: preferred_secret_key,
  }.merge! address_for(payment)

  source = update_source!(payment.source)
  if source.number.blank? && source.gateway_payment_profile_id.present?
    creditcard = source.gateway_payment_profile_id
  else
    creditcard = source
  end

  response = gateway.store(creditcard, options)
  if response.success?
    payment.source.update_attributes!({
      cc_type: payment.source.cc_type, # side-effect of update_source!
      gateway_customer_profile_id: response.params['id'],
      gateway_payment_profile_id: response.params['default_source'] || response.params['default_card']
    })

  else
    payment.send(:gateway_error, response.message)
  end
end

#credit(money, _creditcard, response_code, _transaction_options) ⇒ Object



44
45
46
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 44

def credit(money, _creditcard, response_code, _transaction_options)
  gateway.refund(money, response_code, {})
end

#gateway_classObject



24
25
26
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 24

def gateway_class
  ActiveMerchant::Billing::StripeGateway
end

#partial_nameObject



16
17
18
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 16

def partial_name
  'stripe'
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 28

def payment_profiles_supported?
  true
end

#purchase(money, creditcard, transaction_options) ⇒ Object



32
33
34
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 32

def purchase(money, creditcard, transaction_options)
  gateway.purchase(*options_for_purchase_or_auth(money, creditcard, transaction_options))
end

#v3_elements?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 20

def v3_elements?
  !!preferred_v3_elements
end

#void(response_code, _creditcard, _transaction_options) ⇒ Object



48
49
50
# File 'app/models/spree/payment_method/stripe_credit_card.rb', line 48

def void(response_code, _creditcard, _transaction_options)
  gateway.void(response_code, {})
end