Class: Mollie::Payment

Inherits:
Base
  • Object
show all
Defined in:
lib/mollie/payment.rb,
lib/mollie/payment/line.rb,
lib/mollie/payment/refund.rb,
lib/mollie/payment/capture.rb,
lib/mollie/payment/chargeback.rb

Defined Under Namespace

Classes: Capture, Chargeback, Line, Refund

Constant Summary collapse

STATUS_OPEN =
'open'.freeze
STATUS_CANCELED =
'canceled'.freeze
STATUS_PENDING =
'pending'.freeze
STATUS_EXPIRED =
'expired'.freeze
STATUS_FAILED =
'failed'.freeze
STATUS_PAID =
'paid'.freeze
STATUS_AUTHORIZED =
'authorized'.freeze
RECURRINGTYPE_NONE =
nil
RECURRINGTYPE_FIRST =
'first'.freeze
RECURRINGTYPE_RECURRING =
'recurring'.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes

Instance Method Summary collapse

Methods inherited from Base

all, #assign_attributes, cancel, create, #delete, delete, get, id_param, #initialize, parent_id, request, resource_name, update, #update

Constructor Details

This class inherits a constructor from Mollie::Base

Instance Attribute Details

Returns the value of attribute _links.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def _links
  @_links
end

#amountObject

Returns the value of attribute amount.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def amount
  @amount
end

#amount_capturedObject

Returns the value of attribute amount_captured.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def amount_captured
  @amount_captured
end

#amount_charged_backObject

Returns the value of attribute amount_charged_back.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def amount_charged_back
  @amount_charged_back
end

#amount_refundedObject

Returns the value of attribute amount_refunded.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def amount_refunded
  @amount_refunded
end

#amount_remainingObject

Returns the value of attribute amount_remaining.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def amount_remaining
  @amount_remaining
end

#application_feeObject

Returns the value of attribute application_fee.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def application_fee
  @application_fee
end

#authorized_atObject

Returns the value of attribute authorized_at.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def authorized_at
  @authorized_at
end

#billing_addressObject

Returns the value of attribute billing_address.



52
53
54
# File 'lib/mollie/payment.rb', line 52

def billing_address
  @billing_address
end

#cancel_urlObject

Returns the value of attribute cancel_url.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def cancel_url
  @cancel_url
end

#canceled_atObject

Returns the value of attribute canceled_at.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def canceled_at
  @canceled_at
end

#country_codeObject

Returns the value of attribute country_code.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def country_code
  @country_code
end

#created_atObject

Returns the value of attribute created_at.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def created_at
  @created_at
end

#customer_idObject

Returns the value of attribute customer_id.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def customer_id
  @customer_id
end

#descriptionObject

Returns the value of attribute description.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def description
  @description
end

#detailsObject

Returns the value of attribute details.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def details
  @details
end

#expired_atObject

Returns the value of attribute expired_at.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def expired_at
  @expired_at
end

#expires_atObject

Returns the value of attribute expires_at.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def expires_at
  @expires_at
end

#failed_atObject

Returns the value of attribute failed_at.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def failed_at
  @failed_at
end

#idObject

Returns the value of attribute id.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def id
  @id
end

#is_cancelableObject

Returns the value of attribute is_cancelable.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def is_cancelable
  @is_cancelable
end

#linesObject

Returns the value of attribute lines.



52
53
54
# File 'lib/mollie/payment.rb', line 52

def lines
  @lines
end

#localeObject

Returns the value of attribute locale.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def locale
  @locale
end

#mandate_idObject

Returns the value of attribute mandate_id.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def mandate_id
  @mandate_id
end

#metadataObject

Returns the value of attribute metadata.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def 
  @metadata
end

#methodObject

Returns the value of attribute method.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def method
  @method
end

#modeObject

Returns the value of attribute mode.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def mode
  @mode
end

#order_idObject

Returns the value of attribute order_id.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def order_id
  @order_id
end

Returns the value of attribute paid_at.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def paid_at
  @paid_at
end

#profile_idObject

Returns the value of attribute profile_id.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def profile_id
  @profile_id
end

#redirect_urlObject

Returns the value of attribute redirect_url.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def redirect_url
  @redirect_url
end

#restrict_payment_methods_to_countryObject

Returns the value of attribute restrict_payment_methods_to_country.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def restrict_payment_methods_to_country
  @restrict_payment_methods_to_country
end

#sequence_typeObject

Returns the value of attribute sequence_type.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def sequence_type
  @sequence_type
end

#settlement_amountObject

Returns the value of attribute settlement_amount.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def settlement_amount
  @settlement_amount
end

#settlement_idObject

Returns the value of attribute settlement_id.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def settlement_id
  @settlement_id
end

#shipping_addressObject

Returns the value of attribute shipping_address.



52
53
54
# File 'lib/mollie/payment.rb', line 52

def shipping_address
  @shipping_address
end

#statusObject

Returns the value of attribute status.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def status
  @status
end

#subscription_idObject

Returns the value of attribute subscription_id.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def subscription_id
  @subscription_id
end

#webhook_urlObject

Returns the value of attribute webhook_url.



15
16
17
# File 'lib/mollie/payment.rb', line 15

def webhook_url
  @webhook_url
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/mollie/payment.rb', line 82

def authorized?
  status == STATUS_AUTHORIZED
end

#cancelable?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/mollie/payment.rb', line 94

def cancelable?
  is_cancelable
end

#canceled?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/mollie/payment.rb', line 62

def canceled?
  status == STATUS_CANCELED
end

#captures(options = {}) ⇒ Object



239
240
241
242
243
244
245
246
247
# File 'lib/mollie/payment.rb', line 239

def captures(options = {})
  resources = (attributes['_embedded']['captures'] if attributes['_embedded'])

  if resources.nil?
    Payment::Capture.all(options.merge(payment_id: id))
  else
    List.new({ '_embedded' => { 'captures' => resources } }, Payment::Capture)
  end
end

#chargebacks(options = {}) ⇒ Object



229
230
231
232
233
234
235
236
237
# File 'lib/mollie/payment.rb', line 229

def chargebacks(options = {})
  resources = (attributes['_embedded']['chargebacks'] if attributes['_embedded'])

  if resources.nil?
    Payment::Chargeback.all(options.merge(payment_id: id))
  else
    List.new({ '_embedded' => { 'chargebacks' => resources } }, Payment::Chargeback)
  end
end

#checkout_urlObject



204
205
206
# File 'lib/mollie/payment.rb', line 204

def checkout_url
  Util.extract_url(links, 'checkout')
end

#customer(options = {}) ⇒ Object



249
250
251
252
# File 'lib/mollie/payment.rb', line 249

def customer(options = {})
  return if customer_id.nil?
  Customer.get(customer_id, options)
end

#expired?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/mollie/payment.rb', line 70

def expired?
  status == STATUS_EXPIRED
end

#failed?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/mollie/payment.rb', line 74

def failed?
  status == STATUS_FAILED
end

#mandate(options = {}) ⇒ Object



254
255
256
257
258
259
# File 'lib/mollie/payment.rb', line 254

def mandate(options = {})
  return if customer_id.nil?
  return if mandate_id.nil?
  options = options.merge(customer_id: customer_id)
  Customer::Mandate.get(mandate_id, options)
end

#open?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/mollie/payment.rb', line 58

def open?
  status == STATUS_OPEN
end

#order(options = {}) ⇒ Object



273
274
275
276
# File 'lib/mollie/payment.rb', line 273

def order(options = {})
  return if order_id.nil?
  Order.get(order_id, options)
end

#paid?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/mollie/payment.rb', line 78

def paid?
  status == STATUS_PAID
end

#pending?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/mollie/payment.rb', line 66

def pending?
  status == STATUS_PENDING
end

#refund!(options = {}) ⇒ Object



208
209
210
211
212
213
# File 'lib/mollie/payment.rb', line 208

def refund!(options = {})
  options[:payment_id] = id
  # refund full amount by default
  options[:amount] ||= amount.to_h
  Payment::Refund.create(options)
end

#refunded?Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
92
# File 'lib/mollie/payment.rb', line 86

def refunded?
  if amount_refunded
    amount_refunded.value > 0
  else
    false
  end
end

#refunds(options = {}) ⇒ Object



219
220
221
222
223
224
225
226
227
# File 'lib/mollie/payment.rb', line 219

def refunds(options = {})
  resources = (attributes['_embedded']['refunds'] if attributes['_embedded'])

  if resources.nil?
    Payment::Refund.all(options.merge(payment_id: id))
  else
    List.new({ '_embedded' => { 'refunds' => resources } }, Payment::Refund)
  end
end

#release_authorization(options = {}) ⇒ Object



215
216
217
# File 'lib/mollie/payment.rb', line 215

def release_authorization(options = {})
  Client.instance.perform_http_call("POST", "payments/#{id}", "release-authorization", {}, options) == {}
end

#settlement(options = {}) ⇒ Object



261
262
263
264
# File 'lib/mollie/payment.rb', line 261

def settlement(options = {})
  return if settlement_id.nil?
  Settlement.get(settlement_id, options)
end

#subscription(options = {}) ⇒ Object



266
267
268
269
270
271
# File 'lib/mollie/payment.rb', line 266

def subscription(options = {})
  return if customer_id.nil?
  return if subscription_id.nil?
  options = options.merge(customer_id: customer_id)
  Customer::Subscription.get(subscription_id, options)
end