Skip to content

Commit

Permalink
Merge pull request #102 from solidusio/gsmendoza/91-ssf-dummy-app
Browse files Browse the repository at this point in the history
Make Solidus Braintree compatible with Starter Frontend
  • Loading branch information
George Mendoza authored Feb 22, 2023
2 parents c2c6452 + 96a259c commit 26dd805
Show file tree
Hide file tree
Showing 75 changed files with 908 additions and 324 deletions.
47 changes: 39 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: 2.1

orbs:
# Required for feature specs.
browser-tools: circleci/[email protected]

# Always take the latest version of the orb, this allows us to
Expand All @@ -10,28 +9,59 @@ orbs:
# or goes EOL.
solidusio_extensions: solidusio/extensions@volatile

commands:
test-with-starter-frontend:
steps:
- checkout
- browser-tools/install-chrome
- run:
name: Install libvips
command: |
sudo apt-get update
sudo apt-get install -yq libvips-dev
- solidusio_extensions/test-branch:
branch: master
command: |
export FRONTEND=starter
sudo gem update --system
gem install bundler rails
bin/dummy-app
bin/rspec
- solidusio_extensions/store-test-results

jobs:
run-specs-with-postgres:
executor: solidusio_extensions/postgres
executor:
name: solidusio_extensions/postgres
ruby_version: '3.1'
steps:
- browser-tools/install-browser-tools
- solidusio_extensions/run-tests
- test-with-starter-frontend

run-specs-with-mysql:
executor: solidusio_extensions/mysql
executor:
name: solidusio_extensions/mysql
ruby_version: '3.0'
steps:
- browser-tools/install-browser-tools
- solidusio_extensions/run-tests
- test-with-starter-frontend

run-specs-with-sqlite:
executor:
name: solidusio_extensions/sqlite
ruby_version: '2.7'
steps:
- test-with-starter-frontend

lint-code:
executor: solidusio_extensions/sqlite-memory
steps:
- browser-tools/install-browser-tools
- solidusio_extensions/lint-code

workflows:
"Run specs on supported Solidus versions":
jobs:
- run-specs-with-postgres
- run-specs-with-mysql
- run-specs-with-sqlite
- lint-code

"Weekly run specs against master":
Expand All @@ -45,3 +75,4 @@ workflows:
jobs:
- run-specs-with-postgres
- run-specs-with-mysql
- run-specs-with-sqlite
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.project
.sass-cache
coverage
dummy-app
Gemfile.lock
tmp
nbproject
Expand Down
9 changes: 8 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ require:

AllCops:
NewCops: disable
TargetRubyVersion: '2.7'
Exclude:
- sandbox/**/*
- dummy-app/**/*
- spec/dummy/**/*
- vendor/bundle/**/*

Layout/FirstArgumentIndentation:
EnforcedStyle: consistent
Expand Down Expand Up @@ -72,7 +78,8 @@ RSpec/MultipleMemoizedHelpers:
- spec/models/solidus_braintree/response_spec.rb
- spec/models/solidus_braintree/gateway_spec.rb
- spec/controllers/solidus_braintree/client_tokens_controller_spec.rb
- spec/features/frontend/braintree_credit_card_checkout_spec.rb
- spec/system/frontend/braintree_credit_card_checkout_spec.rb
- spec/system/frontend/paypal_checkout_spec.rb

Rails/ApplicationRecord:
Exclude:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

`solidus_braintree` is an extension that adds support for using [Braintree](https://www.braintreepayments.com) as a payment source in your [Solidus](https://solidus.io/) store. It supports Apple Pay, PayPal, and credit card transactions.

🚧 This extension is currently only compatible with the legacy `solidus_frontend` 🚧
🚧 This extension is currently only compatible with the `solidus_starter_frontend` 🚧

## Installation

Expand Down Expand Up @@ -119,7 +119,7 @@ Your payment method can accept payments in three ways: through Paypal, through A
end
```

4. If your site uses an unmodified `solidus_frontend`, it should now be ready to take payments. See below for more information on configuring Paypal and ApplePay.
4. If your site uses an unmodified Solidus Starter Frontend, it should now be ready to take payments. See below for more information on configuring Paypal and ApplePay.

5. Typical Solidus sites will have customized frontend code, and may require some additional work. Use `lib/views/frontend/spree/checkout/payment/_braintree.html.erb` and `app/assets/javascripts/solidus_braintree/checkout.js` as models.

Expand Down
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
require 'solidus_dev_support/rake_tasks'
SolidusDevSupport::RakeTasks.install

task default: 'extension:specs'
task :default do
require 'bundler'
Bundler.with_unbundled_env do
sh 'bin/rspec'
end
end
14 changes: 0 additions & 14 deletions app/assets/javascripts/solidus_braintree/frontend.js

This file was deleted.

8 changes: 4 additions & 4 deletions app/assets/javascripts/spree/backend/solidus_braintree.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//= require solidus_braintree/constants
//= require solidus_braintree/client
//= require solidus_braintree/promise
//= require solidus_braintree/hosted_form
//= require spree/backend/solidus_braintree/constants
//= require spree/backend/solidus_braintree/client
//= require spree/backend/solidus_braintree/promise
//= require spree/backend/solidus_braintree/hosted_form

$(function() {
var $paymentForm = $("#new_payment"),
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/spree/frontend/paypal_button.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//= require solidus_braintree/paypal_button
//= require spree/frontend/solidus_braintree/paypal_button

// This is the PayPal button on the cart page
$(document).ready(function() {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/spree/frontend/solidus_braintree.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//= require solidus_braintree/frontend
//= require spree/frontend/solidus_braintree/frontend
13 changes: 13 additions & 0 deletions app/assets/javascripts/spree/frontend/solidus_braintree/ajax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SolidusBraintree.ajax = function(url, options) {
if (typeof url === "object") {
options = url;
url = undefined;
}
options = options || {};
options = $.extend(options, {
headers: {
'Authorization': 'Bearer '
}
});
return $.ajax(url, options);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//= require solidus_braintree/constants
//= require spree/frontend/solidus_braintree/constants
/**
* Constructor for Apple Pay button object
* @constructor
Expand Down Expand Up @@ -94,7 +94,7 @@ SolidusBraintree.ApplepayButton.prototype.tokenize = function (session, payment)
};

SolidusBraintree.ApplepayButton.prototype._createTransaction = function (session, payment, payload) {
Spree.ajax({
SolidusBraintree.ajax({
data: this._transactionParams(payload, payment.shippingContact),
dataType: 'json',
type: 'POST',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//= require solidus_braintree/frontend
//= require spree/frontend/solidus_braintree/frontend

$(function() {
/* This provides a default error handler for Braintree. Since we prevent
Expand Down Expand Up @@ -40,7 +40,7 @@ $(function() {
$paymentForm.on("submit",function(event) {
var $field = $(hostedField);

if ($field.is(":visible") && !$field.data("submitting")) {
if ($field.is(":visible") && $field.is(":enabled") && !$field.data("submitting")) {
var $nonce = $("#payment_method_nonce", $field);

if ($nonce.length > 0 && $nonce.val() === "") {
Expand Down Expand Up @@ -84,7 +84,7 @@ $(function() {

var $paymentForm = $("#checkout_form_payment");
var $hostedFields = $("[data-braintree-hosted-fields]");
var $submitButton = $("input[type='submit']", $paymentForm);
var $submitButton = $("[type='submit']", $paymentForm);

// If we're not using hosted fields, the form doesn't need to wait.
if ($hostedFields.length > 0) {
Expand Down
Loading

0 comments on commit 26dd805

Please sign in to comment.