Last active
July 26, 2019 13:58
-
-
Save anchietajunior/9caa4fbfe7ba34e261d78e71c84fab87 to your computer and use it in GitHub Desktop.
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 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