shoppe-paypal 1.1.1 → 1.2.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/lib/shoppe/paypal.rb +33 -0
- data/lib/shoppe/paypal/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 149ca45ed4702ca50cfff2797012414742c1abbc
|
|
4
|
+
data.tar.gz: 5c2f756d6083746302853be9c82b194a64c495c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e365a8c07a0e96a645978d476ff65ba2f1c826de902b28e85a540f91a4860fe8c15f6c2066f723fa3bab285c1aae5b9ef2da5bf0e3585c9f36bb330d6382641
|
|
7
|
+
data.tar.gz: d326770f05c6c9e5a937f4e90783f2df4dd28ac4fd2b6ece740f9ba2712f7792aaa6dd502838c2a6ce8f32fdc3c33bbb80742afd6d20a298179bc0198359414b
|
data/lib/shoppe/paypal.rb
CHANGED
|
@@ -34,12 +34,45 @@ module Shoppe
|
|
|
34
34
|
self.payments.where(confirmed: false, method: "PayPal").each do |payment|
|
|
35
35
|
begin
|
|
36
36
|
payment.paypal_payment.execute(payer_id: payment.order.properties["paypal_payer_id"])
|
|
37
|
+
|
|
38
|
+
transaction = payment.paypal_payment.transactions.first.related_resources.first.sale.id
|
|
39
|
+
|
|
37
40
|
payment.update_attribute(:confirmed, true)
|
|
41
|
+
payment.update_attribute(:reference, transaction)
|
|
38
42
|
rescue
|
|
39
43
|
raise Shoppe::Errors::PaymentDeclined, "Payment ##{payment.id} could not be captured by PayPal. Investigate with PayPal. Do not accept the order."
|
|
40
44
|
end
|
|
41
45
|
end
|
|
42
46
|
end
|
|
47
|
+
|
|
48
|
+
# Refund the PayPal transaction
|
|
49
|
+
Shoppe::Payment.before_refund do
|
|
50
|
+
if self.method == "PayPal"
|
|
51
|
+
Shoppe::Paypal.setup_paypal
|
|
52
|
+
|
|
53
|
+
begin
|
|
54
|
+
@sale = PayPal::SDK::REST::Sale.find(self.reference)
|
|
55
|
+
@refund = @sale.refund({
|
|
56
|
+
:amount => {
|
|
57
|
+
:currency => Shoppe::Paypal.currency,
|
|
58
|
+
:total => "#{'%.2f' % self.refundable_amount}"}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
# Check refund status
|
|
62
|
+
if @refund.success?
|
|
63
|
+
true
|
|
64
|
+
else
|
|
65
|
+
raise Shoppe::Errors::RefundFailed, message: "Unable to Refund"
|
|
66
|
+
logger.error "Unable to Refund"
|
|
67
|
+
logger.error @refund.error.inspect
|
|
68
|
+
end
|
|
69
|
+
rescue
|
|
70
|
+
raise Shoppe::Errors::RefundFailed, message: "PayPal Sale '#{self.reference}' Not Found"
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
43
76
|
end
|
|
44
77
|
|
|
45
78
|
# Setup the PayPal configuration
|