lib/docdata/order/response.rb in docdata-order-1.0.3 vs lib/docdata/order/response.rb in docdata-order-2.0.0
- old
+ new
@@ -61,11 +61,11 @@
case payment_method
when PaymentMethod::IDEAL
params[:default_act] = true
params[:ideal_issuer_id] = issuer_id if issuer_id
- when PaymentMethod::PAYPAL
+ when PaymentMethod::PAYPAL, PaymentMethod::SOFORT
params[:default_act] = true
end
end
if return_url
@@ -91,19 +91,24 @@
Urls::MENU_LIVE_URL
end
end
def merchant_name
- options.fetch(:merchant).fetch(:name)
+ # Use subject merchant when present, otherwise fallback to merchant.
+ if options[:subject_merchant]
+ options.fetch(:subject_merchant).fetch(:name)
+ else
+ options.fetch(:merchant).fetch(:name)
+ end
end
def client_language
options.fetch(:shopper).fetch(:language)
end
def payment_method
- options[:payment_method]
+ options[:payment_method].to_s
end
def issuer_id
options[:issuer_id]
end
@@ -278,33 +283,33 @@
def cancelled?
authorization_status == "CANCELED"
end
- def account_iban
+ def consumer_iban
case payment_method
when PaymentMethod::IDEAL
payment_info = payment[:extended][:i_deal_payment_info]
payment_info[:shopper_bank_account][:iban] if payment_info && payment_info[:shopper_bank_account]
when PaymentMethod::SEPA_DIRECT_DEBIT
payment_info = payment[:extended][:sepa_direct_debit_payment_info]
payment_info[:iban] if payment_info
end
end
- def account_bic
+ def consumer_bic
case payment_method
when PaymentMethod::IDEAL
payment_info = payment[:extended][:i_deal_payment_info]
payment_info[:shopper_bank_account][:bic] if payment_info && payment_info[:shopper_bank_account]
when PaymentMethod::SEPA_DIRECT_DEBIT
payment_info = payment[:extended][:sepa_direct_debit_payment_info]
payment_info[:bic] if payment_info
end
end
- def account_name
+ def consumer_name
if payment_method == PaymentMethod::IDEAL
payment_info = payment[:extended][:i_deal_payment_info]
payment_info[:holder_name] if payment_info
end
end
@@ -317,12 +322,56 @@
end
private
def to_decimal(cents)
- total = BigDecimal(cents)
- total /= 100.0
- total
+ Amount.from_cents(cents).to_d
+ end
+ end
+
+ # Response to a refund operation.
+ class RefundResponse < Response
+ def data
+ body[:refund_response]
+ end
+
+ def success?
+ data.key?(:refund_success)
+ end
+
+ def error?
+ data.key?(:refund_errors)
+ end
+
+ def errors
+ data[:refund_errors]
+ end
+ end
+
+ # Response to a list payment methods operation.
+ class ListPaymentMethodsResponse < Response
+ def data
+ body[:list_payment_methods_response]
+ end
+
+ def success?
+ data.key?(:list_payment_methods_success)
+ end
+
+ def error?
+ data.key?(:list_payment_methods_errors)
+ end
+
+ def errors
+ data[:list_payment_methods_errors]
+ 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
+ end
end
end
end
end