effective_orders 6.12.2 → 6.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/datatables/admin/effective_orders_datatable.rb +1 -1
- data/app/datatables/effective_orders_datatable.rb +1 -1
- data/app/models/effective/deluxe_api.rb +98 -54
- data/app/models/effective/order.rb +6 -2
- data/lib/effective_orders/version.rb +1 -1
- data/lib/effective_orders.rb +2 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4f5fbabf9c4012193962576f7ef67838e17e382740ad3860ab9c9f527ce86787
         | 
| 4 | 
            +
              data.tar.gz: 71f6af17259b5b62ee66b2fd993bb085dc8411ad8040c21fa0a3bc639381c655
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 60eff8ba4e046b46575a23c98daf14b0ba07cf548041826590ac49c3bf193cde6632437baeae38bfe011f37a3cae0e7d3d5d444aeeb0340a0990d1c93a88ce2b
         | 
| 7 | 
            +
              data.tar.gz: 9b91126b76b01d50fefc86b31d1a163dfe8164c523f69a2c3a523a827c632faaf0b0b5e13e0174b01450078dd32754a76157b5c4338b39b16b47a10ca1d25c59
         | 
| @@ -19,7 +19,7 @@ module Admin | |
| 19 19 | 
             
                    scope :all
         | 
| 20 20 | 
             
                    scope :purchased
         | 
| 21 21 |  | 
| 22 | 
            -
                    scope :deferred if EffectiveOrders. | 
| 22 | 
            +
                    scope :deferred if EffectiveOrders.deferred? || EffectiveOrders.delayed?
         | 
| 23 23 | 
             
                    scope :voided
         | 
| 24 24 |  | 
| 25 25 | 
             
                    scope :pending_refunds if EffectiveOrders.refund && !EffectiveOrders.buyer_purchases_refund?
         | 
| @@ -6,7 +6,7 @@ class EffectiveOrdersDatatable < Effective::Datatable | |
| 6 6 | 
             
                  scope :all
         | 
| 7 7 | 
             
                  scope :purchased
         | 
| 8 8 |  | 
| 9 | 
            -
                  scope :deferred if EffectiveOrders. | 
| 9 | 
            +
                  scope :deferred if EffectiveOrders.deferred? || EffectiveOrders.delayed?
         | 
| 10 10 | 
             
                  scope :refunds if EffectiveOrders.refund
         | 
| 11 11 | 
             
                  scope :not_purchased
         | 
| 12 12 | 
             
                end
         | 
| @@ -23,15 +23,51 @@ module Effective | |
| 23 23 | 
             
                  self.currency = currency || EffectiveOrders.deluxe.fetch(:currency)
         | 
| 24 24 | 
             
                end
         | 
| 25 25 |  | 
| 26 | 
            -
                def  | 
| 27 | 
            -
                   | 
| 28 | 
            -
             | 
| 26 | 
            +
                def health_check
         | 
| 27 | 
            +
                  get('/')
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def healthy?
         | 
| 31 | 
            +
                  response = health_check()
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  return false unless response.kind_of?(Hash)
         | 
| 34 | 
            +
                  return false unless response['appName'].present?
         | 
| 35 | 
            +
                  return false unless response['environment'].present?
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  true
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                # Decode the base64 encoded JSON object into a Hash
         | 
| 41 | 
            +
                def decode_payment_intent_payload(payload)
         | 
| 42 | 
            +
                  raise('expected a string') unless payload.kind_of?(String)
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  payment_intent = (JSON.parse(Base64.decode64(payload)) rescue nil)
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  raise('expected payment_intent to be a Hash') unless payment_intent.kind_of?(Hash)
         | 
| 47 | 
            +
                  raise('expected a token payment') unless payment_intent['type'] == 'Token'
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  payment_intent
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                # Takes a payment_intent and returns the card info we can store
         | 
| 53 | 
            +
                def card_info(payment_intent)
         | 
| 54 | 
            +
                  token = extract_token(payment_intent)
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  # Return the authorization params merged with the card info
         | 
| 57 | 
            +
                  last4 = token['maskedPan'].to_s.last(4)
         | 
| 58 | 
            +
                  card = token['cardType'].to_s.downcase
         | 
| 59 | 
            +
                  date = token['expDate']
         | 
| 60 | 
            +
                  cvv = token['cvv']
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  active_card = "**** **** **** #{last4} #{card} #{date}" if last4.present?
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  { 'active_card' => active_card, 'card' => card, 'expDate' => date, 'cvv' => cvv }.compact
         | 
| 29 65 | 
             
                end
         | 
| 30 66 |  | 
| 67 | 
            +
                # After we store a payment intent we can call purchase! immediately or wait till later.
         | 
| 31 68 | 
             
                # This calls Authorize Payment and Complete Payment
         | 
| 32 | 
            -
                # Returns true  | 
| 33 | 
            -
                #  | 
| 34 | 
            -
                # Always sets the @purchase_response which is api.payment
         | 
| 69 | 
            +
                # Returns true when purchased. Returns false when declined.
         | 
| 70 | 
            +
                # The response is stored in api.payment() after this is run
         | 
| 35 71 | 
             
                def purchase!(order, payment_intent)
         | 
| 36 72 | 
             
                  payment_intent = decode_payment_intent_payload(payment_intent) if payment_intent.kind_of?(String)
         | 
| 37 73 | 
             
                  raise('expected payment_intent to be a Hash') unless payment_intent.kind_of?(Hash)
         | 
| @@ -58,21 +94,56 @@ module Effective | |
| 58 94 | 
             
                  true
         | 
| 59 95 | 
             
                end
         | 
| 60 96 |  | 
| 61 | 
            -
                 | 
| 62 | 
            -
             | 
| 63 | 
            -
                   | 
| 97 | 
            +
                def payment
         | 
| 98 | 
            +
                  raise('expected purchase response to be present') unless purchase_response.kind_of?(Hash)
         | 
| 99 | 
            +
                  purchase_response
         | 
| 64 100 | 
             
                end
         | 
| 65 101 |  | 
| 66 | 
            -
                def  | 
| 67 | 
            -
                   | 
| 102 | 
            +
                def purchase_delayed_orders!(orders)
         | 
| 103 | 
            +
                  now = Time.zone.now
         | 
| 68 104 |  | 
| 69 | 
            -
                   | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 105 | 
            +
                  Array(orders).each do |order|
         | 
| 106 | 
            +
                    puts "Trying order #{order.id}"
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                    begin
         | 
| 109 | 
            +
                      raise('expected a delayed order') unless order.delayed?
         | 
| 110 | 
            +
                      raise('expected a deferred order') unless order.deferred?
         | 
| 111 | 
            +
                      raise('expected delayed payment intent') unless order.delayed_payment_intent.present?
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                      order.update_columns(delayed_payment_purchase_ran_at: now, delayed_payment_purchase_result: nil)
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                      purchased = purchase!(order, order.delayed_payment_intent)
         | 
| 116 | 
            +
                      provider = order.payment_provider
         | 
| 117 | 
            +
                      payment = self.payment()
         | 
| 118 | 
            +
                      card = payment["card"]
         | 
| 119 | 
            +
             | 
| 120 | 
            +
                      if purchased
         | 
| 121 | 
            +
                        order.assign_attributes(delayed_payment_purchase_result: "success")
         | 
| 122 | 
            +
                        order.purchase!(payment: payment, provider: provider, card: card, email: true, skip_buyer_validations: true)
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                        puts "Successfully purchased order #{order.id}"
         | 
| 125 | 
            +
                      else
         | 
| 126 | 
            +
                        order.assign_attributes(delayed_payment_purchase_result: "failed with message: #{Array(payment['responseMessage']).to_sentence.presence || 'none'}.")
         | 
| 127 | 
            +
                        order.decline!(payment: payment, provider: provider, card: card)
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                        puts "Failed to purchase order #{order.id} #{order.delayed_payment_purchase_result}"
         | 
| 130 | 
            +
                      end
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                    rescue => e
         | 
| 133 | 
            +
                      order.update_columns(delayed_payment_purchase_ran_at: now, delayed_payment_purchase_result: "error: #{e.message}")
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                      EffectiveLogger.error(e.message, associated: order) if defined?(EffectiveLogger)
         | 
| 136 | 
            +
                      ExceptionNotifier.notify_exception(e, data: { order_id: order.id }) if defined?(ExceptionNotifier)
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                      puts "Error purchasing #{order.id}: #{e.message}"
         | 
| 139 | 
            +
                    end
         | 
| 140 | 
            +
                  end
         | 
| 72 141 |  | 
| 73 142 | 
             
                  true
         | 
| 74 143 | 
             
                end
         | 
| 75 144 |  | 
| 145 | 
            +
                protected
         | 
| 146 | 
            +
             | 
| 76 147 | 
             
                # Authorize Payment
         | 
| 77 148 | 
             
                def authorize_payment(order, payment_intent)
         | 
| 78 149 | 
             
                  response = post('/payments/authorize', params: authorize_payment_params(order, payment_intent))
         | 
| @@ -117,19 +188,6 @@ module Effective | |
| 117 188 | 
             
                  response.reverse_merge(authorization)
         | 
| 118 189 | 
             
                end
         | 
| 119 190 |  | 
| 120 | 
            -
                def complete_payment_params(order, payment_intent)
         | 
| 121 | 
            -
                  raise('expected an Effective::Order') unless order.kind_of?(Effective::Order)
         | 
| 122 | 
            -
             | 
| 123 | 
            -
                  payment_id = extract_payment_id(payment_intent)
         | 
| 124 | 
            -
                  amount = { amount: order.total_to_f, currency: currency }
         | 
| 125 | 
            -
             | 
| 126 | 
            -
                  # Params passed into Complete Payment
         | 
| 127 | 
            -
                  { 
         | 
| 128 | 
            -
                    paymentId: payment_id, 
         | 
| 129 | 
            -
                    amount: amount
         | 
| 130 | 
            -
                  }
         | 
| 131 | 
            -
                end
         | 
| 132 | 
            -
             | 
| 133 191 | 
             
                def authorize_payment_params(order, payment_intent)
         | 
| 134 192 | 
             
                  raise('expected an Effective::Order') unless order.kind_of?(Effective::Order)
         | 
| 135 193 |  | 
| @@ -183,6 +241,19 @@ module Effective | |
| 183 241 | 
             
                  }.compact
         | 
| 184 242 | 
             
                end
         | 
| 185 243 |  | 
| 244 | 
            +
                def complete_payment_params(order, payment_intent)
         | 
| 245 | 
            +
                  raise('expected an Effective::Order') unless order.kind_of?(Effective::Order)
         | 
| 246 | 
            +
             | 
| 247 | 
            +
                  payment_id = extract_payment_id(payment_intent)
         | 
| 248 | 
            +
                  amount = { amount: order.total_to_f, currency: currency }
         | 
| 249 | 
            +
             | 
| 250 | 
            +
                  # Params passed into Complete Payment
         | 
| 251 | 
            +
                  { 
         | 
| 252 | 
            +
                    paymentId: payment_id, 
         | 
| 253 | 
            +
                    amount: amount
         | 
| 254 | 
            +
                  }
         | 
| 255 | 
            +
                end
         | 
| 256 | 
            +
             | 
| 186 257 | 
             
                def get(endpoint, params: nil)
         | 
| 187 258 | 
             
                  query = ('?' + params.compact.map { |k, v| "$#{k}=#{v}" }.join('&')) if params.present?
         | 
| 188 259 |  | 
| @@ -223,33 +294,6 @@ module Effective | |
| 223 294 | 
             
                  JSON.parse(result.body)
         | 
| 224 295 | 
             
                end
         | 
| 225 296 |  | 
| 226 | 
            -
                # Takes a payment_intent and returns the card info we can store
         | 
| 227 | 
            -
                def card_info(payment_intent)
         | 
| 228 | 
            -
                  token = extract_token(payment_intent)
         | 
| 229 | 
            -
             | 
| 230 | 
            -
                  # Return the authorization params merged with the card info
         | 
| 231 | 
            -
                  last4 = token['maskedPan'].to_s.last(4)
         | 
| 232 | 
            -
                  card = token['cardType'].to_s.downcase
         | 
| 233 | 
            -
                  date = token['expDate']
         | 
| 234 | 
            -
                  cvv = token['cvv']
         | 
| 235 | 
            -
             | 
| 236 | 
            -
                  active_card = "**** **** **** #{last4} #{card} #{date}" if last4.present?
         | 
| 237 | 
            -
             | 
| 238 | 
            -
                  { 'active_card' => active_card, 'card' => card, 'expDate' => date, 'cvv' => cvv }.compact
         | 
| 239 | 
            -
                end
         | 
| 240 | 
            -
             | 
| 241 | 
            -
                # Decode the base64 encoded JSON object into a Hash
         | 
| 242 | 
            -
                def decode_payment_intent_payload(payload)
         | 
| 243 | 
            -
                  raise('expected a string') unless payload.kind_of?(String)
         | 
| 244 | 
            -
             | 
| 245 | 
            -
                  payment_intent = (JSON.parse(Base64.decode64(payload)) rescue nil)
         | 
| 246 | 
            -
             | 
| 247 | 
            -
                  raise('expected payment_intent to be a Hash') unless payment_intent.kind_of?(Hash)
         | 
| 248 | 
            -
                  raise('expected a token payment') unless payment_intent['type'] == 'Token'
         | 
| 249 | 
            -
             | 
| 250 | 
            -
                  payment_intent
         | 
| 251 | 
            -
                end
         | 
| 252 | 
            -
             | 
| 253 297 | 
             
                private
         | 
| 254 298 |  | 
| 255 299 | 
             
                def headers
         | 
| @@ -241,7 +241,9 @@ module Effective | |
| 241 241 | 
             
                  validates :payment_provider, presence: true
         | 
| 242 242 |  | 
| 243 243 | 
             
                  validate do
         | 
| 244 | 
            -
                     | 
| 244 | 
            +
                    unless EffectiveOrders.deferred_providers.include?(payment_provider) || EffectiveOrders.delayed_providers.include?(payment_provider)
         | 
| 245 | 
            +
                      errors.add(:payment_provider, "unknown deferred payment provider") 
         | 
| 246 | 
            +
                    end
         | 
| 245 247 | 
             
                  end
         | 
| 246 248 | 
             
                end
         | 
| 247 249 |  | 
| @@ -673,7 +675,9 @@ module Effective | |
| 673 675 |  | 
| 674 676 | 
             
                    payment: payment_to_h(payment.presence || 'none'),
         | 
| 675 677 | 
             
                    payment_provider: (provider.presence || 'none'),
         | 
| 676 | 
            -
                    payment_card: (card.presence || 'none')
         | 
| 678 | 
            +
                    payment_card: (card.presence || 'none'),
         | 
| 679 | 
            +
             | 
| 680 | 
            +
                    delayed_payment_intent: nil # Do not store the delayed payment intent any longer
         | 
| 677 681 | 
             
                  )
         | 
| 678 682 |  | 
| 679 683 | 
             
                  if current_user&.email.present?
         | 
    
        data/lib/effective_orders.rb
    CHANGED
    
    | @@ -185,8 +185,9 @@ module EffectiveOrders | |
| 185 185 | 
             
                ].compact
         | 
| 186 186 | 
             
              end
         | 
| 187 187 |  | 
| 188 | 
            +
              # Should not include delayed providers
         | 
| 188 189 | 
             
              def self.deferred_providers
         | 
| 189 | 
            -
                [('cheque' if cheque?), (' | 
| 190 | 
            +
                [('cheque' if cheque?), ('etransfer' if etransfer?), ('phone' if phone?)].compact
         | 
| 190 191 | 
             
              end
         | 
| 191 192 |  | 
| 192 193 | 
             
              def self.delayed_providers
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: effective_orders
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 6.12. | 
| 4 | 
            +
              version: 6.12.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Code and Effect
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024-05- | 
| 11 | 
            +
            date: 2024-05-31 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |