Class: Reji::Payment

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

Instance Method Summary collapse

Constructor Details

#initialize(payment_intent) ⇒ Payment

Returns a new instance of Payment.



5
6
7
# File 'lib/reji/payment.rb', line 5

def initialize(payment_intent)
  @payment_intent = payment_intent
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key) ⇒ Object

Dynamically get values from the Stripe PaymentIntent.



57
58
59
# File 'lib/reji/payment.rb', line 57

def method_missing(key)
  @payment_intent[key]
end

Instance Method Details

#amountObject

Get the total amount that will be paid.



10
11
12
# File 'lib/reji/payment.rb', line 10

def amount
  Reji.format_amount(raw_amount, @payment_intent.currency)
end

#as_stripe_payment_intentObject

The Stripe PaymentIntent instance.



52
53
54
# File 'lib/reji/payment.rb', line 52

def as_stripe_payment_intent
  @payment_intent
end

#cancelled?Boolean

Determine if the payment was cancelled.

Returns:

  • (Boolean)


35
36
37
# File 'lib/reji/payment.rb', line 35

def cancelled?
  @payment_intent.status == 'canceled'
end

#client_secretObject

The Stripe PaymentIntent client secret.



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

def client_secret
  @payment_intent.client_secret
end

#raw_amountObject

Get the raw total amount that will be paid.



15
16
17
# File 'lib/reji/payment.rb', line 15

def raw_amount
  @payment_intent.amount
end

#requires_actionObject

Determine if the payment needs an extra action like 3D Secure.



30
31
32
# File 'lib/reji/payment.rb', line 30

def requires_action
  @payment_intent.status == 'requires_action'
end

#requires_payment_methodObject

Determine if the payment needs a valid payment method.



25
26
27
# File 'lib/reji/payment.rb', line 25

def requires_payment_method
  @payment_intent.status == 'requires_payment_method'
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/reji/payment.rb', line 61

def respond_to_missing?(method_name, include_private = false)
  super
end

#succeeded?Boolean

Determine if the payment was successful.

Returns:

  • (Boolean)


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

def succeeded?
  @payment_intent.status == 'succeeded'
end

#validateObject

Validate if the payment intent was successful and throw an exception if not.



45
46
47
48
49
# File 'lib/reji/payment.rb', line 45

def validate
  raise Reji::PaymentFailureError.invalid_payment_method(self) if requires_payment_method

  raise Reji::PaymentActionRequiredError.incomplete(self) if requires_action
end