Created
June 18, 2012 05:25
-
-
Save aileron/2946980 to your computer and use it in GitHub Desktop.
Gem (active_paypal_adaptive_payment) を使用した事前承認支払いのコントローラ サンプル
This file contains hidden or 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 PaypalController < ApplicationController | |
def approval | |
raise "not loggined" unless login_user | |
@approval = Approval.find_or_create_by :user_id => login_user.id, :item_id => params[:item_id] | |
raise "subscribed!" if @approval.key | |
start_date = Time.now.gmtime | |
end_date = 3.months.from_now.gmttime | |
r= PaypalGateway.preapprove_payment :return_url => url_for(:action=> :complete, :only_path=> false), | |
:cancel_url => url_for(:action=> :cancel, :only_path=> false), | |
:start_date => start_date, | |
:end_date => end_date, | |
:currency_code =>"JPY", | |
:max_amount => "20000", | |
:max_number_of_payments => "300" | |
# :ipn_url => url_for(:action=> :ipn, :only_path=> false), | |
raise "error" unless r["preapproval_key"] | |
@approval.key = r["preapproval_key"] | |
@approval.save | |
redirect_to PaypalGateway.redirect_pre_approval_url_for(r["preapproval_key"]) | |
end | |
def complete | |
@approval = Approval.where(:item_id=> params[:item_id], :user_id=> login_user.id).one | |
r = PaypalGateway.preapproval_details_for :preapproval_key => @approval.key | |
@approval.approved = r["approved"] | |
@approval.save | |
redirect_to item_path(params[:item_id]) | |
end | |
def cancel | |
end | |
def ipn | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment