solidus_paypal_commerce_platform 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +17 -0
- data/.rubocop.yml +5 -1
- data/README.md +10 -2
- data/app/models/solidus_paypal_commerce_platform/gateway.rb +97 -10
- data/app/models/solidus_paypal_commerce_platform/payment_method.rb +1 -0
- data/app/models/solidus_paypal_commerce_platform/payment_source.rb +2 -2
- data/app/models/solidus_paypal_commerce_platform/paypal_address.rb +26 -10
- data/app/models/solidus_paypal_commerce_platform/paypal_order.rb +1 -1
- data/app/models/solidus_paypal_commerce_platform/wizard.rb +1 -1
- data/app/{decorators/models/solidus_paypal_commerce_platform/spree/address_decorator.rb → patches/models/solidus_paypal_commerce_platform/spree/address_patch.rb} +1 -1
- data/app/{decorators/models/solidus_paypal_commerce_platform/spree/variant/pricing_options_decorator.rb → patches/models/solidus_paypal_commerce_platform/spree/variant/pricing_options_patch.rb} +1 -1
- data/bin/dummy-app +21 -2
- data/bin/rspec +1 -1
- data/bin/sandbox +72 -34
- data/config/locales/en.yml +6 -0
- data/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb +18 -6
- data/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js +1 -1
- data/lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb +5 -1
- data/lib/paypal/paypal_http_client.rb +1 -2
- data/lib/solidus_paypal_commerce_platform/engine.rb +7 -3
- data/lib/solidus_paypal_commerce_platform/version.rb +1 -1
- data/solidus_paypal_commerce_platform.gemspec +3 -3
- data/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb +168 -6
- data/spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb +100 -0
- data/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb +18 -0
- data/spec/requests/solidus_paypal_commerce_platform/orders_controller_spec.rb +72 -0
- data/spec/solidus_paypal_commerce_platform_spec_helper.rb +5 -1
- data/spec/system/backend/new_payment_method_spec.rb +1 -1
- metadata +11 -15
- data/.circleci/config.yml +0 -80
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5a09746abd568f135d0775fd0c7bb40817270afd574aa37ff345b7adfb4cf99a
|
|
4
|
+
data.tar.gz: 2b145c8d649383daf8c6567fd3a1c7052a1490224b326110cbd988f1acd60d32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f4a6865f0941911abc8070732c13bab790e8ecb3c0af13f0e4ec5bcd1d01374fe6bdf0d78c64415733bc024589d9c30aef6420cc9585b57585673e7e15de9f5
|
|
7
|
+
data.tar.gz: ec867e5c0b10d3dade249bda6607a99305cd00f4606aa32d814caca7d112f485aba488b0f909d5ad01ad950530a1091d92b5ec9c7f556d16f776eceaa1d650db
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
schedule:
|
|
9
|
+
- cron: "0 0 * * 4" # every Thursday
|
|
10
|
+
workflow_call:
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
rspec:
|
|
17
|
+
uses: solidusio/test-solidus-extension/.github/workflows/test.yml@main
|
data/.rubocop.yml
CHANGED
|
@@ -3,7 +3,7 @@ require:
|
|
|
3
3
|
|
|
4
4
|
AllCops:
|
|
5
5
|
NewCops: disable
|
|
6
|
-
TargetRubyVersion:
|
|
6
|
+
TargetRubyVersion: "3.1"
|
|
7
7
|
Exclude:
|
|
8
8
|
- sandbox/**/*
|
|
9
9
|
- dummy-app/**/*
|
|
@@ -64,8 +64,12 @@ RSpec/MultipleMemoizedHelpers:
|
|
|
64
64
|
- spec/jobs/solidus_paypal_commerce_platform/webhook_job_spec.rb
|
|
65
65
|
- spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb
|
|
66
66
|
- spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb
|
|
67
|
+
- spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb
|
|
67
68
|
|
|
68
69
|
Rails/Inquiry:
|
|
69
70
|
Enabled: true
|
|
70
71
|
Exclude:
|
|
71
72
|
- spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb
|
|
73
|
+
|
|
74
|
+
Layout/LineLength:
|
|
75
|
+
Enabled: false
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Solidus Paypal Commerce Platform
|
|
2
2
|
|
|
3
|
-
[](https://github.com/solidusio/solidus_paypal_commerce_platform/actions/workflows/<WORKFLOW_FILE>)
|
|
4
|
+
[](https://codecov.io/gh/solidusio-contrib/solidus_paypal_commerce_platform)
|
|
5
5
|
|
|
6
6
|
The official PayPal integration of Solidus.
|
|
7
7
|
|
|
@@ -179,6 +179,14 @@ The easiest way to change the `Payment Method`'s preferences is through admin: `
|
|
|
179
179
|
|
|
180
180
|
See more about preferences [here](https://guides.solidus.io/developers/preferences/add-model-preferences.html#access-your-preferences)/
|
|
181
181
|
|
|
182
|
+
### Verifying the payment recipient
|
|
183
|
+
|
|
184
|
+
Set the payment method's **Merchant ID** preference to your PayPal Merchant ID (also shown as
|
|
185
|
+
Account ID in your PayPal account settings). When it is set, the gateway confirms that each
|
|
186
|
+
approved PayPal order pays your own account before capturing or authorizing it, and refuses
|
|
187
|
+
payments that would be paid to a different account. The check is only active once the Merchant ID
|
|
188
|
+
is configured; leaving it blank keeps the previous behaviour.
|
|
189
|
+
|
|
182
190
|
## Development
|
|
183
191
|
|
|
184
192
|
### Testing the extension
|
|
@@ -6,7 +6,7 @@ module SolidusPaypalCommercePlatform
|
|
|
6
6
|
include PayPalCheckoutSdk::Payments
|
|
7
7
|
|
|
8
8
|
def initialize(options)
|
|
9
|
-
# Cannot use kwargs because of how the Gateway is
|
|
9
|
+
# Cannot use kwargs because of how the Gateway is initialized by Solidus.
|
|
10
10
|
@client = Client.new(
|
|
11
11
|
test_mode: options.fetch(:test_mode, nil),
|
|
12
12
|
client_id: options.fetch(:client_id),
|
|
@@ -16,25 +16,43 @@ module SolidusPaypalCommercePlatform
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def purchase(money, source, options)
|
|
19
|
+
refusal = refuse_insufficient_approval(money, source, options)
|
|
20
|
+
return refusal if refusal
|
|
21
|
+
|
|
22
|
+
refusal = refuse_wrong_payee(source)
|
|
23
|
+
return refusal if refusal
|
|
24
|
+
|
|
19
25
|
request = OrdersCaptureRequest.new(source.paypal_order_id)
|
|
20
26
|
request.request_body(amount: { currency_code: options[:currency], value: Money.new(money).dollars })
|
|
21
27
|
|
|
22
28
|
response = @client.execute_with_response(request)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
return response unless response.success?
|
|
30
|
+
|
|
31
|
+
capture = response.params["result"].purchase_units[0].payments.captures&.first
|
|
32
|
+
unsettled = refuse_unless_settled(capture, money, options, allowed_statuses: ["COMPLETED"])
|
|
33
|
+
return unsettled if unsettled
|
|
34
|
+
|
|
35
|
+
source.update(capture_id: capture.id)
|
|
27
36
|
response
|
|
28
37
|
end
|
|
29
38
|
|
|
30
|
-
def authorize(
|
|
39
|
+
def authorize(money, source, options)
|
|
40
|
+
refusal = refuse_insufficient_approval(money, source, options)
|
|
41
|
+
return refusal if refusal
|
|
42
|
+
|
|
43
|
+
refusal = refuse_wrong_payee(source)
|
|
44
|
+
return refusal if refusal
|
|
45
|
+
|
|
31
46
|
request = OrdersAuthorizeRequest.new(source.paypal_order_id)
|
|
32
47
|
|
|
33
48
|
response = @client.execute_with_response(request)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
return response unless response.success?
|
|
50
|
+
|
|
51
|
+
authorization = response.params["result"].purchase_units[0].payments.authorizations&.first
|
|
52
|
+
unsettled = refuse_unless_settled(authorization, money, options, allowed_statuses: ["CREATED"])
|
|
53
|
+
return unsettled if unsettled
|
|
54
|
+
|
|
55
|
+
source.update(authorization_id: authorization.id)
|
|
38
56
|
response
|
|
39
57
|
end
|
|
40
58
|
|
|
@@ -84,6 +102,75 @@ module SolidusPaypalCommercePlatform
|
|
|
84
102
|
|
|
85
103
|
private
|
|
86
104
|
|
|
105
|
+
# PayPal authorizes and captures the amount the customer approved, whatever
|
|
106
|
+
# amount it is sent, so it must be checked against the payment's amount.
|
|
107
|
+
def refuse_insufficient_approval(money, source, options)
|
|
108
|
+
request = OrdersGetRequest.new(source.paypal_order_id)
|
|
109
|
+
response = @client.execute(request)
|
|
110
|
+
unless response.status_code.between?(200, 299)
|
|
111
|
+
return ActiveMerchant::Billing::Response.new(
|
|
112
|
+
false,
|
|
113
|
+
I18n.t(
|
|
114
|
+
"#{@client.i18n_scope_for(request)}.failure",
|
|
115
|
+
default: "Your payment was declined - please try again using a different payment method."
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
approved = response.result.purchase_units[0].amount
|
|
121
|
+
approved_cents = Money.from_amount(BigDecimal(approved.value), approved.currency_code).cents
|
|
122
|
+
return unless approved.currency_code != options[:currency] || approved_cents < money
|
|
123
|
+
|
|
124
|
+
ActiveMerchant::Billing::Response.new(
|
|
125
|
+
false,
|
|
126
|
+
I18n.t(
|
|
127
|
+
'solidus_paypal_commerce_platform.responses.insufficient_approval',
|
|
128
|
+
default: "The amount approved with PayPal doesn't cover this payment - please pay with PayPal again."
|
|
129
|
+
)
|
|
130
|
+
)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# PayPal can return a 2xx for a capture or authorization that is pending,
|
|
134
|
+
# denied or for less than the payment. Only treat it as paid when PayPal
|
|
135
|
+
# confirms it settled for at least the payment's amount in its currency.
|
|
136
|
+
def refuse_unless_settled(settlement, money, options, allowed_statuses:)
|
|
137
|
+
if settlement && allowed_statuses.include?(settlement.status) &&
|
|
138
|
+
settlement.amount.currency_code == options[:currency] &&
|
|
139
|
+
Money.from_amount(BigDecimal(settlement.amount.value), settlement.amount.currency_code).cents >= money
|
|
140
|
+
return
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
ActiveMerchant::Billing::Response.new(
|
|
144
|
+
false,
|
|
145
|
+
I18n.t(
|
|
146
|
+
'solidus_paypal_commerce_platform.responses.unsettled_payment',
|
|
147
|
+
default: "PayPal didn't confirm this payment - please try again using a different payment method."
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Refuse to capture or authorize a PayPal order unless it pays the store's
|
|
153
|
+
# own merchant. A buyer can create an order against the store's public
|
|
154
|
+
# client ID while naming a different payee, so the approved order's payee
|
|
155
|
+
# must match the configured merchant before any money moves.
|
|
156
|
+
def refuse_wrong_payee(source)
|
|
157
|
+
expected_merchant_id = @options[:merchant_id].to_s.strip
|
|
158
|
+
# Only stores that record their PayPal merchant ID can be protected. When
|
|
159
|
+
# it is set, every purchase unit must pay that merchant; a missing,
|
|
160
|
+
# mismatched, or unreadable order is refused.
|
|
161
|
+
return if expected_merchant_id.empty?
|
|
162
|
+
|
|
163
|
+
response = @client.execute(OrdersGetRequest.new(source.paypal_order_id))
|
|
164
|
+
purchase_units = response.result.purchase_units if response.respond_to?(:result)
|
|
165
|
+
return if purchase_units.present? &&
|
|
166
|
+
purchase_units.all? { |unit| unit.payee&.merchant_id == expected_merchant_id }
|
|
167
|
+
|
|
168
|
+
ActiveMerchant::Billing::Response.new(
|
|
169
|
+
false,
|
|
170
|
+
I18n.t("solidus_paypal_commerce_platform.responses.wrong_payee")
|
|
171
|
+
)
|
|
172
|
+
end
|
|
173
|
+
|
|
87
174
|
def capture_with_response(request, success_message: nil, failure_message: nil)
|
|
88
175
|
response = @client.execute(request)
|
|
89
176
|
if response.result&.status == "PENDING"
|
|
@@ -5,6 +5,7 @@ module SolidusPaypalCommercePlatform
|
|
|
5
5
|
include SolidusPaypalCommercePlatform::ButtonOptionsHelper
|
|
6
6
|
preference :client_id, :string
|
|
7
7
|
preference :client_secret, :string
|
|
8
|
+
preference :merchant_id, :string
|
|
8
9
|
preference :paypal_button_color, :paypal_select, default: "gold"
|
|
9
10
|
preference :paypal_button_size, :paypal_select, default: "responsive"
|
|
10
11
|
preference :paypal_button_shape, :paypal_select, default: "rect"
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
module SolidusPaypalCommercePlatform
|
|
4
4
|
class PaymentSource < ::Spree::PaymentSource
|
|
5
5
|
self.table_name = "paypal_commerce_platform_sources"
|
|
6
|
-
enum paypal_funding_source
|
|
6
|
+
enum :paypal_funding_source, {
|
|
7
7
|
applepay: 0, bancontact: 1, blik: 2, boleto: 3, card: 4, credit: 5, eps: 6, giropay: 7, ideal: 8,
|
|
8
8
|
itau: 9, maxima: 10, mercadopago: 11, mybank: 12, oxxo: 13, p24: 14, paylater: 15, paypal: 16, payu: 17,
|
|
9
9
|
sepa: 18, sofort: 19, trustly: 20, venmo: 21, verkkopankki: 22, wechatpay: 23, zimpler: 24
|
|
10
|
-
},
|
|
10
|
+
}, suffix: :funding
|
|
11
11
|
validates :paypal_order_id, :payment_method_id, presence: true
|
|
12
12
|
|
|
13
13
|
def display_paypal_funding_source
|
|
@@ -42,12 +42,26 @@ module SolidusPaypalCommercePlatform
|
|
|
42
42
|
@order.update(email: recipient[:email_address])
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
def find_country(state_name, country_code)
|
|
46
|
+
country = ::Spree::Country.find_by(iso: country_code)
|
|
47
|
+
return country if country.present?
|
|
48
|
+
|
|
49
|
+
state = ::Spree::State.find_by("lower(name) LIKE '%#{state_name.downcase}%'")
|
|
50
|
+
state.country
|
|
51
|
+
end
|
|
52
|
+
|
|
45
53
|
def find_state(state_name, country)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
return nil if country.blank?
|
|
55
|
+
|
|
56
|
+
state = country.states.find_by(abbr: state_name) ||
|
|
57
|
+
country.states.find_by(name: state_name)
|
|
58
|
+
return state if state.present?
|
|
59
|
+
|
|
60
|
+
state = SolidusPaypalCommercePlatform.config.state_guesser_class.new(
|
|
61
|
+
state_name,
|
|
62
|
+
country
|
|
63
|
+
)
|
|
64
|
+
state.guess
|
|
51
65
|
end
|
|
52
66
|
|
|
53
67
|
def format_simulated_address(paypal_address)
|
|
@@ -60,11 +74,13 @@ module SolidusPaypalCommercePlatform
|
|
|
60
74
|
end
|
|
61
75
|
|
|
62
76
|
def address_attributes(address, recipient)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
state_name = address[:admin_area_1] ||
|
|
78
|
+
address[:admin_area_2] ||
|
|
79
|
+
address[:state]
|
|
80
|
+
country_code = address[:country_code]
|
|
81
|
+
|
|
82
|
+
country = find_country(state_name, country_code)
|
|
83
|
+
state = find_state(state_name, country)
|
|
68
84
|
|
|
69
85
|
attributes = {
|
|
70
86
|
address1: address[:address_line_1],
|
|
@@ -92,7 +92,7 @@ module SolidusPaypalCommercePlatform
|
|
|
92
92
|
item_total: price(@order.item_total),
|
|
93
93
|
shipping: price(@order.shipment_total),
|
|
94
94
|
tax_total: price(@order.additional_tax_total),
|
|
95
|
-
discount: price(@order.
|
|
95
|
+
discount: price(@order.promo_total.abs)
|
|
96
96
|
}
|
|
97
97
|
end
|
|
98
98
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module SolidusPaypalCommercePlatform
|
|
4
4
|
module Spree
|
|
5
|
-
module
|
|
5
|
+
module AddressPatch
|
|
6
6
|
# PayPal doesn't use the phone number, so in cases where the user checks out via
|
|
7
7
|
# PayPal, this field will be unpopulated. If you want to require phone numbers,
|
|
8
8
|
# you'll need to turn off cart & product page displays on the payment method edit
|
data/bin/dummy-app
CHANGED
|
@@ -14,7 +14,8 @@ function unbundled {
|
|
|
14
14
|
test "$DB" = "sqlite" && export DB="sqlite3"
|
|
15
15
|
|
|
16
16
|
rm -rf ./dummy-app
|
|
17
|
-
|
|
17
|
+
rails_version=`bundle exec ruby -e'require "rails"; puts Rails.version'`
|
|
18
|
+
bundle exec rails _${rails_version}_ new dummy-app \
|
|
18
19
|
--database=${DB:-sqlite3} \
|
|
19
20
|
--skip-git \
|
|
20
21
|
--skip-keeps \
|
|
@@ -28,9 +29,27 @@ if [ ! -d "dummy-app" ]; then
|
|
|
28
29
|
fi
|
|
29
30
|
|
|
30
31
|
cd ./dummy-app
|
|
32
|
+
|
|
33
|
+
if [ -n "$DB_HOST" ]; then
|
|
34
|
+
echo "~~~> Configuring database.yml for DB_HOST=$DB_HOST"
|
|
35
|
+
ruby -i -pe '
|
|
36
|
+
if $_ =~ /^ (pool|max_connections):/
|
|
37
|
+
$_ += " host: <%= ENV.fetch(\"DB_HOST\", \"localhost\") %>\n"
|
|
38
|
+
$_ += " username: <%= ENV[\"DB_USERNAME\"] %>\n"
|
|
39
|
+
end
|
|
40
|
+
' config/database.yml
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
echo "Generating manifest file"
|
|
44
|
+
mkdir -p app/assets/config
|
|
45
|
+
cat <<MANIFESTJS > app/assets/config/manifest.js
|
|
46
|
+
//= link_tree ../images
|
|
47
|
+
//= link_directory ../javascripts .js
|
|
48
|
+
//= link_directory ../stylesheets .css
|
|
49
|
+
MANIFESTJS
|
|
50
|
+
|
|
31
51
|
unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-main}" --version '> 0.a'
|
|
32
52
|
unbundled bundle exec rake db:drop db:create
|
|
33
53
|
unbundled bundle exec rails generate solidus:install --auto-accept --payment-method=none --no-seed --no-sample "$@"
|
|
34
54
|
unbundled bundle add $extension_name --path ..
|
|
35
55
|
unbundled bundle exec rails generate $extension_name:install --migrate --specs=all
|
|
36
|
-
|
data/bin/rspec
CHANGED
data/bin/sandbox
CHANGED
|
@@ -1,61 +1,99 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
|
|
3
3
|
set -e
|
|
4
|
+
test -z "${DEBUG+empty_string}" || set -x
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
postgres|postgresql)
|
|
7
|
-
RAILSDB="postgresql"
|
|
8
|
-
;;
|
|
9
|
-
mysql)
|
|
10
|
-
RAILSDB="mysql"
|
|
11
|
-
;;
|
|
12
|
-
sqlite|'')
|
|
13
|
-
RAILSDB="sqlite3"
|
|
14
|
-
;;
|
|
15
|
-
*)
|
|
16
|
-
echo "Invalid DB specified: $DB"
|
|
17
|
-
exit 1
|
|
18
|
-
;;
|
|
19
|
-
esac
|
|
6
|
+
test "$DB" = "sqlite" && export DB="sqlite3"
|
|
20
7
|
|
|
21
|
-
if [
|
|
8
|
+
if [ -z "$SOLIDUS_BRANCH" ]
|
|
22
9
|
then
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
BRANCH="main"
|
|
10
|
+
echo "~~> Use 'export SOLIDUS_BRANCH=[main|v4.0|...]' to control the Solidus branch"
|
|
11
|
+
SOLIDUS_BRANCH="main"
|
|
26
12
|
fi
|
|
27
|
-
|
|
28
|
-
extension_name="solidus_paypal_commerce_platform"
|
|
13
|
+
echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
|
|
29
14
|
|
|
30
15
|
# Stay away from the bundler env of the containing extension.
|
|
31
16
|
function unbundled {
|
|
32
|
-
ruby -rbundler -e'
|
|
17
|
+
ruby -rbundler -e'
|
|
18
|
+
Bundler.with_unbundled_env {system *ARGV}' -- \
|
|
19
|
+
env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@
|
|
33
20
|
}
|
|
34
21
|
|
|
22
|
+
echo "~~~> Removing the old sandbox"
|
|
35
23
|
rm -rf ./sandbox
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
|
|
25
|
+
echo "~~~> Creating a pristine Rails app"
|
|
26
|
+
rails_version=`bundle exec ruby -e'require "rails"; puts Rails.version'`
|
|
27
|
+
|
|
28
|
+
# --skip-solid was added in Rails 8.0 to skip Solid Cache, Queue, and Cable
|
|
29
|
+
# setup which is unnecessary for the sandbox and fails during generation.
|
|
30
|
+
rails_major=$(echo "$rails_version" | cut -d. -f1)
|
|
31
|
+
skip_solid_flag=""
|
|
32
|
+
if [ "$rails_major" -ge 8 ] 2>/dev/null; then
|
|
33
|
+
skip_solid_flag="--skip-solid"
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
bundle exec rails _${rails_version}_ new sandbox \
|
|
37
|
+
--database="${DB:-sqlite3}" \
|
|
38
38
|
--skip-git \
|
|
39
39
|
--skip-keeps \
|
|
40
40
|
--skip-rc \
|
|
41
41
|
--skip-bootsnap \
|
|
42
|
-
--skip-test
|
|
42
|
+
--skip-test \
|
|
43
|
+
$skip_solid_flag
|
|
43
44
|
|
|
44
45
|
if [ ! -d "sandbox" ]; then
|
|
45
46
|
echo 'sandbox rails application failed'
|
|
46
47
|
exit 1
|
|
47
48
|
fi
|
|
48
49
|
|
|
50
|
+
echo "~~~> Adding solidus (with i18n) to the Gemfile"
|
|
49
51
|
cd ./sandbox
|
|
50
|
-
|
|
52
|
+
|
|
53
|
+
if [ -n "$DB_HOST" ]; then
|
|
54
|
+
echo "~~~> Configuring database.yml for DB_HOST=$DB_HOST"
|
|
55
|
+
ruby -i -pe '
|
|
56
|
+
if $_ =~ /^ pool:/
|
|
57
|
+
$_ += " host: <%= ENV.fetch(\"DB_HOST\", \"localhost\") %>\n"
|
|
58
|
+
$_ += " username: <%= ENV[\"DB_USERNAME\"] %>\n"
|
|
59
|
+
end
|
|
60
|
+
' config/database.yml
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
cat <<RUBY >> Gemfile
|
|
64
|
+
gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
|
|
65
|
+
gem 'rails-i18n'
|
|
66
|
+
gem 'solidus_i18n'
|
|
67
|
+
gem 'solidus_auth_devise', github: "solidusio/solidus_auth_devise"
|
|
68
|
+
|
|
69
|
+
# Ruby 4.0 removed benchmark from default gems, but ActiveSupport requires it.
|
|
70
|
+
gem 'benchmark' if RUBY_VERSION >= '4.0'
|
|
71
|
+
|
|
72
|
+
group :test, :development do
|
|
73
|
+
platforms :mri do
|
|
74
|
+
gem 'pry-byebug'
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
RUBY
|
|
78
|
+
|
|
79
|
+
echo "Generating manifest file"
|
|
80
|
+
mkdir -p app/assets/config
|
|
81
|
+
cat <<MANIFESTJS > app/assets/config/manifest.js
|
|
82
|
+
//= link_tree ../images
|
|
83
|
+
//= link_directory ../javascripts .js
|
|
84
|
+
//= link_directory ../stylesheets .css
|
|
85
|
+
MANIFESTJS
|
|
86
|
+
|
|
87
|
+
unbundled bundle install --gemfile Gemfile
|
|
88
|
+
|
|
51
89
|
unbundled bundle exec rake db:drop db:create
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
unbundled bundle exec rails generate
|
|
90
|
+
|
|
91
|
+
export FRONTEND="$PWD/../template.rb"
|
|
92
|
+
unbundled bundle exec rails generate solidus:install \
|
|
93
|
+
--auto-accept \
|
|
94
|
+
$@
|
|
55
95
|
|
|
56
96
|
echo
|
|
57
|
-
echo "🚀 Sandbox app successfully created for
|
|
58
|
-
echo "🚀
|
|
59
|
-
echo "
|
|
60
|
-
echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
|
|
61
|
-
echo "🚀 This app is intended for test purposes."
|
|
97
|
+
echo "🚀 Sandbox app successfully created for the storefront!"
|
|
98
|
+
echo "🚀 Use 'export DB=[postgres|mysql|sqlite3]' to control the DB adapter"
|
|
99
|
+
echo "🧪 This app is intended for test purposes."
|
data/config/locales/en.yml
CHANGED
|
@@ -3,6 +3,7 @@ en:
|
|
|
3
3
|
hints:
|
|
4
4
|
solidus_paypal_commerce_platform/payment_method:
|
|
5
5
|
available_to_users: You must verify that your email is confirmed with PayPal before users will be able to check out with this payment method.
|
|
6
|
+
merchant_id: Your PayPal Merchant ID (Account ID), found in your PayPal account settings. Set this so the gateway can confirm that payments are made to your account.
|
|
6
7
|
payment_source: source
|
|
7
8
|
activerecord:
|
|
8
9
|
attributes:
|
|
@@ -28,9 +29,14 @@ en:
|
|
|
28
29
|
invalid_paypal_order_id: "Invalid order confirmation data passed in"
|
|
29
30
|
order_complete: "Order is already in complete state"
|
|
30
31
|
responses:
|
|
32
|
+
insufficient_approval: "The amount approved with PayPal doesn't cover this payment - please pay with PayPal again."
|
|
33
|
+
unsettled_payment: "PayPal didn't confirm this payment - please try again using a different payment method."
|
|
34
|
+
wrong_payee: "This payment couldn't be verified - please try again using a different payment method."
|
|
31
35
|
pay_pal_checkout_sdk/orders/orders_capture_request:
|
|
32
36
|
success: "Payment captured"
|
|
33
37
|
failure: "Your payment was declined - please try again using a different payment method."
|
|
38
|
+
pay_pal_checkout_sdk/orders/orders_get_request:
|
|
39
|
+
failure: "Your payment was declined - please try again using a different payment method."
|
|
34
40
|
pay_pal_checkout_sdk/orders/orders_authorize_request:
|
|
35
41
|
success: "Payment authorized"
|
|
36
42
|
failure: "Your payment was declined - please try again using a different payment method."
|
|
@@ -16,7 +16,7 @@ module SolidusPaypalCommercePlatform
|
|
|
16
16
|
def normalize_components_options
|
|
17
17
|
@components = {
|
|
18
18
|
backend: options[:backend],
|
|
19
|
-
|
|
19
|
+
storefront: options[:frontend] == 'starter' || options[:frontend] == 'storefront',
|
|
20
20
|
classic_frontend: options[:frontend] == 'classic',
|
|
21
21
|
}
|
|
22
22
|
end
|
|
@@ -25,7 +25,7 @@ module SolidusPaypalCommercePlatform
|
|
|
25
25
|
directory 'config/initializers', 'config/initializers'
|
|
26
26
|
rake 'railties:install:migrations FROM=solidus_paypal_commerce_platform'
|
|
27
27
|
run 'bin/rails db:migrate' if options[:migrate]
|
|
28
|
-
route "mount SolidusPaypalCommercePlatform::Engine, at: '
|
|
28
|
+
route "mount SolidusPaypalCommercePlatform::Engine, at: '#{solidus_mount_point}solidus_paypal_commerce_platform'"
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def install_solidus_backend_support
|
|
@@ -43,15 +43,21 @@ module SolidusPaypalCommercePlatform
|
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def
|
|
47
|
-
support_code_for(:
|
|
46
|
+
def install_solidus_storefront_support
|
|
47
|
+
support_code_for(:storefront) do
|
|
48
48
|
directory 'app', 'app'
|
|
49
|
+
js_manifest = File.exist?('app/assets/javascripts/solidus_storefront.js') ?
|
|
50
|
+
'app/assets/javascripts/solidus_storefront.js' :
|
|
51
|
+
'app/assets/javascripts/solidus_starter_frontend.js'
|
|
52
|
+
css_manifest = File.exist?('app/assets/stylesheets/solidus_storefront.css') ?
|
|
53
|
+
'app/assets/stylesheets/solidus_storefront.css' :
|
|
54
|
+
'app/assets/stylesheets/solidus_starter_frontend.css'
|
|
49
55
|
append_file(
|
|
50
|
-
|
|
56
|
+
js_manifest,
|
|
51
57
|
"//= require spree/frontend/solidus_paypal_commerce_platform\n"
|
|
52
58
|
)
|
|
53
59
|
inject_into_file(
|
|
54
|
-
|
|
60
|
+
css_manifest,
|
|
55
61
|
" *= require spree/frontend/solidus_paypal_commerce_platform\n",
|
|
56
62
|
before: %r{\*/},
|
|
57
63
|
verbose: true,
|
|
@@ -91,6 +97,12 @@ module SolidusPaypalCommercePlatform
|
|
|
91
97
|
|
|
92
98
|
private
|
|
93
99
|
|
|
100
|
+
def solidus_mount_point
|
|
101
|
+
mount_point = ::Spree::Core::Engine.routes.find_script_name({})
|
|
102
|
+
mount_point += "/" unless mount_point.end_with?("/")
|
|
103
|
+
mount_point
|
|
104
|
+
end
|
|
105
|
+
|
|
94
106
|
def support_code_for(component_name, &block)
|
|
95
107
|
if @components[component_name]
|
|
96
108
|
say_status :install, "[#{engine.engine_name}] solidus_#{component_name}", :blue
|
|
@@ -33,7 +33,7 @@ const authHeader = (options = {}) => {
|
|
|
33
33
|
|
|
34
34
|
return {
|
|
35
35
|
'Authorization': `Bearer ${apiKey}`,
|
|
36
|
-
|
|
36
|
+
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]')?.content,
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
SolidusPaypalCommercePlatform.showOverlay = function() {
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
module SolidusPaypalCommercePlatform
|
|
4
4
|
class OrdersController < ::Spree::Api::BaseController
|
|
5
5
|
skip_before_action :authenticate_user
|
|
6
|
+
protect_from_forgery with: :exception
|
|
7
|
+
|
|
6
8
|
include ::Spree::Core::ControllerHelpers::Auth
|
|
7
9
|
|
|
8
10
|
def create
|
|
@@ -77,7 +79,9 @@ module SolidusPaypalCommercePlatform
|
|
|
77
79
|
end
|
|
78
80
|
|
|
79
81
|
def order_params
|
|
80
|
-
params.require(:order).permit(
|
|
82
|
+
params.require(:order).permit([
|
|
83
|
+
line_items_attributes: permitted_line_item_attributes
|
|
84
|
+
])
|
|
81
85
|
end
|
|
82
86
|
|
|
83
87
|
def load_order
|
|
@@ -45,8 +45,7 @@ module PayPal
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def _is_auth_request(request)
|
|
48
|
-
|
|
49
|
-
request.path == '/v1/identity/openidconnect/tokenservice'
|
|
48
|
+
['/v1/oauth2/token', '/v1/identity/openidconnect/tokenservice'].include?(request.path)
|
|
50
49
|
end
|
|
51
50
|
|
|
52
51
|
def _has_auth_header(request)
|