Skip to content

Commit

Permalink
Make Spree::CreditCard more flexible for handling paypal payments by …
Browse files Browse the repository at this point in the history
…marshalling payment info into json field.

* Add data json field to credit_card
* Marshal payment info received from braintree into data field
* Look at data field for credit card attributes, fall back to super
* Add additional specs for paypal functionality
* Update README
  • Loading branch information
allisonlarson committed Sep 16, 2015
1 parent 9f095e8 commit 38e69af
Show file tree
Hide file tree
Showing 40 changed files with 2,285 additions and 1,854 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in solidus_braintree.gemspec
#gem "solidus", github: "solidusio/solidus", branch: "master"
gem "solidus", github: "solidusio/solidus", branch: "master"
gemspec
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

`solidus_braintree` is a gem that adds [Braintree v.zero](https://www.braintreepayments.com/v.zero) support to the [solidus](http://solidus.io/) E-commerce platform.

It provides support for credit card and Paypal payment methods via the `Spree::CreditCard`

It will add the braintree-drop-in form for payment methods in the payment form of spree/backend. Spree front-end is currently unsupported.

## Installation

Add this line to your solidus application's Gemfile:
Expand All @@ -13,16 +17,19 @@ gem "solidus_braintree"
And then execute:

$ bundle
$ bundle exec rails g solidus_braintree:install

## Usage

This gem extends your solidus application by adding a `POST /api/payment_client_token` endpoint to you application to generate Braintree payment client token. This endpoint requires an authentication token in your request header.

It also creates a new `PaymentMethod` class called `Solidus::Gateway::BraintreeGateway`. You can configure this payment method in the admin and add your Braintree public/private keys and merchant id. The admin will render a Braintree dropin container when prompting you to create an order payment.
It creates a new `PaymentMethod` class called `Solidus::Gateway::BraintreeGateway`. You can configure this payment method in the admin and add your Braintree public/private keys and merchant id. The admin will render a Braintree dropin container when prompting you to create an order payment.

It adds a json or text `data` field on `Spree::CreditCard` for storing additional information received from Braintree for addtional payment methods.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
After checking out the repo, run `bin/setup` to install dependencies. To run tests, first generate a test app by running `rake test_app`. Then, run `rake rspec` which will run the test suite. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'spree/testing_support/common_rake'
require 'spree/testing_support/extension_rake'

RSpec::Core::RakeTask.new(:spec)

Expand All @@ -11,5 +11,5 @@ task default: :spec
desc "Generates a dummy app for testing"
task :test_app do
ENV['LIB_NAME'] = 'solidus_braintree'
Rake::Task['common:test_app'].invoke
Rake::Task['extension:test_app'].invoke
end
21 changes: 21 additions & 0 deletions app/models/concerns/use_data_field_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module UseDataFieldConcern
extend ActiveSupport::Concern
included do
prepend(InstanceMethods)
end

module InstanceMethods

def email
details["email"]
end

def display_number
cc_type == 'paypal' ? email : super
end

def details
@details ||= (data.is_a?(String) ? JSON.parse(data) : data)
end
end
end
1 change: 1 addition & 0 deletions app/models/credit_card_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Spree::CreditCard.include SolidusBraintree::SkipRequireCardNumbersConcern
Spree::CreditCard.include SolidusBraintree::AddNameValidationConcern
Spree::CreditCard.include SolidusBraintree::UseDataFieldConcern
5 changes: 4 additions & 1 deletion app/models/solidus/gateway/braintree_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def create_profile(payment)
source.tap do |solidus_cc|
if card.is_a?(::Braintree::PayPalAccount)
solidus_cc.cc_type = 'paypal'
solidus_cc.name = card.email
data = {
email: card.email
}
solidus_cc.data = data.to_json
else
solidus_cc.name = card.cardholder_name
solidus_cc.cc_type = CARD_TYPE_MAPPING[card.card_type]
Expand Down
7 changes: 7 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/solidus_braintree/engine', __FILE__)

require 'rails/all'
require 'rails/engine/commands'
5 changes: 5 additions & 0 deletions db/migrate/20150910170527_add_data_to_credit_card.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDataToCreditCard < ActiveRecord::Migration
def change
add_column :spree_credit_cards, :data, :json
end
end
2 changes: 1 addition & 1 deletion lib/solidus_braintree/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SolidusBraintree
VERSION = "0.1.5"
VERSION = "0.1.6"
end
2 changes: 1 addition & 1 deletion solidus_braintree.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "solidus_core", [">= 1.0.0", "< 2"]
spec.add_dependency "solidus", [">= 1.0.0", "< 2"]
spec.add_dependency "braintree", "~> 2.46"

spec.add_development_dependency "bundler", "~> 1.10"
Expand Down
Loading

0 comments on commit 38e69af

Please sign in to comment.