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
58
59
60
61
|
# File 'lib/squake/calculation_with_pricing.rb', line 24
def self.quote(
items:, product:, currency: 'EUR', carbon_unit: 'gram',
expand: [], payment_link_return_url: nil, payment_method: nil,
client: Squake::Client.new, request_id: nil
)
items = items.map do |item|
item.is_a?(T::Struct) ? item.serialize : item
end
result = client.call(
path: ENDPOINT,
method: :post,
headers: { 'X-Request-Id' => request_id }.compact,
params: {
items: items,
product: product,
currency: currency,
carbon_unit: carbon_unit,
expand: expand,
payment_link_return_url: payment_link_return_url,
payment_method: payment_method&.serialize,
},
)
if result.success?
pricing = Squake::Model::Pricing.from_api_response(
T.cast(result.body, T::Hash[Symbol, T.untyped]),
)
Return.new(result: pricing)
else
error = Squake::Errors::APIErrorResult.new(
code: :"api_error_#{result.code}",
detail: result.error_message,
)
Return.new(errors: [error])
end
end
|