solidus_paypal_commerce_platform 0.5.0 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +21 -9
- data/.github/stale.yml +1 -17
- data/.gitignore +1 -0
- data/.rspec +0 -1
- data/.rubocop.yml +3 -2
- data/CHANGELOG.md +42 -9
- data/Gemfile +0 -41
- data/README.md +9 -12
- data/Rakefile +6 -1
- data/app/models/solidus_paypal_commerce_platform/payment_method.rb +6 -5
- data/app/models/solidus_paypal_commerce_platform/paypal_address.rb +6 -2
- data/app/models/solidus_paypal_commerce_platform/paypal_order.rb +22 -15
- data/bin/dummy-app +37 -0
- data/bin/rails-dummy-app +17 -0
- data/bin/rspec +11 -0
- data/bin/sandbox +3 -29
- data/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb +62 -23
- data/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js +272 -0
- data/{app → lib/generators/solidus_paypal_commerce_platform/install/templates/app}/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/buttons.js +0 -0
- data/{app → lib/generators/solidus_paypal_commerce_platform/install/templates/app}/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/namespace.js +0 -0
- data/{app → lib/generators/solidus_paypal_commerce_platform/install/templates/app}/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js +7 -0
- data/{app → lib/generators/solidus_paypal_commerce_platform/install/templates/app}/assets/stylesheets/spree/frontend/solidus_paypal_commerce_platform.css +0 -0
- data/{app → lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/orders_controller.rb +2 -1
- data/{app → lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/payments_controller.rb +0 -0
- data/{app → lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb +1 -1
- data/{app → lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/shipping_rates_controller.rb +0 -0
- data/{app → lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/wizard_controller.rb +0 -0
- data/lib/{views/frontend/spree/checkout → generators/solidus_paypal_commerce_platform/install/templates/app/views/checkouts}/payment/_paypal_commerce_platform.html.erb +5 -4
- data/lib/{views/frontend/spree → generators/solidus_paypal_commerce_platform/install/templates/app/views}/orders/payment/_paypal_commerce_platform.html.erb +4 -3
- data/lib/{views/frontend/spree → generators/solidus_paypal_commerce_platform/install/templates/app/views}/products/payment/_paypal_commerce_platform.html.erb +1 -1
- data/lib/{views/frontend → generators/solidus_paypal_commerce_platform/install/templates/app/views}/solidus_paypal_commerce_platform/cart/_cart_buttons.html.erb +0 -0
- data/lib/{views/frontend → generators/solidus_paypal_commerce_platform/install/templates/app/views}/solidus_paypal_commerce_platform/payments/_payment.html.erb +0 -0
- data/lib/{views/frontend → generators/solidus_paypal_commerce_platform/install/templates/app/views}/solidus_paypal_commerce_platform/product/_product_buttons.html.erb +0 -0
- data/lib/{views/frontend → generators/solidus_paypal_commerce_platform/install/templates/app/views}/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb +4 -2
- data/lib/generators/solidus_paypal_commerce_platform/install/templates/{initializer.rb → config/initializers/solidus_paypal_commerce_platform.rb} +0 -0
- data/lib/paypal/paypal_checkout_sdk/orders/orders_authorize_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/orders/orders_capture_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/orders/orders_create_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/orders/orders_get_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/orders/orders_patch_request.rb +0 -52
- data/lib/paypal/paypal_checkout_sdk/orders/orders_validate_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/payments/authorizations_capture_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/payments/authorizations_get_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/payments/authorizations_reauthorize_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/payments/authorizations_void_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/payments/captures_get_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/payments/captures_refund_request.rb +0 -2
- data/lib/paypal/paypal_checkout_sdk/payments/refunds_get_request.rb +0 -2
- data/lib/paypal/paypal_http_client.rb +4 -4
- data/lib/solidus_paypal_commerce_platform/client.rb +6 -3
- data/lib/solidus_paypal_commerce_platform/paypal_checkout_sdk/orders/orders_patch_request.rb +1 -54
- data/lib/solidus_paypal_commerce_platform/version.rb +1 -1
- data/solidus_paypal_commerce_platform.gemspec +1 -2
- data/spec/jobs/solidus_paypal_commerce_platform/fixtures/CHECKOUT.ORDER.COMPLETED.v2.json +121 -0
- data/spec/jobs/solidus_paypal_commerce_platform/fixtures/CHECKOUT.ORDER.PROCESSED.v2.json +121 -0
- data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.COMPLETED.v1.json +50 -0
- data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.COMPLETED.v2.json +72 -0
- data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.DENIED.v1.json +50 -0
- data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.DENIED.v2.json +68 -0
- data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.REFUNDED.v1.json +51 -0
- data/spec/jobs/solidus_paypal_commerce_platform/fixtures/PAYMENT.CAPTURE.REFUNDED.v2.json +63 -0
- data/spec/jobs/solidus_paypal_commerce_platform/webhook_job_spec.rb +44 -0
- data/spec/lib/solidus_paypal_commerce_platform/client_spec.rb +21 -0
- data/spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb +91 -0
- data/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb +200 -0
- data/spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb +119 -0
- data/spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb +67 -0
- data/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb +80 -0
- data/spec/models/solidus_paypal_commerce_platform/state_guesser_spec.rb +38 -0
- data/spec/models/solidus_paypal_commerce_platform/wizard_spec.rb +9 -0
- data/spec/requests/solidus_paypal_commerce_platform/orders_controller_spec.rb +36 -0
- data/spec/requests/solidus_paypal_commerce_platform/shipping_rates_controller_spec.rb +44 -0
- data/spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb +59 -0
- data/spec/solidus_paypal_commerce_platform_spec_helper.rb +5 -0
- data/spec/support/solidus_paypal_commerce_platform/factories.rb +5 -0
- data/spec/support/solidus_paypal_commerce_platform/paypal_sdk_script_tag_helper.rb +13 -0
- data/spec/system/backend/new_payment_method_spec.rb +40 -0
- data/spec/system/frontend/cart_spec.rb +53 -0
- data/spec/system/frontend/checkout_spec.rb +104 -0
- data/spec/system/frontend/product_spec.rb +98 -0
- metadata +53 -37
- data/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js +0 -203
@@ -3,45 +3,84 @@
|
|
3
3
|
module SolidusPaypalCommercePlatform
|
4
4
|
module Generators
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
6
|
-
class_option :
|
7
|
-
class_option :
|
6
|
+
class_option :migrate, type: :boolean, default: true
|
7
|
+
class_option :backend, type: :boolean, default: true
|
8
|
+
class_option :starter_frontend, type: :boolean, default: true
|
9
|
+
class_option :specs, type: :string, enum: %w[all frontend], default: 'frontend'
|
8
10
|
|
9
11
|
source_root File.expand_path('templates', __dir__)
|
10
12
|
|
11
|
-
def
|
12
|
-
|
13
|
+
def install_solidus_core_support
|
14
|
+
directory 'config/initializers', 'config/initializers'
|
15
|
+
rake 'railties:install:migrations FROM=solidus_paypal_commerce_platform'
|
16
|
+
run 'bin/rails db:migrate' if options[:migrate]
|
17
|
+
route "mount SolidusPaypalCommercePlatform::Engine, at: '/solidus_paypal_commerce_platform'"
|
13
18
|
end
|
14
19
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
20
|
+
def install_solidus_backend_support
|
21
|
+
support_code_for(:solidus_backend) do
|
22
|
+
append_file(
|
23
|
+
'vendor/assets/javascripts/spree/backend/all.js',
|
24
|
+
"//= require spree/backend/solidus_paypal_commerce_platform\n"
|
25
|
+
)
|
26
|
+
inject_into_file(
|
27
|
+
'vendor/assets/stylesheets/spree/backend/all.css',
|
28
|
+
" *= require spree/backend/solidus_paypal_commerce_platform\n",
|
29
|
+
before: %r{\*/},
|
30
|
+
verbose: true,
|
31
|
+
)
|
32
|
+
end
|
18
33
|
end
|
19
34
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
35
|
+
def install_solidus_starter_frontend_support
|
36
|
+
support_code_for(:solidus_starter_frontend) do
|
37
|
+
directory 'app', 'app'
|
38
|
+
append_file(
|
39
|
+
'app/assets/javascripts/solidus_starter_frontend.js',
|
40
|
+
"//= require spree/frontend/solidus_paypal_commerce_platform\n"
|
41
|
+
)
|
42
|
+
inject_into_file(
|
43
|
+
'app/assets/stylesheets/solidus_starter_frontend.css',
|
44
|
+
" *= require spree/frontend/solidus_paypal_commerce_platform\n",
|
45
|
+
before: %r{\*/},
|
46
|
+
verbose: true,
|
47
|
+
)
|
24
48
|
|
25
|
-
|
26
|
-
|
27
|
-
|
49
|
+
spec_paths =
|
50
|
+
case options[:specs]
|
51
|
+
when 'all' then %w[spec]
|
52
|
+
when 'frontend'
|
53
|
+
%w[
|
54
|
+
spec/solidus_paypal_commerce_platform_spec_helper.rb
|
55
|
+
spec/system/frontend
|
56
|
+
spec/support
|
57
|
+
]
|
58
|
+
end
|
28
59
|
|
29
|
-
|
30
|
-
|
31
|
-
|
60
|
+
spec_paths.each do |path|
|
61
|
+
if engine.root.join(path).directory?
|
62
|
+
directory engine.root.join(path), path
|
63
|
+
else
|
64
|
+
template engine.root.join(path), path
|
65
|
+
end
|
66
|
+
end
|
32
67
|
end
|
33
68
|
end
|
34
69
|
|
35
|
-
|
36
|
-
return if options[:skip_migrations]
|
70
|
+
private
|
37
71
|
|
38
|
-
|
39
|
-
if
|
40
|
-
|
72
|
+
def support_code_for(component_name, &block)
|
73
|
+
if options[component_name]
|
74
|
+
say_status :install, "[#{engine.engine_name}] solidus_#{component_name}", :blue
|
75
|
+
shell.indent(&block)
|
41
76
|
else
|
42
|
-
|
77
|
+
say_status :skip, "[#{engine.engine_name}] solidus_#{component_name}", :blue
|
43
78
|
end
|
44
79
|
end
|
80
|
+
|
81
|
+
def engine
|
82
|
+
SolidusPaypalCommercePlatform::Engine
|
83
|
+
end
|
45
84
|
end
|
46
85
|
end
|
47
86
|
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
// Attach inline GET-compatible params to a path.
|
2
|
+
// The path is assumed to be base off the current location.
|
3
|
+
// The data structure will wrap keys beyond the first level in
|
4
|
+
// square brackets, e.g. `{a: {b: 123}}` will become `a[b]=123`.
|
5
|
+
const urlWithParams = (path, data) => {
|
6
|
+
const url = new URL(path, window.location)
|
7
|
+
|
8
|
+
const formKey = (keys) => {
|
9
|
+
if (keys.length === 0) return ''
|
10
|
+
if (keys.length === 1) return keys[0]
|
11
|
+
|
12
|
+
// Wrap any key beyond the first one in square brackets
|
13
|
+
return `${keys.shift()}${keys.map((k) => `[${k}]`).join()}`
|
14
|
+
}
|
15
|
+
|
16
|
+
const appendSearchParams = (parentKeys, data) =>
|
17
|
+
Object.entries(data).forEach(([key, value]) => {
|
18
|
+
|
19
|
+
if (typeof value === 'object')
|
20
|
+
appendSearchParams([...parentKeys, key], value)
|
21
|
+
else
|
22
|
+
url.searchParams.append(formKey([...parentKeys, key]), value)
|
23
|
+
})
|
24
|
+
|
25
|
+
appendSearchParams([], data)
|
26
|
+
return url
|
27
|
+
}
|
28
|
+
|
29
|
+
const authHeader = (options = {}) => {
|
30
|
+
const apiKey = SolidusPaypalCommercePlatform.api_key
|
31
|
+
if (options.require && !apiKey) throw new Error("Missing api key")
|
32
|
+
|
33
|
+
|
34
|
+
return {
|
35
|
+
'Authorization': `Bearer ${apiKey}`,
|
36
|
+
[document.querySelector('meta[name="csrf-param"]')?.content]: document.querySelector('meta[name="csrf-token"]')?.content,
|
37
|
+
}
|
38
|
+
}
|
39
|
+
SolidusPaypalCommercePlatform.showOverlay = function() {
|
40
|
+
document.getElementById("paypal_commerce_platform_overlay").style.display = "block";
|
41
|
+
}
|
42
|
+
|
43
|
+
SolidusPaypalCommercePlatform.hideOverlay = function() {
|
44
|
+
document.getElementById("paypal_commerce_platform_overlay").style.display = "none";
|
45
|
+
}
|
46
|
+
|
47
|
+
SolidusPaypalCommercePlatform.handleError = function(error) {
|
48
|
+
console.error(error);
|
49
|
+
alert("There was a problem connecting with PayPal.")
|
50
|
+
throw error
|
51
|
+
}
|
52
|
+
|
53
|
+
SolidusPaypalCommercePlatform.sendOrder = async function(payment_method_id) {
|
54
|
+
if (!payment_method_id) throw new Error("payment_method_id is missing!")
|
55
|
+
|
56
|
+
const url = urlWithParams(`/solidus_paypal_commerce_platform/paypal_orders/${SolidusPaypalCommercePlatform.current_order_id}`, {
|
57
|
+
payment_method_id: payment_method_id,
|
58
|
+
order_token: SolidusPaypalCommercePlatform.current_order_token,
|
59
|
+
})
|
60
|
+
|
61
|
+
const response = await fetch(url, {headers: authHeader()})
|
62
|
+
const data = await response.json()
|
63
|
+
|
64
|
+
if (response.ok) {
|
65
|
+
return data.table.result.table.id
|
66
|
+
} else {
|
67
|
+
return data.table.error.table
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
SolidusPaypalCommercePlatform.createAndSendOrder = async function(payment_method_id) {
|
72
|
+
await SolidusPaypalCommercePlatform.createOrder()
|
73
|
+
return await SolidusPaypalCommercePlatform.sendOrder(payment_method_id)
|
74
|
+
}
|
75
|
+
|
76
|
+
SolidusPaypalCommercePlatform.createOrder = async function() {
|
77
|
+
const response = await fetch(
|
78
|
+
"/solidus_paypal_commerce_platform/orders",
|
79
|
+
{
|
80
|
+
method: 'POST',
|
81
|
+
headers: {
|
82
|
+
...authHeader(),
|
83
|
+
'Content-Type': 'application/json'
|
84
|
+
},
|
85
|
+
body: JSON.stringify({
|
86
|
+
order: {
|
87
|
+
line_items_attributes: [{
|
88
|
+
variant_id: SolidusPaypalCommercePlatform.getVariantId(),
|
89
|
+
quantity: SolidusPaypalCommercePlatform.getQuantity()
|
90
|
+
}]
|
91
|
+
}
|
92
|
+
}),
|
93
|
+
}
|
94
|
+
)
|
95
|
+
const data = await response.json()
|
96
|
+
|
97
|
+
if (response.ok) {
|
98
|
+
SolidusPaypalCommercePlatform.current_order_id = data.number
|
99
|
+
SolidusPaypalCommercePlatform.current_order_token = data.guest_token
|
100
|
+
} else {
|
101
|
+
console.error('A problem has occurred while creating your order', data);
|
102
|
+
alert('A problem has occurred while creating your order - ' + JSON.stringify(data))
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
SolidusPaypalCommercePlatform.getVariantId = function() {
|
107
|
+
var variants = document.getElementsByName("variant_id")
|
108
|
+
var variant_id;
|
109
|
+
|
110
|
+
if (variants.length == 1){
|
111
|
+
variant_id = variants[0].value
|
112
|
+
} else {
|
113
|
+
for (var i = 0; i < variants.length; i++) {
|
114
|
+
if (variants[i].checked) {
|
115
|
+
variant_id = variants[i].value
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
return variant_id
|
120
|
+
}
|
121
|
+
|
122
|
+
SolidusPaypalCommercePlatform.getQuantity = function() {
|
123
|
+
return document.getElementById("quantity").value
|
124
|
+
}
|
125
|
+
|
126
|
+
SolidusPaypalCommercePlatform.approveOrder = function(data, actions) {
|
127
|
+
SolidusPaypalCommercePlatform.showOverlay()
|
128
|
+
actions.order.get().then(function(response){
|
129
|
+
SolidusPaypalCommercePlatform.updateAddress(response).then(function() {
|
130
|
+
SolidusPaypalCommercePlatform.verifyTotal(response.purchase_units[0].amount.value).then(function(){
|
131
|
+
document.querySelector("#payments_source_paypal_order_id").value = data.orderID
|
132
|
+
document.querySelector("#payments_source_paypal_email").value = response.payer.email_address
|
133
|
+
document.querySelector("#payments_source_paypal_funding_source").value = SolidusPaypalCommercePlatform.fundingSource
|
134
|
+
document.querySelector("#checkout_form_payment").submit()
|
135
|
+
})
|
136
|
+
})
|
137
|
+
})
|
138
|
+
}
|
139
|
+
|
140
|
+
SolidusPaypalCommercePlatform.shippingChange = async function(paypalData, actions) {
|
141
|
+
const shipping_address = paypalData.shipping_address
|
142
|
+
|
143
|
+
url = urlWithParams('/solidus_paypal_commerce_platform/shipping_rates', {
|
144
|
+
order_id: SolidusPaypalCommercePlatform.current_order_id,
|
145
|
+
order_token: SolidusPaypalCommercePlatform.current_order_token,
|
146
|
+
address: shipping_address,
|
147
|
+
})
|
148
|
+
|
149
|
+
const response = await fetch(url, {headers: authHeader()})
|
150
|
+
const data = await response.json()
|
151
|
+
|
152
|
+
if (response.ok) {
|
153
|
+
return actions.order.patch([data]).catch(function(e) {
|
154
|
+
console.error('There were some problems with your payment address while trying to patch the order', e);
|
155
|
+
actions.reject()
|
156
|
+
})
|
157
|
+
} else {
|
158
|
+
console.error('There were some problems with your payment address', data);
|
159
|
+
return actions.reject()
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
SolidusPaypalCommercePlatform.verifyTotal = async function(paypal_total) {
|
164
|
+
const response = await fetch(
|
165
|
+
urlWithParams('/solidus_paypal_commerce_platform/verify_total', {
|
166
|
+
order_id: SolidusPaypalCommercePlatform.current_order_id,
|
167
|
+
order_token: SolidusPaypalCommercePlatform.current_order_token,
|
168
|
+
paypal_total: paypal_total
|
169
|
+
}), {
|
170
|
+
headers: authHeader()
|
171
|
+
})
|
172
|
+
|
173
|
+
if (!response.ok) {
|
174
|
+
SolidusPaypalCommercePlatform.hideOverlay()
|
175
|
+
alert('There were some problems with your payment - ' + response.responseJSON.errors.expected_total);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
SolidusPaypalCommercePlatform.finalizeOrder = function(payment_method_id, data, actions) {
|
180
|
+
SolidusPaypalCommercePlatform.showOverlay()
|
181
|
+
actions.order.get().then(function(response){
|
182
|
+
SolidusPaypalCommercePlatform.updateAddress(response).then(function() {
|
183
|
+
var paypal_amount = response.purchase_units[0].amount.value
|
184
|
+
SolidusPaypalCommercePlatform.advanceOrder().then(function() {
|
185
|
+
SolidusPaypalCommercePlatform.verifyTotal(paypal_amount).then(function(){
|
186
|
+
SolidusPaypalCommercePlatform.addPayment(paypal_amount, payment_method_id, data, response.payer.email_address).then(function() {
|
187
|
+
window.location.href = SolidusPaypalCommercePlatform.checkout_url
|
188
|
+
})
|
189
|
+
})
|
190
|
+
})
|
191
|
+
})
|
192
|
+
})
|
193
|
+
}
|
194
|
+
|
195
|
+
SolidusPaypalCommercePlatform.advanceOrder = async function() {
|
196
|
+
const response = await fetch(
|
197
|
+
`/api/checkouts/${SolidusPaypalCommercePlatform.current_order_id}/advance`, {
|
198
|
+
headers: {
|
199
|
+
...authHeader(),
|
200
|
+
'Content-Type': 'application/json'
|
201
|
+
},
|
202
|
+
method: 'PUT',
|
203
|
+
body: JSON.stringify({
|
204
|
+
order_token: SolidusPaypalCommercePlatform.current_order_token
|
205
|
+
})
|
206
|
+
})
|
207
|
+
|
208
|
+
if (!response.ok) {
|
209
|
+
SolidusPaypalCommercePlatform.hideOverlay()
|
210
|
+
alert('There were some problems with your order');
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
SolidusPaypalCommercePlatform.addPayment = async function(paypal_amount, payment_method_id, data, email) {
|
215
|
+
const response = await fetch(
|
216
|
+
`/api/checkouts/${SolidusPaypalCommercePlatform.current_order_id}/payments`, {
|
217
|
+
method: 'POST',
|
218
|
+
headers: {
|
219
|
+
...authHeader(),
|
220
|
+
'Content-Type': 'application/json'
|
221
|
+
},
|
222
|
+
body: JSON.stringify({
|
223
|
+
order_token: SolidusPaypalCommercePlatform.current_order_token,
|
224
|
+
payment: {
|
225
|
+
amount: paypal_amount,
|
226
|
+
payment_method_id: payment_method_id,
|
227
|
+
source_attributes: {
|
228
|
+
paypal_order_id: data.orderID,
|
229
|
+
paypal_email: email,
|
230
|
+
paypal_funding_source: SolidusPaypalCommercePlatform.fundingSource
|
231
|
+
}
|
232
|
+
}
|
233
|
+
})
|
234
|
+
})
|
235
|
+
|
236
|
+
if (!response.ok) {
|
237
|
+
SolidusPaypalCommercePlatform.hideOverlay()
|
238
|
+
alert('There were some problems with your payment');
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
SolidusPaypalCommercePlatform.updateAddress = async function(payload) {
|
243
|
+
var shipping = payload.purchase_units[0].shipping
|
244
|
+
if (!shipping) return Promise.resolve({})
|
245
|
+
|
246
|
+
var updated_address = shipping.address
|
247
|
+
|
248
|
+
const response = await fetch(
|
249
|
+
'/solidus_paypal_commerce_platform/update_address', {
|
250
|
+
method: 'POST',
|
251
|
+
headers: {
|
252
|
+
...authHeader(),
|
253
|
+
'Content-Type': 'application/json'
|
254
|
+
},
|
255
|
+
body: JSON.stringify({
|
256
|
+
address: {
|
257
|
+
updated_address: updated_address,
|
258
|
+
recipient: payload.payer
|
259
|
+
},
|
260
|
+
order_id: SolidusPaypalCommercePlatform.current_order_id,
|
261
|
+
order_token: SolidusPaypalCommercePlatform.current_order_token
|
262
|
+
}),
|
263
|
+
}
|
264
|
+
)
|
265
|
+
|
266
|
+
if (!response.ok) {
|
267
|
+
SolidusPaypalCommercePlatform.hideOverlay()
|
268
|
+
const message = await response.text()
|
269
|
+
console.error('There were some problems with your payment address - ', message);
|
270
|
+
alert('There were some problems with your payment address - ' + message)
|
271
|
+
}
|
272
|
+
}
|
File without changes
|
File without changes
|
@@ -1,3 +1,10 @@
|
|
1
1
|
//= require spree/frontend/solidus_paypal_commerce_platform/namespace
|
2
2
|
//= require spree/frontend/solidus_paypal_commerce_platform/button_actions
|
3
3
|
//= require spree/frontend/solidus_paypal_commerce_platform/buttons
|
4
|
+
//= require_self
|
5
|
+
|
6
|
+
Object.assign(SolidusPaypalCommercePlatform, {
|
7
|
+
current_order_id: null,
|
8
|
+
current_order_token: null,
|
9
|
+
api_key: null,
|
10
|
+
})
|
File without changes
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
module SolidusPaypalCommercePlatform
|
4
4
|
class OrdersController < ::Spree::Api::BaseController
|
5
|
-
before_action :load_order, except: :create
|
6
5
|
skip_before_action :authenticate_user
|
7
6
|
include ::Spree::Core::ControllerHelpers::Auth
|
8
7
|
|
@@ -25,6 +24,7 @@ module SolidusPaypalCommercePlatform
|
|
25
24
|
end
|
26
25
|
|
27
26
|
def update_address
|
27
|
+
load_order
|
28
28
|
authorize! :update, @order, order_token
|
29
29
|
paypal_address = SolidusPaypalCommercePlatform::PaypalAddress.new(@order)
|
30
30
|
|
@@ -38,6 +38,7 @@ module SolidusPaypalCommercePlatform
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def verify_total
|
41
|
+
load_order
|
41
42
|
authorize! :show, @order, order_token
|
42
43
|
|
43
44
|
if total_is_correct?(params[:paypal_total])
|
File without changes
|
@@ -15,7 +15,7 @@ module SolidusPaypalCommercePlatform
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def load_payment_method
|
18
|
-
@payment_method = ::Spree::PaymentMethod.find(params
|
18
|
+
@payment_method = ::Spree::PaymentMethod.find(params.require(:payment_method_id))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
File without changes
|
File without changes
|
@@ -9,13 +9,14 @@
|
|
9
9
|
<input type="hidden" name="payment_source[<%= payment_method.id %>][paypal_funding_source]" id="payments_source_paypal_funding_source">
|
10
10
|
|
11
11
|
<script>
|
12
|
-
|
13
|
-
|
12
|
+
SolidusPaypalCommercePlatform.api_key = "<%= spree_current_user.try(:spree_api_key) %>"
|
13
|
+
SolidusPaypalCommercePlatform.current_order_id = "<%= @order.number %>"
|
14
|
+
SolidusPaypalCommercePlatform.current_order_token = "<%= @order.guest_token %>"
|
14
15
|
</script>
|
15
16
|
|
16
17
|
<% unless payment_method.render_only_venmo_standalone? %>
|
17
18
|
<script>
|
18
|
-
|
19
|
+
window.addEventListener('DOMContentLoaded', () => {
|
19
20
|
SolidusPaypalCommercePlatform.renderButton("<%= payment_method.id %>",<%= raw payment_method.button_style.to_json %>)
|
20
21
|
})
|
21
22
|
</script>
|
@@ -23,7 +24,7 @@
|
|
23
24
|
|
24
25
|
<% if payment_method.venmo_standalone_enabled? %>
|
25
26
|
<script>
|
26
|
-
|
27
|
+
window.addEventListener('DOMContentLoaded', () => {
|
27
28
|
SolidusPaypalCommercePlatform.renderVenmoStandalone("<%= payment_method.id %>",<%= raw payment_method.button_style.to_json %>)
|
28
29
|
})
|
29
30
|
</script>
|
@@ -6,10 +6,11 @@
|
|
6
6
|
<div data-pp-message data-pp-placement="cart" data-pp-amount="<%= @order.total %>"></div>
|
7
7
|
|
8
8
|
<script>
|
9
|
-
|
10
|
-
|
9
|
+
SolidusPaypalCommercePlatform.api_key = "<%= spree_current_user.try(:spree_api_key) %>"
|
10
|
+
SolidusPaypalCommercePlatform.current_order_id = "<%= @order.number %>"
|
11
|
+
SolidusPaypalCommercePlatform.current_order_token = "<%= @order.guest_token %>"
|
11
12
|
SolidusPaypalCommercePlatform.checkout_url = "<%= checkout_url %>"
|
12
|
-
|
13
|
+
window.addEventListener('DOMContentLoaded', () => {
|
13
14
|
SolidusPaypalCommercePlatform.renderCartButton("<%= payment_method.id %>",<%= raw payment_method.button_style.to_json %>)
|
14
15
|
})
|
15
16
|
</script>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
<script>
|
9
9
|
SolidusPaypalCommercePlatform.checkout_url = "<%= checkout_url %>"
|
10
|
-
|
10
|
+
window.addEventListener('DOMContentLoaded', () => {
|
11
11
|
SolidusPaypalCommercePlatform.renderProductButton("<%= payment_method.id %>",<%= raw payment_method.button_style.to_json %>)
|
12
12
|
})
|
13
13
|
</script>
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,6 +1,8 @@
|
|
1
1
|
<% currency = @order ? @order.currency : current_pricing_options.currency %>
|
2
2
|
|
3
|
-
<script
|
4
|
-
src="<%= payment_method.javascript_sdk_url(order: @order, currency: currency) %>"
|
3
|
+
<script
|
4
|
+
src="<%= payment_method.javascript_sdk_url(order: @order, currency: currency) %>"
|
5
5
|
data-partner-attribution-id="<%= SolidusPaypalCommercePlatform.config.partner_code %>">
|
6
|
+
|
7
|
+
SolidusPaypalCommercePlatform.api_key = <%= spree_current_user&.spree_api_key.to_json %>
|
6
8
|
</script>
|
File without changes
|
@@ -1,61 +1,9 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# This class was generated on Mon, 27 Aug 2018 13:51:59 PDT by version 0.1.0-dev+904328-dirty of Braintree SDK Generator
|
4
|
-
|
5
3
|
require 'cgi'
|
6
4
|
|
7
5
|
module PayPalCheckoutSdk
|
8
6
|
module Orders
|
9
|
-
#
|
10
|
-
# Updates an order that has the `CREATED` or `APPROVED` status. You cannot update an order with `COMPLETED` status.
|
11
|
-
# You can patch these attributes and objects:
|
12
|
-
# <table>
|
13
|
-
# <thead>
|
14
|
-
# <tr>
|
15
|
-
# <th align="left">Attribute or object</th>
|
16
|
-
# <th align="left">Operations</th>
|
17
|
-
# </tr>
|
18
|
-
# </thead>
|
19
|
-
# <tbody>
|
20
|
-
# <tr>
|
21
|
-
# <td><code>intent</code></td>
|
22
|
-
# <td align="left">Replace</td>
|
23
|
-
# </tr>
|
24
|
-
# <tr>
|
25
|
-
# <td><code>purchase_units</code></td>
|
26
|
-
# <td align="left">Replace, add</td>
|
27
|
-
# </tr>
|
28
|
-
# <tr>
|
29
|
-
# <td><code>purchase_units[].custom_id</code></td>
|
30
|
-
# <td align="left">Replace, add, remove</td>
|
31
|
-
# </tr>
|
32
|
-
# <tr>
|
33
|
-
# <td><code>purchase_units[].description</code></td>
|
34
|
-
# <td align="left">Replace, add, remove</td>
|
35
|
-
# </tr>
|
36
|
-
# <tr>
|
37
|
-
# <td><code>purchase_units[].payee.email</code></td>
|
38
|
-
# <td align="left">Replace, add</td>
|
39
|
-
# </tr>
|
40
|
-
# <tr>
|
41
|
-
# <td><code>purchase_units[].shipping</code></td>
|
42
|
-
# <td align="left">Replace, add, remove</td>
|
43
|
-
# </tr>
|
44
|
-
# <tr>
|
45
|
-
# <td><code>purchase_units[].soft_descriptor</code></td>
|
46
|
-
# <td align="left">Replace, add, remove</td>
|
47
|
-
# </tr>
|
48
|
-
# <tr>
|
49
|
-
# <td><code>purchase_units[].amount</code></td>
|
50
|
-
# <td align="left">Replace</td>
|
51
|
-
# </tr>
|
52
|
-
# <tr>
|
53
|
-
# <td><code>purchase_units[].invoice_id</code></td>
|
54
|
-
# <td align="left">Replace, add, remove</td>
|
55
|
-
# </tr>
|
56
|
-
# </tbody>
|
57
|
-
# </table>
|
58
|
-
#
|
59
7
|
class OrdersPatchRequest
|
60
8
|
attr_accessor :path, :body, :headers, :verb
|
61
9
|
|