Module: Klarna::API::Methods::Invoicing
- Included in:
- Klarna::API::Methods
- Defined in:
- lib/klarna/api/methods/invoicing.rb
Instance Method Summary collapse
-
#activate_invoice(invoice_no, articles = nil) ⇒ Object
(also: #activate_part)
Activate a passive invoice - optionally only partly.
-
#add_invoice(store_user_id, order_id, articles, shipping_fee, handling_fee, shipment_type, pno, first_name, last_name, address, client_ip, currency, country, language, pno_encoding, pclass = nil, annual_salary = nil, password = nil, ready_date = nil, comment = nil, rand_string = nil, new_password = nil, flags = nil) ⇒ Object
(also: #add_transaction)
Create an invoice.
-
#credit_invoice(invoice_no, credit_id, articles = nil) ⇒ Object
Return a invoice - optionally only partly.
-
#delete_invoice(invoice_no) ⇒ Object
Delete a passive invoice.
-
#email_invoice(invoice_no) ⇒ Object
Send an active invoice to the customer via e-mail.
-
#invoice_address(invoice_no) ⇒ Object
(also: #get_invoice_address)
Retrieve the address for an invoice.
-
#invoice_amount(invoice_no, articles = nil) ⇒ Object
(also: #get_invoice_amount)
Retrieve the total amount of an invoice - optionally only partly.
-
#invoice_paid?(invoice_no) ⇒ Boolean
Check if invoice is paid.
-
#make_article(quantity, article_no) ⇒ Object
Create quantity and article number (i.e. the
articles
argument for theactivate_part
andcredit_part
function). -
#return_amount(invoice_no, amount, vat) ⇒ Object
Give discounts for invoices.
-
#send_invoice(invoice_no) ⇒ Object
Request a postal send-out of an active invoice to a customer by Klarna.
-
#update_charge_amount(invoice_no, charge_type, new_amount) ⇒ Object
Change the amount of a fee (for example the invoice fee) in a passive invoice.
-
#update_goods_quantity(invoice_no, article_no, new_quantity) ⇒ Object
Change the quantity of a specific item in a passive invoice.
-
#update_order_no(invoice_no, new_order_no) ⇒ Object
Change the store’s order number for a specific invoice.
Instance Method Details
#activate_invoice(invoice_no, articles = nil) ⇒ Object Also known as: activate_part
Activate a passive invoice - optionally only partly.
Note:
This function call cannot activate an invoice created in test mode. It is however possible
to manually activate such an invoice.
When partially activating an invoice only the articles and quantities specified by
you will be activated. A passive invoice is created containing the articles on the
original invoice not activated.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/klarna/api/methods/invoicing.rb', line 71 def activate_invoice(invoice_no, articles = nil) # TODO: Parse/Validate invoice_no as :integer # TODO: Parse/Valdiate articles as array of articles articles = Array.wrap(articles).compact params = [ self.store_id, invoice_no ] # Only partly? if articles.present? params << articles params << self.digest(invoice_no, articles.collect { |a| [a[:goods][:artno], a[:qty]].join(':') }.join(':')) method = :activate_part else params << self.digest(invoice_no) method = :activate_invoice end self.call(method, *params) end |
#add_invoice(store_user_id, order_id, articles, shipping_fee, handling_fee, shipment_type, pno, first_name, last_name, address, client_ip, currency, country, language, pno_encoding, pclass = nil, annual_salary = nil, password = nil, ready_date = nil, comment = nil, rand_string = nil, new_password = nil, flags = nil) ⇒ Object Also known as: add_transaction
Create an invoice.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/klarna/api/methods/invoicing.rb', line 15 def add_invoice(store_user_id, order_id, articles, shipping_fee, handling_fee, shipment_type, pno, first_name, last_name, address, client_ip, currency, country, language, pno_encoding, pclass = nil, annual_salary = nil, password = nil, ready_date = nil, comment = nil, rand_string = nil, new_password = nil, flags = nil) shipment_type = ::Klarna::API.id_for(:shipment_type, shipment_type) currency = ::Klarna::API.id_for(:currency, currency) country = ::Klarna::API.id_for(:country, country) language = ::Klarna::API.id_for(:language, language) pno_encoding = ::Klarna::API.id_for(:pno_format, pno_encoding) pclass = pclass ? ::Klarna::API.id_for(:pclass, pclass) : -1 flags = ::Klarna::API.parse_flags(:INVOICE, flags) articles = Array.wrap(articles).compact params = [ self.store_id, store_user_id, self.digest(articles.collect { |g| g[:goods][:title] }, :store_id => false), order_id, articles, shipping_fee, shipment_type, handling_fee, pno, first_name, last_name, address, password.to_s, client_ip.to_s, new_password.to_s, flags.to_i, comment.to_s, ready_date.to_s, rand_string.to_s, currency, country, language, pno_encoding, pclass, annual_salary.to_i ] self.call(:add_invoice, *params) end |
#credit_invoice(invoice_no, credit_id, articles = nil) ⇒ Object
Return a invoice - optionally only partly.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/klarna/api/methods/invoicing.rb', line 124 def credit_invoice(invoice_no, credit_id, articles = nil) articles = Array.wrap(articles).compact params = [ self.store_id, invoice_no, credit_id, ] if articles.present? # Only partly? params << articles params << self.digest(invoice_no, articles.collect { |a| [a[:goods][:artno], a[:qty]].join(':') }.join(':')) method = :credit_part else params << self.digest(invoice_no) method = :credit_invoice end self.call(method, *params) end |
#delete_invoice(invoice_no) ⇒ Object
Delete a passive invoice.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/klarna/api/methods/invoicing.rb', line 97 def delete_invoice(invoice_no) # TODO: Parse/Validate invoice_no as :integer params = [ self.store_id, invoice_no, self.digest(invoice_no) ] self.call(:delete_invoice, *params) end |
#email_invoice(invoice_no) ⇒ Object
Send an active invoice to the customer via e-mail.
Note:
Regular postal service is used if the customer lacks an e-mail address.
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/klarna/api/methods/invoicing.rb', line 151 def email_invoice(invoice_no) # TODO: Parse/Validate invoice_no as integer params = [ self.store_id, invoice_no, self.digest(invoice_no) ] self.call(:email_invoice, *params) end |
#invoice_address(invoice_no) ⇒ Object Also known as: get_invoice_address
Retrieve the address for an invoice.
240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/klarna/api/methods/invoicing.rb', line 240 def invoice_address(invoice_no) # TODO: Parse/Validate invoice_no as integer params = [ self.store_id, invoice_no, self.digest(invoice_no) ] self.call(:invoice_address, *params).tap do |result| result[5] = result[5].to_s.upcase end end |
#invoice_amount(invoice_no, articles = nil) ⇒ Object Also known as: get_invoice_amount
Retrieve the total amount of an invoice - optionally only partly.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/klarna/api/methods/invoicing.rb', line 257 def invoice_amount(invoice_no, articles = nil) # TODO: Parse/Validate invoice_no as integer articles = Array.wrap(articles).compact artnos = if articles.first.respond_to?(:key?) && articles.first.key?(:qty) && articles.first.key?(:artno) articles else articles.collect { |a| {:artno => a[:goods][:artno], :qty => a[:qty]} } end params = [ self.store_id, invoice_no ] # Only partly? if articles.present? params << artnos params << self.digest(invoice_no, artnos.collect { |an| [an[:artno], an[:qty]].join(':') }.join(':')) method = :invoice_part_amount else params << self.digest(invoice_no) method = :invoice_amount end self.call(method, *params) end |
#invoice_paid?(invoice_no) ⇒ Boolean
Check if invoice is paid.
288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/klarna/api/methods/invoicing.rb', line 288 def invoice_paid?(invoice_no) # TODO: Parse/Validate invoice_no as numeric value (string) params = [ invoice_no, self.store_id, self.digest(invoice_no) ] result = self.call(:is_invoice_paid, *params) result == 'unpaid' ? false : true end |
#make_article(quantity, article_no) ⇒ Object
Create quantity and article number (i.e. the articles
argument for the activate_part
and credit_part
function).
180 181 182 183 184 |
# File 'lib/klarna/api/methods/invoicing.rb', line 180 def make_article(quantity, article_no) quantity = quantity.to_i article_no = article_no.to_s [quantity, article_no] end |
#return_amount(invoice_no, amount, vat) ⇒ Object
Give discounts for invoices.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/klarna/api/methods/invoicing.rb', line 111 def return_amount(invoice_no, amount, vat) params = [ self.store_id, invoice_no, amount, vat, self.digest(invoice_no) ] self.call(:return_amount, *params) # raise NotImplementedError end |
#send_invoice(invoice_no) ⇒ Object
Request a postal send-out of an active invoice to a customer by Klarna.
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/klarna/api/methods/invoicing.rb', line 165 def send_invoice(invoice_no) # TODO: Parse/Validate invoice_no as integer params = [ self.store_id, invoice_no, self.digest(invoice_no) ] self.call(:send_invoice, *params) end |
#update_charge_amount(invoice_no, charge_type, new_amount) ⇒ Object
Change the amount of a fee (for example the invoice fee) in a passive invoice.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/klarna/api/methods/invoicing.rb', line 206 def update_charge_amount(invoice_no, charge_type, new_amount) # TODO: Parse/Validate invoice_no as integer # TODO: Parse/Validate charge_type as integer/charge-type # TODO: Parse/Validate new_amount as integer (or parse from decimal) params = [ self.store_id, self.digest(invoice_no, charge_type, new_amount), invoice_no, charge_type, new_amount ] self.call(:update_charge_amount, *params) end |
#update_goods_quantity(invoice_no, article_no, new_quantity) ⇒ Object
Change the quantity of a specific item in a passive invoice.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/klarna/api/methods/invoicing.rb', line 188 def update_goods_quantity(invoice_no, article_no, new_quantity) # TODO: Parse/Validate invoice_no as integer # TODO: Parse/Validate article_no as string # TODO: Parse/Validate new_quantity as integer params = [ self.store_id, self.digest(invoice_no, article_no, new_quantity, :store_id => false), invoice_no, article_no, new_quantity ] self.call(:update_goods_qty, *params) end |
#update_order_no(invoice_no, new_order_no) ⇒ Object
Change the store’s order number for a specific invoice.
224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/klarna/api/methods/invoicing.rb', line 224 def update_order_no(invoice_no, new_order_no) # TODO: Parse/Validate invoice_no as integer # TODO: Parse/Validate new_order_no as integer params = [ self.store_id, invoice_no, self.digest(invoice_no, new_order_no), new_order_no ] self.call(:update_orderno, *params) end |