From a6cf9eb59f7c4c5d5ffa022294307e7c1feed055 Mon Sep 17 00:00:00 2001 From: diptib10 Date: Mon, 12 Mar 2018 11:50:45 -0700 Subject: [PATCH 1/8] Clean-up --- LICENSE | 47 +++++++++++++++++++++++--------------------- README.md | 2 +- spree_affirm.gemspec | 8 ++++---- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/LICENSE b/LICENSE index e46f806..f7f2057 100644 --- a/LICENSE +++ b/LICENSE @@ -1,26 +1,29 @@ -Copyright (c) 2014 [name of plugin creator] +BSD 3-Clause License + +Copyright (c) 2018, Affirm All rights reserved. -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name Spree nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md index 2065e3a..8ff40ba 100644 --- a/README.md +++ b/README.md @@ -44,4 +44,4 @@ Simply add this require statement to your spec_helper: require 'spree_affirm/factories' ``` -Copyright (c) 2015 Affirm, released under the New BSD License +Copyright (c) 2018 Affirm, released under the New BSD License diff --git a/spree_affirm.gemspec b/spree_affirm.gemspec index 3028b91..be9d0cf 100644 --- a/spree_affirm.gemspec +++ b/spree_affirm.gemspec @@ -7,12 +7,12 @@ Gem::Specification.new do |s| s.name = 'spree_affirm' s.version = SpreeAffirm::VERSION s.summary = 'Affirm Spree Payment Gateway' - s.description = 'Affirm payment Gateway for spree' + s.description = 'Affirm payment Gateway for Spree' s.required_ruby_version = '>= 1.9.3' - s.author = 'Yu Pan' - s.email = 'yu.pan@affirm.com' - s.homepage = 'http://www.spreecommerce.com' + s.author = 'Affirm' + s.email = 'mts@affirm.com' + s.homepage = 'http://www.affirm.com' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") From 98608f5ab96147b931bd487f45c86d46ae6752b5 Mon Sep 17 00:00:00 2001 From: diptib10 Date: Mon, 12 Mar 2018 11:53:02 -0700 Subject: [PATCH 2/8] Version upgrade --- Gemfile | 6 +++--- lib/spree_affirm/version.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 790bc9f..eb92efd 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' -gem 'spree', github: 'spree/spree', branch: '2-4-stable' -gem 'spree_gateway', github: 'spree/spree_gateway', branch: '2-4-stable' -gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-4-stable' +gem 'spree', github: 'spree/spree', branch: 'master' +gem 'spree_gateway', github: 'spree/spree_gateway', branch: 'master' +gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master' group :test do gem 'coffee-rails' diff --git a/lib/spree_affirm/version.rb b/lib/spree_affirm/version.rb index 2a47de2..ce2b447 100644 --- a/lib/spree_affirm/version.rb +++ b/lib/spree_affirm/version.rb @@ -1,3 +1,3 @@ module SpreeAffirm - VERSION = "0.2.23" + VERSION = "0.2.24" end From 0183c493b43c4cc935ad8765d6409e4e8df3c15f Mon Sep 17 00:00:00 2001 From: diptib10 Date: Mon, 12 Mar 2018 12:00:37 -0700 Subject: [PATCH 3/8] order_id --- app/views/spree/checkout/payment/_affirm.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/spree/checkout/payment/_affirm.html.erb b/app/views/spree/checkout/payment/_affirm.html.erb index 1f3952a..714d3d5 100644 --- a/app/views/spree/checkout/payment/_affirm.html.erb +++ b/app/views/spree/checkout/payment/_affirm.html.erb @@ -23,7 +23,7 @@ total: <%= (@order.total * 100).to_i %>, currency: "USD", tax_amount: <%= (@order.additional_tax_total * 100).to_i %>, - checkout_id: "<%= @order.number %>", + order_id: "<%= @order.number %>", discount_code: "<%= @order.coupon_code %>", shipping_type: "<%= @order.shipments.first.shipping_method.name if @order.shipments %>", shipping_amount: <%= (@order.shipment_total * 100).to_i %>, From 233eded0dcbb07093307bdf1bf65f4eb5c22fdf5 Mon Sep 17 00:00:00 2001 From: diptib10 Date: Mon, 12 Mar 2018 12:03:00 -0700 Subject: [PATCH 4/8] platform metadata changes --- app/views/spree/checkout/payment/_affirm.html.erb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/views/spree/checkout/payment/_affirm.html.erb b/app/views/spree/checkout/payment/_affirm.html.erb index 714d3d5..e6f7266 100644 --- a/app/views/spree/checkout/payment/_affirm.html.erb +++ b/app/views/spree/checkout/payment/_affirm.html.erb @@ -58,10 +58,14 @@ }, + metadata: { + "platform_type": "spree_affirm", + "platform_version": "<%= Spree.version %>", + "platform_affirm": "<%= Spree::Gateway::Affirm.version %>", + }, + meta: { source: { - client_name: "spree_affirm", - version: "<%= Spree::Gateway::Affirm.version %>", data: { <% if spree_current_user %> order_count: "<%= spree_current_user.orders.complete.count %>", @@ -73,7 +77,6 @@ <% end %> is_logged_in: <%= !!spree_current_user %>, - spree_version: "<%= Spree.version %>" } } }, From b395a17b5092ecb8f6349c0cf619759d48d28481 Mon Sep 17 00:00:00 2001 From: diptib10 Date: Mon, 12 Mar 2018 12:54:00 -0700 Subject: [PATCH 5/8] Removed financial product key --- app/models/spree/affirm_checkout.rb | 7 ------- app/models/spree/gateway/affirm.rb | 1 - .../spree/checkout/payment/_affirm.html.erb | 3 +-- config/locales/en.yml | 2 -- .../factories/affirm_checkout_factory.rb | 8 ------- spec/models/spree_affirm_checkout_spec.rb | 21 ------------------- 6 files changed, 1 insertion(+), 41 deletions(-) diff --git a/app/models/spree/affirm_checkout.rb b/app/models/spree/affirm_checkout.rb index d0e4d89..aee64fc 100644 --- a/app/models/spree/affirm_checkout.rb +++ b/app/models/spree/affirm_checkout.rb @@ -22,7 +22,6 @@ def validate_checkout_matches_order check_matching_shipping_address check_matching_billing_address check_matching_billing_email - check_matching_product_key end def check_valid_products @@ -74,12 +73,6 @@ def check_matching_billing_email end end - def check_matching_product_key - if details["config"]["financial_product_key"] != payment_method.preferred_product_key - errors.add :financial_product_key, "Product key mismatch" - end - end - def actions %w{capture void credit} end diff --git a/app/models/spree/gateway/affirm.rb b/app/models/spree/gateway/affirm.rb index 53990f3..8bae70c 100644 --- a/app/models/spree/gateway/affirm.rb +++ b/app/models/spree/gateway/affirm.rb @@ -3,7 +3,6 @@ class Gateway::Affirm < Gateway preference :api_key, :string preference :secret_key, :string preference :server, :string, default: 'www.affirm.com' - preference :product_key, :string def provider_class ActiveMerchant::Billing::Affirm diff --git a/app/views/spree/checkout/payment/_affirm.html.erb b/app/views/spree/checkout/payment/_affirm.html.erb index e6f7266..ac43184 100644 --- a/app/views/spree/checkout/payment/_affirm.html.erb +++ b/app/views/spree/checkout/payment/_affirm.html.erb @@ -185,8 +185,7 @@ clicked \*****************************************************/ window.AffirmPaymentMethods["<%= payment_method.id %>"] = { - public_api_key: "<%= payment_method.preferred_api_key %>", - financial_product_key: "<%= payment_method.preferred_product_key %>" + public_api_key: "<%= payment_method.preferred_api_key %>" }; }()); diff --git a/config/locales/en.yml b/config/locales/en.yml index dbd8814..6cdd1a1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -12,7 +12,6 @@ en: "Quantity mismatch": "Quantity mismatch" "Price mismatch": "Price mismatch" "Billing email mismatch": "Billing email mismatch" - "Product key mismatch": "Product key mismatch" "city mismatch": "city mismatch" "street1 mismatch": "street1 mismatch" "street2 mismatch": "street2 mismatch" @@ -27,5 +26,4 @@ en: billing_address: "billing address" shipping_address: "shipping address" billing_email: "email" - financial_product_key: "Affirm Financial Product" diff --git a/lib/spree_affirm/factories/affirm_checkout_factory.rb b/lib/spree_affirm/factories/affirm_checkout_factory.rb index c6dfe61..ca9073b 100644 --- a/lib/spree_affirm/factories/affirm_checkout_factory.rb +++ b/lib/spree_affirm/factories/affirm_checkout_factory.rb @@ -62,8 +62,6 @@ def BASE_CHECKOUT_DETAILS "misc_fee_amount"=> 0, "shipping_type"=> "Free National UPS", "config"=> { - "financial_product_key"=> "XXXXXXXXXXXXXXX", - "financial_product_type"=> "splitpay", "required_billing_fields"=> [ "name", "address", @@ -84,7 +82,6 @@ def BASE_CHECKOUT_DETAILS transient do stub_details true - product_key_mismatch false shipping_address_mismatch false billing_address_mismatch false alternate_billing_address_format false @@ -101,11 +98,6 @@ def BASE_CHECKOUT_DETAILS _details = BASE_CHECKOUT_DETAILS() - # product keys - unless evaluator.product_key_mismatch - _details['config']['financial_product_key'] = checkout.payment_method.preferred_product_key - end - # case mismatch unless evaluator.full_name_case_mismatch _details['billing']['name'] = { diff --git a/spec/models/spree_affirm_checkout_spec.rb b/spec/models/spree_affirm_checkout_spec.rb index 2965048..e556ef9 100644 --- a/spec/models/spree_affirm_checkout_spec.rb +++ b/spec/models/spree_affirm_checkout_spec.rb @@ -180,27 +180,6 @@ end end - - describe "check_matching_product_key" do - context "with a matching product key" do - it "does not set an error for the financial_product_key" do - valid_checkout.check_matching_product_key - expect(valid_checkout.errors[:financial_product_key]).to be_empty - end - end - - - context "with a mistmatched product key" do - it "adds an error for financial_product_key" do - _checkout = FactoryGirl.build(:affirm_checkout, product_key_mismatch: true) - _checkout.check_matching_product_key - expect(_checkout.errors[:financial_product_key]).not_to be_empty - end - end - end - - - describe "actions" do describe "#actions" do From c4cfa9b7b072da8fbc0d0dadfc71a66389a9b0c2 Mon Sep 17 00:00:00 2001 From: diptib10 Date: Mon, 12 Mar 2018 16:26:23 -0700 Subject: [PATCH 6/8] Test mode, domain clean up --- app/models/spree/gateway/affirm.rb | 3 ++- app/views/spree/checkout/payment/_affirm.html.erb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/spree/gateway/affirm.rb b/app/models/spree/gateway/affirm.rb index 8bae70c..d241439 100644 --- a/app/models/spree/gateway/affirm.rb +++ b/app/models/spree/gateway/affirm.rb @@ -2,7 +2,8 @@ module Spree class Gateway::Affirm < Gateway preference :api_key, :string preference :secret_key, :string - preference :server, :string, default: 'www.affirm.com' + preference :test_mode, :boolean, default: true + preference :server, :string, default: 'sandbox.affirm.com' def provider_class ActiveMerchant::Billing::Affirm diff --git a/app/views/spree/checkout/payment/_affirm.html.erb b/app/views/spree/checkout/payment/_affirm.html.erb index ac43184..77d66d2 100644 --- a/app/views/spree/checkout/payment/_affirm.html.erb +++ b/app/views/spree/checkout/payment/_affirm.html.erb @@ -12,7 +12,7 @@ \*****************************************************/ var _affirm_config = { public_api_key: "<%= payment_method.preferred_api_key %>", - script: "https://<%= payment_method.preferred_server %>/js/v2/affirm.js" + script: "https://<%= payment_method.preferences[:test_mode] ? 'cdn1-sandbox.affirm.com' : 'cdn1.affirm.com' %>/js/v2/affirm.js" }; (function(l,g,m,e,a,f,b){var d,c=l[m]||{},h=document.createElement(f),n=document.getElementsByTagName(f)[0],k=function(a,b,c){return function(){a[b]._.push([c,arguments])}};c[e]=k(c,e,"set");d=c[e];c[a]={};c[a]._=[];d._=[];c[a][b]=k(c,a,b);a=0;for(b="set add save post open empty reset on off trigger ready setProduct".split(" ");a Date: Mon, 12 Mar 2018 16:30:09 -0700 Subject: [PATCH 7/8] Readme updated --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8ff40ba..1e2f993 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,10 @@ Installation 4. Restart your server +Documentation +------------------ +https://docs.affirm.com/Spree + ## Contributing 1. Fork it From 48ecbdfd884c3b3ce560827964ebca9372e87e9f Mon Sep 17 00:00:00 2001 From: diptib10 Date: Tue, 13 Mar 2018 11:23:22 -0700 Subject: [PATCH 8/8] metadata and gemfile changes --- Gemfile | 6 +++--- app/views/spree/checkout/payment/_affirm.html.erb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index eb92efd..df6444a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' -gem 'spree', github: 'spree/spree', branch: 'master' -gem 'spree_gateway', github: 'spree/spree_gateway', branch: 'master' -gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master' +gem 'spree', github: 'spree/spree', tag: 'v0.2.24' +gem 'spree_gateway', github: 'spree/spree_gateway', tag: 'v0.2.24' +gem 'spree_auth_devise', github: 'spree/spree_auth_devise', tag: 'v0.2.24' group :test do gem 'coffee-rails' diff --git a/app/views/spree/checkout/payment/_affirm.html.erb b/app/views/spree/checkout/payment/_affirm.html.erb index 77d66d2..393d558 100644 --- a/app/views/spree/checkout/payment/_affirm.html.erb +++ b/app/views/spree/checkout/payment/_affirm.html.erb @@ -59,7 +59,7 @@ metadata: { - "platform_type": "spree_affirm", + "platform_type": "Spree Commerce", "platform_version": "<%= Spree.version %>", "platform_affirm": "<%= Spree::Gateway::Affirm.version %>", },