Class: Klarna::Checkout::Order
- Inherits:
-
Object
- Object
- Klarna::Checkout::Order
- Extended by:
- ApiUtilities::ParseResponse, Klarna::Checkout::Operations::Acknowledge, Klarna::Checkout::Operations::CreateRecurring, Klarna::Checkout::Operations::Fetch, Resources::Authentication
- Includes:
- ApiUtilities::ConnectionUtilities, ApiUtilities::ParseResponse, Klarna::Checkout::Operations::Cancel, Klarna::Checkout::Operations::Capture, Klarna::Checkout::Operations::Create, Klarna::Checkout::Operations::Refund, Resources::Authentication, Resources::MerchantUrls, Validations::OrderValidations
- Defined in:
- lib/klarna/checkout/order.rb
Constant Summary
Constants included from Klarna::Checkout::Operations::Fetch
Klarna::Checkout::Operations::Fetch::PATH_CHECKOUT, Klarna::Checkout::Operations::Fetch::PATH_CONFIRMED
Constants included from ApiUtilities::ConnectionUtilities
ApiUtilities::ConnectionUtilities::KLARNA_PRODUCTION_URL, ApiUtilities::ConnectionUtilities::KLARNA_SANDBOX_URL
Constants included from Klarna::Checkout::Operations::Create
Klarna::Checkout::Operations::Create::CREATE_ORDER_PATH
Constants included from Validations::OrderValidations
Validations::OrderValidations::REQUIRED_ITEM_KEYS, Validations::OrderValidations::REQUIRED_ORDER_KEYS
Instance Attribute Summary collapse
-
#api_order ⇒ Object
Returns the value of attribute api_order.
-
#klarna_response ⇒ Object
Returns the value of attribute klarna_response.
-
#payment_form ⇒ Object
Returns the value of attribute payment_form.
-
#recurring ⇒ Object
Returns the value of attribute recurring.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
- .acknowledge(ref) ⇒ Object
-
.create_recurring(locale:, order_lines:, order_amount:, order_tax_amount:, purchase_currency:, recurring_token:) ⇒ Object
For creating an order, using a recurring_token.
-
.find(ref) ⇒ Object
Returns an instance of the order.
-
.find_checkout(ref) ⇒ Object
Same as find but to be used during checkout stage.
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancels the order through Klarna API.
-
#capture ⇒ Object
Captures the order through Klarna API.
-
#execute ⇒ Object
Creates an order Returns prepolulated order object based on Klarna API response.
-
#initialize(header:, items:, options: {}, recurring: false, customer: {}, checkout_url: nil, terms_url: nil) ⇒ Order
constructor
A new instance of Order.
-
#refund(amount: nil, description: nil) ⇒ Object
Refunds the order through Klarna API.
Methods included from ApiUtilities::ParseResponse
Methods included from Klarna::Checkout::Operations::Acknowledge
Methods included from Klarna::Checkout::Operations::Fetch
fetch_checkout_order, fetch_confirmed_order
Methods included from ApiUtilities::ConnectionUtilities
Methods included from Klarna::Checkout::Operations::CreateRecurring
Methods included from Resources::Authentication
Methods included from Resources::MerchantUrls
Methods included from Klarna::Checkout::Operations::Refund
Methods included from Klarna::Checkout::Operations::Cancel
Methods included from Klarna::Checkout::Operations::Capture
Methods included from Klarna::Checkout::Operations::Create
Methods included from Validations::OrderValidations
#amount_validation, #header_keys_existance, #item_keys_existance, #tax_amount_validation, #total_amount_validation, #total_tax_amount_validation
Constructor Details
#initialize(header:, items:, options: {}, recurring: false, customer: {}, checkout_url: nil, terms_url: nil) ⇒ Order
Returns a new instance of Order.
54 55 56 57 58 59 60 61 62 |
# File 'lib/klarna/checkout/order.rb', line 54 def initialize(header:, items:, options: {}, recurring: false, customer: {}, checkout_url: nil, terms_url: nil) @header = header @items = items @recurring = recurring @customer = customer @options = @checkout_url = checkout_url || Klarna::Checkout.configuration.checkout_uri @terms_url = terms_url || Klarna::Checkout.configuration.terms_uri end |
Instance Attribute Details
#api_order ⇒ Object
Returns the value of attribute api_order.
22 23 24 |
# File 'lib/klarna/checkout/order.rb', line 22 def api_order @api_order end |
#klarna_response ⇒ Object
Returns the value of attribute klarna_response.
22 23 24 |
# File 'lib/klarna/checkout/order.rb', line 22 def klarna_response @klarna_response end |
#payment_form ⇒ Object
Returns the value of attribute payment_form.
22 23 24 |
# File 'lib/klarna/checkout/order.rb', line 22 def payment_form @payment_form end |
#recurring ⇒ Object
Returns the value of attribute recurring.
22 23 24 |
# File 'lib/klarna/checkout/order.rb', line 22 def recurring @recurring end |
#reference ⇒ Object
Returns the value of attribute reference.
22 23 24 |
# File 'lib/klarna/checkout/order.rb', line 22 def reference @reference end |
#status ⇒ Object
Returns the value of attribute status.
22 23 24 |
# File 'lib/klarna/checkout/order.rb', line 22 def status @status end |
Class Method Details
.acknowledge(ref) ⇒ Object
24 25 26 |
# File 'lib/klarna/checkout/order.rb', line 24 def self.acknowledge(ref) acknowledge_order(ref) end |
.create_recurring(locale:, order_lines:, order_amount:, order_tax_amount:, purchase_currency:, recurring_token:) ⇒ Object
For creating an order, using a recurring_token
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/klarna/checkout/order.rb', line 29 def self.create_recurring(locale:, order_lines:, order_amount:, order_tax_amount:, purchase_currency:, recurring_token:) if recurring_token.nil? raise Klarna::Checkout::Errors::OrderValidationError.new('Argument missing', 'missing_recurring_token') end create_recurring_order( locale: locale, order_lines: order_lines, order_amount: order_amount, order_tax_amount: order_tax_amount, purchase_currency: purchase_currency, recurring_token: recurring_token ) end |
.find(ref) ⇒ Object
Returns an instance of the order
45 46 47 |
# File 'lib/klarna/checkout/order.rb', line 45 def self.find(ref) fetch_confirmed_order(ref) end |
.find_checkout(ref) ⇒ Object
Same as find but to be used during checkout stage
50 51 52 |
# File 'lib/klarna/checkout/order.rb', line 50 def self.find_checkout(ref) fetch_checkout_order(ref) end |
Instance Method Details
#cancel ⇒ Object
Cancels the order through Klarna API
87 88 89 90 91 92 93 |
# File 'lib/klarna/checkout/order.rb', line 87 def cancel unless @status == 'AUTHORIZED' raise Klarna::Checkout::Errors::OrderCancelError.new(@status, 'cancel_not_allowed') end cancel_order end |
#capture ⇒ Object
Captures the order through Klarna API
78 79 80 81 82 83 84 |
# File 'lib/klarna/checkout/order.rb', line 78 def capture unless @status == 'AUTHORIZED' raise Klarna::Checkout::Errors::OrderCaptureError.new(@status, 'capture_not_allowed') end capture_order end |
#execute ⇒ Object
Creates an order Returns prepolulated order object based on Klarna API response
66 67 68 69 70 |
# File 'lib/klarna/checkout/order.rb', line 66 def execute add_defaults validate create(@header, @items) end |
#refund(amount: nil, description: nil) ⇒ Object
Refunds the order through Klarna API
96 97 98 99 100 |
# File 'lib/klarna/checkout/order.rb', line 96 def refund(amount: nil, description: nil) raise Klarna::Checkout::Errors::OrderRefundError.new(@status, 'refund_not_allowed') unless @status == 'CAPTURED' refund_order(amount: amount, description: description) end |