kkt_shoppe-stripe 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +21 -0
- data/Rakefile +1 -0
- data/lib/kkt_shoppe/stripe.rb +87 -0
- data/lib/kkt_shoppe/stripe/engine.rb +20 -0
- data/lib/kkt_shoppe/stripe/order_extensions.rb +32 -0
- data/lib/kkt_shoppe/stripe/payment_extensions.rb +16 -0
- data/lib/kkt_shoppe/stripe/version.rb +5 -0
- data/lib/kkt_shoppe/stripe/view_helpers.rb +14 -0
- data/vendor/assets/javascripts/kkt_shoppe/stripe/form_handler.coffee +23 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 27f6d12d8804ec1f5e6d5011ca6d1fad1350cfe8
|
4
|
+
data.tar.gz: 25e7eb9e3e805fd02f5cd71e13e4ef279eae4094
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 571bc56984d3adce7312e200d50b271d4ea11145f7c7b002016cb8ae44d6a6eace6a103298d902dd1ec919194466f50257b18b3a70e03a74fe587bdf4b8e269b
|
7
|
+
data.tar.gz: e2d166de2262b46710565fefc0b921b4b3557b07fdc9483f65e35b4f69e9abf8d51661230706b5fb28d59732f2cd4b6d610970b6eebcb9a1c9868b794470b98c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Niftyware Limited.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Stripe KktShoppe Module
|
2
|
+
|
3
|
+
This module helps with including Stripe within your KktShoppe application. The
|
4
|
+
information below explains how to get this module installed within your Rails
|
5
|
+
application.
|
6
|
+
|
7
|
+
## Getting Started
|
8
|
+
|
9
|
+
This document includes a short tutorial about how to set up this module within your
|
10
|
+
KktShoppe store. If you have any questions, please just
|
11
|
+
[let me know](http://twitter.com/adamcooke).
|
12
|
+
|
13
|
+
### Installing
|
14
|
+
|
15
|
+
To install the KktShoppe Stripe module, just add it to your Gemfile and run `bundle`.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'kkt_shoppe-stripe', :require => 'kkt_shoppe/stripe'
|
19
|
+
```
|
20
|
+
|
21
|
+
For the latest up to date documentation, please see the [KktShoppe tutorial page](http://trykkt_shoppe.com/docs/tutorials/payment-gateways).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'kkt_shoppe/stripe/version'
|
2
|
+
require 'kkt_shoppe/stripe/engine'
|
3
|
+
|
4
|
+
require 'kkt_shoppe/stripe/order_extensions'
|
5
|
+
require 'kkt_shoppe/stripe/payment_extensions'
|
6
|
+
|
7
|
+
module KktShoppe
|
8
|
+
module Stripe
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def api_key
|
13
|
+
KktShoppe.settings.stripe_api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def publishable_key
|
17
|
+
KktShoppe.settings.stripe_publishable_key
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
# Set the configuration which we would like
|
22
|
+
KktShoppe.add_settings_group :stripe, [:stripe_api_key, :stripe_publishable_key, :stripe_currency]
|
23
|
+
|
24
|
+
# Require the external Stripe library
|
25
|
+
require 'stripe'
|
26
|
+
|
27
|
+
# When an order is confirmed, attempt to authorise the payment
|
28
|
+
KktShoppe::Order.before_confirmation do
|
29
|
+
if self.properties['stripe_customer_token']
|
30
|
+
begin
|
31
|
+
charge = ::Stripe::Charge.create({:customer => self.properties['stripe_customer_token'], :amount => (self.total * BigDecimal(100)).round, :currency => KktShoppe.settings.stripe_currency, :capture => false}, KktShoppe.settings.stripe_api_key)
|
32
|
+
self.payments.create(:amount => self.total, :method => 'Stripe', :reference => charge.id, :refundable => true, :confirmed => false)
|
33
|
+
rescue ::Stripe::CardError
|
34
|
+
raise KktShoppe::Errors::PaymentDeclined, "Payment was declined by the payment processor."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# When an order is accepted, attempt to capture the payment
|
40
|
+
KktShoppe::Order.before_acceptance do
|
41
|
+
self.payments.where(:confirmed => false, :method => 'Stripe').each do |payment|
|
42
|
+
begin
|
43
|
+
payment.stripe_charge.capture
|
44
|
+
payment.update_attribute(:confirmed, true)
|
45
|
+
rescue ::Stripe::CardError
|
46
|
+
raise KktShoppe::Errors::PaymentDeclined, "Payment ##{payment.id} could not be captured by Stripe. Investigate with Stripe. Do not accept the order."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# When an order is rejected, attempt to refund all the payments which have been
|
52
|
+
# created with Stripe and are not confirmed.
|
53
|
+
KktShoppe::Order.before_rejection do
|
54
|
+
self.payments.where(:confirmed => false, :method => 'Stripe').each do |payment|
|
55
|
+
payment.refund!(payment.refundable_amount)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# When a new payment is added which is a refund and associated with another Stripe method,
|
60
|
+
# attempt to refund it automatically.
|
61
|
+
KktShoppe::Payment.before_create do
|
62
|
+
if self.refund? && self.parent && self.parent.method == 'Stripe'
|
63
|
+
begin
|
64
|
+
options = {}
|
65
|
+
if self.parent.confirmed?
|
66
|
+
options[:amount] = (self.amount * BigDecimal(100)).round.abs
|
67
|
+
else
|
68
|
+
# If the original item hasn't been captured and the amount refunded isn't the
|
69
|
+
# same as the orignal value, raise an error.
|
70
|
+
if self.amount.abs != self.parent.refundable_amount
|
71
|
+
raise KktShoppe::Errors::RefundFailed, :message => "Refund could not be processed because charge hasn't been captured and the amount is not the same as the original payment."
|
72
|
+
end
|
73
|
+
end
|
74
|
+
refund = self.parent.stripe_charge.refund(options)
|
75
|
+
self.method = 'Stripe'
|
76
|
+
self.reference = refund.id
|
77
|
+
true
|
78
|
+
rescue ::Stripe::CardError, ::Stripe::InvalidRequestError => e
|
79
|
+
raise KktShoppe::Errors::RefundFailed, :message => "Refund could not be processed with Stripe (#{e.class}: #{e.message}). Please investigate with Stripe."
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module KktShoppe
|
2
|
+
module Stripe
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
|
5
|
+
initializer "kkt_shoppe.stripe.initializer" do
|
6
|
+
KktShoppe::Stripe.setup
|
7
|
+
ActiveSupport.on_load(:action_view) do
|
8
|
+
require 'kkt_shoppe/stripe/view_helpers'
|
9
|
+
ActionView::Base.send :include, KktShoppe::Stripe::ViewHelpers
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
config.to_prepare do
|
14
|
+
KktShoppe::Order.send :include, KktShoppe::Stripe::OrderExtensions
|
15
|
+
KktShoppe::Payment.send :include, KktShoppe::Stripe::PaymentExtensions
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module KktShoppe
|
2
|
+
module Stripe
|
3
|
+
module OrderExtensions
|
4
|
+
|
5
|
+
def accept_stripe_token(token)
|
6
|
+
if token =~ /\Atok/
|
7
|
+
customer = ::Stripe::Customer.create({:description => "Customer for order #{number}", :card => token}, KktShoppe.settings.stripe_api_key)
|
8
|
+
self.properties['stripe_customer_token'] = customer.id
|
9
|
+
self.save
|
10
|
+
elsif token =~ /\Acus/ && self.properties[:stripe_customer_token] != token
|
11
|
+
self.properties['stripe_customer_token'] = token
|
12
|
+
self.save
|
13
|
+
elsif self.properties['stripe_customer_token'] && self.properties['stripe_customer_token'] =~ /\Acus/
|
14
|
+
true
|
15
|
+
else
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def stripe_customer
|
23
|
+
@stripe_customer ||= ::Stripe::Customer.retrieve(self.properties['stripe_customer_token'], KktShoppe.settings.stripe_api_key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def stripe_card
|
27
|
+
@stripe_card ||= stripe_customer.cards.last
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module KktShoppe
|
2
|
+
module Stripe
|
3
|
+
module PaymentExtensions
|
4
|
+
|
5
|
+
def stripe_charge
|
6
|
+
return false unless self.method == 'Stripe'
|
7
|
+
@stripe_charge ||= ::Stripe::Charge.retrieve(self.reference, KktShoppe.settings.stripe_api_key)
|
8
|
+
end
|
9
|
+
|
10
|
+
def transaction_url
|
11
|
+
"https://manage.stripe.com/#{Rails.env.production? ? '/' : 'test/'}payments/#{reference}"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module KktShoppe
|
2
|
+
module Stripe
|
3
|
+
module ViewHelpers
|
4
|
+
|
5
|
+
def kkt_shoppe_stripe_javascript
|
6
|
+
String.new.tap do |s|
|
7
|
+
s << javascript_include_tag('https://js.stripe.com/v2/')
|
8
|
+
s << "<script type=\"text/javascript\">Stripe.setPublishableKey('#{KktShoppe::Stripe.publishable_key}');</script>"
|
9
|
+
end.html_safe
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$ ->
|
2
|
+
$('form.stripeForm').on 'submit', ->
|
3
|
+
# The form
|
4
|
+
form = $(this)
|
5
|
+
|
6
|
+
# Build a hash of params which will be sent to Stripe
|
7
|
+
stripeCardParams = {}
|
8
|
+
$.each ['number', 'exp_month', 'exp_year', 'cvc', 'name', 'address_line1', 'address_line2', 'address_city', 'address_state', 'address_zip', 'address_country'], (i,f)->
|
9
|
+
stripeCardParams[f] = $("[data-stripe='#{f}']").val()
|
10
|
+
|
11
|
+
# Send the data to Stripe and define a method to be executed when the response
|
12
|
+
# comes back from Stripe.
|
13
|
+
Stripe.card.createToken stripeCardParams, (status, response)->
|
14
|
+
if response.error
|
15
|
+
$('p.stripeError', form).remove()
|
16
|
+
$("<p class='stripeError'>#{response.error.message}</p>").prependTo(form)
|
17
|
+
$('input[type=submit]', form).removeClass('disabled').prop('disabled', false)
|
18
|
+
else
|
19
|
+
$('[data-stripe=token]').val(response['id'])
|
20
|
+
form.get(0).submit()
|
21
|
+
|
22
|
+
# Return false to ensure that the form doesn't submit on first click
|
23
|
+
false
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kkt_shoppe-stripe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Thompson
|
8
|
+
- Adam Cooke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: kkt_shoppe
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.0.0
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '3'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">"
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 2.0.0
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: stripe
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.7
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.7
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: coffee-rails
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4'
|
62
|
+
description: A Stripe module to assist with the integration of Stripe.
|
63
|
+
email:
|
64
|
+
- kyle@kylekthompson.com
|
65
|
+
- adam@niftyware.io
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- MIT-LICENSE
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/kkt_shoppe/stripe.rb
|
74
|
+
- lib/kkt_shoppe/stripe/engine.rb
|
75
|
+
- lib/kkt_shoppe/stripe/order_extensions.rb
|
76
|
+
- lib/kkt_shoppe/stripe/payment_extensions.rb
|
77
|
+
- lib/kkt_shoppe/stripe/version.rb
|
78
|
+
- lib/kkt_shoppe/stripe/view_helpers.rb
|
79
|
+
- vendor/assets/javascripts/kkt_shoppe/stripe/form_handler.coffee
|
80
|
+
homepage: http://www.kylekthompson.com/
|
81
|
+
licenses: []
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.3
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: An *edited* Stripe module for KktShoppe.
|
103
|
+
test_files: []
|
104
|
+
has_rdoc:
|