Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
Fixed broken refund feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Apr 23, 2012
1 parent 6d33c32 commit db401bc
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 59 deletions.
92 changes: 48 additions & 44 deletions lib/paypal/recurring/base.rb
Expand Up @@ -129,20 +129,21 @@ def checkout_details
#
def request_payment
params = collect(
:amount,
:return_url,
:cancel_url,
:ipn_url,
:currency,
:description,
:payer_id,
:token,
:reference,
:item_category,
:item_name,
:item_amount,
:item_quantity
).merge(:payment_action => "Sale")
:amount,
:return_url,
:cancel_url,
:ipn_url,
:currency,
:description,
:payer_id,
:token,
:reference,
:item_category,
:item_name,
:item_amount,
:item_quantity
).merge(:payment_action => "Sale")

request.run(:payment, params)
end

Expand Down Expand Up @@ -173,23 +174,23 @@ def request_payment
#
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,
: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,
:trial_amount,
:item_category,
Expand All @@ -199,7 +200,7 @@ def create_recurring_profile
)
request.run(:create_profile, params)
end

# Update a recurring billing profile.
#
# ppr = PayPal::Recurring.new({
Expand All @@ -217,16 +218,19 @@ def create_recurring_profile
# response = ppr.update_recurring_profile
#
def update_recurring_profile
params = collect(:amount,
:currency,
:description,
:note,
:profile_id,
:reference,
:start_at,
:outstanding,
:ipn_url,
:email)
params = collect(
:amount,
:currency,
:description,
:note,
:profile_id,
:reference,
:start_at,
:outstanding,
:ipn_url,
:email
)

request.run(:update_profile, params)
end

Expand All @@ -238,7 +242,7 @@ def update_recurring_profile
def profile
request.run(:profile, :profile_id => profile_id)
end

# Request a refund.
# ppr = PayPal::Recurring.new(:profile_id => "I-VCEL6TRG35CU")
# ppr.refund({
Expand All @@ -258,7 +262,7 @@ def refund
:refund_type,
:amount,
:currency,
:note,
:note
)

request.run(:refund, params)
Expand Down
18 changes: 9 additions & 9 deletions lib/paypal/recurring/request.rb
Expand Up @@ -29,7 +29,7 @@ class Request
:monthly => "Month",
:yearly => "Year"
}

TRIAL_PERIOD = {
:daily => "Day",
:weekly => "Weekly",
Expand All @@ -41,12 +41,12 @@ class Request
:next_billing => "AddToNextBilling",
:no_auto => "NoAutoBill"
}
REFUNDTYPE = {

REFUND_TYPE = {
:full => "Full",
:partial => "Partial",
:external => "ExternalDispute",
:other => "Other",
:other => "Other"
}

ATTRIBUTES = {
Expand Down Expand Up @@ -176,7 +176,7 @@ def normalize_params(params)
def build_period(value) # :nodoc:
PERIOD.fetch(value.to_sym, value) if value
end

def build_trial_period(value)
TRIAL_PERIOD.fetch(value.to_sym, value) if value
end
Expand All @@ -188,10 +188,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_refund_type(value) # :nodoc:
REFUND_TYPE.fetch(value.to_sym, value) if value
end

def build_action(value) # :nodoc:
ACTIONS.fetch(value.to_sym, value) if value
Expand Down
12 changes: 6 additions & 6 deletions lib/paypal/recurring/response/refund.rb
Expand Up @@ -4,14 +4,14 @@ module Response
class Refund < Base
mapping(
:transaction_id => :REFUNDTRANSACTIONID,
:feerefund => :FEEREFUNDAMT,
:grossrefund => :GROSSREFUNDAMT,
:netrefund => :NETREFUNDAMT,
:amount => :TOTALREFUNDEDAMT,
:cunnrecy => :CURRENCYCODE,
:fee_amount => :FEEREFUNDAMT,
:gross_amount => :GROSSREFUNDAMT,
:net_amount => :NETREFUNDAMT,
:amount => :TOTALREFUNDEDAMOUNT,
:currency => :CURRENCYCODE,
:info => :REFUNDINFO,
:status => :REFUNDSTATUS,
:pendingreason => :PENDINGREASON,
:pending_reason => :PENDINGREASON
)

def completed?
Expand Down
38 changes: 38 additions & 0 deletions spec/fixtures/refund/failure.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions spec/fixtures/refund/success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions spec/paypal/response/refund_spec.rb
@@ -0,0 +1,35 @@
require "spec_helper"

describe PayPal::Recurring::Response::Profile do
let(:paypal) {
PayPal::Recurring.new({
:profile_id => "I-1BASBJ9C9WBS",
:transaction_id => "4GP25924UB013401J",
:reference => "12345",
:refund_type => :full,
:amount => "9.00",
:currency => "BRL"
})
}

context "when successful" do
use_vcr_cassette "refund/success"
subject { paypal.refund }

its(:transaction_id) { should eql("5MM61417CA010574T") }
its(:fee_amount) { should eql("0.71") }
its(:gross_amount) { should eql("9.00") }
its(:net_amount) { should eql("8.29") }
its(:amount) { should eql("9.00") }
its(:currency) { should eql("BRL") }
its(:status) { should eql("BRL") }
its(:pending_reason) { should eql("BRL") }
end

context "when failure" do
use_vcr_cassette "refund/failure"
subject { paypal.refund }

its(:errors) { should have(1).items }
end
end

0 comments on commit db401bc

Please sign in to comment.