class DuffelAPI::Services::PaymentIntentsService

Public Instance Methods

confirm(id, options = {}) click to toggle source

Confirms a payment intent by ID

@param id [String] @return [Resources::PaymentIntent] @raise [Errors::Error] when the Duffel API returns an error

# File lib/duffel_api/services/payment_intents_service.rb, line 35
def confirm(id, options = {})
  path = substitute_url_pattern("/payments/payment_intents/:id/actions/confirm",
                                "id" => id)

  params = options.delete(:params) || {}
  options[:params] = {}
  options[:params]["data"] = params

  begin
    response = make_request(:post, path, options)

    # Response doesn't raise any errors until #body is called
    response.tap(&:raw_body)
  end

  return if response.raw_body.nil?

  Resources::PaymentIntent.new(unenvelope_body(response.parsed_body), response)
end
create(options = {}) click to toggle source

Creates an payment intent

@option [required, Hash] :params the payload for creating the payment intent @return [Resources::PaymentIntent] @raise [Errors::Error] when the Duffel API returns an error

# File lib/duffel_api/services/payment_intents_service.rb, line 11
def create(options = {})
  path = "/payments/payment_intents"

  params = options.delete(:params) || {}
  options[:params] = {}
  options[:params]["data"] = params

  begin
    response = make_request(:post, path, options)

    # Response doesn't raise any errors until #body is called
    response.tap(&:raw_body)
  end

  return if response.raw_body.nil?

  Resources::PaymentIntent.new(unenvelope_body(response.parsed_body), response)
end
get(id, options = {}) click to toggle source

Retrieves a single payment intent by ID

@param id [String] @return [Resources::PaymentIntent] @raise [Errors::Error] when the Duffel API returns an error

# File lib/duffel_api/services/payment_intents_service.rb, line 60
def get(id, options = {})
  path = substitute_url_pattern("/payments/payment_intents/:id", "id" => id)

  response = make_request(:get, path, options)

  return if response.raw_body.nil?

  Resources::PaymentIntent.new(unenvelope_body(response.parsed_body), response)
end