lib/docdata/order/response.rb in docdata-order-2.1.0 vs lib/docdata/order/response.rb in docdata-order-2.2.0
- old
+ new
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require "uri"
+require 'uri'
module Docdata
module Order
# Base class for responses.
class Response
@@ -20,11 +20,11 @@
def error_message
errors[:error] if errors
end
def error_code
- errors[:error].attributes["code"] if errors
+ errors[:error].attributes['code'] if errors
end
end
# Response to a create operation.
class CreateResponse < Response
@@ -48,11 +48,11 @@
data[:create_success][:key]
end
def redirect_url
params = {
- command: "show_payment_cluster",
+ command: 'show_payment_cluster',
merchant_name: merchant_name,
client_language: client_language,
payment_cluster_key: order_key
}
@@ -68,14 +68,14 @@
end
end
if return_url
params.merge!(
- return_url_success: build_return_url("success"),
- return_url_canceled: build_return_url("cancelled"),
- return_url_pending: build_return_url("pending"),
- return_url_error: build_return_url("error")
+ return_url_success: build_return_url('success'),
+ return_url_canceled: build_return_url('cancelled'),
+ return_url_pending: build_return_url('pending'),
+ return_url_error: build_return_url('error')
)
end
uri = URI.parse(redirect_base_url)
uri.query = URI.encode_www_form(params)
@@ -117,11 +117,11 @@
options[:return_url]
end
def build_return_url(status)
uri = URI.parse(return_url)
- query = URI.decode_www_form(uri.query || "") << ["status", status]
+ query = URI.decode_www_form(uri.query || '') << ['status', status]
uri.query = URI.encode_www_form(query)
uri.to_s
end
end
@@ -152,10 +152,14 @@
end
def payment_id
payment_success[:id] if payment_success
end
+
+ def payment_status
+ payment_success[:status] if payment_success
+ end
end
# Response to a extended status operation.
class ExtendedStatusResponse < Response
def data
@@ -222,14 +226,26 @@
# CANCEL_REQUESTED A cancel request sent to acquirer.
def authorization_status
authorization[:status] if authorization
end
+ def authorization_amount
+ to_decimal(authorization[:amount]) if authorization
+ end
+
+ def authorization_currency
+ authorization[:amount].attributes['currency'] if authorization
+ end
+
def approximate_totals
report[:approximate_totals]
end
+ def exchanged_to
+ report[:approximate_totals][:@exchanged_to]
+ end
+
def total_registered
to_decimal(approximate_totals[:total_registered])
end
def total_shopper_pending
@@ -275,16 +291,16 @@
def reversed?
total_registered == total_reversed
end
def started?
- (authorization_status == "NEW" || authorization_status == "STARTED" ||
- (total_captured.zero? && total_acquirer_approved.zero?)) && authorization_status != "CANCELED"
+ (authorization_status == 'NEW' || authorization_status == 'STARTED' ||
+ (total_captured.zero? && total_acquirer_approved.zero?)) && authorization_status != 'CANCELED'
end
def cancelled?
- authorization_status == "CANCELED"
+ authorization_status == 'CANCELED'
end
def consumer_iban
case payment_method
when PaymentMethod::IDEAL
@@ -366,10 +382,10 @@
end
def payment_methods
data[:list_payment_methods_success][:payment_method].map do |payment_method|
method = PaymentMethod.new(payment_method[:name])
- method.issuers = payment_method[:issuers][:issuer].map { |issuer| [issuer.attributes["id"], issuer.to_s] }.to_h if payment_method.key?(:issuers)
+ method.issuers = payment_method[:issuers][:issuer].to_h { |issuer| [issuer.attributes['id'], issuer.to_s] } if payment_method.key?(:issuers)
method
end
end
end
end