Class: Pay::Payment

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/payment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(intent) ⇒ Payment

Returns a new instance of Payment.



12
13
14
# File 'lib/pay/payment.rb', line 12

def initialize(intent)
  @intent = intent
end

Instance Attribute Details

#intentObject (readonly)

Returns the value of attribute intent.



3
4
5
# File 'lib/pay/payment.rb', line 3

def intent
  @intent
end

Class Method Details

.from_id(id) ⇒ Object



7
8
9
10
# File 'lib/pay/payment.rb', line 7

def self.from_id(id)
  intent = id.start_with?("seti_") ? ::Stripe::SetupIntent.retrieve(id) : ::Stripe::PaymentIntent.retrieve(id)
  new(intent)
end

Instance Method Details

#amount_with_currencyObject



44
45
46
# File 'lib/pay/payment.rb', line 44

def amount_with_currency
  Pay::Currency.format(amount, currency: currency)
end

#canceled?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/pay/payment.rb', line 24

def canceled?
  status == "canceled"
end

#cancelled?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/pay/payment.rb', line 28

def cancelled?
  canceled?
end

#payment_intent?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/pay/payment.rb', line 36

def payment_intent?
  intent.is_a?(::Stripe::PaymentIntent)
end

#requires_action?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/pay/payment.rb', line 20

def requires_action?
  status == "requires_action"
end

#requires_payment_method?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/pay/payment.rb', line 16

def requires_payment_method?
  status == "requires_payment_method"
end

#setup_intent?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/pay/payment.rb', line 40

def setup_intent?
  intent.is_a?(::Stripe::SetupIntent)
end

#succeeded?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/pay/payment.rb', line 32

def succeeded?
  status == "succeeded"
end

#validateObject



48
49
50
51
52
53
54
# File 'lib/pay/payment.rb', line 48

def validate
  if requires_payment_method?
    raise Pay::InvalidPaymentMethod.new(self)
  elsif requires_action?
    raise Pay::ActionRequired.new(self)
  end
end