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(**args) ⇒ 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:, recurring: false, **args) ⇒ Order
constructor
A new instance of Order.
-
#refund ⇒ 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:, recurring: false, **args) ⇒ Order
Returns a new instance of Order.
47 48 49 50 51 52 53 54 55 |
# File 'lib/klarna/checkout/order.rb', line 47 def initialize(header:, items:, recurring: false, **args) @header = header @items = items @recurring = recurring @customer = args[:customer].nil? ? {} : args[:customer] = args[:options] @checkout_url = args[:checkout_url].nil? ? Klarna::Checkout.configuration.checkout_uri : args[:checkout_url] @terms_url = args[:terms_url].nil? ? Klarna::Checkout.configuration.terms_uri : args[:terms_url] 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(**args) ⇒ Object
For creating an order, using a recurring_token
29 30 31 32 33 34 35 |
# File 'lib/klarna/checkout/order.rb', line 29 def self.create_recurring(**args) if args[:recurring_token].nil? raise Klarna::Checkout::Errors::OrderValidationError.new('Argument missing', 'missing_recurring_token') end create_recurring_order(args) end |
.find(ref) ⇒ Object
Returns an instance of the order
38 39 40 |
# File 'lib/klarna/checkout/order.rb', line 38 def self.find(ref) fetch_confirmed_order(ref) end |
.find_checkout(ref) ⇒ Object
Same as find but to be used during checkout stage
43 44 45 |
# File 'lib/klarna/checkout/order.rb', line 43 def self.find_checkout(ref) fetch_checkout_order(ref) end |
Instance Method Details
#cancel ⇒ Object
Cancels the order through Klarna API
80 81 82 83 84 85 86 |
# File 'lib/klarna/checkout/order.rb', line 80 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
71 72 73 74 75 76 77 |
# File 'lib/klarna/checkout/order.rb', line 71 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
59 60 61 62 63 |
# File 'lib/klarna/checkout/order.rb', line 59 def execute add_defaults validate create(@header, @items) end |
#refund ⇒ Object
Refunds the order through Klarna API
89 90 91 92 93 |
# File 'lib/klarna/checkout/order.rb', line 89 def refund raise Klarna::Checkout::Errors::OrderRefundError.new(@status, 'refund_not_allowed') unless @status == 'CAPTURED' refund_order end |