Skip to content

Commit 866e460

Browse files
authored
Add payment_method option (#20)
1 parent 1accd25 commit 866e460

13 files changed

Lines changed: 239 additions & 10 deletions

File tree

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ Metrics/MethodLength:
5050
CountAsOne: ['array', 'heredoc', 'method_call']
5151

5252
Metrics/ParameterLists:
53-
Max: 8
53+
Max: 10

.rubocop_todo.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
1111
# SupportedStyles: Gemfile, gems.rb, gemspec
1212
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
13+
AllCops:
14+
Exclude:
15+
- 'squake.gemspec'
16+
- 'bin/**/*'
17+
1318
Gemspec/DevelopmentDependencies:
1419
Exclude:
1520
- 'squake.gemspec'

lib/squake/calculation_with_pricing.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ class CalculationWithPricing
1616
carbon_unit: String,
1717
expand: T::Array[String],
1818
payment_link_return_url: T.nilable(String),
19+
payment_method: T.nilable(Squake::Model::PaymentMethod),
1920
client: Squake::Client,
2021
request_id: T.nilable(String),
2122
).returns(Squake::Return[Squake::Model::Pricing])
2223
end
2324
def self.quote(
2425
items:, product:, currency: 'EUR', carbon_unit: 'gram',
25-
expand: [], payment_link_return_url: nil, client: Squake::Client.new, request_id: nil
26+
expand: [], payment_link_return_url: nil, payment_method: nil,
27+
client: Squake::Client.new, request_id: nil
2628
)
2729
# @TODO: add typed objects for all possible items. Until then, we allow either a Hash or a T::Struct
2830
items = items.map do |item|
@@ -40,6 +42,7 @@ def self.quote(
4042
carbon_unit: carbon_unit,
4143
expand: expand,
4244
payment_link_return_url: payment_link_return_url,
45+
payment_method: payment_method&.serialize,
4346
},
4447
)
4548

lib/squake/model/payment_method.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module Squake
5+
module Model
6+
class PaymentMethod < T::Enum
7+
extend T::Sig
8+
9+
enums do
10+
BatchSettlement = new('batch_settlement')
11+
Stripe = new('stripe')
12+
end
13+
end
14+
end
15+
end

lib/squake/pricing.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ class Pricing
1717
carbon_unit: T.nilable(String),
1818
expand: T::Array[String],
1919
payment_link_return_url: T.nilable(String),
20+
payment_method: T.nilable(Squake::Model::PaymentMethod),
2021
client: Squake::Client,
2122
request_id: T.nilable(String),
2223
).returns(Squake::Return[Squake::Model::Pricing])
2324
end
24-
def self.quote( # rubocop:disable Metrics/ParameterLists
25+
def self.quote(
2526
product_id:, fixed_total: nil, currency: 'EUR', carbon_quantity: nil, carbon_unit: 'gram',
26-
expand: [], payment_link_return_url: nil, client: Squake::Client.new, request_id: nil
27+
expand: [], payment_link_return_url: nil, payment_method: nil,
28+
client: Squake::Client.new, request_id: nil
2729
)
28-
2930
result = client.call(
3031
path: ENDPOINT,
3132
method: :get,
@@ -38,6 +39,7 @@ def self.quote( # rubocop:disable Metrics/ParameterLists
3839
carbon_unit: carbon_unit,
3940
expand: expand,
4041
payment_link_return_url: payment_link_return_url,
42+
payment_method: payment_method&.serialize,
4143
},
4244
)
4345

lib/squake/util.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def self.encode_parameters(params)
1414
params.map do |k, v|
1515
case v
1616
when Array
17-
v.map { |e| "#{url_encode(k.to_s)}[]=#{url_encode(e.to_s)}" }.join('&')
17+
v.map { "#{url_encode(k.to_s)}[]=#{url_encode(_1.to_s)}" }
1818
else
1919
"#{url_encode(k.to_s)}=#{url_encode(v.to_s)}" unless v.nil?
2020
end
21-
end.join('&')
21+
end.flatten.compact.join('&')
2222
end
2323

2424
# Encodes a string in a way that makes it suitable for use in a set of

lib/squake/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# typed: true
1+
# typed: strict
22
# frozen_string_literal: true
33

44
module Squake

sorbet/tapioca/require.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# typed: true
1+
# typed: strict
22
# frozen_string_literal: true
33

44
require 'byebug'

spec/fixtures/vcr_cassettes/Squake_Pricing/_quote/when_requesting_with_payment_method/behaves_like_successful_pricing_response/returns_a_pricing_object.yml

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/vcr_cassettes/Squake_Pricing/_quote/when_requesting_with_payment_method/behaves_like_successful_pricing_response/returns_a_success_response.yml

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)