Sha256: 66907e5a6c735dc3f54e2e0f5e3b7151fbba55f8d1d0e142fa6d1129ea850549

Contents?: true

Size: 986 Bytes

Versions: 1

Compression:

Stored size: 986 Bytes

Contents

module Workarea
  decorate Payment::Authorize::CreditCard, with: :checkoutdotcom do
    decorated do
      delegate :address, to: :tender
    end

     def complete!
      transaction.response = handle_active_merchant_errors do
        gateway.authorize(
          transaction.amount.cents,
          tender.to_token_or_active_merchant,
          transaction_options
        )
      end

      if transaction.response.success? && tender.token.blank?
        tender.token = transaction.response.params["source"]["id"]
        tender.save!
      end

      transaction.response
    end

    private

    def transaction_options
      {
        order_id: tender.payment.id,
        email: tender.profile.email,
        billing_address: {
          address1: address.street,
          address2: address.street_2,
          city: address.city,
          state: address.region,
          country: address.country.alpha2,
          zip: address.postal_code
        }
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-checkoutdotcom-1.2.0 app/models/workarea/payment/authorize/credit_card.decorator