class YandexMoney::ExternalPayment

Payments from bank cards without authorization

@see api.yandex.com/money/doc/dg/reference/process-external-payments.xml @see tech.yandex.ru/money/doc/dg/reference/process-external-payments-docpage/

Public Class Methods

get_instance_id(client_id) click to toggle source

Registers instance of application

@see api.yandex.com/money/doc/dg/reference/instance-id.xml @see tech.yandex.ru/money/doc/dg/reference/instance-id-docpage/

@param client_id [String] An identifier of application

@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error). The application should repeat the request with the same parameters later.

@return [RecursiveOpenStruct] A status of operation

# File lib/yandex_money/external_payment.rb, line 26
def self.get_instance_id(client_id)
  response = send_external_payment_request("/api/instance-id", client_id: client_id)
  RecursiveOpenStruct.new response.body
end
new(instance_id) click to toggle source
# File lib/yandex_money/external_payment.rb, line 11
def initialize(instance_id)
  @instance_id = instance_id
end

Private Class Methods

send_external_payment_request(uri, options) click to toggle source
# File lib/yandex_money/external_payment.rb, line 67
def self.send_external_payment_request(uri, options)
  response = self.post(uri, headers: {
    "Content-Type" => "application/x-www-form-urlencoded"
  }, body: options)
  case response.status
  when 400 then raise YandexMoney::InvalidRequestError.new response
  when 401 then raise YandexMoney::UnauthorizedError.new response
  when 403 then raise YandexMoney::InsufficientScopeError response
  when 500 then raise YandexMoney::ServerError
  else
    response
  end
end

Public Instance Methods

process_external_payment(payment_options) click to toggle source

Confirms a payment that was created using the request-extenral-payment method

@see api.yandex.com/money/doc/dg/reference/process-external-payment.xml @see tech.yandex.ru/money/doc/dg/reference/process-external-payment-docpage/

@param payment_options [Hash] Method's parameters. Check out docs for more information.

@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error). The application should repeat the request with the same parameters later.

@return [RecursiveOpenStruct] A status of payment and additional steps for authorization (if needed)

# File lib/yandex_money/external_payment.rb, line 59
def process_external_payment(payment_options)
  payment_options[:instance_id] = @instance_id
  response = self.class.send_external_payment_request("/api/process-external-payment", payment_options)
  RecursiveOpenStruct.new response.body
end
request_external_payment(payment_options) click to toggle source

Requests a external payment

@see api.yandex.com/money/doc/dg/reference/request-external-payment.xml @see tech.yandex.ru/money/doc/dg/reference/request-external-payment-docpage/

@param payment_options [Hash] Method's parameters. Check out docs for more information.

@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error). The application should repeat the request with the same parameters later.

@return [RecursiveOpenStruct] A struct, containing `payment_id` and additional information about a recipient and payer

# File lib/yandex_money/external_payment.rb, line 42
def request_external_payment(payment_options)
  payment_options[:instance_id] = @instance_id
  response = self.class.send_external_payment_request("/api/request-external-payment", payment_options)
  RecursiveOpenStruct.new response.body
end