Class: Afterpay::Refund
- Inherits:
-
Object
- Object
- Afterpay::Refund
- Defined in:
- lib/afterpay/refund.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#error ⇒ Object
Returns the value of attribute error.
-
#merchant_reference ⇒ Object
Returns the value of attribute merchant_reference.
-
#refund_id ⇒ Object
Returns the value of attribute refund_id.
-
#refund_merchant_reference ⇒ Object
Returns the value of attribute refund_merchant_reference.
-
#refunded_at ⇒ Object
Returns the value of attribute refunded_at.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
Class Method Summary collapse
-
.execute(order_id:, amount:, request_id: nil, merchant_reference: nil, refund_merchant_reference: nil) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity.
-
.from_response(response) ⇒ Object
Builds Refund from response.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Refund
constructor
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
- #success? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Refund
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
5 6 7 |
# File 'lib/afterpay/refund.rb', line 5 def amount @amount end |
#error ⇒ Object
Returns the value of attribute error.
5 6 7 |
# File 'lib/afterpay/refund.rb', line 5 def error @error end |
#merchant_reference ⇒ Object
Returns the value of attribute merchant_reference.
5 6 7 |
# File 'lib/afterpay/refund.rb', line 5 def merchant_reference @merchant_reference end |
#refund_id ⇒ Object
Returns the value of attribute refund_id.
5 6 7 |
# File 'lib/afterpay/refund.rb', line 5 def refund_id @refund_id end |
#refund_merchant_reference ⇒ Object
Returns the value of attribute refund_merchant_reference.
5 6 7 |
# File 'lib/afterpay/refund.rb', line 5 def refund_merchant_reference @refund_merchant_reference end |
#refunded_at ⇒ Object
Returns the value of attribute refunded_at.
5 6 7 |
# File 'lib/afterpay/refund.rb', line 5 def refunded_at @refunded_at end |
#request_id ⇒ Object
Returns the value of attribute request_id.
5 6 7 |
# File 'lib/afterpay/refund.rb', line 5 def request_id @request_id end |
Class Method Details
.execute(order_id:, amount:, request_id: nil, merchant_reference: nil, refund_merchant_reference: nil) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity
24 25 26 27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
Builds Refund from response
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 |
Instance Method Details
#success? ⇒ Boolean
37 38 39 |
# File 'lib/afterpay/refund.rb', line 37 def success? @error.nil? end |