class Afterpay::Refund
Attributes
amount[RW]
error[RW]
merchant_reference[RW]
refund_id[RW]
refund_merchant_reference[RW]
refunded_at[RW]
request_id[RW]
Public Class Methods
execute(order_id:, amount:, request_id: nil, merchant_reference: nil, refund_merchant_reference: nil)
click to toggle source
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity
# File lib/afterpay/refund.rb, line 24 def self.execute(order_id:, amount:, request_id: nil, merchant_reference: nil, refund_merchant_reference: nil) request = Afterpay.client.post("/v2/payments/#{order_id}/refund") do |req| req.body = { requestId: request_id, amount: Utils::Money.api_hash(amount), merchantReference: merchant_reference, refundMerchantReference: refund_merchant_reference } end from_response(request.body) end
from_response(response)
click to toggle source
Builds Refund
from response
# File lib/afterpay/refund.rb, line 42 def self.from_response(response) return nil if response.nil? new( request_id: response[:requestId], amount: Utils::Money.from_response(response[:amount]), merchant_reference: response[:merchantReference], refund_id: response[:refundId], refunded_at: response[:refundedAt], refund_merchant_reference: response[:refundMerchantReference], error: response ) end
new(attributes = {})
click to toggle source
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
# File lib/afterpay/refund.rb, line 11 def initialize(attributes = {}) @request_id = attributes[:request_id] || "" @amount = attributes[:amount] || Money.from_amount(0) @merchant_reference = attributes[:merchant_reference] || "" @refund_id = attributes[:refund_id] || "" @refunded_at = attributes[:refunded_at] || "" @refund_merchant_reference = attributes[:refund_merchant_reference] || "" @error = Error.new(attributes[:error]) if attributes[:error] && attributes[:error][:errorId] end
Public Instance Methods
success?()
click to toggle source
# File lib/afterpay/refund.rb, line 37 def success? @error.nil? end