spree_vpago 2.4.4.pre.pre1 → 2.4.4.pre.pre2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2407757bf856836db8119fd75b066e773c8cea45c9806021ad2ce815e86a1067
4
- data.tar.gz: 6954c4fcd84a2ac644cd961e21e58fd4c89e8945e4d7f041f11ba21a3dfa5642
3
+ metadata.gz: 202902b6e4c3b29b5b45a8c0471682383677fccdd17e97a22c64a756aa44860b
4
+ data.tar.gz: 03a0c008c59b265e6fba2cd0ccdf03aefdd0d0bd0e00441ebd1166f18645ad68
5
5
  SHA512:
6
- metadata.gz: 58e9096a7433cc3302ec05489ff1e8f73ed5703ac750d33fd1f6ded8e2a57b012f1d50d332d3424b05923f6279da7a4a37b6da6d97a504a82d8edd35850d7787
7
- data.tar.gz: 1a4b00503775fc10ff60d916bc32b897a48c592c5ee38f375791ad8ee8db75ca9b39d39e05dd3725786726705be8f2ca97e3df0828e2fee576d2c1cee9ee44a0
6
+ metadata.gz: 054dc39c5550b3a6b8389b646960199ae0ea9c85a331088b1f811dc11ffdbb5df721bb7eb0a59e978d7cd4f941cede25d751d266e86fa02b047afb3ce2c56ff5
7
+ data.tar.gz: 3394860ee34f39008253d2aea8162036cb290ffb887d4d36124ee3176676fc9cd30d762f2be395dba2cbbc40369efbadf4bd91ddf33c64b5f9af9534df49b51e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.4.4.pre.pre1)
4
+ spree_vpago (2.4.4.pre.pre2)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-cloud-check" viewBox="0 0 16 16">
2
+ <path fill-rule="evenodd" d="M10.354 6.146a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 1 1 .708-.708L7 8.793l2.646-2.647a.5.5 0 0 1 .708 0z"/>
3
+ <path d="M4.406 3.342A5.53 5.53 0 0 1 8 2c2.69 0 4.923 2 5.166 4.579C14.758 6.804 16 8.137 16 9.773 16 11.569 14.502 13 12.687 13H3.781C1.708 13 0 11.366 0 9.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383zm.653.757c-.757.653-1.153 1.44-1.153 2.056v.448l-.445.049C2.064 6.805 1 7.952 1 9.318 1 10.785 2.23 12 3.781 12h8.906C13.98 12 15 10.988 15 9.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 4.825 10.328 3 8 3a4.53 4.53 0 0 0-2.941 1.1z"/>
4
+ </svg>
@@ -155,6 +155,27 @@ module Spree
155
155
  ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Payment has been canceled.')
156
156
  end
157
157
 
158
+ # Payment#sync_capture!: completes the payment only when ABA reports it captured for the full amount. Always the v2
159
+ # checker, unlike #check_transaction: v1's status 0 covers both held and captured.
160
+ def sync_capture(payment)
161
+ checker = Vpago::PaywayV2::TransactionStatusV2.new(payment).tap(&:call)
162
+ params = { check_transaction: checker.json_response }
163
+
164
+ unless checker.captured_in_full?
165
+ reported = [checker.payment_status || checker.error_message, checker.total_amount].compact.join(' ')
166
+ return ActiveMerchant::Billing::Response.new(false, "Payway Gateway: Not Captured in Full at ABA (#{reported}, expected #{checker.amount})", params)
167
+ end
168
+
169
+ success = true
170
+ success, params[:payout] = confirm_payouts(payment) if payout_total_from_response(payment).present?
171
+
172
+ if success
173
+ ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Captured at ABA', params)
174
+ else
175
+ ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Capture Failed', params)
176
+ end
177
+ end
178
+
158
179
  def check_transaction(payment)
159
180
  # ABA requires the use of the v2 API, but it does not yet support payout responses.
160
181
  # Until v2 fully supports payouts, we fall back to v1 when payouts are enabled.
@@ -26,7 +26,7 @@ class Spree::VpagoPaymentSource < Spree::Base
26
26
  #
27
27
  # override
28
28
  def actions
29
- %w[open_checkout process capture void cancel]
29
+ %w[open_checkout process capture sync_capture void cancel]
30
30
  end
31
31
 
32
32
  def can_open_checkout?(payment)
@@ -51,6 +51,16 @@ class Spree::VpagoPaymentSource < Spree::Base
51
51
  payment.pending?
52
52
  end
53
53
 
54
+ # The flow is as follows: our capture failed -> ops captured the pre-auth in the ABA portal -> sync capture -> end.
55
+ # Capture would call ABA's completion again and fail on the already-captured hold; this only reads ABA's status.
56
+ # `failed` too: a pre-auth whose capture failed before captures stopped failing the payment is left there, and
57
+ # only this action can still complete it, since it completes nothing unless ABA confirms the full capture.
58
+ def can_sync_capture?(payment)
59
+ return false unless payment.order.completed? && payment.payment_method.enable_pre_auth?
60
+
61
+ payment.pending? || payment.processing? || payment.failed?
62
+ end
63
+
54
64
  # Spree has different refund logic, called credit. We use cancel as refund for now, but only for Vattanac/True Money.
55
65
  # In the future, we can adopt Spree's credit logic instead of cancel if needed.
56
66
  #
@@ -15,7 +15,7 @@
15
15
  #
16
16
  # Pre-auth capture! is the exception: it never leaves `pending` on failure, see #pre_auth_capture!.
17
17
  module Vpago
18
- module PaymentDecorator
18
+ module PaymentDecorator # rubocop:disable Metrics/ModuleLength
19
19
  def self.prepended(base)
20
20
  base.has_many :payouts, class_name: 'Spree::Payout', inverse_of: :payment
21
21
  base.after_create -> { Vpago::PayoutsGenerator.new(self).call }, if: :should_generate_payouts?
@@ -64,6 +64,25 @@ module Vpago
64
64
  super
65
65
  end
66
66
 
67
+ # Admin action (Spree::VpagoPaymentSource#can_sync_capture?) for a pre-auth captured outside our capture call,
68
+ # e.g. by ops in the ABA portal: reads ABA's status instead of capturing again.
69
+ def sync_capture!
70
+ return true if completed?
71
+
72
+ response = begin
73
+ payment_method.sync_capture(self)
74
+ rescue Faraday::Error => e
75
+ gateway_error(ActiveMerchant::ConnectionError.new(e.message, e))
76
+ end
77
+
78
+ record_response(response)
79
+ gateway_error(response) unless response.success?
80
+
81
+ capture_events.create!(amount: amount)
82
+ reset_for_retry! if failed? # Spree has no failed -> completed transition
83
+ complete!
84
+ end
85
+
67
86
  # override:
68
87
  # to allow capture faraday connection error. gateway_error method already write rails log for this.
69
88
  def protect_from_connection_error
@@ -10,6 +10,7 @@ en:
10
10
  insufficient_payment_amount_to_cover_the_total: "Payment amount is insufficient to cover the total"
11
11
  qr_code: "QR code"
12
12
  open_checkout: "Open Checkout"
13
+ sync_capture: "Sync capture from ABA"
13
14
  admin:
14
15
  orders:
15
16
  suspicious_orders: "Suspicious Orders"
@@ -6,6 +6,7 @@ spree:
6
6
  insufficient_payment_amount_to_cover_the_total: "ចំនួនទឹកប្រាក់នៃការទូទាត់គឺមិនគ្រប់គ្រាន់"
7
7
  qr_code: "QR code"
8
8
  open_checkout: "Open Checkout"
9
+ sync_capture: "Sync capture from ABA"
9
10
  admin:
10
11
  orders:
11
12
  suspicious_orders: "ការបង់ប្រាក់គួរឱ្យសង្ស័យ"
@@ -1,7 +1,7 @@
1
1
  module SpreeVpago
2
2
  module_function
3
3
 
4
- VERSION = '2.4.4-pre1'.freeze
4
+ VERSION = '2.4.4-pre2'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
@@ -39,6 +39,17 @@ module Vpago
39
39
  %w[APPROVED PRE-AUTH].include?(payment_status)
40
40
  end
41
41
 
42
+ # A captured pre-auth reads APPROVED (PRE-AUTH while only held). The amount must be what completion
43
+ # captures, so a partial capture made in the ABA portal is never taken for the full payment.
44
+ def captured_in_full?
45
+ payment_status == 'APPROVED' && total_amount.present? && BigDecimal(total_amount.to_s) == BigDecimal(amount)
46
+ end
47
+
48
+ def total_amount
49
+ data = json_response['data']
50
+ data['total_amount'] if data.is_a?(Hash)
51
+ end
52
+
42
53
  # request failed does not mean payment failed.
43
54
  # but it failed when status is failed.
44
55
  def pending?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_vpago
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.4.pre.pre1
4
+ version: 2.4.4.pre.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - You
@@ -132,6 +132,7 @@ files:
132
132
  - app/.gitkeep
133
133
  - app/assets/config/spree_vpago_manifest.js
134
134
  - app/assets/images/backend-process.svg
135
+ - app/assets/images/backend-sync_capture.svg
135
136
  - app/assets/images/payment_logos/acleda-cards.png
136
137
  - app/assets/images/payment_logos/acleda-khqr.png
137
138
  - app/assets/images/payment_logos/acleda.png