Skip to content

Instantly share code, notes, and snippets.

@PerezIgnacio
Last active February 3, 2020 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PerezIgnacio/3d8014da7564e13e529cb55042d3132d to your computer and use it in GitHub Desktop.
Save PerezIgnacio/3d8014da7564e13e529cb55042d3132d to your computer and use it in GitHub Desktop.
Service example
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