-
-
Save PerezIgnacio/3d8014da7564e13e529cb55042d3132d to your computer and use it in GitHub Desktop.
Service example
This file contains 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 OrdersChargeService | |
attr_accessor :user | |
def initialize(user) | |
@user = user | |
end | |
def charge_order_to_user(amount, discount, products) | |
create_order(amount, discount, products) | |
send_order_charge | |
# ... | |
end | |
private | |
def create_order(amount, discount, products) | |
@order = Order.create!(amount: amount, discount: discount, products: products, user: user) | |
end | |
def send_order_charge | |
# logic related to payment process, usually calling an external API | |
end | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment