Module: Klarna::API::Methods::Standard
- Included in:
- Klarna::API::Methods
- Defined in:
- lib/klarna/api/methods/standard.rb
Instance Method Summary collapse
-
#get_address(*args) ⇒ Object
Same as
get_addresses
but returns only first address. -
#get_addresses(pno, pno_encoding, address_type = :GIVEN) ⇒ Object
Retrieve a customer’s address(es).
-
#has_account?(pno, pno_encoding) ⇒ Boolean
Check if a user has an account.
-
#make_address(co_address, street_address, zip, city, country, phone, cell_phone, email, house_number = nil, house_extension = nil) ⇒ Object
(also: #mk_address)
Create addresses (i.e. the
address
argument to theadd_transaction
method). -
#make_goods(quantity, article_no, title, price, vat, discount = nil, flags = nil) ⇒ Object
(also: #mk_goods, #mk_goods_flags)
Create an inventory (i.e. the
goods_list
argument) to theadd_transaction
function.
Instance Method Details
#get_address(*args) ⇒ Object
Same as get_addresses
but returns only first address.
48 49 50 |
# File 'lib/klarna/api/methods/standard.rb', line 48 def get_address(*args) self.get_addresses(*args).first end |
#get_addresses(pno, pno_encoding, address_type = :GIVEN) ⇒ Object
Retrieve a customer’s address(es). Using this, the customer is not required to enter any information – only confirm the one presented to him/her. Can also be used for companies: If the customer enters a company number, it will return all the addresses where the company is registered at.
Note:
ONLY allowed to be used for Swedish persons with the following conditions:
* It can be only used if invoice or part payment is the default payment method
* It has to disappear if the customer chooses another payment method
* The button is not allowed to be called get address ("hämta adress"), but continue ("fortsätt")
or it can be picked up automatically when all the numbers have been typed.
In the other Nordic countries you will have to have input fields for name, last name, street name,
zip code and city so that the customer can enter this information by himself.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/klarna/api/methods/standard.rb', line 25 def get_addresses(pno, pno_encoding, address_type = :GIVEN) pno = pno.to_s.gsub(/[\W]/, '') pno_encoding = ::Klarna::API.id_for(:pno_format, pno_encoding) address_type = ::Klarna::API.id_for(:address_format, address_type) params = [ ::Klarna::API::PROTOCOL_VERSION, ::XMLRPC::Client::USER_AGENT, pno, self.store_id, self.digest(pno), pno_encoding, address_type, self.client_ip ] self.call(:get_addresses, *params).tap do |result| result = result.first country_id = ::Klarna::API.id_for(:country, result[5]) result[5] = ::Klarna::API::COUNTRIES.key(country_id) end end |
#has_account?(pno, pno_encoding) ⇒ Boolean
Check if a user has an account.
114 115 116 117 118 119 120 121 |
# File 'lib/klarna/api/methods/standard.rb', line 114 def has_account?(pno, pno_encoding) params = [ self.store_id, self.digest(pno), pno_encoding ] self.call(:has_account, *params) end |
#make_address(co_address, street_address, zip, city, country, phone, cell_phone, email, house_number = nil, house_extension = nil) ⇒ Object Also known as: mk_address
Create addresses (i.e. the address
argument to the add_transaction
method).
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/klarna/api/methods/standard.rb', line 54 def make_address(co_address, street_address, zip, city, country, phone, cell_phone, email, house_number = nil, house_extension = nil) country = ::Klarna::API.id_for(:country, country) phone = phone.to_s.gsub(/[\W\s\t]/, '') cell_phone = cell_phone.to_s.gsub(/[\W\s\t]/, '') { :careof => co_address, :street => street_address, :postno => zip, :city => city, :country => country, :telno => phone, :cellno => cell_phone, :email => email }.with_indifferent_access end |
#make_goods(quantity, article_no, title, price, vat, discount = nil, flags = nil) ⇒ Object Also known as: mk_goods, mk_goods_flags
Create an inventory (i.e. the goods_list
argument) to the add_transaction
function.
Flags:
Argument flags
can be used to set the precision of the article, to indicate a shipment or a fee or sending the price with VAT.
By using either PRINT_1000
, PRINT_100
, or PRINT_10
, the flags
function can be used to set article quantity (quantity
). Unit is either 1/10
, 1/100
or 1/1000
. This is useful for goods measured in meters or kilograms, rather than number of items.
By using the IS_SHIPMENT
or IS_HANDLING
flags a shipping or handling fee can be applied. The fees are sent excluding VAT with the arguments shipping_fee
or handling_fee
.
By using the INC_VAT
flag, you can send the price including VAT.
Note:
If you are implementing sales with Euros, use the function mk_goods_flags instead
since using this method can result in round off problems. With +mk_goods_flags+ you
are able to send the price with VAT.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/klarna/api/methods/standard.rb', line 94 def make_goods(quantity, article_no, title, price, vat, discount = nil, flags = nil) flags = ::Klarna::API.parse_flags(:GOODS, flags) goods = { :goods => { :artno => article_no, :title => title, :price => price.to_i, :vat => vat.to_f.round(2), :discount => discount.to_f.round(2), }, :qty => quantity.to_i } goods[:goods].merge!(:flags => flags.to_i) # if flags.present? goods.with_indifferent_access end |