diff --git a/app/models/solidus_paypal_braintree/gateway.rb b/app/models/solidus_paypal_braintree/gateway.rb
index 3cd50971..4b8ccd2a 100644
--- a/app/models/solidus_paypal_braintree/gateway.rb
+++ b/app/models/solidus_paypal_braintree/gateway.rb
@@ -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)
@@ -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]
diff --git a/spec/fixtures/cassettes/solidus_paypal_braintree_gateway.yml b/spec/fixtures/cassettes/solidus_paypal_braintree_gateway.yml
index 71d2c6ee..6c20c131 100644
--- a/spec/fixtures/cassettes/solidus_paypal_braintree_gateway.yml
+++ b/spec/fixtures/cassettes/solidus_paypal_braintree_gateway.yml
@@ -323,4 +323,212 @@ http_interactions:
AP//AwD//Oai5AYAAA==
http_version:
recorded_at: Thu, 01 Sep 2016 22:31:40 GMT
+- request:
+ method: post
+ uri: https://api.sandbox.braintreegateway.com/merchants/7rdg92j7bm7fk5h3/transactions
+ body:
+ encoding: UTF-8
+ string: |
+
+
+ 10.0
+ fake-paypal-future-nonce
+
+ true
+ true
+
+ sale
+
+ headers:
+ Accept-Encoding:
+ - gzip
+ Accept:
+ - application/xml
+ User-Agent:
+ - Braintree Ruby Gem 2.66.0
+ X-Apiversion:
+ - '4'
+ Authorization:
+ - Basic bXdqa2t4d2NwMzJja2huZjphOTI5OGY0M2IzMGM2OTlkYjMwNzJjYzRhMDBmN2Y0OQ==
+ Content-Type:
+ - application/xml
+ response:
+ status:
+ code: 201
+ message: Created
+ headers:
+ Date:
+ - Fri, 02 Sep 2016 19:57:19 GMT
+ Content-Type:
+ - application/xml; charset=utf-8
+ Transfer-Encoding:
+ - chunked
+ X-Frame-Options:
+ - SAMEORIGIN
+ - SAMEORIGIN
+ X-Xss-Protection:
+ - 1; mode=block
+ X-Content-Type-Options:
+ - nosniff
+ X-Authentication:
+ - basic_auth
+ X-User:
+ - 3v249hqtptsg744y
+ Vary:
+ - Accept-Encoding
+ Content-Encoding:
+ - gzip
+ Etag:
+ - W/"57243e6e5b1d7c3d3076256c897c2adf"
+ Cache-Control:
+ - max-age=0, private, must-revalidate
+ X-Request-Id:
+ - bd0ae012-9995-48e1-af4c-251945acdf33
+ X-Runtime:
+ - '0.439370'
+ Strict-Transport-Security:
+ - max-age=31536000; includeSubDomains
+ body:
+ encoding: ASCII-8BIT
+ string: !binary |-
+ H4sIAJ/ZyVcAA+xYS3PbNhC+51d4dIcpyZJtZWQmTuxm3PEhk8SH9uIBiaWI
+ mgRYAJSl/vouCJIiRTB2Z9KZzLQ3affDYx/Y/Zbrd7s8O9mC0lyKq8nsdDo5
+ ARFLxsXmavLw7RdyOXkXvlkbRYWmsUFU+ObkZM1ZGLEi2l9Gy3WAf6xMG2pK
+ HWowJsPl66AWWJ3ZFxBqmsE6qH5aWVwqhWftCdeS4JEQPny9WQdDsQXTXJbC
+ hLPp6XS6Dup/VpGDilMqDKFxbIUEb6MN5JHMzDrwaau7lhHx6E4Ez64mRpUw
+ CdzuFPdSr4JKxRDpUcQKqAFGqDmxtl9NGP41PIdJOJ/Ozsl0Rabzb7PV2+XF
+ 29nqd/RAu6BaXxbsn60/LKj9rI1EC+wfF7rlxfnqbLlsQ4fShCttiKA5HN8f
+ lRkd18UyL6jYezSQU5555M8QaW58exWpFD55QncDrwZds9YRz2zOtSb6Nvnx
+ FmqjADApGFOgtc8FOwOC2VCMQjIZ04wb3/YKNvjefH6S+LSy6nF474sZqvbj
+ 5ji1XU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 drMLA4OjuW76U0/lj01n8PEf38cMvuG8Eg476wBszsp/DTsEYqYiXfdtWMax
+ Z67BiIzYbi0vSgO+1KiJBeEC6XfpBkn74QrlBc0e6+9A62AM1ye3HVv7HHhx
+ xJBHgS/vV7Hij1LgbJn3ifMouqKrKZYYgs/N5iGgHYn0TNXW6BfZKcKwzVef
+ fcLq93vYYU3MwBWurrpd4JzHws/Xv5HZWUwXqyS+uIA5W1A6X8DqbMrijpcb
+ ZtEfSlD89fr+lswvF+fL+XwGbEnj6ZxiYT3G/SiS6Vzyeo6JhLDc2Avc3H54
+ +EQuotUsuVjNzpIzWrFFpzz4EcjY57Pu0OqrVZWXnUdvvzze3ZCL8ylElCXJ
+ IjpfzlbTJhK98xQ5fJMIf5WpaFAdcRfdfqQIbyQ02IOweeJZhmLMRFNPm3UX
+ vL2/+3T34f4WK/kYpJkXClOlJQs/Xn/+9vDlFi1C+ncQN58nRj4rHfXIQ/0M
+ sfPO+o2yo/SvHPli/TKsyYG2aQ2LVPPGetuFb/4GAAD//wMAlnBpVKEXAAA=
+ http_version:
+ recorded_at: Fri, 02 Sep 2016 19:57:57 GMT
+- request:
+ method: post
+ uri: https://api.sandbox.braintreegateway.com/merchants/7rdg92j7bm7fk5h3/transactions
+ body:
+ encoding: UTF-8
+ string: |
+
+
+ 10.0
+ fake-paypal-future-nonce
+
+ true
+
+ sale
+
+ headers:
+ Accept-Encoding:
+ - gzip
+ Accept:
+ - application/xml
+ User-Agent:
+ - Braintree Ruby Gem 2.66.0
+ X-Apiversion:
+ - '4'
+ Authorization:
+ - Basic bXdqa2t4d2NwMzJja2huZjphOTI5OGY0M2IzMGM2OTlkYjMwNzJjYzRhMDBmN2Y0OQ==
+ Content-Type:
+ - application/xml
+ response:
+ status:
+ code: 201
+ message: Created
+ headers:
+ Date:
+ - Fri, 02 Sep 2016 19:57:21 GMT
+ Content-Type:
+ - application/xml; charset=utf-8
+ Transfer-Encoding:
+ - chunked
+ X-Frame-Options:
+ - SAMEORIGIN
+ - SAMEORIGIN
+ X-Xss-Protection:
+ - 1; mode=block
+ X-Content-Type-Options:
+ - nosniff
+ X-Authentication:
+ - basic_auth
+ X-User:
+ - 3v249hqtptsg744y
+ Vary:
+ - Accept-Encoding
+ Content-Encoding:
+ - gzip
+ Etag:
+ - W/"9007d859cb2f21aa18df3eabcf9d4742"
+ Cache-Control:
+ - max-age=0, private, must-revalidate
+ X-Request-Id:
+ - 6f491380-f451-4b3f-a24e-e64637870057
+ X-Runtime:
+ - '0.362678'
+ Strict-Transport-Security:
+ - max-age=31536000; includeSubDomains
+ body:
+ encoding: ASCII-8BIT
+ string: !binary |-
+ H4sIAKHZyVcAA+xYS3PbNhC+51d4dIcpSn5maOYxdjPu5NBp4kN78YDEUkQM
+ AgwAylJ+fRd8iRTB2J3JoYfexN0PC+wDux8UvdsV4mQL2nAlbxbh6XJxAjJV
+ jMvNzeLh62/kavEufhNZTaWhqUVU/ObkJOIsvraQmXx3GQX44WTGUluZmFY2
+ V5r/ABYFrchp7b6E2FABUVD/dLK00hp32xNuFMFNIX74chsFU7ED00JV0sbh
+ 8nS5jIL2yykK0GlOpSU0TZ2Q4HmMhSJRwkaBT1uftkqIR3ciubhZWF3BImis
+ U7SlXwVVmiHSo0g1UAuMUHvifL9ZMPy0vIBFvFqGF2R5TZarr+H12/PLt6vw
+ b4xAv6BeX5Xs360/LGjjbKxCD9xHk7z1+vpifbG+6pKH0oxrY4mkBRyfH5WC
+ zutSVZRU7j0aKCgXHvkzJIZbn60yV9Inz+huEtVg6FaUcCGwaHsXfUZ+vYfG
+ agAsCsY0GOMLwc6CZC4VsxChUiq49ZnXsMEb54uTwqsl6svhPS9WqN7Pu9Oo
+ 3WpCRZnT1atQ65dQssJs8HSaqUFy0Kesksx3TXqNacucak33IyUGctCKfEZK
+ qi3H0BiwVkABeFXHK3zGDz3rJfMDswm1ae7F5Lws/6/F/2gtDrPTdkaScRDM
+ tLWwNQS0VppgjEolDXhdq3ED18fo+B5H1E8BnYlx1v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1iwN2ZpesvSMXmVwDlfr6/RsFQ4C
+ 242NMeNE8ZcPn+9IGGbrlF3B6vwM6Lrupce4X8UgmpC8nkDgtK827gC3dx8f
+ PpElzdKz82USAoWaCjTKQxyBzP03MnyR+NpTHeUmond/Pt7fkovLi2V4xpJV
+ kl6Gq+V1l4nRfpocHpzx7yqXHWogHqL7F2h8q6DDHoTdrRYCxViJtn1KtIPv
+ 7vP9p/uPn++wec9BOjJY2rosfa7O/lFwNAvn+6QH+Jpu1XV1D4GNgu6yjOZu
+ /OYfAAAA//8DAB+7P4VJFQAA
+ http_version:
+ recorded_at: Fri, 02 Sep 2016 19:57:59 GMT
recorded_with: VCR 3.0.3
diff --git a/spec/models/solidus_paypal_braintree/gateway_spec.rb b/spec/models/solidus_paypal_braintree/gateway_spec.rb
index 479b016e..5a016f7b 100644
--- a/spec/models/solidus_paypal_braintree/gateway_spec.rb
+++ b/spec/models/solidus_paypal_braintree/gateway_spec.rb
@@ -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 }