Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Make http open and read timeouts configurable
Browse files Browse the repository at this point in the history
The default timeout of 60 seconds is way too long for real life
scenarios. Ideally we would drop the open timeout to 1 second and
the read timeout below the heroku timeout of 30 seconds.

I left the default values for now, to not impact any existing stores.
  • Loading branch information
tvdeyen committed Dec 16, 2019
1 parent af58f37 commit df6d02f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/solidus_paypal_braintree/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Gateway < ::Spree::PaymentMethod
preference(:merchant_id, :string, default: nil)
preference(:public_key, :string, default: nil)
preference(:private_key, :string, default: nil)
preference(:http_open_timeout, :integer, default: 60)
preference(:http_read_timeout, :integer, default: 60)
preference(:merchant_currency_map, :hash, default: {})
preference(:paypal_payee_email_map, :hash, default: {})

Expand All @@ -60,6 +62,8 @@ def gateway_options
merchant_id: preferred_merchant_id,
public_key: preferred_public_key,
private_key: preferred_private_key,
http_open_timeout: preferred_http_open_timeout,
http_read_timeout: preferred_http_read_timeout,
logger: logger
}
end
Expand Down
14 changes: 14 additions & 0 deletions spec/models/solidus_paypal_braintree/gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@
it { is_expected.to eq "paypal_braintree" }
end

describe '#gateway_options' do
subject(:gateway_options) { gateway.gateway_options }

it 'includes http_open_timeout' do
is_expected.to have_key(:http_open_timeout)
expect(gateway_options[:http_open_timeout]).to eq(60)
end

it 'includes http_read_timeout' do
is_expected.to have_key(:http_read_timeout)
expect(gateway_options[:http_read_timeout]).to eq(60)
end
end

describe '#purchase' do
subject(:purchase) { gateway.purchase(1000, source, gateway_options) }

Expand Down

0 comments on commit df6d02f

Please sign in to comment.