spree_emerchantpay_genesis 0.1.5 → 0.1.6

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: d2dbd23a908a23677fb4ee2bea0a49cc739052aa5d882e57b7c532d57c480602
4
- data.tar.gz: d6b2c2fbbe86dcc820946edda7c79d7ff34b83ba702e0b678226ad5c87667306
3
+ metadata.gz: 9c220bb96644c56f0979a39ad4e8465ef9560f5e58c45acf36e89faf4dcafb9d
4
+ data.tar.gz: 42f7abcc36024c096e88a39a072e57d0138aac80decc629a8278d6b1642616d9
5
5
  SHA512:
6
- metadata.gz: '0487117b7c98132dd864200b76d52c9b9c2b678244726bb6386a3c4c2c3220de2b729dc3c6f8d767abc46bf460c6655e158c301664777b10cf71d6a22f9268a9'
7
- data.tar.gz: 861e78025ac386920634ddacb4c130d2d6285067fb693ddad00da2b9fc897a3e0011999d567795cd385931aada42d280e0e105225c07652bd618d786e282cfbf
6
+ metadata.gz: fdbeb22309bc146f4cc8c957eda170fb17249afb73f7fc8e544f8d15a6560a5e22d2ed6a4749c8e0e3bdb455b533a5f8400165db6f812b6706f149addb8dbbce
7
+ data.tar.gz: 774446783c40d05322b15dd9768fda5db2873ccd2b87320ca75eb4cebee3401a2e1759e17e4d28e02ea8b5420d4e656987a20a1522608623a06820bfee73d94d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ 0.1.6
2
+ -----
3
+ **Features**:
4
+
5
+ * Added Docker project
6
+ * Added Spree Rails FrontEnd Redirect URL handling (asynchronous payments)
7
+ * Updated README
8
+
1
9
  0.1.5
2
10
  -----
3
11
  **Features**:
data/README.md CHANGED
@@ -1,4 +1,10 @@
1
- # emerchantpay Genesis Gateway for Spree
1
+ emerchantpay Genesis Gateway for Spree
2
+ ===========
3
+ [![Gem Version](https://badge.fury.io/rb/spree_emerchantpay_genesis.svg)](https://badge.fury.io/rb/spree_emerchantpay_genesis)
4
+ [![Software License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](LICENSE)
5
+
6
+ Overview
7
+ --------
2
8
  This is a Payment Module for Spree eCommerce that gives you the ability to process payments through emerchantpay's Payment Gateway - Genesis.
3
9
 
4
10
  # Requirements
@@ -385,6 +391,32 @@ _Note_: If you have trouble with your credentials or terminal configuration, get
385
391
 
386
392
  `bundle exec appraisal install`
387
393
 
394
+ ### Build Demo store
395
+ Requires [Docker Engine](https://docs.docker.com/engine/install/)
396
+
397
+ 1. Clone the project
398
+ 2. Create .env file in the project rood based on the .env.example
399
+ * Set `RAILS_ENV=production`
400
+ 3. Execute inside project root:
401
+ ```shell
402
+ docker compose up
403
+ ```
404
+ 4. Setup Web Server with reverse proxy configuration
405
+
406
+ ### Setup plugin for development
407
+ 1. Clone the project
408
+ 2. Create .env file based on the .env.example
409
+ * Set `RAILS_ENV=development`
410
+ * Set `PLUGIN_SOURCE=/<local path to the plugin source>`
411
+ 3. Execute inside project root:
412
+ ```shell
413
+ docker compose -f compose.yaml -f development-compose.yaml up -d
414
+ ```
415
+ * Optional you can set project name with the -p flag
416
+ * You can attach to the container and debug with `pry` (`docker attach <container>`).
417
+ Requires `config.web_console.whitelisted_ips = '<host_ip>'` inside the container (/mnt/spree/config/environments/development.rb)
418
+ * If you expose the localhost (ex. ngrok) requires `config.hosts.clear` inside the container (/mnt/spree/config/environments/development.rb)
419
+
388
420
  ## License
389
421
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/license/mit).
390
422
 
@@ -0,0 +1,88 @@
1
+ module Spree
2
+ module CheckoutControllerDecorator
3
+
4
+ # Updates the order and advances to the next state (when possible.)
5
+ def update
6
+ result = process_emp_direct_payment? ? process_emp_direct_payment : default_payment_processing
7
+
8
+ if result
9
+ @order.temporary_address = !params[:save_user_address]
10
+
11
+ order_next
12
+
13
+ process_completed_order && return if @order.completed?
14
+
15
+ redirect_to spree.checkout_state_path @order.state
16
+ else
17
+ render :edit, status: :unprocessable_entity
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ # Default Rails FrontEnd Checkout controller `update` logic
24
+ def default_payment_processing
25
+ @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
26
+ end
27
+
28
+ # Proceed with Spree Order current state execution and move to the next
29
+ def order_next
30
+ return if @order.next
31
+
32
+ flash[:error] = @order.errors.full_messages.join("\n")
33
+ end
34
+
35
+ # Get payment_method_id from the params
36
+ def payment_method_id
37
+ params[:order][:payments_attributes].last[:payment_method_id].presence
38
+ rescue NoMethodError
39
+ nil
40
+ end
41
+
42
+ # Handle completed order
43
+ def process_completed_order
44
+ redirect_url = nil
45
+ @current_order = nil
46
+ flash['order_completed'] = true
47
+
48
+ redirect_url = @order.payments.last.private_metadata['redirect_url'] if @order.payments.last.private_metadata
49
+
50
+ redirect_to redirect_url || completion_route, allow_other_host: true
51
+ end
52
+
53
+ # Check for Emerchantpay Direct Payment process
54
+ def process_emp_direct_payment?
55
+ @order.state == 'payment' && emerchantpay_direct_payment?
56
+ end
57
+
58
+ # Check if the current payment method is Emerchantpay Direct
59
+ def emerchantpay_direct_payment?
60
+ return false unless payment_method_id
61
+
62
+ payment_method = Spree::PaymentMethod.find(payment_method_id)
63
+
64
+ payment_method&.type == Spree::Gateway::EmerchantpayDirect.name
65
+ end
66
+
67
+ # Process Emerchantpay Direct Payment
68
+ def process_emp_direct_payment
69
+ result = create_payment_service.call(
70
+ order: @order,
71
+ params: {
72
+ payment_method_id: payment_method_id,
73
+ source_attributes: params[:payment_source][payment_method_id.to_s.to_sym].presence
74
+ }
75
+ )
76
+
77
+ result.success?
78
+ end
79
+
80
+ # Spree Storefront Create Payment Service
81
+ def create_payment_service
82
+ Spree::Api::Dependencies.storefront_payment_create_service.constantize
83
+ end
84
+
85
+ end
86
+ end
87
+
88
+ Spree::CheckoutController.prepend(Spree::CheckoutControllerDecorator)
@@ -26,6 +26,7 @@ module SpreeEmerchantpayGenesis
26
26
  last_digits: params[:last_digits],
27
27
  month: params[:month],
28
28
  year: params[:year],
29
+ expiry: params[:expiry],
29
30
  name: params[:name],
30
31
  number: params[:number],
31
32
  verification_value: params[:verification_value],
@@ -20,11 +20,57 @@
20
20
  </div>
21
21
 
22
22
  <input type="hidden" name="payment_source[<%= payment_method.id %>][cc_type]" id="emp_cc_type" value="" class="ccType">
23
+ <input name="payment_source[<%= payment_method.id %>][accept_header]"
24
+ type="hidden"
25
+ id="emp_cc_3dsv2_accept_header"
26
+ value="*/*"
27
+ >
28
+ <input name="payment_source[<%= payment_method.id %>][java_enabled]"
29
+ type="hidden"
30
+ id="emp_cc_3dsv2_java_enabled"
31
+ value=""
32
+ >
33
+ <input name="payment_source[<%= payment_method.id %>][language]"
34
+ type="hidden"
35
+ id="emp_cc_3dsv2_language"
36
+ value=""
37
+ >
38
+ <input name="payment_source[<%= payment_method.id %>][color_depth]"
39
+ type="hidden"
40
+ id="emp_cc_3dsv2_color_depth"
41
+ value=""
42
+ >
43
+ <input name="payment_source[<%= payment_method.id %>][screen_height]"
44
+ type="hidden"
45
+ id="emp_cc_3dsv2_screen_height"
46
+ value=""
47
+ >
48
+ <input name="payment_source[<%= payment_method.id %>][screen_width]"
49
+ type="hidden"
50
+ id="emp_cc_3dsv2_screen_width"
51
+ value=""
52
+ >
53
+ <input name="payment_source[<%= payment_method.id %>][time_zone_offset]"
54
+ type="hidden"
55
+ id="emp_cc_3dsv2_time_zone_offset"
56
+ value=""
57
+ >
58
+ <input name="payment_source[<%= payment_method.id %>][user_agent]"
59
+ type="hidden"
60
+ id="emp_cc_3dsv2_user_agent"
61
+ value=""
62
+ >
63
+
23
64
  </div>
24
65
  </div>
25
66
 
26
67
  <script type="text/javascript">
27
68
  document.addEventListener("DOMContentLoaded", function(){
69
+ initBrowserParams()
70
+ initCreditCard()
71
+ });
72
+
73
+ function initCreditCard() {
28
74
  new Card({
29
75
  form: document.getElementById('checkout_form_payment'),
30
76
  container: '.emerchantpay-card-wrapper',
@@ -47,5 +93,23 @@
47
93
  cvc: '***'
48
94
  }
49
95
  });
50
- });
96
+ }
97
+
98
+ function initBrowserParams() {
99
+ document.getElementById('emp_cc_3dsv2_java_enabled').value = fetchJavaEnabled()
100
+ document.getElementById('emp_cc_3dsv2_color_depth').value = screen.colorDepth.toString()
101
+ document.getElementById('emp_cc_3dsv2_language').value = navigator.language
102
+ document.getElementById('emp_cc_3dsv2_screen_height').value = screen.height.toString()
103
+ document.getElementById('emp_cc_3dsv2_screen_width').value = screen.width.toString()
104
+ document.getElementById('emp_cc_3dsv2_time_zone_offset').value = (new Date()).getTimezoneOffset().toString()
105
+ document.getElementById('emp_cc_3dsv2_user_agent').value = navigator.userAgent
106
+ }
107
+
108
+ function fetchJavaEnabled() {
109
+ try {
110
+ return navigator.javaEnabled();
111
+ } catch (e) {
112
+ return false;
113
+ }
114
+ }
51
115
  </script>
@@ -1,7 +1,7 @@
1
1
  # :nocov:
2
2
  module SpreeEmerchantpayGenesis
3
3
 
4
- VERSION = '0.1.5'.freeze
4
+ VERSION = '0.1.6'.freeze
5
5
 
6
6
  end
7
7
  # :nocov:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_emerchantpay_genesis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - emerchantpay ltd.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-27 00:00:00.000000000 Z
11
+ date: 2024-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: genesis_ruby
@@ -324,6 +324,7 @@ files:
324
324
  - app/controllers/spree/api/v2/storefront/checkout_controller_decorator.rb
325
325
  - app/controllers/spree/api/v2/storefront/emerchantpay_notification_controller.rb
326
326
  - app/controllers/spree/api/v2/storefront/emerchantpay_threeds_controller.rb
327
+ - app/controllers/spree/checkout_controller_decorator.rb
327
328
  - app/controllers/spree/emerchantpay_threeds_controller.rb
328
329
  - app/helpers/spree/admin/payment_methods_helper.rb
329
330
  - app/helpers/spree_emerchantpay_genesis/mappers/genesis.rb
@@ -400,7 +401,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
400
401
  version: '0'
401
402
  requirements:
402
403
  - none
403
- rubygems_version: 3.2.33
404
+ rubygems_version: 3.4.10
404
405
  signing_key:
405
406
  specification_version: 4
406
407
  summary: emerchantpay Gateway Module for Spree