Sha256: 0bfe383860f5fca65a53136b5660adabfb450cb87d15877b5811cb9643919875

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Solidus
  class Gateway::PayuLatamGateway < ::Spree::PaymentMethod::CreditCard
    preference :merchant_id, :string
    preference :account_id, :string
    preference :api_login, :string
    preference :api_key, :string
    preference :payment_country, :string, default: 'PE'

    def gateway_class
      ActiveMerchant::Billing::PayuLatamGateway
    end

    def partial_name
      'payu_latam'
    end

    def authorize(amount, credit_card, gateway_options)
      cvv = credit_card.verification_value
      options = add_missing_fields(gateway_options, cvv)
      gateway.authorize(amount, credit_card, options)
    end

    def capture(amount, authorization, gateway_options)
      gateway.capture(amount, authorization, gateway_options)
    end

    def void(authorization, gateway_options)
      gateway.void(authorization, gateway_options)
    end

    def purchase(amount, credit_card, gateway_options)
      cvv = credit_card.verification_value
      options = add_missing_fields(gateway_options, cvv)
      gateway.purchase(amount, credit_card, options)
    end

    def credit(amount, authorization, gateway_options)
      gateway.refund(amount, authorization, gateway_options)
    end

    private

    def add_missing_fields(options, cvv)
      dni_number = options[:customer_document]
      options.merge(
        buyer_email: options[:email],
        buyer_name: options[:shipping_address][:name],
        buyer_dni_number: dni_number,
        dni_number: dni_number,
        cvv: cvv
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_payu_latam-0.1.0 app/models/solidus/gateway/payu_latam_gateway.rb