spree_vpago 2.2.2.pre.pre17 → 2.2.2.pre.pre18

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: a41c53551544436fc2973a85d085bf8dd9712ebd84ae9d6b8d820ffeeea6d5b2
4
- data.tar.gz: e0141d5b5968a647843616bfcea9a458c2805215cc78bc3651a999565bed6a59
3
+ metadata.gz: df57ee8f0d9491a0059e01819c47fd3620f9f9f0602f82c7e9ae4bd4f05fe01c
4
+ data.tar.gz: 90e49af5baece5e10f5f03f20d99f428e34c1ea50922992957a7f181da3d2e51
5
5
  SHA512:
6
- metadata.gz: dc3468dcff8511b38149ec840b73c09ed669c0347d0daa84956983edde8b8e4470f23825efc5e662424f6057d008f5ca788623a580cd21f45f3ab726923638a8
7
- data.tar.gz: 9ed4fe39e71672992963611effb80f9e781b24b677a9ac040de0b75cf56762d2e210a3c60abde7e3e69a838816715d7969412a92db588de3cf543eba81a39cd2
6
+ metadata.gz: 5f642f68de641579f20895fa58497b1e6f65852a145aed4d32af5e62bf3dd376867cb71adc7545f3778e273e90610d0d66e201c4192cff713b81dff842986a82
7
+ data.tar.gz: 7047fb3b5e701621ef108c321c78e46ed8b5e9570b1af3879a6dd8e952e7679483a33640c994d1b19e52db61fc18e48e81150ec9a3f3cf32d64ae41b62a73403
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.2.2.pre.pre17)
4
+ spree_vpago (2.2.2.pre.pre18)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
@@ -18,6 +18,22 @@ module Spree
18
18
  @order = @payment.order
19
19
  end
20
20
 
21
+ # GET
22
+ def check_transaction
23
+ @payment = Vpago::PaymentFinder.new(params.permit!.to_h).find_and_verify
24
+ raise ActiveRecord::RecordNotFound unless @payment.present?
25
+
26
+ checker = @payment.payment_method.check_transaction(@payment)
27
+
28
+ if checker.success?
29
+ render json: { status: :success }, status: :ok
30
+ elsif checker.failed?
31
+ render json: { status: :failed }, status: :payment_required
32
+ else
33
+ render json: { status: :pending }, status: :accepted
34
+ end
35
+ end
36
+
21
37
  # GET
22
38
  def processing
23
39
  @payment = Vpago::PaymentFinder.new(params.permit!.to_h).find_and_verify
@@ -9,8 +9,10 @@ module Vpago
9
9
  render partial: "spree/vpago_payments/forms/#{@payment.payment_method.class.to_s.underscore}"
10
10
  end
11
11
 
12
- def render_payment_status_listener
13
- render partial: 'spree/vpago_payments/payment_status_listener'
12
+ def render_transaction_checker
13
+ if @payment.payment_method.support_check_transaction_api?
14
+ render partial: 'spree/vpago_payments/transaction_checker'
15
+ end
14
16
  end
15
17
 
16
18
  # when return nil, each payment method should use their default URL.
@@ -33,6 +33,11 @@ module Spree
33
33
  preferred_abapay_khqr_deeplink_option.in?(%w[open_both open_checkout_url_only])
34
34
  end
35
35
 
36
+ # override
37
+ def support_check_transaction_api?
38
+ true
39
+ end
40
+
36
41
  # override
37
42
  def default_payout_profile
38
43
  Spree::PayoutProfiles::PaywayV2.default
@@ -67,6 +72,12 @@ module Spree
67
72
  !enable_pre_auth?
68
73
  end
69
74
 
75
+ # override
76
+ def check_status(payment)
77
+ checker = check_transaction(payment)
78
+ checker.success?
79
+ end
80
+
70
81
  # override
71
82
  # authorize is used when pre auth enabled
72
83
  def authorize(_amount, _source, gateway_options = {})
@@ -148,14 +159,15 @@ module Spree
148
159
  ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Payment has been canceled.')
149
160
  end
150
161
 
151
- private
152
-
162
+ # override
153
163
  def check_transaction(payment)
154
164
  checker = Vpago::PaywayV2::TransactionStatus.new(payment)
155
165
  checker.call
156
166
  checker
157
167
  end
158
168
 
169
+ private
170
+
159
171
  def cancel_pre_auth(payment)
160
172
  canceler = Vpago::PaywayV2::PreAuthCanceler.new(payment)
161
173
  canceler.call
@@ -20,6 +20,7 @@ module Vpago
20
20
 
21
21
  base.delegate :checkout_url,
22
22
  :web_checkout_url,
23
+ :check_transaction_url,
23
24
  :processing_url,
24
25
  :success_url,
25
26
  :process_payment_url,
@@ -35,6 +35,13 @@ module Vpago
35
35
  def support_payout? = false
36
36
  def support_pre_auth? = false
37
37
 
38
+ # Must be explicitly overridden to true by each payment method.
39
+ # Payment method must implement check_transaction(payment), and its response
40
+ # must provide: success?, failed?, pending?.
41
+ def support_check_transaction_api?
42
+ false
43
+ end
44
+
38
45
  # TODO: we have already implement purchase for payway_v2.
39
46
  # make sure to implement this on other payment method as well.
40
47
  def purchase(_amount, _source, _gateway_options = {})
@@ -12,6 +12,7 @@ module Vpago
12
12
  def checkout_url = "#{base_url}/vpago_payments/checkout?#{query}&platform=app"
13
13
  def web_checkout_url = "#{base_url}/vpago_payments/checkout?#{query}&platform=web"
14
14
 
15
+ def check_transaction_url = "#{base_url}/vpago_payments/check_transaction?#{query}"
15
16
  def processing_url = "#{base_url}/vpago_payments/processing?#{query}"
16
17
 
17
18
  def success_url = "#{base_url}/vpago_payments/success?#{query}"
@@ -1,35 +1,40 @@
1
- <%# This partial listens to payment status changes and does not process the payment. %>
1
+ <%# This partial listens to payment status changes from bank and does not process the payment. %>
2
2
  <%# When it detects a status change, it automatically redirects to the processing URL for actual processing. %>
3
3
  <%# Designed to be used in checkout.html.erb %>
4
4
 
5
5
  <script>
6
6
  document.addEventListener("DOMContentLoaded", function() {
7
- let firebaseConfigs = <%= Rails.application.credentials.firebase_web_config.to_json.html_safe %>;
7
+ var checkTransactionUrl = "<%= j @payment.check_transaction_url %>";
8
+ var processingUrl = "<%= j @payment.processing_url %>";
9
+ var pollIntervalMs = 5000;
10
+ var hasRedirected = false;
11
+ var intervalId;
8
12
 
9
- window.listenToProcessingState({
10
- firebaseConfigs: firebaseConfigs,
11
- documentReferencePath: "<%= @payment.user_informer.document_reference_path %>",
12
- onPaymentIsProcessing: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
13
- window.location.href = "<%= @payment.processing_url %>";
14
- },
15
- onPaymentIsRetrying: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
16
- window.location.href = "<%= @payment.processing_url %>";
17
- },
18
- onOrderIsProcessing: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
19
- window.location.href = "<%= @payment.processing_url %>";
20
- },
21
- onOrderIsCompleted: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
22
- window.location.href = "<%= @payment.processing_url %>";
23
- },
24
- onOrderProcessFailed: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
25
- window.location.href = "<%= @payment.processing_url %>";
26
- },
27
- onPaymentProcessFailed: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
28
- window.location.href = "<%= @payment.processing_url %>";
29
- },
30
- onCompleted: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
31
- window.location.href = "<%= @payment.success_url %>";
32
- },
33
- });
13
+ var pollStatus = function() {
14
+ if (hasRedirected) return;
15
+
16
+ fetch(checkTransactionUrl, {
17
+ method: "GET",
18
+ headers: { "Accept": "application/json" },
19
+ credentials: "same-origin"
20
+ })
21
+ .then(function(response) {
22
+ return response.json().then(function(body) {
23
+ return { ok: response.ok, body: body };
24
+ });
25
+ })
26
+ .then(function(result) {
27
+ var status = result.body && result.body.status ? String(result.body.status) : "pending";
28
+
29
+ if (status === "success" || status === "failed") {
30
+ hasRedirected = true;
31
+ if (intervalId) clearInterval(intervalId);
32
+ window.location.replace(processingUrl);
33
+ }
34
+ })
35
+ .catch(function() {});
36
+ };
37
+
38
+ intervalId = window.setInterval(pollStatus, pollIntervalMs);
34
39
  });
35
40
  </script>
@@ -5,5 +5,5 @@
5
5
  <%# See: app/views/spree/vpago_payments/forms/spree/gateway/_payway_v2.html.erb for example %>
6
6
  <button id="vpago_primary_button" style="display: none;"></button>
7
7
 
8
- <%= render_payment_status_listener %>
8
+ <%= render_transaction_checker %>
9
9
  <%= render_form %>
data/config/routes.rb CHANGED
@@ -20,6 +20,7 @@ Spree::Core::Engine.add_routes do
20
20
  resource :vpago_payments do
21
21
  collection do
22
22
  get :checkout
23
+ get :check_transaction
23
24
  get :processing
24
25
  get :success
25
26
 
@@ -1,7 +1,7 @@
1
1
  module SpreeVpago
2
2
  module_function
3
3
 
4
- VERSION = '2.2.2-pre17'.freeze
4
+ VERSION = '2.2.2-pre18'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
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.2.2.pre.pre17
4
+ version: 2.2.2.pre.pre18
5
5
  platform: ruby
6
6
  authors:
7
7
  - You