Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Vargas Mattheus danielVargas

View GitHub Profile
View test_capistrano.conf
<VirtualHost *:80>
ServerName test.com
ServerAlias test.com
ServerAdmin webmaster@localhost
#PassengerAppEnv staging
DocumentRoot /var/www/html/ruta_al_proyecto
#Redirect "/" "https://test.com/"
<Directory "/var/www/html/ruta_al_proyecto">
#DirectoryIndex index.php
Options +Indexes +FollowSymLinks +MultiViews
@danielVargas
danielVargas / staging.rb
Created Apr 22, 2019
Entorno de staging para Capistrano
View staging.rb
# Se definen los distintos roles para el despliegue, que pueden ser distintas instancias de amazon.
role :app, %w{tu_usuario@ec2-tu-ip.us-east-2.compute.amazonaws.com}
role :web, %w{tu_usuario@ec2-tu-ip.us-east-2.compute.amazonaws.com}
role :db, %w{tu_usuario@ec2-tu-ip.us-east-2.compute.amazonaws.com}
# Se definen los distintos servidores, asociados a un rol para hacer el despliegue.
set :user, "tu_usuario"
server "ec2-tu-ip.us-east-2.compute.amazonaws.com", roles: %w{web}
# Se indica la ubicación de la llave.pem descargada desde amazon. Esto para poder hacer la autenticación por SSH
@danielVargas
danielVargas / deploy.rb
Created Apr 22, 2019
Configuraciones del deploy.rb
View deploy.rb
lock "~> 3.11.0"
# Es el stage de la aplicación, obviamente producción
set :stage, 'production'
# Nombre de la aplicación
set :application, "test_capistrano"
# URL de la aplicación en git (github, bitbucket, etc). DEBE SER SSH
set :repo_url, "git@github.com:danielVargas/test-capistrano.git"
# Default branch is :master
@danielVargas
danielVargas / Capfile
Created Apr 18, 2019
Capfile para despliegue de capistrano
View Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/sidekiq'
@danielVargas
danielVargas / database.yml
Created Apr 18, 2019
Archivo de configuración de la base de datos
View database.yml
default: &default
adapter: postgresql
encoding: unicode
username: nombre_de_usuario
password: contraseña
pool: 5
timeout: 5000
development:
<<: *default
@danielVargas
danielVargas / secrets.yml
Created Jun 20, 2018
Variables de la aplicación RoR
View secrets.yml
development:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
mail_admin: <%= ENV["MAIL_ADMIN"] %>
pass_admin: <%= ENV["PASS_ADMIN"] %>
webpay_wsdl: https://webpay3gint.transbank.cl/WSWebpayTransaction/cxf/WSWebpayService?wsdl
webpay_client_certificate: config/public_cert_develop.crt
webpay_client_private_key: config/private_key_develop.key
webpay_tbk_certificate: config/tbk_develop.key
webpay_commerce_code: '597020000541'
webpay_return_url: /webpay/webpay_return_url
@danielVargas
danielVargas / webpay_success.html.erb
Created Jun 20, 2018
WebPay Success información de pago realizado con webpay
View webpay_success.html.erb
<section class="content-header">
<h1>
Detalle de pago
<small>Revise el detalle de su pago. Muchas gracias por preferirnos.</small>
</h1>
<ol class="breadcrumb">
<li>Mi cuenta</li>
<li class="active">Detalle del pago</li>
</ol>
</section>
@danielVargas
danielVargas / _payment_from.html.erb
Created Jun 20, 2018
Formulario de creación de pago con webpay
View _payment_from.html.erb
<!-- PAGO CON WEBPAY -->
<div id="webpay-row" class="container-fluid" align="center">
<%= form_for(@payment, html: {name: 'new_payment', class: "form-inline"}) do |f| %>
<%= image_tag('webpay_logo.png', alt: 'Logo WebPay', class: 'logo-webpay')%><br>
<input id="payment_amount" type="text" class="form-control" required='true' name="payment[webpay_amount]">
<button class="btn btn-success">Pagar con WebPay</button>
<% end %>
</div>
<!-- FIN PAGO CON WEBPAY -->
@danielVargas
danielVargas / webpay_controller.rb
Created Jun 20, 2018
Controlador de WebPay que se encarga de comunicar las funciones, con los resultados que se obtienen desde WebPay
View webpay_controller.rb
class WebpayController < ApplicationController
skip_before_action :verify_authenticity_token
#Normal transaction
def webpay_return_url
result = WebpayInit.get_transaction_result(params[:token_ws], request.base_url.to_s)
puts 'resultado obtenido: ' + result['buyorder'].to_s
puts 'token de transbank: ' + params[:token_ws]
payment = Payment.find(result['buyorder'])
payment.update(tbk_token: params[:token_ws])
payment.update(state: 'pending')
@danielVargas
danielVargas / webpay_init.rb
Last active Jun 20, 2018
Modelo que se encarga de inicializar webay y disponibilizar las funcionalidades a los controladores
View webpay_init.rb
class WebpayInit
#Normal transacition
def self.init_transaction(payment, base_url)
puts 'start init transaction'
self.init_webpay(base_url)
amount = payment.amount.to_i
sessionId = rand(1111111..9999999).to_s
payment.update(tbk_transaction_id: sessionId)
return @webpay.getNormalTransaction.initTransaction(amount, payment.id, sessionId, @urlReturn, @urlFinal)
end
You can’t perform that action at this time.