Class: ActiveMerchant::Billing::Integrations::Klarna::Helper
- Inherits:
-
Helper
- Object
- Helper
- ActiveMerchant::Billing::Integrations::Klarna::Helper
show all
- Defined in:
- lib/active_merchant/billing/integrations/klarna/helper.rb
Instance Attribute Summary
Attributes inherited from Helper
#fields
Instance Method Summary
collapse
Methods inherited from Helper
#add_field, #add_fields, #add_raw_html_field, #form_method, inherited, mapping, #raw_html_fields, #test?
Constructor Details
#initialize(order, account, options = {}) ⇒ Helper
Returns a new instance of Helper.
11
12
13
14
15
16
17
18
|
# File 'lib/active_merchant/billing/integrations/klarna/helper.rb', line 11
def initialize(order, account, options = {})
super
@shared_secret = options[:credential2]
@order = order
add_field('platform_type', application_id)
add_field('test_mode', test?)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ActiveMerchant::Billing::Integrations::Helper
Instance Method Details
#billing_address(billing_fields) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/active_merchant/billing/integrations/klarna/helper.rb', line 47
def billing_address(billing_fields)
country = billing_fields[:country]
add_field('purchase_country', country)
add_field('locale', guess_locale_based_on_country(country))
end
|
67
68
69
70
71
|
# File 'lib/active_merchant/billing/integrations/klarna/helper.rb', line 67
def form_fields
sign_fields
super
end
|
#line_item(item) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/active_merchant/billing/integrations/klarna/helper.rb', line 30
def line_item(item)
@line_items ||= []
@line_items << item
i = @line_items.size - 1
add_field("cart_item-#{i}_type", item.fetch(:type, ''))
add_field("cart_item-#{i}_reference", item.fetch(:reference, ''))
add_field("cart_item-#{i}_name", item.fetch(:name, ''))
add_field("cart_item-#{i}_quantity", item.fetch(:quantity, ''))
add_field("cart_item-#{i}_unit_price", tax_included_unit_price(item)).to_s
add_field("cart_item-#{i}_discount_rate", item.fetch(:discount_rate, ''))
add_field("cart_item-#{i}_tax_rate", tax_rate_for(item)).to_s
@fields
end
|
#notify_url(url) ⇒ Object
20
21
22
23
|
# File 'lib/active_merchant/billing/integrations/klarna/helper.rb', line 20
def notify_url(url)
url = append_order_query_param(url)
add_field('merchant_push_uri', url)
end
|
#return_url(url) ⇒ Object
25
26
27
28
|
# File 'lib/active_merchant/billing/integrations/klarna/helper.rb', line 25
def return_url(url)
url = append_order_query_param(url)
add_field('merchant_confirmation_uri', url)
end
|
#shipping_address(shipping_fields) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/active_merchant/billing/integrations/klarna/helper.rb', line 54
def shipping_address(shipping_fields)
add_field('shipping_address_given_name', shipping_fields[:first_name])
add_field('shipping_address_family_name', shipping_fields[:last_name])
street_address = [shipping_fields[:address1], shipping_fields[:address2]].compact.join(', ')
add_field('shipping_address_street_address', street_address)
add_field('shipping_address_postal_code', shipping_fields[:zip])
add_field('shipping_address_city', shipping_fields[:city])
add_field('shipping_address_country', shipping_fields[:country])
add_field('shipping_address_phone', shipping_fields[:phone])
end
|
#sign_fields ⇒ Object
73
74
75
76
|
# File 'lib/active_merchant/billing/integrations/klarna/helper.rb', line 73
def sign_fields
merchant_digest = Klarna.sign(@fields, @line_items, @shared_secret)
add_field('merchant_digest', merchant_digest)
end
|