spree_paypal_checkout 0.5.5 → 0.6.0
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/app/javascript/spree_paypal_checkout/controllers/checkout_paypal_controller.js +27 -9
- data/app/models/spree_paypal_checkout/gateway.rb +36 -14
- data/app/views/spree/admin/payments/source_forms/_spree_paypal_checkout.html.erb +7 -0
- data/app/views/spree_paypal_checkout/_head.html.erb +1 -0
- data/lib/spree_paypal_checkout/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e93096fd5f88baa021c6d077b03ec743036f7193f00410cee544c3c2662ab559
|
|
4
|
+
data.tar.gz: 354f5e005d1aabcab8709de1bef7f4298986bf3dbcbbb6089d096ede2f77bde3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7df72e3c2201e90ae60a61ab37c30b84d00b074743ef63be0f6eb90ac60b454ff2dac778fb20a44730a56d5464ee42b6660e22cbb146ad85d3b3f7937d706776
|
|
7
|
+
data.tar.gz: a9552304abcfdf6ffd8899514c81efab45c90506cf6541f3004e96c4c212bffa08e08d3ed2118791ee3dff01c85894456f644e22a170773bcab9faf79cc6e714
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus'
|
|
2
|
-
import showFlashMessage from 'spree/storefront/helpers/show_flash_message'
|
|
3
2
|
import { post, put } from '@rails/request.js'
|
|
3
|
+
import showFlashMessage from 'spree/storefront/helpers/show_flash_message'
|
|
4
4
|
|
|
5
5
|
export default class extends Controller {
|
|
6
6
|
static values = {
|
|
@@ -16,21 +16,35 @@ export default class extends Controller {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
connect() {
|
|
19
|
-
this.initPayPal();
|
|
20
|
-
|
|
21
19
|
this.submitTarget = document.querySelector('#checkout-payment-submit')
|
|
22
20
|
this.billingAddressCheckbox = document.querySelector('#order_use_shipping')
|
|
23
21
|
this.billingAddressForm = document.querySelector('form.edit_order')
|
|
24
22
|
|
|
25
23
|
// hide submit button
|
|
26
24
|
this.submitTarget.style.display = 'none'
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
this.initPayPal();
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('Failed to initialize PayPal:', error);
|
|
30
|
+
this.showPayPalError();
|
|
31
|
+
}
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
disconnect() {
|
|
30
35
|
this.submitTarget.style.display = 'block'
|
|
31
36
|
}
|
|
32
37
|
|
|
38
|
+
showPayPalError() {
|
|
39
|
+
showFlashMessage('Failed to load PayPal. Please contact support or try a different payment method.', 'error');
|
|
40
|
+
}
|
|
41
|
+
|
|
33
42
|
initPayPal() {
|
|
43
|
+
// Check if PayPal SDK is loaded
|
|
44
|
+
if (typeof window.paypal === 'undefined') {
|
|
45
|
+
throw new Error('PayPal SDK not loaded');
|
|
46
|
+
}
|
|
47
|
+
|
|
34
48
|
const paypalButtons = window.paypal.Buttons({
|
|
35
49
|
style: {
|
|
36
50
|
shape: "rect",
|
|
@@ -68,7 +82,7 @@ export default class extends Controller {
|
|
|
68
82
|
return String(orderId);
|
|
69
83
|
} else {
|
|
70
84
|
console.error('Failed to create PayPal order:', response.error);
|
|
71
|
-
showFlashMessage(
|
|
85
|
+
showFlashMessage(`Sorry, your transaction could not be processed...<br><br>${response.error}`, 'error');
|
|
72
86
|
throw new Error(response.error || 'Failed to create PayPal order');
|
|
73
87
|
}
|
|
74
88
|
},
|
|
@@ -83,17 +97,21 @@ export default class extends Controller {
|
|
|
83
97
|
);
|
|
84
98
|
|
|
85
99
|
if (response.ok) {
|
|
86
|
-
window.location.href = this.returnUrlValue;
|
|
100
|
+
window.location.href = this.returnUrlValue;
|
|
87
101
|
} else {
|
|
88
102
|
console.error('Failed to capture PayPal order:', response.error);
|
|
89
|
-
showFlashMessage(
|
|
103
|
+
showFlashMessage(`Sorry, your transaction could not be processed...<br><br>${response.error}`, 'error');
|
|
90
104
|
}
|
|
91
105
|
},
|
|
92
106
|
onError: (err) => {
|
|
93
|
-
showFlashMessage(
|
|
107
|
+
showFlashMessage(`Your transaction was cancelled...<br><br>${err}`, 'error');
|
|
94
108
|
}
|
|
95
109
|
});
|
|
96
110
|
|
|
97
|
-
|
|
111
|
+
// Render PayPal buttons - catch any rendering errors
|
|
112
|
+
paypalButtons.render(this.element).catch((error) => {
|
|
113
|
+
console.error('PayPal buttons render failed:', error);
|
|
114
|
+
this.showPayPalError();
|
|
115
|
+
});
|
|
98
116
|
}
|
|
99
|
-
}
|
|
117
|
+
};
|
|
@@ -2,6 +2,10 @@ module SpreePaypalCheckout
|
|
|
2
2
|
class Gateway < ::Spree::Gateway
|
|
3
3
|
include PaypalServerSdk
|
|
4
4
|
|
|
5
|
+
GatewayResponse = Struct.new(:success, :message, :params, :authorization) do
|
|
6
|
+
alias_method :success?, :success
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
#
|
|
6
10
|
# Preferences
|
|
7
11
|
#
|
|
@@ -114,8 +118,15 @@ module SpreePaypalCheckout
|
|
|
114
118
|
end
|
|
115
119
|
end
|
|
116
120
|
|
|
117
|
-
def void(authorization,
|
|
118
|
-
|
|
121
|
+
def void(authorization, _source, gateway_options = {})
|
|
122
|
+
protect_from_error do
|
|
123
|
+
response = client.payments.void_payment({
|
|
124
|
+
'authorization_id' => authorization,
|
|
125
|
+
'prefer' => 'return=representation'
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
success(authorization, response.data.as_json)
|
|
129
|
+
end
|
|
119
130
|
end
|
|
120
131
|
|
|
121
132
|
def credit(amount_in_cents, _payment_source, paypal_payment_id, gateway_options = {})
|
|
@@ -140,7 +151,27 @@ module SpreePaypalCheckout
|
|
|
140
151
|
end
|
|
141
152
|
|
|
142
153
|
def cancel(authorization, payment = nil)
|
|
143
|
-
|
|
154
|
+
protect_from_error do
|
|
155
|
+
if payment&.completed?
|
|
156
|
+
amount = payment.credit_allowed
|
|
157
|
+
return success(authorization, {}) if amount.zero?
|
|
158
|
+
|
|
159
|
+
refund = payment.refunds.create!(
|
|
160
|
+
amount: amount,
|
|
161
|
+
reason: Spree::RefundReason.order_canceled_reason,
|
|
162
|
+
refunder_id: payment.order.canceler_id
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
success(payment.response_code, refund.response.params)
|
|
166
|
+
else
|
|
167
|
+
response = client.payments.void_payment({
|
|
168
|
+
'authorization_id' => authorization,
|
|
169
|
+
'prefer' => 'return=representation'
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
success(authorization, response.data.as_json)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
144
175
|
end
|
|
145
176
|
|
|
146
177
|
private
|
|
@@ -166,20 +197,11 @@ module SpreePaypalCheckout
|
|
|
166
197
|
end
|
|
167
198
|
|
|
168
199
|
def success(authorization, response)
|
|
169
|
-
|
|
170
|
-
true,
|
|
171
|
-
'Transaction successful',
|
|
172
|
-
response,
|
|
173
|
-
authorization: authorization
|
|
174
|
-
)
|
|
200
|
+
GatewayResponse.new(true, 'Transaction successful', response, authorization)
|
|
175
201
|
end
|
|
176
202
|
|
|
177
203
|
def failure(message, response = {})
|
|
178
|
-
|
|
179
|
-
false,
|
|
180
|
-
message,
|
|
181
|
-
response
|
|
182
|
-
)
|
|
204
|
+
GatewayResponse.new(false, message, response, nil)
|
|
183
205
|
end
|
|
184
206
|
end
|
|
185
207
|
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if previous_cards.any? %>
|
|
2
|
+
<%= render 'spree/admin/payments/source_forms/previous_cards', previous_cards: previous_cards, f: f %>
|
|
3
|
+
<% else %>
|
|
4
|
+
<span class="text-gray-600">
|
|
5
|
+
<%= Spree.t(:no_payment_sources_available, default: 'No saved PayPal accounts available.') %>
|
|
6
|
+
</span>
|
|
7
|
+
<% end %>
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
src="https://www.paypal.com/sdk/js?client-id=<%= current_store.paypal_checkout_gateway.preferred_client_id %>¤cy=<%= current_currency %>&components=buttons&enable-funding=paylater&disable-funding=venmo,card,p24"
|
|
5
5
|
data-sdk-integration-source="developer-studio"
|
|
6
6
|
defer
|
|
7
|
+
data-turbo-eval="false"
|
|
7
8
|
></script>
|
|
8
9
|
|
|
9
10
|
<%= javascript_import_module_tag 'application-spree-paypal-checkout' %>
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spree_paypal_checkout
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vendo Connect Inc.
|
|
@@ -135,6 +135,7 @@ files:
|
|
|
135
135
|
- app/services/spree_paypal_checkout/create_source.rb
|
|
136
136
|
- app/views/spree/admin/payment_methods/configuration_guides/_spree_paypal_checkout.html.erb
|
|
137
137
|
- app/views/spree/admin/payment_methods/descriptions/_spree_paypal_checkout.html.erb
|
|
138
|
+
- app/views/spree/admin/payments/source_forms/_spree_paypal_checkout.html.erb
|
|
138
139
|
- app/views/spree/checkout/payment/_spree_paypal_checkout.html.erb
|
|
139
140
|
- app/views/spree/payment_sources/_paypal_checkout.html.erb
|
|
140
141
|
- app/views/spree_paypal_checkout/_head.html.erb
|
|
@@ -154,9 +155,9 @@ licenses:
|
|
|
154
155
|
- MIT
|
|
155
156
|
metadata:
|
|
156
157
|
bug_tracker_uri: https://github.com/spree/spree_paypal_checkout/issues
|
|
157
|
-
changelog_uri: https://github.com/spree/spree_paypal_checkout/releases/tag/v0.
|
|
158
|
+
changelog_uri: https://github.com/spree/spree_paypal_checkout/releases/tag/v0.6.0
|
|
158
159
|
documentation_uri: https://docs.spreecommerce.org/
|
|
159
|
-
source_code_uri: https://github.com/spree/spree_paypal_checkout/tree/v0.
|
|
160
|
+
source_code_uri: https://github.com/spree/spree_paypal_checkout/tree/v0.6.0
|
|
160
161
|
rdoc_options: []
|
|
161
162
|
require_paths:
|
|
162
163
|
- lib
|