Skip to content

Commit

Permalink
Add Request Refund
Browse files Browse the repository at this point in the history
  • Loading branch information
jhliberty committed Dec 9, 2011
1 parent 29657b1 commit 76c3e33
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
69 changes: 67 additions & 2 deletions lib/paypal/recurring/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Base
attr_accessor :cancel_url
attr_accessor :currency
attr_accessor :description
attr_accessor :note
attr_accessor :email
attr_accessor :failed
attr_accessor :frequency
Expand All @@ -21,6 +22,11 @@ class Base
attr_accessor :return_url
attr_accessor :start_at
attr_accessor :token
attr_accessor :transaction_id
attr_accessor :item_category
attr_accessor :item_name
attr_accessor :item_amount
attr_accessor :item_quantity
attr_accessor :trial_frequency
attr_accessor :trial_length
attr_accessor :trial_period
Expand Down Expand Up @@ -117,7 +123,17 @@ def checkout_details
# response.completed? && response.approved?
#
def request_payment
params = collect(:amount, :return_url, :cancel_url, :ipn_url, :currency, :description, :payer_id, :token, :reference).merge(:payment_action => "Sale")
params = collect(
:amount,
:return_url,
:cancel_url,
:ipn_url,
:currency,
:description,
:payer_id,
:token,
:reference
).merge(:payment_action => "Sale")
request.run(:payment, params)
end

Expand Down Expand Up @@ -146,9 +162,58 @@ def request_payment
# response = ppr.create_recurring_profile
#
def create_recurring_profile
params = collect(:amount, :initial_amount, :initial_amount_action, :currency, :description, :payer_id, :token, :reference, :start_at, :failed, :outstanding, :ipn_url, :frequency, :period, :email, :trial_length, :trial_period, :trial_frequency)
params = collect(
:amount,
:initial_amount,
:initial_amount_action,
:currency,
:description,
:payer_id,
:token,
:reference,
:start_at,
:failed,
:outstanding,
:ipn_url,
:frequency,
:period,
:email,
:trial_length,
:trial_period,
:trial_frequency
)
request.run(:create_profile, params)
end

# Update a recurring billing profile.
#
# ppr = PayPal::Recurring.new({
# :amount => "99.00",
# :currency => "USD",
# :description => "Awesome - Monthly Subscription",
# :note => "Changed plan to Gold",
# :ipn_url => "http://example.com/paypal/ipn",
# :reference => "1234",
# :profile_id => "I-VCEL6TRG35CU",
# :start_at => Time.now,
# :outstanding => :next_billing
# })
#
# response = ppr.update_recurring_profile
#
def update_recurring_profile
params = collect(:amount,
:currency,
:description,
:note,
:profile_id,
:reference,
:start_at,
:outstanding,
:ipn_url,
:email)
request.run(:update_profile, params)
end

# Retrieve information about existing recurring profile.
#
Expand Down
9 changes: 9 additions & 0 deletions lib/paypal/recurring/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Request
:create_profile => "CreateRecurringPaymentsProfile",
:profile => "GetRecurringPaymentsProfileDetails",
:manage_profile => "ManageRecurringPaymentsProfileStatus"
:manage_profile => "ManageRecurringPaymentsProfileStatus",
:update_profile => "UpdateRecurringPaymentsProfile",
:refund => "RefundTransaction"
}

INITIAL_AMOUNT_ACTIONS = {
Expand Down Expand Up @@ -70,10 +73,12 @@ class Request
:period => "BILLINGPERIOD",
:profile_id => "PROFILEID",
:reference => ["PROFILEREFERENCE", "PAYMENTREQUEST_0_CUSTOM", "PAYMENTREQUEST_0_INVNUM"],
:refund_type => "REFUNDTYPE",
:return_url => "RETURNURL",
:signature => "SIGNATURE",
:start_at => "PROFILESTARTDATE",
:token => "TOKEN",
:transaction_id => "TRANSACTIONID",
:trial_frequency => "TRIALBILLINGFREQUENCY",
:trial_length => "TRIALTOTALBILLINGCYCLES",
:trial_period => "TRIALBILLINGPERIOD",
Expand Down Expand Up @@ -178,6 +183,10 @@ def build_start_at(value) # :nodoc:
def build_outstanding(value) # :nodoc:
OUTSTANDING.fetch(value.to_sym, value) if value
end

def build_refundtype(value) # :nodoc:
REFUNDTYPE.fetch(value.to_sym, value) if value
end

def build_action(value) # :nodoc:
ACTIONS.fetch(value.to_sym, value) if value
Expand Down

0 comments on commit 76c3e33

Please sign in to comment.