solidus_oxxo_pay 1.0.0 → 1.1.0

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: 4a67c8525d3ca13b4ef0c58656688a7ce4b0d12926e27bfafef78c7404ee104c
4
- data.tar.gz: 19023765bd1f752e8f844fb3e7ca5b4a69a6239ad3d14c6e716e0094027f4020
3
+ metadata.gz: 948805a97162f094d5c1fd6582e17be907b2c72b238822e3305020dec9054afd
4
+ data.tar.gz: 296dbdbe258a176534c35bca3dc04b6455d6b6b767babb5ef849c955909a1175
5
5
  SHA512:
6
- metadata.gz: c73e5c4b115b1b53b7b497ec5ec571e88ec6278ad3b17f485aa5ee908d0439e62529ed1670a3eeb31c45b801085b76c124e452dd55d367333f2c04d5041ec5b6
7
- data.tar.gz: cdbaa65fd03881925198e2103773df9a85acb4386f20e610dd50639ab6f685bbcbbbae8a5643c4bb95064f4d2c80ebc550d117581c934e02a5dc2f7b8e84259c
6
+ metadata.gz: bfb074c36374c87dca424bb320f4a4de8ac7c39810cc342056c0fc8c96860a36396d4b173a7b94acd65e8ff60ec56cef45ec069055c89faa1fe54f6654e6c484
7
+ data.tar.gz: 3a979d9916105c36d2fd3b665374ebe7507ca2b71687a697326aeccabe3a5ed42a5e98896247a62cf02203b9a95aa7b1b30b672b25f33553c83a93c8fa5f467d
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class ConektaOxxoController < StoreController
3
5
  skip_before_action :verify_authenticity_token
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree::BaseHelper
2
4
  def conekta_oxxo_receipt(order = nil)
3
- @order ||= order
4
- if @order.paid_with?('Oxxo')
5
- response_code = @order.payments&.last.response_code
6
- render partial: 'spree/conekta/payments/conekta_oxxo', locals: { order: @order, response_code: response_code }
5
+ order_oxxo_payments = order&.payments&.
6
+ where(source_type: 'Spree::ConektaOxxoPayment')
7
+ if order_oxxo_payments.any?
8
+ response_code = order_oxxo_payments.last&.response_code
9
+ render partial: 'spree/conekta/payments/conekta_oxxo',
10
+ locals: { order: order, response_code: response_code }
7
11
  end
8
12
  end
9
13
  end
@@ -1,20 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class ConektaOxxoPayment < Spree::PaymentSource
3
5
  attr_accessor :server, :test_mode, :api_key
4
6
 
5
- def authorize(money, creditcard, gateway_options)
6
-
7
- ::Conekta.api_key = api_key
8
- ::Conekta.api_version = "2.0.0"
7
+ def authorize(_money, source, _gateway_options)
8
+ Conekta.api_key = api_key
9
+ Conekta.api_version = '2.0.0'
9
10
 
10
- order = Spree::Order.find_by(number: creditcard.number)
11
+ order = Spree::Order.find_by(number: source.number)
11
12
 
12
13
  begin
13
- response = ::Conekta::Order.create(payload(order))
14
- creditcard.update_attribute :conekta_order_id, response.id
14
+ response = Conekta::Order.create(payload(order))
15
+ source.update_attribute :conekta_order_id, response.id
15
16
  ActiveMerchant::Billing::Response.new(true, 'Orden creada satisfactoriamente', {}, parse_response(response))
16
- rescue ::Conekta::Error => error
17
- ActiveMerchant::Billing::Response.new(false, error.details.map(&:message).join(', '))
17
+ rescue ::Conekta::Error => e
18
+ ActiveMerchant::Billing::Response.new(false, e.details.map(&:message).join(', '))
18
19
  end
19
20
  end
20
21
 
@@ -51,46 +52,59 @@ module Spree
51
52
  end
52
53
 
53
54
  private
55
+
54
56
  def payload(order)
55
57
  {
56
- currency: 'MXN',
57
- customer_info: {
58
- name: order.ship_address.full_name,
59
- email: order.email,
60
- phone: order.ship_address.phone
61
- },
62
- charges: [
63
- {
64
- payment_method: {
65
- type: 'oxxo_cash'
66
- }
67
- }
68
- ],
69
- line_items: order_line_items(order),
70
- shipping_lines: shipping_lines(order),
71
- shipping_contact: {
72
- address: {
73
- street1: order.ship_address.address1,
74
- postal_code: order.ship_address.zipcode,
75
- country: 'mx'
76
- }
58
+ currency: 'MXN',
59
+ customer_info: {
60
+ name: order.ship_address.full_name,
61
+ email: order.email,
62
+ phone: order.ship_address.phone
63
+ },
64
+ charges: [
65
+ {
66
+ payment_method: {
67
+ type: 'oxxo_cash'
68
+ }
77
69
  }
70
+ ],
71
+ line_items: order_line_items(order),
72
+ shipping_lines: shipping_lines(order),
73
+ shipping_contact: {
74
+ address: {
75
+ street1: order.ship_address.address1,
76
+ postal_code: order.ship_address.zipcode,
77
+ country: 'MX'
78
+ }
79
+ }
78
80
  }
79
81
  end
80
82
 
81
83
  def order_line_items(order)
82
- order.line_items.map { |li| {name: li.product.name, unit_price: (li.price * 100).to_i, quantity: li.quantity} }
84
+ order.line_items.map do |li|
85
+ {
86
+ name: li.product.name,
87
+ unit_price: (li.price * 100).to_i,
88
+ quantity: li.quantity
89
+ }
90
+ end
83
91
  end
84
92
 
85
93
  def parse_response(response)
86
94
  {
87
- authorization: response.charges.first.payment_method.reference,
88
- conekta_order_id: response.id
95
+ authorization: response.charges.first.payment_method.reference,
96
+ conekta_order_id: response.id
89
97
  }
90
98
  end
91
99
 
92
100
  def shipping_lines(order)
93
- order.shipments.map {|s| {id: s.id, carrier: s.shipping_method.name, amount: (s.cost * 100).to_i} }
101
+ order.shipments.map do |s|
102
+ {
103
+ id: s.id,
104
+ carrier: s.shipping_method.name,
105
+ amount: (s.cost * 100).to_i
106
+ }
107
+ end
94
108
  end
95
109
  end
96
110
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class PaymentMethod::ConektaOxxo < Spree::PaymentMethod
3
5
  preference :api_key, :string, default: ''
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PaymentOxxoPolicy
2
4
  attr_reader :payment
3
5
 
@@ -8,7 +10,7 @@ class PaymentOxxoPolicy
8
10
  def process(options)
9
11
  return unless options[:status].eql?('paid')
10
12
 
11
- payment.complete if (options[:amount].to_i/100 - payment.amount).abs < 0.01
13
+ payment.complete if (options[:amount].to_i / 100 - payment.amount).abs < 0.01
12
14
  payment.order.updater.update
13
15
  end
14
16
  end
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
@@ -1,29 +1,33 @@
1
- <div class="opps">
2
- <div class="opps-header">
3
- <div class="opps-info">
4
- <div class="opps-brand">
1
+ <div class='opps'>
2
+ <div class='opps-header'>
3
+ <div class='opps-info'>
4
+ <div class='opps-brand'>
5
5
  <%= image_tag 'oxxopay_brand.png', alt: 'OXXOPay', class: 'summary-oxxo-image' %>
6
6
  </div>
7
- <div class="opps-ammount">
8
- <h3 class="opps-title">Monto a pagar</h3>
7
+
8
+ <div class='opps-ammount'>
9
+ <h3 class='opps-title'>Monto a pagar</h3>
9
10
  <h2><%= order.display_total %> <sup>MXN</sup></h2>
10
11
  <p>OXXO cobrará una comisión adicional al momento de realizar el pago.</p>
11
12
  </div>
12
13
  </div>
13
- <div class="opps-reference">
14
- <h3 class="opps-reference-title">Referencia</h3>
15
- <h1 class="opps-reference"><%= response_code.scan(/.{1,4}/).join('-') %></h1>
14
+
15
+ <div class='opps-reference'>
16
+ <h3 class='opps-reference-title'>Referencia</h3>
17
+ <h1 class='opps-reference'><%= response_code&.scan(/.{1,4}/)&.join('-') %></h1>
16
18
  </div>
17
19
  </div>
18
- <div class="opps-instructions">
20
+
21
+ <div class='opps-instructions'>
19
22
  <h3>Instrucciones</h3>
20
- <ol class="steps-list">
21
- <li>Acude a la tienda OXXO más cercana. <a href="https://www.google.com.mx/maps/search/oxxo/" target="_blank">Encuéntrala aquí</a>.</li>
23
+
24
+ <ol class='steps-list'>
25
+ <li>Acude a la tienda OXXO más cercana. <a href='https://www.google.com.mx/maps/search/oxxo/' target='_blank'>Encuéntrala aquí</a>.</li>
22
26
  <li>Indica en caja que quieres realizar un pago de <strong>OXXOPay</strong>.</li>
23
27
  <li>Dicta al cajero el número de referencia en esta ficha para que tecleé directamete en la pantalla de venta.</li>
24
28
  <li>Realiza el pago correspondiente con dinero en efectivo.</li>
25
29
  <li>Al confirmar tu pago, el cajero te entregará un comprobante impreso. <strong>En el podrás verificar que se haya realizado correctamente.</strong> Conserva este comprobante de pago.</li>
26
30
  </ol>
27
- <div class="opps-footnote">Al completar estos pasos recibirás un correo confirmando tu pago.</div>
31
+ <div class='opps-footnote'>Al completar estos pasos recibirás un correo confirmando tu pago.</div>
28
32
  </div>
29
33
  </div>
@@ -1,6 +1,6 @@
1
1
  <html>
2
2
  <head>
3
- <%= stylesheet_link_tag 'oxxo_pay', media: 'all', 'data-turbolinks-track': 'false' %>
3
+ <%= stylesheet_link_tag 'spree/frontend/solidus_oxxo_pay', media: 'all', 'data-turbolinks-track': 'false' %>
4
4
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700" rel="stylesheet">
5
5
  </head>
6
6
  <body>
@@ -8,7 +8,7 @@
8
8
  </body>
9
9
  <script type="text/javascript" charset="utf-8">
10
10
  document.addEventListener('DOMContentLoaded', function () {
11
- window.print();
11
+ window.print();
12
12
  });
13
13
  </script>
14
14
  </html>
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Spree::Core::Engine.routes.draw do
2
4
  get 'oxxo-pay/receipt', to: 'conekta_oxxo#receipt'
3
5
  post 'oxxo-pay', to: 'conekta_oxxo#create'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateConektaOxxoPayments < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  create_table :spree_conekta_oxxo_payments do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusOxxoPay
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'solidus_core'
2
4
  require 'solidus_support'
3
5
  require 'deface'
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusOxxoPay
2
4
  class Engine < Rails::Engine
3
5
  require 'spree/core'
4
6
  isolate_namespace Spree
5
7
  engine_name 'solidus_oxxo_pay'
6
8
 
9
+ config.autoload_paths += %W(#{config.root}/lib)
10
+
7
11
  # use rspec for tests
8
12
  config.generators do |g|
9
13
  g.test_framework :rspec
@@ -11,7 +15,7 @@ module SolidusOxxoPay
11
15
 
12
16
  initializer 'spree_payment_network.register.payment_methods' do |app|
13
17
  app.config.spree.payment_methods << Spree::PaymentMethod::ConektaOxxo
14
- app.config.assets.precompile += %w( oxxopay_brand.png )
18
+ app.config.assets.precompile += %w(oxxopay_brand.png)
15
19
  end
16
20
 
17
21
  def self.activate
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusOxxoPay
2
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
3
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_oxxo_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magmalabs
@@ -48,16 +48,16 @@ dependencies:
48
48
  name: deface
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '1.0'
53
+ version: '0'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '1.0'
60
+ version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: conekta
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -275,6 +275,7 @@ files:
275
275
  - app/policies/payment_oxxo_policy.rb
276
276
  - app/views/spree/admin/payments/source_forms/_conektaoxxo.html.erb
277
277
  - app/views/spree/admin/payments/source_views/_conektaoxxo.html.erb
278
+ - app/views/spree/api/source_views/_conektaoxxo.json.jbuilder
278
279
  - app/views/spree/checkout/payment/_conektaoxxo.html.erb
279
280
  - app/views/spree/checkout/payment_label/_conektaoxxo_label.html.erb
280
281
  - app/views/spree/conekta/payments/_conekta_oxxo.html.erb