Class: Payola::PaymentGateways::StripePaymentGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/payola/payment_gateways/stripe_payment_gateway.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ StripePaymentGateway

Returns a new instance of StripePaymentGateway.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 17

def initialize(**args)
  args.each do |name, value|
    public_send("#{name}=", value)
  end

  Stripe.api_key       = api_key || Payola.config.payment_gateway_api_key

  combined_id          = subscription_id || ''
  self.customer_id     = combined_id[/\A(cus_[A-Za-z0-9]{14})\:/, 1] || 'no_customer'
  self.subscription_id = combined_id[/\:(sub_[A-Za-z0-9]{14})\z/, 1] || 'no_subscription'
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



7
8
9
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 7

def amount
  @amount
end

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 7

def api_key
  @api_key
end

#customer_idObject

Returns the value of attribute customer_id.



7
8
9
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 7

def customer_id
  @customer_id
end

#intervalObject

Returns the value of attribute interval.



7
8
9
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 7

def interval
  @interval
end

#interval_countObject

Returns the value of attribute interval_count.



7
8
9
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 7

def interval_count
  @interval_count
end

#payment_tokenObject

Returns the value of attribute payment_token.



7
8
9
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 7

def payment_token
  @payment_token
end

#plan_idObject

Returns the value of attribute plan_id.



7
8
9
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 7

def plan_id
  @plan_id
end

#plan_nameObject

Returns the value of attribute plan_name.



7
8
9
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 7

def plan_name
  @plan_name
end

#subscription_idObject

Returns the value of attribute subscription_id.



7
8
9
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 7

def subscription_id
  @subscription_id
end

Class Method Details

.apply_subscription(**args) ⇒ Object



41
42
43
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 41

def self.apply_subscription(**args)
  new(**args).apply_subscription
end

Instance Method Details

#apply_subscriptionObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/payola/payment_gateways/stripe_payment_gateway.rb', line 29

def apply_subscription
  update_subscription_plan
  update_subscription_payment_token

  {
    status:                   subscription.status,
    plan:                     subscription.plan[:id],
    subscription_id:          "#{subscription.customer}:#{subscription.id}",
    last_four_of_credit_card: last_four_of_credit_card,
  }
end