spree_vpago 2.0.8.pre.beta2 → 2.0.8.pre.beta3

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: d006f101539dd059e92dd575c6a40c036a753638e0f095c4680fb8fec2e3fc27
4
- data.tar.gz: 5b7137318a4d5be9fea18f55951414bfc973d39cef0d67b8459aacefcee78c01
3
+ metadata.gz: a60df6ffc7539631a90fd4076f856cb62517d0c589a6f0bb18f9e109e4708dc5
4
+ data.tar.gz: 572c3179370f5ddc763cfffe3a4cbbce054537b0a26620c7e4e9041e2e5b14bb
5
5
  SHA512:
6
- metadata.gz: 40a1984b36bf03669c53488af115deac0ca3b694fe5c039864b0589abf94be54bdd47154d19b47e5a834af13e2ec581dd55e90d54f6021e6543d6c1e0980c3bd
7
- data.tar.gz: d0fa00d9485ac9493cbe82d49e1c7a4f5f671f000ea7dd385e17b08dc7304cacb061ff9c3bc3d106bc5bbb76883e2afd8ab7029f702fb1da64ab6fee97251ce4
6
+ metadata.gz: bb331771b411e9b54d85d2810d4849e18574c5155a878922730014a0618393b27392d167c3596471e3322a32b12b111c8eda97718955675c72450d1ffee02a46
7
+ data.tar.gz: 89f4e3adbb4a08772e0b32a584a412934b6697d9b96a92da2af2904ada71233f481886b50a9c863a98eea5015d41d969376b61e8af499a5be84938d318481b7a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.0.8.pre.beta2)
4
+ spree_vpago (2.0.8.pre.beta3)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
@@ -5,7 +5,7 @@ module Spree
5
5
 
6
6
  skip_before_action :verify_authenticity_token, only: [:process_payment]
7
7
 
8
- rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
8
+ rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
9
9
  rescue_from CanCan::AccessDenied, with: :access_denied
10
10
 
11
11
  # GET
@@ -8,9 +8,8 @@ module Spree
8
8
  preference :client_id, :string
9
9
  preference :client_secret, :string
10
10
  preference :private_key, :text
11
- preference :merchant_scheme, :string
12
- preference :merchant_android_package_name, :string
13
- preference :redirection_type, :string
11
+ preference :return_url_scheme, :string
12
+ preference :android_package_name, :string
14
13
 
15
14
  def method_type
16
15
  'true_money'
@@ -56,12 +55,12 @@ module Spree
56
55
  success, params[:refund_response] = true_money_refund(payment)
57
56
 
58
57
  if success
59
- ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: successfully canceled.', params)
58
+ ActiveMerchant::Billing::Response.new(true, 'True money Gateway: successfully canceled.', params)
60
59
  else
61
- ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Failed to canceleed', params)
60
+ ActiveMerchant::Billing::Response.new(false, 'True money Gateway: Failed to canceleed', params)
62
61
  end
63
62
  else
64
- ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Payment has been voided.')
63
+ ActiveMerchant::Billing::Response.new(true, 'True money Gateway: Payment has been voided.')
65
64
  end
66
65
  end
67
66
 
@@ -69,12 +68,12 @@ module Spree
69
68
  refund_issuer = Vpago::TrueMoney::RefundIssuer.new(payment, {})
70
69
  refund_issuer.call
71
70
 
72
- [refund_issuer.success?, refund_issuer.response]
71
+ [refund_issuer.success?, refund_issuer.parsed_response]
73
72
  end
74
73
 
75
74
  def cancel(_response_code, _payment)
76
75
  # we can use this to send request to payment gateway api to cancel the payment ( void )
77
- # currently Payway does not support to cancel the gateway
76
+ # currently True money does not support to cancel the gateway
78
77
 
79
78
  # in our case don't do anything
80
79
  ActiveMerchant::Billing::Response.new(true, '')
@@ -5,10 +5,11 @@ module Vpago
5
5
  base.after_create -> { Vpago::PayoutsGenerator.new(self).call }, if: :should_generate_payouts?
6
6
 
7
7
  base.delegate :checkout_url,
8
+ :web_checkout_url,
8
9
  :processing_url,
10
+ :processing_deeplink_url,
9
11
  :success_url,
10
12
  :process_payment_url,
11
- :processing_app_url,
12
13
  :payment_url,
13
14
  to: :url_constructor
14
15
  end
@@ -58,6 +59,10 @@ module Vpago
58
59
  pre_auth_status == 'CANCELLED'
59
60
  end
60
61
 
62
+ def true_money_payment?
63
+ payment_method.type_true_money?
64
+ end
65
+
61
66
  def vattanac_mini_app_payment?
62
67
  payment_method.type_vattanac_mini_app?
63
68
  end
@@ -3,7 +3,7 @@ module Spree
3
3
  module Storefront
4
4
  module PaymentSerializerDecorator
5
5
  def self.prepended(base)
6
- base.attributes :pre_auth_status, :checkout_url, :process_payment_url
6
+ base.attributes :pre_auth_status, :checkout_url, :process_payment_url, :web_checkout_url
7
7
  end
8
8
  end
9
9
  end
@@ -16,7 +16,7 @@ module Vpago
16
16
  # 2. Pre-auth is enabled, ensuring funds can be released to user if processing fails.
17
17
  # PaymentProcessor is usually called after payment is made, so canceling pre-auth typically works.
18
18
  def can_cancel_pre_auth?
19
- @payment.pending? || @payment.payment_method.enable_pre_auth? || @payment.vattanac_mini_app_payment?
19
+ @payment.pending? || @payment.payment_method.enable_pre_auth? || @payment.vattanac_mini_app_payment? || @payment.true_money_payment?
20
20
  end
21
21
 
22
22
  def extract_completer_failure_reason_code(error)
@@ -10,26 +10,24 @@ module Vpago
10
10
  end
11
11
 
12
12
  def checkout_url = "#{base_url}/vpago_payments/checkout?#{query}"
13
+ def web_checkout_url = "#{base_url}/vpago_payments/checkout?#{query}&platform=web"
13
14
  def processing_url = "#{base_url}/vpago_payments/processing?#{query}"
15
+ def processing_deeplink_url = "#{@payment.payment_method.preferred_return_url_scheme}/vpago_payments/processing?#{query}"
14
16
  def success_url = "#{base_url}/vpago_payments/success?#{query}"
15
17
  def process_payment_url = "#{base_url}/vpago_payments/process_payment?#{query}"
16
-
17
- def processing_app_url = "#{@payment.payment_method.preferred_merchant_scheme}/vpago_payments/processing?#{query}"
18
+ def payment_url = "#{base_url}/book/payment?number=#{@payment.order.number}&tk=#{@payment.order.token}"
18
19
 
19
20
  def query
20
- params = {
21
+ {
21
22
  payment_number: payment.number,
22
23
  order_number: order.number,
23
- order_jwt_token: order_jwt_token
24
- }
25
-
26
- params[:offsite_payment] = true if payment.payment_method.type_true_money?
27
-
28
- params.to_query
24
+ order_jwt_token: order_jwt_token,
25
+ offsite_payment: offsite_payment? ? true : nil
26
+ }.compact.to_query
29
27
  end
30
28
 
31
- def payment_url
32
- "#{base_url}/book/payment?number=#{@payment.order.number}&tk=#{@payment.order.token}"
29
+ def offsite_payment?
30
+ payment.payment_method.type_true_money?
33
31
  end
34
32
 
35
33
  private
@@ -30,4 +30,4 @@ module Vpago
30
30
  Base64.strict_encode64(private_key.sign(sign_hash, payload))
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -1,12 +1,9 @@
1
1
  <% @checkout = ::Vpago::TrueMoney::Checkout.new(@payment) %>
2
- <% webview_url = @checkout.generate_payment_urls[:webview] rescue nil %>
2
+ <% redirect_url = @checkout.generate_payment_urls(params[:platform])%>
3
3
 
4
- <% if webview_url.present? %>
5
4
  <script>
6
5
  document.addEventListener("DOMContentLoaded", function () {
7
- window.top.location.href = "<%= j webview_url %>";
6
+ window.top.location.href = "<%= j redirect_url %>";
8
7
  });
9
8
  </script>
10
- <% else %>
11
- <p>Unable to generate the payment URL. Please try again.</p>
12
- <% end %>
9
+
@@ -1,7 +1,7 @@
1
1
  module SpreeVpago
2
2
  module_function
3
3
 
4
- VERSION = '2.0.8-beta2'.freeze
4
+ VERSION = '2.0.8-beta3'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
@@ -69,10 +69,6 @@ module Vpago
69
69
  }
70
70
  end
71
71
 
72
- def redirection_type
73
- payment_method.preferred_redirection_type
74
- end
75
-
76
72
  def check_transaction_url
77
73
  "#{payment_method.preferred_check_transaction_url}/#{external_ref_id}"
78
74
  end
@@ -89,8 +85,8 @@ module Vpago
89
85
  payment_method.preferred_access_token_url
90
86
  end
91
87
 
92
- def merchant_android_package_name
93
- payment_method.preferred_merchant_android_package_name
88
+ def android_package_name
89
+ payment_method.preferred_android_package_name
94
90
  end
95
91
 
96
92
  def parse_json(body)
@@ -130,10 +126,6 @@ module Vpago
130
126
  def signature_input
131
127
  "#{timestamp}#{payload.to_json}"
132
128
  end
133
-
134
- def processing_url
135
- "#{@payment.processing_url}&offsite_payment=true"
136
- end
137
129
  end
138
130
  end
139
131
  end
@@ -1,32 +1,27 @@
1
1
  module Vpago
2
2
  module TrueMoney
3
3
  class Checkout < Base
4
- def generate_payment_urls
4
+ def generate_payment_urls(platform)
5
+ redirection_type = platform == 'web' ? 'web_redirect' : 'mobileapp'
6
+
5
7
  request_body = {
6
8
  payment_info: payload.to_json,
7
- redirectionType: redirection_type
9
+ redirectionType: redirection_type,
10
+ merchantDeepLink: @payment.processing_deeplink_url,
11
+ merchantAndroidPackageName: android_package_name,
12
+ refererLink: @payment.processing_url
8
13
  }
9
14
 
10
- if redirection_type == 'mobileapp'
11
- request_body[:merchantDeepLink] = @payment.processing_app_url
12
- request_body[:merchantAndroidPackageName] = merchant_android_package_name
13
- else
14
- request_body[:refererLink] = @payment.processing_url
15
- end
16
-
17
15
  response = Faraday.post(generate_payment_url) do |req|
18
16
  req.headers = default_headers
19
17
  req.body = request_body.to_json
20
18
  end
21
19
 
22
20
  body = parse_json(response.body)
23
-
24
- raise "Generate Payment Error: #{response.status} - #{body['message'] || response.body}" unless response.success? && body.dig('status', 'code') == '000001'
25
-
26
- {
27
- webview: body['data']['webview'],
28
- deeplink: body['data']['deeplink']
29
- }
21
+ platform == 'web' ? body['data']['webview'] : body['data']['deeplink']
22
+ rescue Faraday::Error, JSON::ParserError, NoMethodError => e
23
+ Rails.logger.error("Failed to generate payment URL: #{e.class} - #{e.message}")
24
+ raise
30
25
  end
31
26
  end
32
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_vpago
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8.pre.beta2
4
+ version: 2.0.8.pre.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - You
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-17 00:00:00.000000000 Z
11
+ date: 2025-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday