Sha256: 9cf932165994e4673d5316a59146f10ac0e7d688fa88bbccb5af8b1baae63d78

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module SolidusPaypalCommercePlatform
  class PaymentSource < SolidusSupport.payment_source_parent_class
    self.table_name = "paypal_commerce_platform_sources"
    enum paypal_funding_source: {
      applepay: 0, bancontact: 1, blik: 2, boleto: 3, card: 4, credit: 5, eps: 6, giropay: 7, ideal: 8,
      itau: 9, maxima: 10, mercadopago: 11, mybank: 12, oxxo: 13, p24: 14, paylater: 15, paypal: 16, payu: 17,
      sepa: 18, sofort: 19, trustly: 20, venmo: 21, verkkopankki: 22, wechatpay: 23, zimpler: 24
    }, _suffix: :funding
    validates :paypal_order_id, :payment_method_id, presence: true

    def display_paypal_funding_source
      I18n.t(paypal_funding_source,
        scope: 'solidus_paypal_commerce_platform.paypal_funding_sources',
        default: paypal_funding_source)
    end

    def actions
      %w(capture void credit)
    end

    def can_capture?(payment)
      payment.pending? || payment.checkout?
    end

    def can_void?(payment)
      can_capture?(payment)
    end

    def can_credit?(payment)
      payment.completed? &&
      payment.credit_allowed > 0 &&
      capture_id &&
      payment_method.gateway.get_order(paypal_order_id).status == "COMPLETED"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_paypal_commerce_platform-0.4.0 app/models/solidus_paypal_commerce_platform/payment_source.rb