Skip to content

Instantly share code, notes, and snippets.

@anchietajunior
Last active July 26, 2019 13:58
Show Gist options
  • Select an option

  • Save anchietajunior/9caa4fbfe7ba34e261d78e71c84fab87 to your computer and use it in GitHub Desktop.

Select an option

Save anchietajunior/9caa4fbfe7ba34e261d78e71c84fab87 to your computer and use it in GitHub Desktop.
class Subscription
def initialize(user)
@user = user
end
def call
create_payment!
create_invoice!
rescue StandardError => e
puts e.message
end
private
attr_accessor :user, :payment
def create_payment!
payment_result = payment_request
@payment = Payment.create!(user: user, amount: 30.00, status: payment_result[:status], transaction_id: payment_result[:id])
end
def payment_request
# Requisição API/Gateway de pagamentos
end
def create_invoice!
invoice_result = invoice_request
Invoice.create!(payment: payment, status: invoice_result[:status], transaction_id: invoice_result[:id])
end
def invoice_request
# Requisição API/Gateway de notas fiscais
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment