Sha256: 072cd7a21fa100db8a09756c9659f2bdeb741fa6158a1b104a960cc7f2111a5e

Contents?: true

Size: 963 Bytes

Versions: 3

Compression:

Stored size: 963 Bytes

Contents

# frozen_string_literal: true

module SolidusPaypalCommercePlatform
  class WebhookJob < SolidusPaypalCommercePlatform::ApplicationJob
    def perform(payload)
      case payload["resource_type"]
      when "checkout-order"
        payment_source = PaymentSource.find_by!(paypal_order_id: payload.dig("resource", "id"))
        payment = Spree::Payment.where(source: payment_source).last!
        payment.log_entries.create!(details: payload.to_yaml)
      when "capture"
        payment_source = PaymentSource.find_by!(capture_id: payload.dig("resource", "id"))
        payment = Spree::Payment.where(source: payment_source).last!
        payment.log_entries.create!(details: payload.to_yaml)
      when "refund"
        payment_source = PaymentSource.find_by!(refund_id: payload.dig("resource", "id"))
        payment = Spree::Payment.where(source: payment_source).last!
        payment.log_entries.create!(details: payload.to_yaml)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_paypal_commerce_platform-0.2.0 app/jobs/solidus_paypal_commerce_platform/webhook_job.rb
solidus_paypal_commerce_platform-0.1.0 app/jobs/solidus_paypal_commerce_platform/webhook_job.rb
solidus_paypal_commerce_platform-0.0.1 app/jobs/solidus_paypal_commerce_platform/webhook_job.rb