Skip to content

Instantly share code, notes, and snippets.

@anchietajunior
Created January 23, 2018 14:35
Show Gist options
  • Save anchietajunior/f44e8002961255c29a7dd8734443e17b to your computer and use it in GitHub Desktop.
Save anchietajunior/f44e8002961255c29a7dd8734443e17b to your computer and use it in GitHub Desktop.
def create
@payment = Payment.new(payment_params)
respond_to do |format|
if @payment.save
result = CreateInvoiceService.new({payment_id: @payment.id}).charge
if result == "pending"
format.html { redirect_to @payment, notice: 'Payment was successfully created and Invoice is pending.' }
format.json { render :show, status: :created, location: @payment }
else
format.html { redirect_to @payment, notice: 'Payment was successfully created and Invoice is issued.' }
format.json { render :show, status: :created, location: @payment }
end
else
format.html { render :new }
format.json { render json: @payment.errors, status: :unprocessable_entity }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment