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

Add implementation for authorization transactions #4

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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