Class: Klarna::Checkout::Order

Inherits:
Resource
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/klarna/checkout/order.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

defaults=, #initialize, #json_sanitize, #to_json

Methods included from HasOne

#has_one

Methods included from HasMany

#has_many

Constructor Details

This class inherits a constructor from Klarna::Checkout::Resource

Instance Attribute Details

#completed_atObject

Returns the value of attribute completed_at.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def completed_at
  @completed_at
end

#created_atObject

Returns the value of attribute created_at.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def created_at
  @created_at
end

#expires_atObject

Returns the value of attribute expires_at.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def expires_at
  @expires_at
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def id
  @id
end

#last_modified_atObject

Returns the value of attribute last_modified_at.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def last_modified_at
  @last_modified_at
end

#localeObject

Returns the value of attribute locale.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def locale
  @locale
end

#merchant_order_dataObject

Returns the value of attribute merchant_order_data.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def merchant_order_data
  @merchant_order_data
end

#purchase_countryObject

Returns the value of attribute purchase_country.



13
14
15
# File 'lib/klarna/checkout/order.rb', line 13

def purchase_country
  @purchase_country
end

#purchase_currencyObject

Returns the value of attribute purchase_currency.



13
14
15
# File 'lib/klarna/checkout/order.rb', line 13

def purchase_currency
  @purchase_currency
end

#referenceObject

Returns the value of attribute reference.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def reference
  @reference
end

#reservationObject

Returns the value of attribute reservation.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def reservation
  @reservation
end

#started_atObject

Returns the value of attribute started_at.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def started_at
  @started_at
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/klarna/checkout/order.rb', line 9

def status
  @status
end

Class Method Details

.defaultsObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/klarna/checkout/order.rb', line 63

def defaults
  defaults = super

  defaults = {
    purchase_country:  Klarna::Checkout.default_country,
    purchase_currency: Klarna::Checkout.default_currency,
    merchant: {
      id: Klarna::Checkout.merchant_id
    }
  }.deep_merge(defaults)

  defaults
end

Instance Method Details

#as_jsonObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/klarna/checkout/order.rb', line 27

def as_json
  json = json_sanitize({
    :merchant_reference => (@merchant_reference && @merchant_reference.as_json),
    :purchase_country => @purchase_country,
    :purchase_currency => @purchase_currency,
    :locale => @locale,
    :merchant_order_data => @merchant_order_data,
    :cart => @cart.as_json,
    :gui => (@gui && @gui.as_json),
    :merchant => @merchant.as_json,
    :status => status,
    :shipping_address => (@shipping_address && @shipping_address.as_json)
  })
  if id || json[:gui].nil?
    json.delete(:gui)
  end
  if id
    json.delete(:merchant)
  end
  if status != 'created'
    json.delete(:status)
  end
  json
end