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

Commit

Permalink
Add method implementation for Gateway#authorize
Browse files Browse the repository at this point in the history
  • Loading branch information
stewart committed Sep 2, 2016
1 parent 205118e commit fd88bfd
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/models/solidus_paypal_braintree/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class Gateway < ::Spree::PaymentMethod
submit_for_settlement: true
}.freeze

PAYPAL_AUTHORIZE_OPTIONS = {
store_in_vault_on_success: true
}.freeze

# This is useful in feature tests to avoid rate limited requests from
# Braintree
preference(:client_sdk_enabled, :boolean, default: true)
Expand All @@ -35,8 +39,14 @@ def purchase(money, source, _gateway_options)
end

# @return [Response]
def authorize(_money, _source, _gateway_options)
raise NotImplementedError
def authorize(money, source, _gateway_options)
result = ::Braintree::Transaction.sale(
amount: money,
payment_method_nonce: source.nonce,
options: PAYPAL_AUTHORIZE_OPTIONS
)

Response.build(result)
end

# @return [Response]
Expand Down
208 changes: 208 additions & 0 deletions spec/fixtures/cassettes/solidus_paypal_braintree_gateway.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -57,6 +57,20 @@
end
end

describe "#authorize" do
subject(:authorize) do
gateway.authorize(10.00, source, {})
end

it { is_expected.to be_a ActiveMerchant::Billing::Response }
it { is_expected.to be_success }
it { is_expected.to be_test }

it 'is authorized' do
expect(authorize.message).to eq 'authorized'
end
end

describe '.generate_token', :braintree_integration do
subject { gateway.generate_token }

Expand Down

0 comments on commit fd88bfd

Please sign in to comment.