Created
January 24, 2009 20:40
-
-
Save dodeja/51545 to your computer and use it in GitHub Desktop.
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 PaymentController < ApplicationController | |
require 'rexml/document' | |
def index | |
@caller_token = AWS_FPS::Tokens.get_caller_token | |
@recipient_token = AWS_FPS::Tokens.get_recipient_token | |
end | |
def amazon_pipeline | |
return_path = "payment/pay" | |
unique_id = (Time.now.to_i + rand(1000)).to_s | |
# Prepare configuration for the Amazon Payments Pipeline | |
pipeline_params = { 'transactionAmount' => params[:Amount], | |
'pipelineName' => 'Recurring', | |
'paymentReason' => 'Sunago Subscription', | |
'recurringPeriod' => '1 Month', | |
'callerReference' => 'SenderToken-' + unique_id } | |
# Params for the return URL after the request is processed. | |
return_params = { 'Amount' => params[:Amount], | |
'CallerTokenId' => params[:CallerTokenId], | |
'RecipientTokenId' => params[:RecipientTokenId] } | |
pipeline_url = AWS_FPS::Pipeline.make_url(pipeline_params, return_params, return_path) | |
redirect_to(pipeline_url) | |
end | |
def pay | |
@amount = params[:Amount] | |
@sender_token = params[:tokenID] | |
@caller_token = params[:CallerTokenId] | |
@recipient_token = params[:RecipientTokenId] | |
unique_id = (Time.now.to_i + rand(1000)).to_s | |
# Prepare the FPS Payment Call | |
fps_call = { 'Action' => 'Pay', | |
# Tokens | |
'CallerTokenId' => @caller_token, | |
'SenderTokenId' => @sender_token, | |
'RecipientTokenId' => @recipient_token, | |
# Transaction Details | |
'TransactionAmount.Amount' => @amount, | |
'TransactionAmount.CurrencyCode' => 'USD', | |
'TransactionDate' => Time.now.gmtime.iso8601, # Example: 2007-05-10T13:08:02 | |
'ChargeFeeTo' => 'Recipient', # Must match the true/false value from the recipient token | |
# Your Reference Codes / Numbers | |
'CallerReference' => 'Order-' + unique_id, | |
'SenderReference' => 'Questions? Contact [email protected].', # Optional unique reference for the sender | |
'RecipientReference' => 'Sunago monthly app subscription' # Optional unique reference for the recipient | |
} | |
# Make the payment call | |
@fps_response = AWS_FPS::Query.do(fps_call) | |
response_xml = REXML::Document.new(@fps_response) | |
result = response_xml.root.elements | |
@status = result["Status"].text | |
@request_id = result["RequestId"].text | |
@success = false | |
if @status == "Success" | |
@success = true | |
@transaction_id = result["TransactionResponse"].elements['TransactionId'].text | |
end | |
redirect_to :controller => :payment, :action => :receipt, :id => @transaction_id | |
end | |
def receipt | |
# Pull transaction data back from Amazon | |
call = { 'Action' => 'GetTransaction', 'TransactionId' => params[:id] } | |
@transaction_data = AWS_FPS::Query.do(call) | |
# Parse the response | |
response = REXML::Document.new(@transaction_data) | |
result = response.root.elements | |
@status = result["Status"].text | |
@request_id = result["RequestId"].text | |
@status == "Success" ? @success = true : @success = false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment