Sha256: f20a397f2d5929f165535baf448275aeb5d0f61909c5570f9afdd117dbb6b4a5

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

class PaypalController < ApplicationController
  before_action :find_payment

  def create
    response = @paypal.set_checkout! paypal_success_url(id: @payment.payment_token), paypal_cancel_url(id: @payment.payment_token)

    redirect_to response.popup_uri
  end

  def success
    response = @paypal.get_checkout!(params[:token], params[:PayerID])
    @payment.paypal_capture!(response.payment_info.first.transaction_id)

    @redirect_url = payments_integrations_success_path(provider: :paypal)
    render template: 'paypal/close_flow', layout: 'payments'
  end

  def cancel
    @redirect_url = payments_integrations_fail_path(provider: :paypal, tr: @payment.payment_token)
    render template: 'paypal/close_flow', layout: 'payments'
  end

  protected

  def find_payment
    @payment = TranslationCms::Api::Payment.find(params[:id])
    raise ActiveRecord::RecordNotFound, "Payment #{params[:id]} not found" if @payment.nil?

    @paypal = TranslationCms::PaypalExpress.new @payment
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/controllers/paypal_controller.rb