Class: OffsitePayments::Integrations::Klarna::Helper
- Inherits:
-
Helper
- Object
- Helper
- OffsitePayments::Integrations::Klarna::Helper
show all
- Defined in:
- lib/offsite_payments/integrations/klarna.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.
70
71
72
73
74
75
76
77
|
# File 'lib/offsite_payments/integrations/klarna.rb', line 70
def initialize(order, account, options = {})
super
@shared_secret = options[:credential2]
@order = order
add_field('platform_type', application_id)
add_field('test_mode', test?.to_s)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class OffsitePayments::Helper
Instance Method Details
#billing_address(billing_fields) ⇒ Object
106
107
108
109
110
111
|
# File 'lib/offsite_payments/integrations/klarna.rb', line 106
def billing_address(billing_fields)
country = billing_fields[:country]
add_field('purchase_country', country)
add_field('locale', guess_locale_based_on_country(country))
end
|
126
127
128
129
130
|
# File 'lib/offsite_payments/integrations/klarna.rb', line 126
def form_fields
sign_fields
super
end
|
#line_item(item) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/offsite_payments/integrations/klarna.rb', line 89
def line_item(item)
@line_items ||= []
@line_items << item
i = @line_items.size - 1
add_field("cart_item-#{i}_type", type_for(item))
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
79
80
81
82
|
# File 'lib/offsite_payments/integrations/klarna.rb', line 79
def notify_url(url)
url = append_order_query_param(url)
add_field('merchant_push_uri', url)
end
|
#return_url(url) ⇒ Object
84
85
86
87
|
# File 'lib/offsite_payments/integrations/klarna.rb', line 84
def return_url(url)
url = append_order_query_param(url)
add_field('merchant_confirmation_uri', url)
end
|
#shipping_address(shipping_fields) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/offsite_payments/integrations/klarna.rb', line 113
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
132
133
134
135
|
# File 'lib/offsite_payments/integrations/klarna.rb', line 132
def sign_fields
merchant_digest = Klarna.sign(@fields, @line_items, @shared_secret)
add_field('merchant_digest', merchant_digest)
end
|