Sha256: 53e0e37be51f522c8c23b40ef0a88113f8eae170f7c0c77f4c0de522cc053467

Contents?: true

Size: 1022 Bytes

Versions: 13

Compression:

Stored size: 1022 Bytes

Contents

module Pay
  class Payment
    attr_reader :intent

    delegate :id, :amount, :client_secret, :customer, :status, :confirm, to: :intent

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

    def initialize(intent)
      @intent = intent
    end

    def requires_payment_method?
      status == "requires_payment_method"
    end

    def requires_action?
      status == "requires_action"
    end

    def canceled?
      status == "canceled"
    end

    def cancelled?
      canceled?
    end

    def succeeded?
      status == "succeeded"
    end

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

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

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pay-3.0.13 lib/pay/payment.rb
pay-3.0.12 lib/pay/payment.rb
pay-3.0.11 lib/pay/payment.rb
pay-3.0.10 lib/pay/payment.rb
pay-3.0.9 lib/pay/payment.rb
pay-3.0.8 lib/pay/payment.rb
pay-3.0.7 lib/pay/payment.rb
pay-3.0.6 lib/pay/payment.rb
pay-3.0.5 lib/pay/payment.rb
pay-3.0.4 lib/pay/payment.rb
pay-3.0.2 lib/pay/payment.rb
pay-3.0.1 lib/pay/payment.rb
pay-3.0.0 lib/pay/payment.rb