spree_vpago 2.0.8.pre.beta → 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: a199976c2692ad4d201ea9890163e430f6ac62eaa65104585718ca081c303fa4
4
- data.tar.gz: 076e9460e262219196e66ee01e280274d8920bba2d484989e5caf5eee86a9eeb
3
+ metadata.gz: a60df6ffc7539631a90fd4076f856cb62517d0c589a6f0bb18f9e109e4708dc5
4
+ data.tar.gz: 572c3179370f5ddc763cfffe3a4cbbce054537b0a26620c7e4e9041e2e5b14bb
5
5
  SHA512:
6
- metadata.gz: 67e72026f867e78955f05fe93aed5dfa86d1ef51a919d8af699c372db0067f6a40ad11cbe39d96f6354f33f49117084ecf17f09fc5a23b3f7dfa116635eff961
7
- data.tar.gz: 877c24547ea819b7b10fe4c2410b30f6776e859b72b382e11c712854247b02cfa44bbcb39f7c1807d8bd6e2cbda344549e1c151ed7f18a43b95a34bdc92be1a1
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.beta)
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
@@ -33,6 +33,12 @@ module Spree
33
33
 
34
34
  @order = @payment.order
35
35
  raise CanCan::AccessDenied unless @order.completed?
36
+
37
+ if params[:offsite_payment].present?
38
+ redirect_to @payment.payment_url, allow_other_host: true
39
+ else
40
+ render :success
41
+ end
36
42
  end
37
43
 
38
44
  # POST
@@ -8,8 +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
11
+ preference :return_url_scheme, :string
12
+ preference :android_package_name, :string
13
13
 
14
14
  def method_type
15
15
  'true_money'
@@ -55,12 +55,12 @@ module Spree
55
55
  success, params[:refund_response] = true_money_refund(payment)
56
56
 
57
57
  if success
58
- ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: successfully canceled.', params)
58
+ ActiveMerchant::Billing::Response.new(true, 'True money Gateway: successfully canceled.', params)
59
59
  else
60
- ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Failed to canceleed', params)
60
+ ActiveMerchant::Billing::Response.new(false, 'True money Gateway: Failed to canceleed', params)
61
61
  end
62
62
  else
63
- ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Payment has been voided.')
63
+ ActiveMerchant::Billing::Response.new(true, 'True money Gateway: Payment has been voided.')
64
64
  end
65
65
  end
66
66
 
@@ -68,12 +68,12 @@ module Spree
68
68
  refund_issuer = Vpago::TrueMoney::RefundIssuer.new(payment, {})
69
69
  refund_issuer.call
70
70
 
71
- [refund_issuer.success?, refund_issuer.response]
71
+ [refund_issuer.success?, refund_issuer.parsed_response]
72
72
  end
73
73
 
74
74
  def cancel(_response_code, _payment)
75
75
  # we can use this to send request to payment gateway api to cancel the payment ( void )
76
- # currently Payway does not support to cancel the gateway
76
+ # currently True money does not support to cancel the gateway
77
77
 
78
78
  # in our case don't do anything
79
79
  ActiveMerchant::Billing::Response.new(true, '')
@@ -5,10 +5,12 @@ 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,
13
+ :payment_url,
12
14
  to: :url_constructor
13
15
  end
14
16
 
@@ -57,10 +59,13 @@ module Vpago
57
59
  pre_auth_status == 'CANCELLED'
58
60
  end
59
61
 
62
+ def true_money_payment?
63
+ payment_method.type_true_money?
64
+ end
65
+
60
66
  def vattanac_mini_app_payment?
61
67
  payment_method.type_vattanac_mini_app?
62
68
  end
63
-
64
69
  end
65
70
  end
66
71
 
@@ -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,14 +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
- { payment_number: payment.number, order_number: order.number, order_jwt_token: order_jwt_token }.to_query
21
+ {
22
+ payment_number: payment.number,
23
+ order_number: order.number,
24
+ order_jwt_token: order_jwt_token,
25
+ offsite_payment: offsite_payment? ? true : nil
26
+ }.compact.to_query
27
+ end
28
+
29
+ def offsite_payment?
30
+ payment.payment_method.type_true_money?
21
31
  end
22
32
 
23
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[:deeplink] 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.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-beta'.freeze
4
+ VERSION = '2.0.8-beta3'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
@@ -85,8 +85,8 @@ module Vpago
85
85
  payment_method.preferred_access_token_url
86
86
  end
87
87
 
88
- def merchant_android_package_name
89
- payment_method.preferred_merchant_android_package_name
88
+ def android_package_name
89
+ payment_method.preferred_android_package_name
90
90
  end
91
91
 
92
92
  def parse_json(body)
@@ -1,25 +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
+
7
+ request_body = {
8
+ payment_info: payload.to_json,
9
+ redirectionType: redirection_type,
10
+ merchantDeepLink: @payment.processing_deeplink_url,
11
+ merchantAndroidPackageName: android_package_name,
12
+ refererLink: @payment.processing_url
13
+ }
14
+
5
15
  response = Faraday.post(generate_payment_url) do |req|
6
16
  req.headers = default_headers
7
- req.body = {
8
- payment_info: payload.to_json,
9
- redirectionType: 'mobileapp',
10
- merchantDeepLink: @payment.processing_app_url,
11
- merchantAndroidPackageName: merchant_android_package_name
12
- }.to_json
17
+ req.body = request_body.to_json
13
18
  end
14
19
 
15
20
  body = parse_json(response.body)
16
-
17
- raise "Generate Payment Error: #{response.status} - #{body['message'] || response.body}" unless response.success? && body['status']['code'] == '000001'
18
-
19
- {
20
- webview: body['data']['webview'],
21
- deeplink: body['data']['deeplink']
22
- }
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
23
25
  end
24
26
  end
25
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.beta
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-15 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