effective_orders 5.4.3 → 5.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93201b2a28d118f01d4404c0a1b1e7ce9cfccfa17e5449923d827f804297146f
4
- data.tar.gz: 33c7e7c0b13f149bbea2c46d4f3aa70dbf3d4157c73be9dfe0b84f965e17bd13
3
+ metadata.gz: c85d15408b6f15085acae0e838a73738f06b302c1730a2d5dd63bfc14aeab232
4
+ data.tar.gz: 3ef013aef146e28669878e441b942bb9f4b0dc19e1871ced2097a2367fad9ab5
5
5
  SHA512:
6
- metadata.gz: b6e7b680b06ac025f6b4b8bad7845f95f92f04ab952479ee8cc66025b55da853a4c8871c910f322fdb4062860c66695fb8f9c3b52b3e56bc041bc243078d076b
7
- data.tar.gz: 4750b01b2d298736a05e6f9290146695816f9c0a15dcd80701c2c0a04c1516cf4ebedd790ec334674aaf335abc77a7f58241274b1812897bc6b5b408650dff80
6
+ metadata.gz: bdbb7867bd6336373a78ee7a601fc5866b90e8dce68f2ca19d8e47c90a88a0b18ada917e4fa485a416cabc75fb0c95fab37bd65c069c0b30e030b6761f1675f6
7
+ data.tar.gz: e30f27c7a2801feae282487ed6e1d5414c78b94e1f50dbb800f016782299ed02afa329164585af50d7933ae7269f4fb3ebf9eda0eb94ad68a6cfd22b8a13b1b6
@@ -11,10 +11,10 @@ module Effective
11
11
  EffectiveResources.authorize!(self, :update, @order)
12
12
  EffectiveResources.authorize!(self, :admin, :effective_orders)
13
13
 
14
- @order.assign_attributes(mark_as_paid_params.except(:payment, :payment_provider, :payment_card))
14
+ @order.assign_attributes(mark_as_paid_params.except(:payment_provider, :payment_card))
15
15
 
16
16
  order_purchased(
17
- payment: mark_as_paid_params[:payment],
17
+ payment: 'mark as paid',
18
18
  provider: mark_as_paid_params[:payment_provider],
19
19
  card: mark_as_paid_params[:payment_card],
20
20
  email: @order.send_mark_as_paid_email_to_buyer?,
@@ -25,7 +25,7 @@ module Effective
25
25
 
26
26
  def mark_as_paid_params
27
27
  params.require(:effective_order).permit(
28
- :purchased_at, :payment, :payment_provider, :payment_card,
28
+ :purchased_at, :payment_provider, :payment_card,
29
29
  :note_to_buyer, :note_internal, :send_mark_as_paid_email_to_buyer
30
30
  )
31
31
  end
@@ -47,6 +47,16 @@ module EffectiveStripeHelper
47
47
 
48
48
  def stripe_payment_intent(order)
49
49
  customer = Effective::Customer.for_user(order.user)
50
+
51
+ begin
52
+ stripe_payment_intent_payload(order, customer)
53
+ rescue => e
54
+ raise unless Rails.env.development?
55
+ stripe_payment_intent_payload(order, Effective::Customer.new(user: order.user))
56
+ end
57
+ end
58
+
59
+ def stripe_payment_intent_payload(order, customer)
50
60
  customer.create_stripe_customer! # Only creates if customer not already present
51
61
 
52
62
  payment = {
@@ -335,6 +335,18 @@ module Effective
335
335
  else payment_card.to_s
336
336
  end
337
337
 
338
+ # Try again
339
+ if card == 'none' && payment['card_type'].present?
340
+ card = case payment['card_type'].to_s.downcase.gsub(' ', '').strip
341
+ when '' then nil
342
+ when 'v', 'visa' then 'Visa'
343
+ when 'm', 'mc', 'master', 'mastercard' then 'MasterCard'
344
+ when 'a', 'ax', 'american', 'americanexpress' then 'American Express'
345
+ when 'd', 'discover' then 'Discover'
346
+ else payment_card.to_s
347
+ end
348
+ end
349
+
338
350
  last4 = if payment[:active_card] && payment[:active_card].include?('**** **** ****')
339
351
  payment[:active_card][15,4]
340
352
  end
@@ -486,14 +498,18 @@ module Effective
486
498
 
487
499
  # Effective::Order.new(items: Product.first, user: User.first).purchase!(email: false)
488
500
  def purchase!(payment: 'none', provider: 'none', card: 'none', email: true, skip_buyer_validations: false, skip_quickbooks: false)
501
+ return true if purchased?
502
+
489
503
  # Assign attributes
490
- self.state = EffectiveOrders::PURCHASED
491
- self.skip_buyer_validations = skip_buyer_validations
504
+ assign_attributes(
505
+ state: EffectiveOrders::PURCHASED,
506
+ skip_buyer_validations: skip_buyer_validations,
492
507
 
493
- self.payment_provider ||= provider
494
- self.payment_card ||= (card.presence || 'none')
495
- self.purchased_at ||= Time.zone.now
496
- self.payment = payment_to_h(payment) if self.payment.blank?
508
+ payment_provider: provider,
509
+ payment_card: (card.presence || 'none'),
510
+ purchased_at: Time.zone.now,
511
+ payment: payment_to_h(payment)
512
+ )
497
513
 
498
514
  begin
499
515
  Effective::Order.transaction do
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.4.3'.freeze
2
+ VERSION = '5.5.1'.freeze
3
3
  end
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: 5.4.3
4
+ version: 5.5.1
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: 2022-03-21 00:00:00.000000000 Z
11
+ date: 2022-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails