This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@payment = Payment.new(payment_params) | |
respond_to do |format| | |
if @payment.save | |
#Business Logic | |
ServiceInvoice.create(payment: @payment, | |
status: @payment.amount > 100000 ? “pending” : “issued”) | |
format.html { redirect_to @payment, notice: ‘Payment was successfully created.’ } | |
else | |
format.html { render :new } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Payment < ApplicationRecord | |
has_one :service_invoice | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ServiceInvoice < ApplicationRecord | |
belongs_to :payment | |
validates :payment, presence: true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe CreateInvoiceService do | |
before(:each) do | |
@payment = Payment.create(amount: 200000, description: "Xbox One", quantity: 1) | |
end | |
context "creating payments" do | |
it "has a invoice with pending status" do | |
result = CreateInvoiceService.new({payment_id: @payment.id}).charge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
has_one :plan | |
has_many :payments | |
def update_plan(plan) | |
self.update_columns(plan: plan) | |
end | |
def create_payment | |
Payment.create(user: self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Notebook = Struct.new(:cpu, :ram, :ssd) do | |
def all_configs | |
"PC configs: #{cpu} - #{ram} - #{ssd}" | |
end | |
end | |
notebook = Notebook.new("i7", "16GB", "256") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
notebook = ["i7 CPU", "16GB RAM", "256 HD"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Notebook = Struct.new(:cpu, :ram, :ssd) | |
notebook = Notebook.new("i7", "16GB", "256SSD") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StatusService | |
Status = Struct.new(success?, errors) | |
def initialize(request_params) | |
@request_params = request_params | |
end | |
def call | |
if @request_params[:status].present? && @request_params[:status] == "success" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getStarWarsPeople() { | |
fetch('https://swapi.co/api/people') | |
.then(data => data.json()) | |
.then(data => data.results.map(person => { | |
console.log(person.name); | |
})) | |
console.log('Luke i`m your father!'); | |
} |