shoppe-paypal 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1813df55015dfeec5bdca0267c32cf77dc9f493
4
+ data.tar.gz: a0ba3fd1776c4dee76d2e4390fb4222ada3e5450
5
+ SHA512:
6
+ metadata.gz: b73e4c91731564567a67b33b77b547e9faf40668fb7f31f4eb5524f399d462e6dd4649d8e573de3e62fa610370f744eadeff7ea1b6c68853b6a58af4e179dedd
7
+ data.tar.gz: b3bc80129b546e5fede96d68814450c4726cbd6c04b0bd5b8221aa5af56609543cd100e12b08fd2bb59fbf47e167564c55dd828581faf4ebe8f39ac655e18cfd
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # PayPal Shoppe Module
2
+
3
+ This module helps with including PayPal within your Shoppe application.
4
+ The information below explains how to get this module installed within your Rails application.
5
+
6
+ ## Installing
7
+
8
+ Add the gem to your Gemfile and run `bundle install`
9
+
10
+ `gem "shoppe-paypal"`
11
+
12
+ For the latest up to date documentation, please see the [Shoppe tutorial page](http://tryshoppe.com/docs/payment-gateways/paypal).
13
+
14
+ ## Workflow
15
+
16
+ + Start an order
17
+ + Give the user the decision of payment
18
+ + Create a PayPal payment
19
+ + Redirect the user to PayPal using the previous URL
20
+ + User logs in & accepts payment
21
+ + Redirected to success URL and payment details are stored with the order
22
+ + Complete order
23
+ + When the order is accepted in the Shoppe admin, the payment will be executed/captured
24
+
25
+ ## To Do
26
+
27
+ + Tests!
28
+ + When rejecting an order, payment is not refunded
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ module Shoppe
2
+ module Paypal
3
+ class Engine < Rails::Engine
4
+
5
+ initializer "shoppe.paypal.initializer" do
6
+ Shoppe::Paypal.setup
7
+ end
8
+
9
+ config.to_prepare do
10
+ Shoppe::Order.send :include, Shoppe::Paypal::OrderExtensions
11
+ Shoppe::Payment.send :include, Shoppe::Paypal::PaymentExtensions
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ module Shoppe
2
+ module Paypal
3
+ module OrderExtensions
4
+
5
+ # Create a PayPal payment and respond with the approval URL
6
+ # Requires return_url and cancel_url parameters
7
+ def redirect_to_paypal(return_url, cancel_url)
8
+ @payment = PayPal::SDK::REST::Payment.new({
9
+ :intent => "sale",
10
+ :payer => {
11
+ :payment_method => "paypal" },
12
+ :redirect_urls => {
13
+ :return_url => return_url,
14
+ :cancel_url => cancel_url },
15
+ :transactions => [ {
16
+ :amount => {
17
+ :total => '%.2f' % self.total,
18
+ :currency => Shoppe::Paypal.currency },
19
+ :description => "Order #{self.number}" } ] } )
20
+
21
+ if @payment.create
22
+ @payment.links.find{|v| v.method == "REDIRECT" }.href
23
+ elsif @payment.error
24
+ raise Shoppe::Errors::PaymentDeclined, "There was an error contacting the payment processor"
25
+ end
26
+ end
27
+
28
+ # Accept a PayPal payment after redirected back to the Rails app
29
+ def accept_paypal_payment(payment_id, token, payer_id)
30
+ self.payments.create(amount: self.total, method: "PayPal", reference: payment_id, refundable: true, confirmed: false)
31
+
32
+ self.properties["paypal_payment_id"] = payment_id
33
+ self.properties["paypal_payment_token"] = token
34
+ self.properties["paypal_payer_id"] = payer_id
35
+ self.save
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ module Shoppe
2
+ module Paypal
3
+ module PaymentExtensions
4
+
5
+ # Get the PayPal payment information from the API
6
+ def paypal_payment
7
+ return false unless self.method == "PayPal"
8
+
9
+ @paypal_payment ||= PayPal::SDK::REST::Payment.find(self.reference)
10
+ end
11
+
12
+ # The PayPal transaction URL
13
+ def transaction_url
14
+ if Rails.env.production?
15
+ "https://history.paypal.com/uk/cgi-bin/webscr?cmd=_history-details-from-hub&id=#{reference}"
16
+ else
17
+ "https://www.sandbox.paypal.com/uk/cgi-bin/webscr?cmd=_history-details-from-hub&id=#{reference}"
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Shoppe
2
+ module Paypal
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ require 'shoppe/paypal/version'
2
+ require 'shoppe/paypal/engine'
3
+
4
+ require 'shoppe/paypal/order_extensions'
5
+ require 'shoppe/paypal/payment_extensions'
6
+
7
+ module Shoppe
8
+ module Paypal
9
+
10
+ class << self
11
+
12
+ def client_id
13
+ Shoppe.settings.paypal_client_id
14
+ end
15
+
16
+ def client_secret
17
+ Shoppe.settings.paypal_secret_id
18
+ end
19
+
20
+ def currency
21
+ Shoppe.settings.paypal_currency
22
+ end
23
+
24
+ def setup
25
+ # Set the configuration
26
+ Shoppe.add_settings_group :paypal, [:paypal_client_id, :paypal_secret_id, :currency]
27
+
28
+ # Require the PayPal library
29
+ require 'paypal-sdk-rest'
30
+
31
+ include PayPal::SDK::REST
32
+
33
+ # Configure the PayPal library
34
+ PayPal::SDK.configure({
35
+ mode: (Rails.env.production? ? "live" : "sandbox"),
36
+ client_id: Shoppe.settings.paypal_client_id,
37
+ client_secret: Shoppe.settings.paypal_secret_id
38
+ })
39
+
40
+ # When an order is accepted, attempt to capture/execute the payment
41
+ Shoppe::Order.before_acceptance do
42
+ self.payments.where(confirmed: false, method: "PayPal").each do |payment|
43
+ begin
44
+ payment.paypal_payment.execute(payer_id: payment.order.properties["paypal_payer_id"])
45
+ payment.update_attribute(:confirmed, true)
46
+ rescue
47
+ raise Shoppe::Errors::PaymentDeclined, "Payment ##{payment.id} could not be captured by PayPal. Investigate with PayPal. Do not accept the order."
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoppe-paypal
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dean Perry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoppe
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: paypal-sdk-rest
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: A Shoppe module to assist with the integration of PayPal.
48
+ email:
49
+ - dean@voupe.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - README.md
55
+ - Rakefile
56
+ - lib/shoppe/paypal.rb
57
+ - lib/shoppe/paypal/engine.rb
58
+ - lib/shoppe/paypal/order_extensions.rb
59
+ - lib/shoppe/paypal/payment_extensions.rb
60
+ - lib/shoppe/paypal/version.rb
61
+ homepage: http://voupe.com
62
+ licenses: []
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: A PayPal payment module for Shoppe.
84
+ test_files: []
85
+ has_rdoc: