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 69ba1b0 commit d513e96
Show file tree
Hide file tree
Showing 3 changed files with 128 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
103 changes: 103 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.

13 changes: 13 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,19 @@
end
end

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

it "returns a successful billing response", aggregate_failures: true do
expect(authorize).to be_a ActiveMerchant::Billing::Response
expect(authorize).to be_success
expect(authorize).to be_test
expect(authorize.message).to eq "authorized"
end
end

describe "#void" do
subject(:void) { gateway.void(response_code, source, {}) }

Expand Down

0 comments on commit d513e96

Please sign in to comment.