payola-payments 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Rakefile +7 -11
- data/app/assets/javascripts/payola.js +1 -0
- data/app/assets/javascripts/payola/checkout_button.js +62 -0
- data/app/controllers/payola/application_controller.rb +2 -0
- data/app/controllers/payola/transactions_controller.rb +48 -58
- data/app/helpers/payola/price_helper.rb +7 -0
- data/{lib → app/models/concerns}/payola/sellable.rb +11 -1
- data/app/models/payola/affiliate.rb +5 -0
- data/app/models/payola/coupon.rb +5 -0
- data/app/models/payola/sale.rb +15 -4
- data/app/models/payola/stripe_webhook.rb +5 -0
- data/app/services/payola/charge_card.rb +6 -5
- data/app/services/payola/create_sale.rb +9 -5
- data/app/views/payola/transactions/_checkout.html.erb +48 -0
- data/app/views/payola/transactions/_form.html.erb +141 -0
- data/app/views/payola/transactions/iframe.html.erb +2 -0
- data/app/views/payola/transactions/new.html.erb +1 -0
- data/app/views/payola/transactions/show.html.erb +5 -0
- data/app/views/payola/transactions/wait.html.erb +25 -0
- data/config/routes.rb +0 -3
- data/db/migrate/20141001170138_create_payola_sales.rb +4 -4
- data/db/migrate/20141001203541_create_payola_stripe_webhooks.rb +9 -0
- data/db/migrate/20141002013618_create_payola_coupons.rb +10 -0
- data/db/migrate/20141002013701_create_payola_affiliates.rb +11 -0
- data/db/migrate/20141002203725_add_stripe_customer_id_to_sale.rb +6 -0
- data/lib/payola.rb +30 -5
- data/lib/payola/engine.rb +8 -0
- data/lib/payola/version.rb +1 -1
- data/lib/payola/worker.rb +22 -4
- data/spec/concerns/sellable_spec.rb +32 -0
- data/spec/controllers/payola/transactions_controller_spec.rb +7 -0
- data/{test → spec}/dummy/README.rdoc +0 -0
- data/{test → spec}/dummy/Rakefile +0 -0
- data/{test → spec}/dummy/app/assets/javascripts/application.js +1 -0
- data/spec/dummy/app/assets/javascripts/buy.js +2 -0
- data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
- data/spec/dummy/app/assets/stylesheets/buy.css +4 -0
- data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/buy_controller.rb +7 -0
- data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
- data/spec/dummy/app/helpers/buy_helper.rb +2 -0
- data/spec/dummy/app/models/product.rb +7 -0
- data/spec/dummy/app/views/buy/index.html.erb +1 -0
- data/{test → spec}/dummy/app/views/layouts/application.html.erb +2 -1
- data/{test → spec}/dummy/bin/bundle +0 -0
- data/{test → spec}/dummy/bin/rails +0 -0
- data/{test → spec}/dummy/bin/rake +0 -0
- data/{test → spec}/dummy/config.ru +0 -0
- data/{test → spec}/dummy/config/application.rb +0 -0
- data/{test → spec}/dummy/config/boot.rb +0 -0
- data/{test → spec}/dummy/config/database.yml +0 -0
- data/{test → spec}/dummy/config/environment.rb +0 -0
- data/{test → spec}/dummy/config/environments/development.rb +0 -0
- data/{test → spec}/dummy/config/environments/production.rb +0 -0
- data/{test → spec}/dummy/config/environments/test.rb +0 -0
- data/{test → spec}/dummy/config/initializers/assets.rb +0 -0
- data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/{test → spec}/dummy/config/initializers/cookies_serializer.rb +0 -0
- data/{test → spec}/dummy/config/initializers/filter_parameter_logging.rb +0 -0
- data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
- data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
- data/spec/dummy/config/initializers/payola.rb +5 -0
- data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
- data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/{test → spec}/dummy/config/locales/en.yml +0 -0
- data/{test → spec}/dummy/config/routes.rb +1 -1
- data/{test → spec}/dummy/config/secrets.yml +0 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20141001230848_create_products.rb +11 -0
- data/spec/dummy/db/schema.rb +76 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +7452 -0
- data/spec/dummy/log/test.log +9849 -0
- data/{test → spec}/dummy/public/404.html +0 -0
- data/{test → spec}/dummy/public/422.html +0 -0
- data/{test → spec}/dummy/public/500.html +0 -0
- data/{test → spec}/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/controllers/buy_controller_spec.rb +5 -0
- data/spec/dummy/spec/factories/products.rb +9 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0e585aeb88c1555ae8f5292f7c7a9068 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0f0c99469c51f1b2d76b08f481781d09 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1b54952339cbc96811097cee5f8923b4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1cbc4f4790f2067a2c161c1eb480f276 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5afa4bc970e0bc781b3500c696ba25ff +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/664efeb51d1b486dcfc30d142db56f3c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/68a3bbdc64a0729b5896fa1e33fce4b1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/aea159adbc0944b120d91d5b578612ba +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b83da90cb58011313e13a97a4a41cb6e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c0b954b40f2881a6d286061bc069643e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c5b3877d49b39932a7557611cefca9a6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ca491e325ff6948be9292f701aa4ce64 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d9856638a3c7b9cfd9d1b884e3b33982 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ddba6e841f28d3005e828fbfffd18b74 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/df935e399019055729aa968bd7062096 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ef82c31948061751bb026663b54484e1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f0b5d4bea0c6cdd1904e1e9a0a45532f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f8018075b7aca72974f4014bbbc75ab5 +0 -0
- data/spec/factories/payola_affiliates.rb +9 -0
- data/spec/factories/payola_coupons.rb +8 -0
- data/spec/factories/product.rb +7 -0
- data/spec/factories/sales.rb +7 -0
- data/spec/models/payola/sale_spec.rb +71 -0
- data/spec/models/payola/stripe_webhook_spec.rb +17 -0
- data/spec/payola_spec.rb +93 -0
- data/spec/services/payola/charge_card_spec.rb +37 -0
- data/spec/services/payola/create_sale_spec.rb +64 -0
- data/spec/spec_helper.rb +73 -0
- data/spec/worker_spec.rb +36 -0
- metadata +275 -81
- data/test/fixtures/payola/sales.yml +0 -11
- data/test/integration/navigation_test.rb +0 -10
- data/test/models/payola/sale_test.rb +0 -9
- data/test/payola_test.rb +0 -7
- data/test/test_helper.rb +0 -15
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjIxZGY2MjlkN2Q2ZDQzNjY5MzJmYjk5ZGNlYTJmMjQxMzk3YjdkNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWE1MjhiMjBjYjU5ODI3ZjFmZjUyNzQ2NGJhOTI3NDQ1MGFkODg5Mg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzUyYzEzMTZhZDBiMWM0MmVhNDQxNWZiZGFlZmI1ZGZiYzE0NzM4ZDIyZGQ3
|
10
|
+
ZDRlZjI2OWNjNGMxY2QzMjhjZWMxNmQ1NjhhNjU0NmE5NTc4NmQyZWEyNDk4
|
11
|
+
MjNhZGQ2YmY0MGQ0ZGM4MTRiYmE5ZDE1ZDQzZDJiMzk0NDViOWI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGEwNzI3NjdmMmRiNTg0OTgxNTczODllMGQ5MTQzZTk1ODc3MzUxYzQ2YWJj
|
14
|
+
NjdhYjBiYjkwMjA5YTk3NDU5MjUyNWEzZjQ4ODU0MTkyMzk3ZDQ2Y2QzYzFj
|
15
|
+
YTBlMTZlZDVmZmU0OWU5ZDA2YzBiYjMyOGJkYjMwMzQyOTE2YjM=
|
data/Rakefile
CHANGED
@@ -14,21 +14,17 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
17
|
-
APP_RAKEFILE = File.expand_path("../
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
18
|
load 'rails/tasks/engine.rake'
|
19
19
|
|
20
|
-
|
21
|
-
|
22
20
|
Bundler::GemHelper.install_tasks
|
23
21
|
|
24
|
-
|
22
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
t.libs << 'test'
|
29
|
-
t.pattern = 'test/**/*_test.rb'
|
30
|
-
t.verbose = false
|
31
|
-
end
|
24
|
+
require 'rspec/core'
|
25
|
+
require 'rspec/core/rake_task'
|
32
26
|
|
27
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
28
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
33
29
|
|
34
|
-
task default
|
30
|
+
task :default => :spec
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require_tree './payola'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
var Payola = {
|
2
|
+
setUpStripeCheckoutButton: function(options) {
|
3
|
+
var handler = StripeCheckout.configure({
|
4
|
+
key: options.publishable_key,
|
5
|
+
image: options.product_image_path,
|
6
|
+
token: function(token) { Payola.tokenHandler(token, options) }
|
7
|
+
});
|
8
|
+
|
9
|
+
document.getElementById(options.button_id).addEventListener('click', function(e) {
|
10
|
+
handler.open({
|
11
|
+
name: options.name,
|
12
|
+
description: options.description,
|
13
|
+
amount: options.amount,
|
14
|
+
panelLabel: options.panel_label,
|
15
|
+
allowRememberMe: options.allow_remember_me,
|
16
|
+
zipCode: options.verify_zip_code,
|
17
|
+
email: options.email || undefined
|
18
|
+
});
|
19
|
+
e.preventDefault();
|
20
|
+
});
|
21
|
+
},
|
22
|
+
|
23
|
+
tokenHandler: function(token, options) {
|
24
|
+
var form = $("#" + options.form_id);
|
25
|
+
console.log(options.form_id);
|
26
|
+
form.append($('<input type="hidden" name="stripeToken">').val(token.id));
|
27
|
+
form.append($('<input type="hidden" name="stripeEmail">').val(token.email));
|
28
|
+
$("#" + options.button_id).prop("disabled", true);
|
29
|
+
$("#" + options.button_text_id).hide();
|
30
|
+
$("#" + options.button_spinner_id).show();
|
31
|
+
$.ajax({
|
32
|
+
type: "POST",
|
33
|
+
url: "/payola/buy/" + options.product_class + "/" + options.product_permalink,
|
34
|
+
data: form.serialize(),
|
35
|
+
success: function(data) { Payola.poll(data.guid, 60, options.error_div_id) },
|
36
|
+
error: function(data) { Payola.showError(data.responseJSON.error, options.error_div_id) }
|
37
|
+
});
|
38
|
+
},
|
39
|
+
|
40
|
+
showError: function(error, error_div_id) {
|
41
|
+
var error_div = $("#" + error_div_id);
|
42
|
+
error_div.toggle();
|
43
|
+
error_div.html(error);
|
44
|
+
},
|
45
|
+
|
46
|
+
poll: function(guid, num_retries_left, error_div_id) {
|
47
|
+
if (num_retries_left == 0) {
|
48
|
+
Payola.showError("This seems to be taking too long. Please contact support and give them transaction ID: " + guid, error_div_id);
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
$.get("/payola/status/" + guid, function(data) {
|
53
|
+
if (data.status === "finished") {
|
54
|
+
window.location = "/payola/confirm/" + guid;
|
55
|
+
} else if (data.status === "errored") {
|
56
|
+
Payola.showError(data.error, error_div_id);
|
57
|
+
} else {
|
58
|
+
setTimeout(function() { Payola.poll(guid, num_retries_left - 1) }, 500);
|
59
|
+
}
|
60
|
+
});
|
61
|
+
}
|
62
|
+
}
|
@@ -1,75 +1,65 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Payola
|
2
|
+
class TransactionsController < ApplicationController
|
3
|
+
before_filter :find_product_and_coupon_and_affiliate, only: [:create]
|
3
4
|
|
4
|
-
|
5
|
+
def show
|
6
|
+
@sale = Sale.find_by!(guid: params[:guid])
|
7
|
+
@product = @sale.product
|
5
8
|
|
6
|
-
|
7
|
-
@sale = Sale.new(product: @product)
|
8
|
-
set_page_title "Buy #{@product.name}"
|
9
|
-
end
|
10
|
-
|
11
|
-
def iframe
|
12
|
-
@sale = Sale.new(product: @product)
|
13
|
-
end
|
14
|
-
|
15
|
-
def show
|
16
|
-
@sale = Sale.find_by!(guid: params[:guid])
|
17
|
-
@product = @sale.product
|
18
|
-
end
|
19
|
-
|
20
|
-
def status
|
21
|
-
@sale = Sale.where(guid: params[:guid]).first
|
22
|
-
render nothing: true, status: 404 and return unless @sale
|
23
|
-
render json: {guid: @sale.guid, status: @sale.state, error: @sale.error}
|
24
|
-
end
|
25
|
-
|
26
|
-
def create
|
27
|
-
@sale = CreateSale.call(sale_params, @product, @coupon, @affiliate)
|
28
|
-
|
29
|
-
if @sale.save
|
30
|
-
Payola.queue(@sale)
|
31
|
-
render json: { guid: @sale.guid }
|
32
|
-
else
|
33
|
-
render json: { error: @sale.errors.full_messages.join(". ") }, status: 400
|
9
|
+
redirect_to product.redirect_path(sale)
|
34
10
|
end
|
35
|
-
end
|
36
11
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
12
|
+
def status
|
13
|
+
@sale = Sale.where(guid: params[:guid]).first
|
14
|
+
render nothing: true, status: 404 and return unless @sale
|
15
|
+
render json: {guid: @sale.guid, status: @sale.state, error: @sale.error}
|
16
|
+
end
|
41
17
|
|
42
|
-
|
18
|
+
def create
|
19
|
+
create_params = sale_params.merge(
|
20
|
+
product: @product,
|
21
|
+
coupon: @coupon,
|
22
|
+
affiliate: @affiliate
|
23
|
+
)
|
24
|
+
|
25
|
+
@sale = CreateSale.call(create_params)
|
26
|
+
|
27
|
+
if @sale.save
|
28
|
+
Payola.queue!(@sale)
|
29
|
+
render json: { guid: @sale.guid }
|
30
|
+
else
|
31
|
+
render json: { error: @sale.errors.full_messages.join(". ") }, status: 400
|
32
|
+
end
|
33
|
+
end
|
43
34
|
|
44
|
-
|
35
|
+
private
|
36
|
+
def find_product_and_coupon_and_affiliate
|
37
|
+
@product_class = Payola.sellables[params[:product_class]]
|
45
38
|
|
46
|
-
|
47
|
-
def strip_iframe_protection
|
48
|
-
response.headers.delete('X-Frame-Options')
|
49
|
-
end
|
39
|
+
raise ActionController::RoutingError.new('Not Found') unless @product_class && @product_class.sellable?
|
50
40
|
|
51
|
-
|
52
|
-
|
41
|
+
@product = @product_class.find_by!(permalink: params[:permalink])
|
42
|
+
coupon_code = cookies[:cc] || params[:cc] || params[:coupon_code]
|
53
43
|
|
54
|
-
|
44
|
+
@coupon = Coupon.where('lower(code) = lower(?)', coupon_code).first
|
45
|
+
if @coupon
|
46
|
+
cookies[:cc] = coupon_code
|
47
|
+
@price = @product.price * (1 - @coupon.percent_off / 100.0)
|
48
|
+
else
|
49
|
+
@price = @product.price
|
50
|
+
end
|
55
51
|
|
56
|
-
|
57
|
-
|
52
|
+
affiliate_code = cookies[:aff] || params[:aff]
|
53
|
+
@affiliate = Affiliate.where('lower(code) = lower(?)', affiliate_code).first
|
54
|
+
if @affiliate
|
55
|
+
cookies[:aff] = affiliate_code
|
56
|
+
end
|
58
57
|
|
59
|
-
@coupon = Coupon.where('lower(code) = lower(?)', coupon_code).first
|
60
|
-
if @coupon
|
61
|
-
cookies[:cc] = coupon_code
|
62
|
-
@price = @product.price * (1 - @coupon.percent_off / 100.0)
|
63
|
-
else
|
64
|
-
@price = @product.price
|
65
58
|
end
|
66
59
|
|
67
|
-
|
68
|
-
|
69
|
-
if @affiliate
|
70
|
-
cookies[:aff] = affiliate_code
|
60
|
+
def sale_params
|
61
|
+
params.permit(:stripeToken, :stripe_token, :stripeTokenType, :stripeEmail)
|
71
62
|
end
|
72
63
|
|
73
64
|
end
|
74
|
-
|
75
65
|
end
|
@@ -6,14 +6,24 @@ module Payola
|
|
6
6
|
|
7
7
|
included do
|
8
8
|
validates_presence_of :name
|
9
|
-
|
9
|
+
validates_presence_of :permalink
|
10
10
|
validates_uniqueness_of :permalink
|
11
|
+
|
12
|
+
Payola.register_sellable(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def product_class
|
16
|
+
self.class.product_class
|
11
17
|
end
|
12
18
|
|
13
19
|
module ClassMethods
|
14
20
|
def sellable?
|
15
21
|
true
|
16
22
|
end
|
23
|
+
|
24
|
+
def product_class
|
25
|
+
self.to_s.underscore
|
26
|
+
end
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
data/app/models/payola/sale.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
+
require 'aasm'
|
2
|
+
|
1
3
|
module Payola
|
2
4
|
class Sale < ActiveRecord::Base
|
3
5
|
has_paper_trail if respond_to? :has_paper_trail
|
4
6
|
|
5
7
|
validates_presence_of :email
|
6
8
|
validates_presence_of :product_id
|
9
|
+
validates_presence_of :product_type
|
7
10
|
validates_presence_of :stripe_token
|
8
11
|
|
9
12
|
validates_uniqueness_of :guid
|
10
13
|
|
11
14
|
before_save :populate_guid
|
12
15
|
|
13
|
-
belongs_to :product
|
16
|
+
belongs_to :product, polymorphic: true
|
14
17
|
belongs_to :coupon
|
15
18
|
belongs_to :affiliate
|
16
19
|
|
@@ -48,15 +51,23 @@ module Payola
|
|
48
51
|
end
|
49
52
|
|
50
53
|
def instrument_finish
|
51
|
-
Payola.instrument('
|
54
|
+
Payola.instrument(instrument_key('finished'), self)
|
52
55
|
end
|
53
56
|
|
54
57
|
def instrument_fail
|
55
|
-
Payola.instrument('
|
58
|
+
Payola.instrument(instrument_key('failed'), self)
|
56
59
|
end
|
57
60
|
|
58
61
|
def instrument_refund
|
59
|
-
Payola.instrument('
|
62
|
+
Payola.instrument(instrument_key('refunded'), self)
|
63
|
+
end
|
64
|
+
|
65
|
+
def product_class
|
66
|
+
product.product_class
|
67
|
+
end
|
68
|
+
|
69
|
+
def instrument_key(instrument_type)
|
70
|
+
"payola.#{product_class}.sale.#{instrument_type}"
|
60
71
|
end
|
61
72
|
|
62
73
|
def populate_guid
|
@@ -25,11 +25,12 @@ module Payola
|
|
25
25
|
end
|
26
26
|
|
27
27
|
sale.update_attributes(
|
28
|
-
stripe_id:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
stripe_id: charge.id,
|
29
|
+
stripe_customer_id: customer.id,
|
30
|
+
card_last4: charge.card.last4,
|
31
|
+
card_expiration: Date.new(charge.card.exp_year, charge.card.exp_month, 1),
|
32
|
+
card_type: charge.card.respond_to?(:brand) ? charge.card.brand : charge.card.type,
|
33
|
+
fee_amount: fee
|
33
34
|
)
|
34
35
|
sale.finish!
|
35
36
|
rescue Stripe::StripeError => e
|
@@ -1,17 +1,21 @@
|
|
1
1
|
module Payola
|
2
2
|
class CreateSale
|
3
|
-
def self.call(params
|
3
|
+
def self.call(params)
|
4
|
+
product = params[:product]
|
5
|
+
affiliate = params[:affiliate]
|
6
|
+
coupon = params[:coupon]
|
7
|
+
|
4
8
|
Payola::Sale.new do |s|
|
5
9
|
s.product = product
|
6
|
-
s.email = params[:email]
|
7
|
-
s.stripe_token = params[:stripe_token]
|
10
|
+
s.email = params[:email] || params[:stripeEmail]
|
11
|
+
s.stripe_token = params[:stripeToken] || params[:stripe_token]
|
8
12
|
s.affiliate_id = affiliate.try(:id)
|
9
13
|
|
10
14
|
if coupon
|
11
15
|
s.coupon = coupon
|
12
|
-
s.amount =
|
16
|
+
s.amount = product.price * (1 - s.coupon.percent_off / 100.0)
|
13
17
|
else
|
14
|
-
s.amount =
|
18
|
+
s.amount = product.price
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<%
|
2
|
+
button_class ||= "stripe-button-el"
|
3
|
+
button_text ||= "Pay Now"
|
4
|
+
description ||= "#{sale.product.name} (#{formatted_price(sale.product.price)})"
|
5
|
+
name ||= sale.product.name
|
6
|
+
product_image_path ||= ""
|
7
|
+
panel_label ||= ""
|
8
|
+
allow_remember_me = defined?(allow_remember_me) ? allow_remember_me : true
|
9
|
+
email ||= ""
|
10
|
+
verify_zip_code = defined?(verify_zip_code) ? verify_zip_code : false
|
11
|
+
|
12
|
+
button_id ||= "payola-button-#{sale.product.product_class}-#{sale.product.permalink}"
|
13
|
+
error_div_id ||= "#{button_id}-errors"
|
14
|
+
form_id ||= "#{button_id}-form"
|
15
|
+
button_text_id = "#{button_id}-span"
|
16
|
+
button_spinner_id = "#{button_id}-spinner"
|
17
|
+
%>
|
18
|
+
|
19
|
+
<script src="https://checkout.stripe.com/checkout.js"></script>
|
20
|
+
<link rel="stylesheet" href="https://checkout.stripe.com/v3/checkout/button.css"></link>
|
21
|
+
|
22
|
+
<%= form_tag payola.buy_path(product_class: sale.product.product_class, permalink: sale.product.permalink), id: form_id do %>
|
23
|
+
<button class="stripe-button-el" id="<%= button_id %>">
|
24
|
+
<span id="<%= button_text_id %>" style="display: block; min-height: 30px;"><%= button_text %></span>
|
25
|
+
<span id="<%= button_spinner_id %>" style="display:none;min-iehgt: 30px;">Please wait...</span>
|
26
|
+
</button>
|
27
|
+
<div style="display:none", id="<%= error_div_id %>"></div>
|
28
|
+
<% end %>
|
29
|
+
<script type="text/javascript">
|
30
|
+
Payola.setUpStripeCheckoutButton({
|
31
|
+
form_id: "<%= form_id %>",
|
32
|
+
button_id: "<%= button_id %>",
|
33
|
+
button_text_id: "<%= button_text_id %>",
|
34
|
+
button_spinner_id: "<%= button_spinner_id %>",
|
35
|
+
error_div_id: "<%= error_div_id %>",
|
36
|
+
product_class: "<%= sale.product.product_class %>",
|
37
|
+
product_permalink: "<%= sale.product.permalink %>",
|
38
|
+
price: <%= sale.product.price %>,
|
39
|
+
name: "<%= name %>",
|
40
|
+
description: "<%= description %>",
|
41
|
+
product_image_path: "<%= product_image_path %>",
|
42
|
+
publishable_key: "<%= Payola.publishable_key %>",
|
43
|
+
panel_label: "<%= panel_label %>",
|
44
|
+
allow_remember_me: <%= allow_remember_me %>,
|
45
|
+
email: "<%= email %>",
|
46
|
+
verify_zip_code: <%= verify_zip_code %>
|
47
|
+
});
|
48
|
+
</script>
|