shoppe-paypal 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e70a1c2e91a9828544317ff41c4ea7e8400abb05
4
- data.tar.gz: fa1705dcb816747c590655395db88e62ead78201
3
+ metadata.gz: 149ca45ed4702ca50cfff2797012414742c1abbc
4
+ data.tar.gz: 5c2f756d6083746302853be9c82b194a64c495c8
5
5
  SHA512:
6
- metadata.gz: ab62e796bad7b85d0d26e2fd01ae9f2ad97249ba4d22e2ccc6eeda5e8cb5a33166bfc34e2486f15730697c2e74b8a76fbf74419016ad8cbf5220e19e032c9aab
7
- data.tar.gz: f2cb77bdbe1fa1032ab652475ef34c0685b4ca77b14eda2779c0ccb08bd5105524a5bda992eb5c8a2797cfe4d9646cbd9743cdea7bfd2cd7802ea597381e1a0b
6
+ metadata.gz: 8e365a8c07a0e96a645978d476ff65ba2f1c826de902b28e85a540f91a4860fe8c15f6c2066f723fa3bab285c1aae5b9ef2da5bf0e3585c9f36bb330d6382641
7
+ data.tar.gz: d326770f05c6c9e5a937f4e90783f2df4dd28ac4fd2b6ece740f9ba2712f7792aaa6dd502838c2a6ce8f32fdc3c33bbb80742afd6d20a298179bc0198359414b
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Shoppe
2
2
  module Paypal
3
- VERSION = "1.1.1"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoppe-paypal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry