From d513e96d807f9630fc12be28e686074d880191d0 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Fri, 2 Sep 2016 13:37:09 -0700 Subject: [PATCH] Add method implementation for Gateway#authorize --- .../solidus_paypal_braintree/gateway.rb | 14 ++- .../solidus_paypal_braintree_gateway.yml | 103 ++++++++++++++++++ .../solidus_paypal_braintree/gateway_spec.rb | 13 +++ 3 files changed, 128 insertions(+), 2 deletions(-) diff --git a/app/models/solidus_paypal_braintree/gateway.rb b/app/models/solidus_paypal_braintree/gateway.rb index 5cc33c44..4bbbb874 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 1b51a54d..83bc39b2 100644 --- a/spec/fixtures/cassettes/solidus_paypal_braintree_gateway.yml +++ b/spec/fixtures/cassettes/solidus_paypal_braintree_gateway.yml @@ -494,4 +494,107 @@ http_interactions: //8DAClJQu3QBwAA http_version: recorded_at: Fri, 02 Sep 2016 20:34:54 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 20:53:42 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/"eec960fb352853646fa7900b424a49ea" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 458eb419-22b2-44dc-b065-bffb34ed1c12 + X-Runtime: + - '0.426770' + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: !binary |- + H4sIANbmyVcAA+xYS2/jNhC+768IfGdky07sLBTtA0mLFHsouptDewkocWyx + kUiVpBy7v75DUZIli9qkwB566M2a+TjkPDjz0dGHQ5Ff7EFpLsXtbHE5n12A + SCXjYnc7e/z2E9nMPsTvIqOo0DQ1iIrfXVxEnMVqMT+W2yuIAvywMm2oqXRM + K5NJxf8GFgWNyGrNsYRY0xzx9U8rSyulcLcj4VoS3BTix693UTAWWzAtZCVM + vJhfzudR0HxZRQEqzagwhKapFRI8jzZQJDI3UeDT1qetEuLRXQie386MqmAW + OOsUbak3QaViiPQoUgXUACPUXFjfb2cMPw0vYBaH88U1md+QefgtnL+/Wr5f + hX9gBLoF9fqqZP9u/WlBE2dtJHpgP1zyNsvVar1cr9vkoXTLlTZE0ALOz4/K + nE7rUlmUVBw9Gigozz3yF0g0Nz5bZSaFT76lh1FUg75bUcLzHIu2c9Fn5Md7 + qI0CwKJgTIHWvhAcDAhmUzEJyWVKc2585hXs8Mb54iTxauX15fCeFytUHafd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ZkwnfreVkZ8JVGM0IIF0i0KvdksH9RoLyk+VPz4o+C + KdyQxvR8HbKdPpOZBL1uq+Y+r9nqCJLJsKsQvGG29ACPvpWeJ5P181XqgTDs + 4fWbPq5/f4QDNsIcXK/qq7sFLl4s/vXT72Qd0pAlC3qzhuUmoevwOrlKVmvW + C2w7NoaME8VfP325J+slzLeLm9X19SKFMNliLz3H/SgG4ULydgKB077a2QPc + 3X9+/JlAckWBhnATbq5rKuCUpzgCmfpvpP8i8bWnOsouove/PT3ckfl6vQwX + NywEtko2m0WbicF+ipwenPEvMhMtqifuo7sXaHwnocWehO2tznMUYyWa5inR + DL77Lw8/P3z+co/NewrSksHS1GXpc3Xyj4KzWTjdJz3At3Srtqt7CGwUtJdl + MHfjd/8AAAD//wMAKgyqnkkVAAA= + http_version: + recorded_at: Fri, 02 Sep 2016 20:54:20 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 825d8e30..03f623fe 100644 --- a/spec/models/solidus_paypal_braintree/gateway_spec.rb +++ b/spec/models/solidus_paypal_braintree/gateway_spec.rb @@ -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, {}) }