Skip to content

Instantly share code, notes, and snippets.

@masonforest
Created February 22, 2011 04:39
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 masonforest/838236 to your computer and use it in GitHub Desktop.
Save masonforest/838236 to your computer and use it in GitHub Desktop.
class PaymentsController < ApplicationController
def show
@payment = Payment.find(params[:id])
@response = Remit::PipelineResponse.new(
request.fullpath,
params,
remit
)
fps_pay(@payment.amount,@response.tokenID)
end
def new
@payment = Payment.new
end
def edit
@payment = Payment.find(params[:id])
end
def create
@payment = Payment.new(params[:payment])
if @payment.save
redirect_to fps_payment_url(
@payment.id,
params[:payment][:amount],
payment_url(@payment)
)
else
render :action => "new"
end
end
private
def fps_pay(amount,sender_token)
request = Remit::InstallPaymentInstruction::Request.new(
:payment_instruction => "MyRole == 'Caller' orSay 'Role does not match';",
:caller_reference => Time.now.to_i.to_s,
:token_friendly_name => "TriggerFood Caller Token",
:token_type => "Unrestricted"
)
caller_token = remit.install_payment_instruction(request).install_payment_instruction_result.token_id
request = Remit::InstallPaymentInstruction::Request.new(
:payment_instruction => "MyRole == 'Recipient' orSay 'Role does not match';",
:caller_reference => Time.now.to_i.to_s,
:token_friendly_name => "Friendly Name For Your Token",
:token_type => "Unrestricted"
)
recipient_token = remit.install_payment_instruction(request).install_payment_instruction_result.token_id
install_caller_response = remit.install_payment_instruction(request)
request = Remit::Pay::Request.new(
:caller_token_id => caller_token,
:recipient_token_id => recipient_token,
:sender_token_id => sender_token,
:transaction_amount => Remit::RequestTypes::Amount.new(:currency_code => 'USD', :amount => amount),
:charge_fee_to => "Recipient",
:caller_reference => Time.now.to_i.to_s
)
pay_response = remit.pay(request)
puts pay_response.inspect
end
def fps_payment_url(id,amount,return_url)
remit.get_single_use_pipeline(
:caller_reference => (0...8).map{65.+(rand(25)).chr}.join,
:transaction_amount => amount,
:return_url => return_url
).url
end
end
#<Remit::Pay::Response:0x348e4fc @response_metadata=#<Remit::ResponseMetadata:0x34788f0 @raw=nil, @parser=#<Relax::Parsers::Hpricot:0x347888c @parent=#<Remit::ResponseMetadata:0x34788f0 ...>, @parameters={:signature_version=>{}, :signature_method=>{}, :request_id=>{}}, @xml=#<Hpricot::Doc>>>, @raw="<?xml version=\"1.0\"?>\n<Response><Errors><Error><Code>InvalidParams</Code><Message>Invalid Amount</Message></Error></Errors><RequestID>8e54624f-cffc-4eb6-a49f-dc34cd65e972</RequestID></Response>", @errors=[#<Remit::Error:0x3471834 @raw=<Error> ... </>, @message="Invalid Amount", @parser=#<Relax::Parsers::Hpricot:0x34717d0 @parent=#<Remit::Error:0x3471834 ...>, @parameters={:code=>{:element=>"Code"}, :message=>{:element=>"Message"}}, @xml=#<Hpricot::Doc {elem <Error> {elem <Code> "InvalidParams" </Code>} {elem <Message> "Invalid Amount" </Message>} </Error>}>>, @code="InvalidParams">], @parser=#<Relax::Parsers::REXML:0x348e2e0 @parent=#<Remit::Pay::Response:0x348e4fc ...>, @parameters={:pay_result=>{:type=>Remit::TransactionResponse, :element=>"PayResult"}, :response_metadata=>{:type=>Remit::ResponseMetadata, :element=>"ResponseMetadata", :required=>true}}, @xml=<UNDEFINED> ... </>>, @pay_result=#<Remit::TransactionResponse:0x347a90c @raw=nil, @parser=#<Relax::Parsers::Hpricot:0x347a86c @parent=#<Remit::TransactionResponse:0x347a90c ...>, @parameters={:transaction_id=>{:element=>"TransactionId"}, :transaction_status=>{:element=>"TransactionStatus"}}, @xml=#<Hpricot::Doc>>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment