workarea-braintree 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +37 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +11 -0
- data/LICENSE +52 -0
- data/README.md +43 -0
- data/Rakefile +50 -0
- data/app/models/workarea/payment/authorize/credit_card.decorator +72 -0
- data/app/models/workarea/payment/capture/credit_card.decorator +14 -0
- data/app/models/workarea/payment/purchase/credit_card.decorator +52 -0
- data/app/models/workarea/payment/refund/credit_card.decorator +14 -0
- data/app/models/workarea/payment/store_credit_card.decorator +13 -0
- data/bin/rails +18 -0
- data/config/initializers/workarea.rb +1 -0
- data/lib/active_merchant/billing/bogus_braintree_gateway.rb +284 -0
- data/lib/tasks/braintree.rake +25 -0
- data/lib/workarea/braintree.rb +26 -0
- data/lib/workarea/braintree/engine.rb +8 -0
- data/lib/workarea/braintree/version.rb +5 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +56 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +44 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +23 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/models/workarea/payment/authorize/credit_card_test.decorator +92 -0
- data/test/models/workarea/payment/capture/credit_card_test.decorator +25 -0
- data/test/models/workarea/payment/credit_card_integration_test.decorator +8 -0
- data/test/models/workarea/payment/purchase/credit_card_test.decorator +78 -0
- data/test/models/workarea/payment/refund/credit_card_test.decorator +25 -0
- data/test/models/workarea/payment/store_credit_card_test.decorator +23 -0
- data/test/support/workarea/braintree_support_vcr_config.rb +23 -0
- data/test/test_helper.rb +16 -0
- data/test/vcr_cassettes/braintree/authorize_failure.yml +98 -0
- data/test/vcr_cassettes/braintree/authorize_success.yml +89 -0
- data/test/vcr_cassettes/braintree/capture_success.yml +64 -0
- data/test/vcr_cassettes/braintree/purchase_failure.yml +97 -0
- data/test/vcr_cassettes/braintree/purchase_success.yml +89 -0
- data/test/vcr_cassettes/braintree/refund_success.yml +64 -0
- data/test/vcr_cassettes/braintree/store_credit_card-sets_token_on_the_card.yml +86 -0
- data/test/vcr_cassettes/braintree/store_without_token.yml +82 -0
- data/test/vcr_cassettes/braintree/void_success.yml +60 -0
- data/test/vcr_cassettes/credit_card/auth_capture.yml +419 -0
- data/test/vcr_cassettes/credit_card/auth_void.yml +415 -0
- data/test/vcr_cassettes/credit_card/purchase_void.yml +415 -0
- data/test/vcr_cassettes/credit_card/store_auth.yml +227 -0
- data/test/vcr_cassettes/credit_card/store_purchase.yml +227 -0
- data/workarea-braintree.gemspec +20 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6cb8f5a96c53e921c6fd4225015282893a60770f1e5991a2306c255849c6dff2
|
4
|
+
data.tar.gz: 23b005105e051936d04e9032d7bf910298ff25e5c5b3be5ec747cad729ae29fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8836abd76088b87d3487c35a3a0f006b9c1129c0b8af9495c11f51bd113243fe2fc8c643a4862d87838c68d4deed60839752f278d022796aec7ffde4492fbc59
|
7
|
+
data.tar.gz: 4273b62ac8b4a0c0f9a27aa0add020044db053c7a60b4a436c465c9c66c6acbabced53deb11ac1b94852b112827526de522f62d0f68e246fdf3b49944be4dc22
|
data/.editorconfig
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# editorconfig.org
|
2
|
+
root = true
|
3
|
+
|
4
|
+
[*]
|
5
|
+
charset = utf-8
|
6
|
+
indent_style = space
|
7
|
+
end_of_line = lf
|
8
|
+
trim_trailing_whitespace = true
|
9
|
+
insert_final_newline = true
|
10
|
+
|
11
|
+
[{*.rb,*.haml,*.decorator,*.yml,*.yaml,*.jbuilder}]
|
12
|
+
indent_size = 2
|
13
|
+
indent_style = space
|
14
|
+
|
15
|
+
[{*.js,*.jst,*.ejs,*.scss}]
|
16
|
+
indent_size = 4
|
17
|
+
|
18
|
+
[*.md]
|
19
|
+
indent_size = 4
|
20
|
+
trim_trailing_whitespace = false
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve Workarea
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
⚠️**Before you create**⚠️
|
11
|
+
Please verify the issue you're experiencing is not part of your Workarea project customizations. The best way to do this is with a [vanilla Workarea installation](https://developer.workarea.com/articles/create-a-new-host-application.html). This will help us spend time on fixes/improvements for the whole community. Thank you!
|
12
|
+
|
13
|
+
**Describe the bug**
|
14
|
+
A clear and concise description of what the bug is.
|
15
|
+
|
16
|
+
**To Reproduce**
|
17
|
+
Steps to reproduce the behavior:
|
18
|
+
1. Go to '...'
|
19
|
+
2. Click on '....'
|
20
|
+
3. Scroll down to '....'
|
21
|
+
4. See error
|
22
|
+
|
23
|
+
**Expected behavior**
|
24
|
+
A clear and concise description of what you expected to happen.
|
25
|
+
|
26
|
+
**Workarea Setup (please complete the following information):**
|
27
|
+
- Workarea Version: [e.g. v3.4.6]
|
28
|
+
- Plugins [e.g. workarea-blog, workarea-sitemaps]
|
29
|
+
|
30
|
+
**Attachments**
|
31
|
+
If applicable, add any attachments to help explain your problem, things like:
|
32
|
+
- screenshots
|
33
|
+
- Gemfile.lock
|
34
|
+
- test cases
|
35
|
+
|
36
|
+
**Additional context**
|
37
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: Documentation request
|
3
|
+
about: Suggest documentation
|
4
|
+
title: ''
|
5
|
+
labels: documentation
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your documentation related to a problem? Please describe.**
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm confused by [...]
|
12
|
+
|
13
|
+
**Describe the article you'd like**
|
14
|
+
A clear and concise description of what would be in the documentation article.
|
15
|
+
|
16
|
+
**Additional context**
|
17
|
+
Add any other context or screenshots about the feature request here.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for Workarea
|
4
|
+
title: ''
|
5
|
+
labels: enhancement
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
12
|
+
|
13
|
+
**Describe the solution you'd like**
|
14
|
+
A clear and concise description of what you want to happen.
|
15
|
+
|
16
|
+
**Describe alternatives you've considered**
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
18
|
+
|
19
|
+
**Additional context**
|
20
|
+
Add any other context or screenshots about the feature request here.
|
data/.gitignore
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
.bundle/
|
2
|
+
log/*.log
|
3
|
+
pkg/
|
4
|
+
spec/dummy/*
|
5
|
+
spec/dummy/db/*.sqlite3
|
6
|
+
spec/dummy/db/*.sqlite3-journal
|
7
|
+
spec/dummy/log/*.log
|
8
|
+
spec/dummy/tmp/
|
9
|
+
spec/dummy/.sass-cache
|
10
|
+
spec/dummy/public/system/dragonfly
|
11
|
+
|
12
|
+
test/dummy/log/*.log
|
13
|
+
test/dummy/tmp/
|
14
|
+
test/dummy/public/system/workarea
|
15
|
+
coverage/
|
16
|
+
Gemfile.lock
|
17
|
+
.DS_STORE
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Workarea Braintree 1.0.3 (2019-08-21)
|
2
|
+
--------------------------------------------------------------------------------
|
3
|
+
|
4
|
+
* Open Source!
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
Workarea Braintree 1.0.2 (2018-11-28)
|
9
|
+
--------------------------------------------------------------------------------
|
10
|
+
|
11
|
+
* Update readme markdown for homebase
|
12
|
+
|
13
|
+
BRAINTREE-5
|
14
|
+
Jake Beresford
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
Workarea Braintree 1.0.1 (2018-09-19)
|
19
|
+
--------------------------------------------------------------------------------
|
20
|
+
|
21
|
+
* Fix broken tests in credit card integration tests
|
22
|
+
|
23
|
+
BRAINTREE-3
|
24
|
+
Jeff Yucis
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Workarea Braintree 1.0.0 (2018-05-22)
|
29
|
+
--------------------------------------------------------------------------------
|
30
|
+
|
31
|
+
* Upgrade braintree for workarea v3
|
32
|
+
|
33
|
+
BRAINTREE-1
|
34
|
+
Eric Pigeon
|
35
|
+
|
36
|
+
|
37
|
+
|
data/CODE_OF_CONDUCT.md
ADDED
data/CONTRIBUTING.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
WebLinc
|
2
|
+
Business Source License
|
3
|
+
|
4
|
+
Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
|
5
|
+
|
6
|
+
Licensed Work: Workarea Commerce Platform
|
7
|
+
The Licensed Work is (c) 2019 WebLinc Corporation
|
8
|
+
|
9
|
+
Additional Use Grant:
|
10
|
+
You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
|
11
|
+
|
12
|
+
A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
|
13
|
+
|
14
|
+
For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
|
15
|
+
|
16
|
+
Change Date: 2019-08-20
|
17
|
+
|
18
|
+
Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
|
19
|
+
|
20
|
+
Terms
|
21
|
+
|
22
|
+
The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
|
23
|
+
|
24
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
|
25
|
+
|
26
|
+
If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
|
27
|
+
|
28
|
+
All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
|
29
|
+
|
30
|
+
You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
|
31
|
+
|
32
|
+
Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
|
33
|
+
|
34
|
+
This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
|
35
|
+
|
36
|
+
Covenants of Licensor
|
37
|
+
In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
|
38
|
+
|
39
|
+
To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
|
40
|
+
|
41
|
+
To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
|
42
|
+
|
43
|
+
To specify a Change Date.
|
44
|
+
|
45
|
+
Not to modify this License in any other way.
|
46
|
+
|
47
|
+
Notice
|
48
|
+
The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
|
49
|
+
|
50
|
+
For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
|
51
|
+
|
52
|
+
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Workarea Braintree
|
2
|
+
|
3
|
+
Braintree plugin for the Workarea platform.
|
4
|
+
|
5
|
+
## Control Panel Login Information
|
6
|
+
|
7
|
+
To access the control panel when testing login with the credentials below:
|
8
|
+
|
9
|
+
email: balexander@weblinc.com
|
10
|
+
password: w3bl1nc!
|
11
|
+
|
12
|
+
## Secrets
|
13
|
+
|
14
|
+
Most of the keys below can be found in the Braintree control panel under Account.
|
15
|
+
Merchant account id can be found under Settings -> Processing under the Merchant Accounts section.
|
16
|
+
|
17
|
+
Add secrets to your environemt
|
18
|
+
|
19
|
+
braintree:
|
20
|
+
merchant_id:
|
21
|
+
public_key:
|
22
|
+
private_key:
|
23
|
+
merchant_account_id:
|
24
|
+
|
25
|
+
## Documentation & Methods
|
26
|
+
|
27
|
+
Braintree Documentation:
|
28
|
+
|
29
|
+
<https://developers.braintreepayments.com/start/hello-server/ruby>
|
30
|
+
|
31
|
+
Braintree Active Merchant Ruby Gateway:
|
32
|
+
|
33
|
+
<https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/braintree_blue.rb>
|
34
|
+
|
35
|
+
## Testing
|
36
|
+
|
37
|
+
### Refund
|
38
|
+
|
39
|
+
A purchase, or captured authorization needs to be settled before it can be refunded. The
|
40
|
+
braintree sandbox settles at 7pm to mimic the production environment. A rake task is provided to
|
41
|
+
settle a transaction now for testing.
|
42
|
+
|
43
|
+
rake workarea:braintree:settle_test_transaction TRANSACTION_ID
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require "bundler/setup"
|
4
|
+
rescue LoadError
|
5
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
6
|
+
end
|
7
|
+
|
8
|
+
require "rdoc/task"
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = "rdoc"
|
11
|
+
rdoc.title = "Braintree"
|
12
|
+
rdoc.options << "--line-numbers"
|
13
|
+
rdoc.rdoc_files.include("Readme.md")
|
14
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load "rails/tasks/engine.rake"
|
19
|
+
load "rails/tasks/statistics.rake"
|
20
|
+
load 'workarea/changelog.rake'
|
21
|
+
|
22
|
+
require "rake/testtask"
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.libs << "lib"
|
25
|
+
t.libs << "test"
|
26
|
+
t.pattern = "test/**/*_test.rb"
|
27
|
+
t.verbose = false
|
28
|
+
end
|
29
|
+
task default: :test
|
30
|
+
|
31
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
32
|
+
require "workarea/braintree/version"
|
33
|
+
|
34
|
+
desc "Release version #{Workarea::Braintree::VERSION} of the gem"
|
35
|
+
task :release do
|
36
|
+
host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
|
37
|
+
|
38
|
+
#Rake::Task['workarea:changelog'].execute
|
39
|
+
#system 'git add CHANGELOG.md'
|
40
|
+
#system 'git commit -m "Update CHANGELOG"'
|
41
|
+
#system 'git push origin HEAD'
|
42
|
+
|
43
|
+
system "git tag -a v#{Workarea::Braintree::VERSION} -m 'Tagging #{Workarea::Braintree::VERSION}'"
|
44
|
+
system "git push --tags"
|
45
|
+
|
46
|
+
system "gem build workarea-braintree.gemspec"
|
47
|
+
system "gem push workarea-braintree-#{Workarea::Braintree::VERSION}.gem"
|
48
|
+
system "gem push workarea-braintree-#{Workarea::Braintree::VERSION}.gem --host #{host}"
|
49
|
+
system "rm workarea-braintree-#{Workarea::Braintree::VERSION}.gem"
|
50
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Workarea
|
2
|
+
decorate Payment::Authorize::CreditCard, with: :braintree do
|
3
|
+
decorated { delegate :address, to: :tender }
|
4
|
+
|
5
|
+
def complete!
|
6
|
+
transaction.response = handle_active_merchant_errors do
|
7
|
+
if tender.token.present?
|
8
|
+
gateway.authorize(
|
9
|
+
transaction.amount.cents,
|
10
|
+
tender.token,
|
11
|
+
{
|
12
|
+
payment_method_token: true,
|
13
|
+
order_id: order_id,
|
14
|
+
email: email,
|
15
|
+
billing_address: billing_address
|
16
|
+
}
|
17
|
+
)
|
18
|
+
else
|
19
|
+
gateway.authorize(
|
20
|
+
transaction.amount.cents,
|
21
|
+
tender.to_active_merchant,
|
22
|
+
{
|
23
|
+
store: true,
|
24
|
+
order_id: order_id,
|
25
|
+
email: email,
|
26
|
+
billing_address: billing_address
|
27
|
+
}
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if transaction.response.success? && tender.token.blank?
|
33
|
+
tender.token = transaction.response.params["braintree_transaction"]["credit_card_details"]["token"]
|
34
|
+
tender.save!
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def cancel!
|
39
|
+
return unless transaction.success?
|
40
|
+
|
41
|
+
transaction.cancellation = handle_active_merchant_errors do
|
42
|
+
gateway.void(transaction.response.authorization)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def email
|
49
|
+
return unless tender.profile.present?
|
50
|
+
|
51
|
+
tender.profile.email
|
52
|
+
end
|
53
|
+
|
54
|
+
def order_id
|
55
|
+
tender.payment.id
|
56
|
+
end
|
57
|
+
|
58
|
+
def billing_address
|
59
|
+
{
|
60
|
+
name: nil,
|
61
|
+
company: nil,
|
62
|
+
address1: address.street,
|
63
|
+
address2: address.street_2,
|
64
|
+
city: address.city,
|
65
|
+
state: address.region,
|
66
|
+
country: address.country.try(:alpha2),
|
67
|
+
zip: address.postal_code,
|
68
|
+
phone: nil
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Workarea
|
2
|
+
decorate Payment::Capture::CreditCard, with: :braintree do
|
3
|
+
def complete!
|
4
|
+
validate_reference!
|
5
|
+
|
6
|
+
transaction.response = handle_active_merchant_errors do
|
7
|
+
gateway.capture(
|
8
|
+
transaction.amount.cents,
|
9
|
+
transaction.reference.response.authorization
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Workarea
|
2
|
+
decorate Payment::Purchase::CreditCard, with: :braintree do
|
3
|
+
decorated { delegate :address, to: :tender }
|
4
|
+
|
5
|
+
def complete!
|
6
|
+
transaction.response = handle_active_merchant_errors do
|
7
|
+
if tender.token.present?
|
8
|
+
gateway.purchase(
|
9
|
+
transaction.amount.cents,
|
10
|
+
tender.token,
|
11
|
+
{ payment_method_token: true }
|
12
|
+
)
|
13
|
+
else
|
14
|
+
gateway.purchase(
|
15
|
+
transaction.amount.cents,
|
16
|
+
tender.to_active_merchant,
|
17
|
+
{ store: true, billing_address: billing_address }
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if transaction.response.success? && tender.token.blank?
|
23
|
+
tender.token = transaction.response.params["braintree_transaction"]["credit_card_details"]["token"]
|
24
|
+
tender.save!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def cancel!
|
29
|
+
return unless transaction.success?
|
30
|
+
|
31
|
+
transaction.cancellation = handle_active_merchant_errors do
|
32
|
+
gateway.void(transaction.response.authorization)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def billing_address
|
39
|
+
{
|
40
|
+
name: nil,
|
41
|
+
company: nil,
|
42
|
+
address1: address.street,
|
43
|
+
address2: address.street_2,
|
44
|
+
city: address.city,
|
45
|
+
state: address.region,
|
46
|
+
country: address.country.try(:alpha2),
|
47
|
+
zip: address.postal_code,
|
48
|
+
phone: nil
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|