Class: Workarea::Paypal::HandleWebhookEvent
- Inherits:
-
Object
- Object
- Workarea::Paypal::HandleWebhookEvent
- Includes:
- Sidekiq::Worker
- Defined in:
- app/workers/workarea/paypal/handle_webhook_event.rb
Instance Method Summary collapse
- #payment_capture_completed(resource) ⇒ Object
- #payment_capture_denied(resource) ⇒ Object
- #perform(event, resource) ⇒ Object
Instance Method Details
#payment_capture_completed(resource) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/workers/workarea/paypal/handle_webhook_event.rb', line 13 def payment_capture_completed(resource) transaction = Payment::Transaction.where( 'response.params.id' => resource['id'] ).first if transaction.nil? logger.error("FAILED: Transaction with capture ID of #{resource['id']} does not exist.") return end tender = transaction.payment.tenders.detect do |t| t.id.to_s == transaction.tender_id end return unless tender.present? amount = resource['amount'] txn = tender.build_transaction( action: 'capture', success: true, reference: transaction, amount: amount['value'].to_m(amount['currency_code']), response: ActiveMerchant::Billing::Response.new( true, 'Paypal capture was confirmed.', resource ) ) txn.save! end |
#payment_capture_denied(resource) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/workers/workarea/paypal/handle_webhook_event.rb', line 44 def payment_capture_denied(resource) transaction = Payment::Transaction.where( 'response.params.id' => resource['id'] ).first if transaction.nil? logger.error("FAILED: Transaction with capture ID of #{resource['id']} does not exist.") return end transaction.cancellation = ActiveMerchant::Billing::Response.new( true, "PayPal capture was denied", resource ) transaction.canceled_at = Time.current transaction.save! end |
#perform(event, resource) ⇒ Object
6 7 8 9 10 11 |
# File 'app/workers/workarea/paypal/handle_webhook_event.rb', line 6 def perform(event, resource) event_method = event.optionize return send(event_method, resource) if respond_to?(event_method) logger.error("FAILED: #{event} webhook is not supported.") end |