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
|
@@ -8,12 +8,16 @@ require 'solidus_support'
|
|
|
8
8
|
|
|
9
9
|
module SolidusPaypalCommercePlatform
|
|
10
10
|
class Engine < Rails::Engine
|
|
11
|
-
include SolidusSupport::EngineExtensions
|
|
11
|
+
include ::SolidusSupport::EngineExtensions
|
|
12
12
|
|
|
13
13
|
isolate_namespace SolidusPaypalCommercePlatform
|
|
14
14
|
|
|
15
15
|
engine_name 'solidus_paypal_commerce_platform'
|
|
16
16
|
|
|
17
|
+
initializer "solidus_paypal_commerce_platform.zeitwerk_ignore_deface_overrides", before: :eager_load! do |app|
|
|
18
|
+
app.autoloaders.main.ignore(root.join('app/overrides'))
|
|
19
|
+
end
|
|
20
|
+
|
|
17
21
|
initializer "solidus_paypal_commerce_platform.add_payment_method", after: "spree.register.payment_methods" do |app|
|
|
18
22
|
app.config.to_prepare do
|
|
19
23
|
app.config.spree.payment_methods << SolidusPaypalCommercePlatform::PaymentMethod
|
|
@@ -30,12 +34,12 @@ module SolidusPaypalCommercePlatform
|
|
|
30
34
|
|
|
31
35
|
initializer "solidus_paypal_commerce_platform.add_wizard", after: "spree.register.payment_methods" do |app|
|
|
32
36
|
# Adding the class set below - if this is ported to core, we can remove this line.
|
|
33
|
-
Spree::Core::Environment.add_class_set("payment_setup_wizards")
|
|
37
|
+
::Spree::Core::Environment.add_class_set("payment_setup_wizards")
|
|
34
38
|
app.config.spree.payment_setup_wizards << "SolidusPaypalCommercePlatform::Wizard"
|
|
35
39
|
end
|
|
36
40
|
|
|
37
41
|
initializer "solidus_paypal_commerce_platform.webhooks" do
|
|
38
|
-
SolidusWebhooks.config.register_webhook_handler :solidus_paypal_commerce_platform, ->(payload) {
|
|
42
|
+
::SolidusWebhooks.config.register_webhook_handler :solidus_paypal_commerce_platform, ->(payload) {
|
|
39
43
|
SolidusPaypalCommercePlatform::WebhooksJob.perform_now(payload)
|
|
40
44
|
}
|
|
41
45
|
end
|
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_paypal_commerce_platform/releases'
|
|
18
18
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
19
19
|
|
|
20
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 3.
|
|
20
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.1')
|
|
21
21
|
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
|
|
31
31
|
spec.add_dependency 'deface', '~> 1.5'
|
|
32
32
|
spec.add_dependency 'solidus_api'
|
|
33
|
-
spec.add_dependency 'solidus_core', '>=
|
|
34
|
-
spec.add_dependency 'solidus_support', '>= 0.
|
|
33
|
+
spec.add_dependency 'solidus_core', '>= 4.1', '< 5.0'
|
|
34
|
+
spec.add_dependency 'solidus_support', '>= 0.14.0'
|
|
35
35
|
spec.add_dependency 'solidus_webhooks', '~> 0.2'
|
|
36
36
|
|
|
37
37
|
spec.add_dependency 'paypalhttp'
|
|
@@ -36,27 +36,189 @@ RSpec.describe SolidusPaypalCommercePlatform::PaymentMethod, type: :model do
|
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
shared_examples "refusing insufficient PayPal approvals" do |request|
|
|
40
|
+
let(:source) { paypal_payment_method.payment_source_class.create(paypal_order_id: SecureRandom.hex(8)) }
|
|
41
|
+
let(:request_class) { SolidusPaypalCommercePlatform::Gateway.const_get(request) }
|
|
42
|
+
|
|
43
|
+
def refuse_to(action, money: 1000)
|
|
44
|
+
response = paypal_payment_method.public_send(action, money, source, currency: "USD")
|
|
45
|
+
|
|
46
|
+
expect(response).not_to be_success
|
|
47
|
+
expect(request_class).not_to have_received(:new)
|
|
48
|
+
response.message
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
before { allow(request_class).to receive(:new).and_call_original }
|
|
52
|
+
|
|
53
|
+
it "refuses when PayPal approved less than the amount" do
|
|
54
|
+
expect(refuse_to(action, money: 1001))
|
|
55
|
+
.to eq(I18n.t("solidus_paypal_commerce_platform.responses.insufficient_approval"))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "when PayPal approved another currency" do
|
|
59
|
+
let(:approved_currency) { "MXN" }
|
|
60
|
+
|
|
61
|
+
it "refuses" do
|
|
62
|
+
expect(refuse_to(action))
|
|
63
|
+
.to eq(I18n.t("solidus_paypal_commerce_platform.responses.insufficient_approval"))
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context "when the PayPal order can't be fetched" do
|
|
68
|
+
let(:response) { SolidusPaypalCommercePlatform::Client::Response.new(status_code: 422, error: Struct(name: "RESOURCE_NOT_FOUND")) }
|
|
69
|
+
|
|
70
|
+
it "refuses" do
|
|
71
|
+
expect(refuse_to(action)).to start_with("Your payment was declined")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
shared_examples "refusing unconfirmed PayPal settlements" do
|
|
77
|
+
let(:unsettled) { I18n.t("solidus_paypal_commerce_platform.responses.unsettled_payment") }
|
|
78
|
+
|
|
79
|
+
context "when PayPal reports the settlement is not complete" do
|
|
80
|
+
let(:settlement_status) { "PENDING" }
|
|
81
|
+
|
|
82
|
+
it "refuses and does not record the settlement" do
|
|
83
|
+
response = paypal_payment_method.public_send(action, 1000, source, currency: "USD")
|
|
84
|
+
expect(response).not_to be_success
|
|
85
|
+
expect(response.message).to eq(unsettled)
|
|
86
|
+
expect(source).to have_attributes(capture_id: nil, authorization_id: nil)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context "when PayPal settled less than the payment" do
|
|
91
|
+
let(:settled_value) { "5.00" }
|
|
92
|
+
|
|
93
|
+
it "refuses" do
|
|
94
|
+
response = paypal_payment_method.public_send(action, 1000, source, currency: "USD")
|
|
95
|
+
expect(response).not_to be_success
|
|
96
|
+
expect(response.message).to eq(unsettled)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "when PayPal settled in another currency" do
|
|
101
|
+
let(:settled_currency) { "MXN" }
|
|
102
|
+
|
|
103
|
+
it "refuses" do
|
|
104
|
+
response = paypal_payment_method.public_send(action, 1000, source, currency: "USD")
|
|
105
|
+
expect(response).not_to be_success
|
|
106
|
+
expect(response.message).to eq(unsettled)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
39
111
|
describe "#purchase" do
|
|
40
|
-
let(:
|
|
41
|
-
let(:
|
|
112
|
+
let(:merchant_id) { SecureRandom.hex(6) }
|
|
113
|
+
let(:payee_merchant_id) { merchant_id }
|
|
114
|
+
let(:result) { Struct(purchase_units: [Struct(payee: Struct(merchant_id: payee_merchant_id), payments: payments, amount: approved_amount)]) }
|
|
115
|
+
let(:payments) { Struct(captures: [Struct(id: SecureRandom.hex(4), status: settlement_status, amount: settled_amount)]) }
|
|
116
|
+
let(:approved_amount) { Struct(value: "10.00", currency_code: approved_currency) }
|
|
117
|
+
let(:approved_currency) { "USD" }
|
|
118
|
+
let(:settlement_status) { "COMPLETED" }
|
|
119
|
+
let(:settled_amount) { Struct(value: settled_value, currency_code: settled_currency) }
|
|
120
|
+
let(:settled_value) { "10.00" }
|
|
121
|
+
let(:settled_currency) { "USD" }
|
|
122
|
+
let(:source) { paypal_payment_method.payment_source_class.create(paypal_order_id: SecureRandom.hex(8)) }
|
|
123
|
+
let(:action) { :purchase }
|
|
124
|
+
|
|
125
|
+
before { paypal_payment_method.update!(preferred_merchant_id: merchant_id) }
|
|
42
126
|
|
|
43
127
|
it "sends a purchase request to paypal" do
|
|
44
128
|
paypal_order_id = SecureRandom.hex(8)
|
|
45
129
|
source = paypal_payment_method.payment_source_class.create(paypal_order_id: paypal_order_id)
|
|
46
130
|
expect_request(:OrdersCaptureRequest).to receive(:new).with(paypal_order_id).and_call_original
|
|
47
|
-
paypal_payment_method.purchase(1000, source,
|
|
131
|
+
paypal_payment_method.purchase(1000, source, currency: "USD")
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "records the capture when PayPal confirms it" do
|
|
135
|
+
expect(paypal_payment_method.purchase(1000, source, currency: "USD")).to be_success
|
|
136
|
+
expect(source.capture_id).to be_present
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "allows approvals for more than the amount" do
|
|
140
|
+
expect(paypal_payment_method.purchase(900, source, currency: "USD")).to be_success
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it_behaves_like "refusing insufficient PayPal approvals", :OrdersCaptureRequest
|
|
144
|
+
it_behaves_like "refusing unconfirmed PayPal settlements"
|
|
145
|
+
|
|
146
|
+
context "when the approved order pays a different merchant" do
|
|
147
|
+
let(:payee_merchant_id) { "a-different-merchant" }
|
|
148
|
+
|
|
149
|
+
it "refuses the payment without capturing" do
|
|
150
|
+
source = paypal_payment_method.payment_source_class.create(paypal_order_id: SecureRandom.hex(8))
|
|
151
|
+
expect_request(:OrdersCaptureRequest).not_to receive(:new)
|
|
152
|
+
expect(paypal_payment_method.purchase(1000, source, currency: "USD").success?).to be(false)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
context "when no merchant is configured" do
|
|
157
|
+
before { paypal_payment_method.update!(preferred_merchant_id: nil) }
|
|
158
|
+
|
|
159
|
+
it "does not verify the payee and captures as before" do
|
|
160
|
+
paypal_order_id = SecureRandom.hex(8)
|
|
161
|
+
source = paypal_payment_method.payment_source_class.create(paypal_order_id: paypal_order_id)
|
|
162
|
+
expect_request(:OrdersCaptureRequest).to receive(:new).with(paypal_order_id).and_call_original
|
|
163
|
+
expect(paypal_payment_method.purchase(1000, source, currency: "USD").success?).to be(true)
|
|
164
|
+
end
|
|
48
165
|
end
|
|
49
166
|
end
|
|
50
167
|
|
|
51
168
|
describe "#authorize" do
|
|
52
|
-
let(:
|
|
53
|
-
let(:
|
|
169
|
+
let(:merchant_id) { SecureRandom.hex(6) }
|
|
170
|
+
let(:payee_merchant_id) { merchant_id }
|
|
171
|
+
let(:result) { Struct(purchase_units: [Struct(payee: Struct(merchant_id: payee_merchant_id), payments: payments, amount: approved_amount)]) }
|
|
172
|
+
let(:payments) { Struct(authorizations: [Struct(id: SecureRandom.hex(4), status: settlement_status, amount: settled_amount)]) }
|
|
173
|
+
let(:approved_amount) { Struct(value: "10.00", currency_code: approved_currency) }
|
|
174
|
+
let(:approved_currency) { "USD" }
|
|
175
|
+
let(:settlement_status) { "CREATED" }
|
|
176
|
+
let(:settled_amount) { Struct(value: settled_value, currency_code: settled_currency) }
|
|
177
|
+
let(:settled_value) { "10.00" }
|
|
178
|
+
let(:settled_currency) { "USD" }
|
|
179
|
+
let(:source) { paypal_payment_method.payment_source_class.create(paypal_order_id: SecureRandom.hex(8)) }
|
|
180
|
+
let(:action) { :authorize }
|
|
181
|
+
|
|
182
|
+
before { paypal_payment_method.update!(preferred_merchant_id: merchant_id) }
|
|
54
183
|
|
|
55
184
|
it "sends an authorize request to paypal" do
|
|
56
185
|
paypal_order_id = SecureRandom.hex(8)
|
|
57
186
|
source = paypal_payment_method.payment_source_class.create(paypal_order_id: paypal_order_id)
|
|
58
187
|
expect_request(:OrdersAuthorizeRequest).to receive(:new).with(paypal_order_id)
|
|
59
|
-
paypal_payment_method.authorize(1000, source,
|
|
188
|
+
paypal_payment_method.authorize(1000, source, currency: "USD")
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "records the authorization when PayPal confirms it" do
|
|
192
|
+
expect(paypal_payment_method.authorize(1000, source, currency: "USD")).to be_success
|
|
193
|
+
expect(source.authorization_id).to be_present
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "allows approvals for more than the amount" do
|
|
197
|
+
expect(paypal_payment_method.authorize(900, source, currency: "USD")).to be_success
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it_behaves_like "refusing insufficient PayPal approvals", :OrdersAuthorizeRequest
|
|
201
|
+
it_behaves_like "refusing unconfirmed PayPal settlements"
|
|
202
|
+
|
|
203
|
+
context "when the approved order pays a different merchant" do
|
|
204
|
+
let(:payee_merchant_id) { "a-different-merchant" }
|
|
205
|
+
|
|
206
|
+
it "refuses the payment without authorizing" do
|
|
207
|
+
source = paypal_payment_method.payment_source_class.create(paypal_order_id: SecureRandom.hex(8))
|
|
208
|
+
expect_request(:OrdersAuthorizeRequest).not_to receive(:new)
|
|
209
|
+
expect(paypal_payment_method.authorize(1000, source, currency: "USD").success?).to be(false)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
context "when no merchant is configured" do
|
|
214
|
+
before { paypal_payment_method.update!(preferred_merchant_id: nil) }
|
|
215
|
+
|
|
216
|
+
it "does not verify the payee and authorizes as before" do
|
|
217
|
+
paypal_order_id = SecureRandom.hex(8)
|
|
218
|
+
source = paypal_payment_method.payment_source_class.create(paypal_order_id: paypal_order_id)
|
|
219
|
+
expect_request(:OrdersAuthorizeRequest).to receive(:new).with(paypal_order_id).and_call_original
|
|
220
|
+
expect(paypal_payment_method.authorize(1000, source, currency: "USD").success?).to be(true)
|
|
221
|
+
end
|
|
60
222
|
end
|
|
61
223
|
end
|
|
62
224
|
|
|
@@ -55,6 +55,106 @@ RSpec.describe SolidusPaypalCommercePlatform::PaypalAddress, type: :model do
|
|
|
55
55
|
expect(subject).to be_present
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
|
+
|
|
59
|
+
context "with international addresses" do
|
|
60
|
+
context "with China address" do
|
|
61
|
+
let!(:country) do
|
|
62
|
+
create(
|
|
63
|
+
:country,
|
|
64
|
+
name: "China",
|
|
65
|
+
iso: "CN",
|
|
66
|
+
states_required: false
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
let!(:state) do
|
|
70
|
+
create(
|
|
71
|
+
:state,
|
|
72
|
+
name: "Beijing Shi",
|
|
73
|
+
abbr: "BJ",
|
|
74
|
+
country: country
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
let(:address) do
|
|
78
|
+
create(
|
|
79
|
+
:address,
|
|
80
|
+
name_attributes.merge({
|
|
81
|
+
address1: "123 Fuqian 2nd St",
|
|
82
|
+
address2: "",
|
|
83
|
+
city: "Beijing City",
|
|
84
|
+
state: state,
|
|
85
|
+
country: country,
|
|
86
|
+
zipcode: "100001"
|
|
87
|
+
})
|
|
88
|
+
)
|
|
89
|
+
end
|
|
90
|
+
let(:params) {
|
|
91
|
+
{
|
|
92
|
+
updated_address: {
|
|
93
|
+
admin_area_1: address.state.abbr,
|
|
94
|
+
admin_area_2: address.city,
|
|
95
|
+
address_line_1: address.address1,
|
|
96
|
+
address_line_2: address.address2,
|
|
97
|
+
postal_code: address.zipcode,
|
|
98
|
+
country_code: address.country.iso
|
|
99
|
+
},
|
|
100
|
+
recipient: {
|
|
101
|
+
name: {
|
|
102
|
+
given_name: "Alexander",
|
|
103
|
+
surname: "Hamilton"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
context "with CN as country code" do
|
|
110
|
+
it "formats PayPal addresses correctly" do
|
|
111
|
+
order.ship_address = original_address
|
|
112
|
+
|
|
113
|
+
described_class.new(order).update(params)
|
|
114
|
+
|
|
115
|
+
expect(subject.state).to eq address.state
|
|
116
|
+
expect(subject.city).to eq address.city
|
|
117
|
+
expect(subject.address1).to eq address.address1
|
|
118
|
+
expect(subject.address2).to eq address.address2
|
|
119
|
+
expect(subject.zipcode).to eq address.zipcode
|
|
120
|
+
expect(subject.country).to eq address.country
|
|
121
|
+
if SolidusSupport.combined_first_and_last_name_in_address?
|
|
122
|
+
expect(subject.name).to eq address.name
|
|
123
|
+
else
|
|
124
|
+
expect(subject.firstname).to eq address.firstname
|
|
125
|
+
expect(subject.lastname).to eq address.lastname
|
|
126
|
+
end
|
|
127
|
+
expect(subject.phone).to eq original_address.phone
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
context "with C2 as country code" do
|
|
132
|
+
before do
|
|
133
|
+
country.update(iso: "C2")
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "formats PayPal addresses correctly" do
|
|
137
|
+
order.ship_address = original_address
|
|
138
|
+
|
|
139
|
+
described_class.new(order).update(params)
|
|
140
|
+
|
|
141
|
+
expect(subject.state).to eq address.state
|
|
142
|
+
expect(subject.city).to eq address.city
|
|
143
|
+
expect(subject.address1).to eq address.address1
|
|
144
|
+
expect(subject.address2).to eq address.address2
|
|
145
|
+
expect(subject.zipcode).to eq address.zipcode
|
|
146
|
+
expect(subject.country).to eq address.country
|
|
147
|
+
if SolidusSupport.combined_first_and_last_name_in_address?
|
|
148
|
+
expect(subject.name).to eq address.name
|
|
149
|
+
else
|
|
150
|
+
expect(subject.firstname).to eq address.firstname
|
|
151
|
+
expect(subject.lastname).to eq address.lastname
|
|
152
|
+
end
|
|
153
|
+
expect(subject.phone).to eq original_address.phone
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
58
158
|
end
|
|
59
159
|
|
|
60
160
|
def name_attributes
|
|
@@ -70,6 +70,24 @@ RSpec.describe SolidusPaypalCommercePlatform::PaypalOrder, type: :model do
|
|
|
70
70
|
)
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
|
+
|
|
74
|
+
context 'when an order has an inapplicable promo adjustment' do
|
|
75
|
+
let(:order) { create :order_with_line_items }
|
|
76
|
+
let(:best_promotion) { create(:promotion, :with_line_item_adjustment, adjustment_rate: 2.5) }
|
|
77
|
+
let(:worst_promotion) { create(:promotion, :with_line_item_adjustment, adjustment_rate: 1) }
|
|
78
|
+
|
|
79
|
+
before do
|
|
80
|
+
best_promotion.activate(order: order)
|
|
81
|
+
worst_promotion.activate(order: order)
|
|
82
|
+
order.recalculate
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'does not include it in the paypal order breakdown' do
|
|
86
|
+
expect(to_json.dig(:purchase_units, 0).dig(:amount, :breakdown)).to match hash_including(
|
|
87
|
+
discount: { currency_code: "USD", value: "2.50" }
|
|
88
|
+
)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
73
91
|
end
|
|
74
92
|
|
|
75
93
|
private
|
|
@@ -33,4 +33,76 @@ RSpec.describe SolidusPaypalCommercePlatform::OrdersController, type: :request d
|
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
describe "CSRF protection" do
|
|
38
|
+
# The test environment disables forgery protection, so enable it here.
|
|
39
|
+
around do |example|
|
|
40
|
+
original = ActionController::Base.allow_forgery_protection
|
|
41
|
+
ActionController::Base.allow_forgery_protection = true
|
|
42
|
+
example.run
|
|
43
|
+
ensure
|
|
44
|
+
ActionController::Base.allow_forgery_protection = original
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
let!(:store) { create(:store) }
|
|
48
|
+
let(:variant) { create(:variant) }
|
|
49
|
+
let(:json_body) { { order: { line_items_attributes: [{ variant_id: variant.id, quantity: 1 }] } }.to_json }
|
|
50
|
+
|
|
51
|
+
def csrf_token
|
|
52
|
+
get '/'
|
|
53
|
+
response.body[/<meta name="csrf-token" content="([^"]+)"/, 1]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Depending on the Rails version, the test environment either raises or
|
|
57
|
+
# renders the error.
|
|
58
|
+
def rejected?
|
|
59
|
+
yield
|
|
60
|
+
response.status == 422
|
|
61
|
+
rescue ActionController::InvalidAuthenticityToken
|
|
62
|
+
true
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
['/solidus_paypal_commerce_platform/orders.json', '/solidus_paypal_commerce_platform/orders?format=json'].each do |path|
|
|
66
|
+
it "rejects a cross-site form POST to #{path}" do
|
|
67
|
+
form_body = "order[line_items_attributes][0][variant_id]=#{variant.id}&" \
|
|
68
|
+
"order[line_items_attributes][0][quantity]=1"
|
|
69
|
+
|
|
70
|
+
expect {
|
|
71
|
+
expect(
|
|
72
|
+
rejected? {
|
|
73
|
+
post path, params: form_body, headers: {
|
|
74
|
+
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
|
|
75
|
+
'Origin' => 'http://attacker.example'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
).to be(true)
|
|
79
|
+
}.not_to change(Spree::Order, :count)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "accepts a JSON POST with the token in the X-CSRF-Token header" do
|
|
84
|
+
token = csrf_token
|
|
85
|
+
|
|
86
|
+
expect {
|
|
87
|
+
post '/solidus_paypal_commerce_platform/orders', params: json_body, headers: {
|
|
88
|
+
'CONTENT_TYPE' => 'application/json',
|
|
89
|
+
'X-CSRF-Token' => token
|
|
90
|
+
}
|
|
91
|
+
}.to change(Spree::Order, :count).by(1)
|
|
92
|
+
|
|
93
|
+
expect(response).to have_http_status(:ok)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "rejects a JSON POST without a token" do
|
|
97
|
+
expect {
|
|
98
|
+
expect(
|
|
99
|
+
rejected? {
|
|
100
|
+
post '/solidus_paypal_commerce_platform/orders', params: json_body, headers: {
|
|
101
|
+
'CONTENT_TYPE' => 'application/json'
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
).to be(true)
|
|
105
|
+
}.not_to change(Spree::Order, :count)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
36
108
|
end
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'solidus_storefront_spec_helper'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'solidus_starter_frontend_spec_helper'
|
|
7
|
+
end
|
|
4
8
|
|
|
5
9
|
Dir["#{__dir__}/support/solidus_paypal_commerce_platform/**/*.rb"].sort.each { |f| require f }
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solidus_paypal_commerce_platform
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sean Denny
|
|
8
8
|
- Elia Schito
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: exe
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: deface
|
|
@@ -45,7 +44,7 @@ dependencies:
|
|
|
45
44
|
requirements:
|
|
46
45
|
- - ">="
|
|
47
46
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: '
|
|
47
|
+
version: '4.1'
|
|
49
48
|
- - "<"
|
|
50
49
|
- !ruby/object:Gem::Version
|
|
51
50
|
version: '5.0'
|
|
@@ -55,7 +54,7 @@ dependencies:
|
|
|
55
54
|
requirements:
|
|
56
55
|
- - ">="
|
|
57
56
|
- !ruby/object:Gem::Version
|
|
58
|
-
version: '
|
|
57
|
+
version: '4.1'
|
|
59
58
|
- - "<"
|
|
60
59
|
- !ruby/object:Gem::Version
|
|
61
60
|
version: '5.0'
|
|
@@ -65,14 +64,14 @@ dependencies:
|
|
|
65
64
|
requirements:
|
|
66
65
|
- - ">="
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 0.
|
|
67
|
+
version: 0.14.0
|
|
69
68
|
type: :runtime
|
|
70
69
|
prerelease: false
|
|
71
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
|
73
72
|
- - ">="
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 0.
|
|
74
|
+
version: 0.14.0
|
|
76
75
|
- !ruby/object:Gem::Dependency
|
|
77
76
|
name: solidus_webhooks
|
|
78
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -115,15 +114,14 @@ dependencies:
|
|
|
115
114
|
- - "~>"
|
|
116
115
|
- !ruby/object:Gem::Version
|
|
117
116
|
version: '2.5'
|
|
118
|
-
description:
|
|
119
117
|
email: contact@solidus.io
|
|
120
118
|
executables: []
|
|
121
119
|
extensions: []
|
|
122
120
|
extra_rdoc_files: []
|
|
123
121
|
files:
|
|
124
|
-
- ".circleci/config.yml"
|
|
125
122
|
- ".gem_release.yml"
|
|
126
123
|
- ".github/stale.yml"
|
|
124
|
+
- ".github/workflows/test.yml"
|
|
127
125
|
- ".github_changelog_generator"
|
|
128
126
|
- ".gitignore"
|
|
129
127
|
- ".rspec"
|
|
@@ -137,8 +135,6 @@ files:
|
|
|
137
135
|
- app/assets/javascripts/spree/backend/solidus_paypal_commerce_platform/namespace.js
|
|
138
136
|
- app/assets/javascripts/spree/backend/solidus_paypal_commerce_platform/wizard.js
|
|
139
137
|
- app/assets/stylesheets/spree/backend/solidus_paypal_commerce_platform.css
|
|
140
|
-
- app/decorators/models/solidus_paypal_commerce_platform/spree/address_decorator.rb
|
|
141
|
-
- app/decorators/models/solidus_paypal_commerce_platform/spree/variant/pricing_options_decorator.rb
|
|
142
138
|
- app/helpers/solidus_paypal_commerce_platform/button_options_helper.rb
|
|
143
139
|
- app/jobs/solidus_paypal_commerce_platform/application_job.rb
|
|
144
140
|
- app/jobs/solidus_paypal_commerce_platform/webhook_job.rb
|
|
@@ -155,6 +151,8 @@ files:
|
|
|
155
151
|
- app/overrides/spree/orders/edit/insert_cart_buttons.rb
|
|
156
152
|
- app/overrides/spree/payments/payment/add_paypal_email_to_payment.rb
|
|
157
153
|
- app/overrides/spree/products/cart_form/insert_product_buttons.rb
|
|
154
|
+
- app/patches/models/solidus_paypal_commerce_platform/spree/address_patch.rb
|
|
155
|
+
- app/patches/models/solidus_paypal_commerce_platform/spree/variant/pricing_options_patch.rb
|
|
158
156
|
- app/views/solidus_paypal_commerce_platform/admin/payment_methods/_available_to_users.html.erb
|
|
159
157
|
- app/views/solidus_paypal_commerce_platform/admin/payment_methods/_paypal_wizard.html.erb
|
|
160
158
|
- app/views/solidus_paypal_commerce_platform/admin/payment_methods/_setup_wizards.html.erb
|
|
@@ -265,7 +263,6 @@ metadata:
|
|
|
265
263
|
source_code_uri: https://github.com/solidusio/solidus_paypal_commerce_platform
|
|
266
264
|
changelog_uri: https://github.com/solidusio/solidus_paypal_commerce_platform/releases
|
|
267
265
|
rubygems_mfa_required: 'true'
|
|
268
|
-
post_install_message:
|
|
269
266
|
rdoc_options: []
|
|
270
267
|
require_paths:
|
|
271
268
|
- lib
|
|
@@ -273,15 +270,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
273
270
|
requirements:
|
|
274
271
|
- - ">="
|
|
275
272
|
- !ruby/object:Gem::Version
|
|
276
|
-
version: '3.
|
|
273
|
+
version: '3.1'
|
|
277
274
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
278
275
|
requirements:
|
|
279
276
|
- - ">="
|
|
280
277
|
- !ruby/object:Gem::Version
|
|
281
278
|
version: '0'
|
|
282
279
|
requirements: []
|
|
283
|
-
rubygems_version:
|
|
284
|
-
signing_key:
|
|
280
|
+
rubygems_version: 4.0.20
|
|
285
281
|
specification_version: 4
|
|
286
282
|
summary: Integrate Solidus with Paypal Commerce Platform
|
|
287
283
|
test_files: []
|
data/.circleci/config.yml
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
version: 2.1
|
|
2
|
-
|
|
3
|
-
orbs:
|
|
4
|
-
browser-tools: circleci/browser-tools@1.1
|
|
5
|
-
|
|
6
|
-
# Always take the latest version of the orb, this allows us to
|
|
7
|
-
# run specs against Solidus supported versions only without the need
|
|
8
|
-
# to change this configuration every time a Solidus version is released
|
|
9
|
-
# or goes EOL.
|
|
10
|
-
solidusio_extensions: solidusio/extensions@volatile
|
|
11
|
-
|
|
12
|
-
commands:
|
|
13
|
-
test-with-starter-frontend:
|
|
14
|
-
steps:
|
|
15
|
-
- checkout
|
|
16
|
-
- browser-tools/install-chrome
|
|
17
|
-
- run:
|
|
18
|
-
name: Install libvips
|
|
19
|
-
command: |
|
|
20
|
-
sudo apt-get update
|
|
21
|
-
sudo apt-get install -yq libvips-dev
|
|
22
|
-
- solidusio_extensions/test-branch:
|
|
23
|
-
branch: main
|
|
24
|
-
command: |
|
|
25
|
-
export FRONTEND=starter
|
|
26
|
-
sudo gem update --system
|
|
27
|
-
gem install bundler rails
|
|
28
|
-
bin/dummy-app
|
|
29
|
-
bin/rspec
|
|
30
|
-
- solidusio_extensions/store-test-results
|
|
31
|
-
|
|
32
|
-
jobs:
|
|
33
|
-
run-specs-with-postgres:
|
|
34
|
-
executor:
|
|
35
|
-
name: solidusio_extensions/postgres
|
|
36
|
-
ruby_version: '3.2'
|
|
37
|
-
steps:
|
|
38
|
-
- test-with-starter-frontend
|
|
39
|
-
|
|
40
|
-
run-specs-with-mysql:
|
|
41
|
-
executor:
|
|
42
|
-
name: solidusio_extensions/mysql
|
|
43
|
-
ruby_version: '3.1'
|
|
44
|
-
steps:
|
|
45
|
-
- test-with-starter-frontend
|
|
46
|
-
|
|
47
|
-
run-specs-with-sqlite:
|
|
48
|
-
executor:
|
|
49
|
-
name: solidusio_extensions/sqlite
|
|
50
|
-
ruby_version: '3.0'
|
|
51
|
-
steps:
|
|
52
|
-
- test-with-starter-frontend
|
|
53
|
-
|
|
54
|
-
lint-code:
|
|
55
|
-
executor:
|
|
56
|
-
name: solidusio_extensions/sqlite-memory
|
|
57
|
-
ruby_version: '3.0'
|
|
58
|
-
steps:
|
|
59
|
-
- solidusio_extensions/lint-code
|
|
60
|
-
|
|
61
|
-
workflows:
|
|
62
|
-
"Run specs on supported Solidus versions":
|
|
63
|
-
jobs:
|
|
64
|
-
- run-specs-with-postgres
|
|
65
|
-
- run-specs-with-mysql
|
|
66
|
-
- run-specs-with-sqlite
|
|
67
|
-
- lint-code
|
|
68
|
-
|
|
69
|
-
"Weekly run specs against main":
|
|
70
|
-
triggers:
|
|
71
|
-
- schedule:
|
|
72
|
-
cron: "0 0 * * 4" # every Thursday
|
|
73
|
-
filters:
|
|
74
|
-
branches:
|
|
75
|
-
only:
|
|
76
|
-
- main
|
|
77
|
-
jobs:
|
|
78
|
-
- run-specs-with-postgres
|
|
79
|
-
- run-specs-with-mysql
|
|
80
|
-
- run-specs-with-sqlite
|