diff --git a/lib/paypal/recurring/base.rb b/lib/paypal/recurring/base.rb index 9c79b63..b528b1a 100644 --- a/lib/paypal/recurring/base.rb +++ b/lib/paypal/recurring/base.rb @@ -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 @@ -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, @@ -199,7 +200,7 @@ def create_recurring_profile ) request.run(:create_profile, params) end - + # Update a recurring billing profile. # # ppr = PayPal::Recurring.new({ @@ -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 @@ -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({ @@ -258,7 +262,7 @@ def refund :refund_type, :amount, :currency, - :note, + :note ) request.run(:refund, params) diff --git a/lib/paypal/recurring/request.rb b/lib/paypal/recurring/request.rb index aa5fa67..79aa49c 100644 --- a/lib/paypal/recurring/request.rb +++ b/lib/paypal/recurring/request.rb @@ -29,7 +29,7 @@ class Request :monthly => "Month", :yearly => "Year" } - + TRIAL_PERIOD = { :daily => "Day", :weekly => "Weekly", @@ -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 = { @@ -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 @@ -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 diff --git a/lib/paypal/recurring/response/refund.rb b/lib/paypal/recurring/response/refund.rb index c010cb3..20335ab 100644 --- a/lib/paypal/recurring/response/refund.rb +++ b/lib/paypal/recurring/response/refund.rb @@ -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? diff --git a/spec/fixtures/refund/failure.yml b/spec/fixtures/refund/failure.yml new file mode 100644 index 0000000..28de394 --- /dev/null +++ b/spec/fixtures/refund/failure.yml @@ -0,0 +1,38 @@ +--- +http_interactions: +- request: + method: post + uri: https://api-3t.sandbox.paypal.com/nvp + body: + encoding: US-ASCII + string: USER=fnando.vieira%2Bseller_api1.gmail.com&PWD=PRTZZX6JDACB95SA&SIGNATURE=AJnjtLN0ozBP-BF2ZJrj5sfbmGAxAnf5tev1-MgK5Z8IASmtj-Fw.5pt&VERSION=72.0&TRANSACTIONID=4GP25924UB013401J&PROFILEREFERENCE=12345&PAYMENTREQUEST_0_CUSTOM=12345&PAYMENTREQUEST_0_INVNUM=12345&REFUNDTYPE=Full&PAYMENTREQUEST_0_AMT=9.00&AMT=9.00&PAYMENTREQUEST_0_CURRENCYCODE=BRL&CURRENCYCODE=BRL&METHOD=RefundTransaction + headers: + accept: + - ! '*/*' + user-agent: + - PayPal::Recurring/1.0.0 + content-type: + - application/x-www-form-urlencoded + connection: + - close + response: + status: + code: 200 + message: OK + headers: + date: + - Mon, 23 Apr 2012 10:55:15 GMT + server: + - Apache + content-length: + - '262' + connection: + - close + content-type: + - text/plain; charset=utf-8 + body: + encoding: US-ASCII + string: TIMESTAMP=2012%2d04%2d23T10%3a55%3a17Z&CORRELATIONID=89f1590a7f107&ACK=Failure&VERSION=72%2e0&BUILD=2808426&L_ERRORCODE0=10009&L_SHORTMESSAGE0=Transaction%20refused&L_LONGMESSAGE0=This%20transaction%20has%20already%20been%20fully%20refunded&L_SEVERITYCODE0=Error + http_version: '1.1' + recorded_at: Mon, 23 Apr 2012 10:55:17 GMT +recorded_with: VCR 2.1.0 diff --git a/spec/fixtures/refund/success.yml b/spec/fixtures/refund/success.yml new file mode 100644 index 0000000..853fe35 --- /dev/null +++ b/spec/fixtures/refund/success.yml @@ -0,0 +1,38 @@ +--- +http_interactions: +- request: + method: post + uri: https://api-3t.sandbox.paypal.com/nvp + body: + encoding: US-ASCII + string: USER=fnando.vieira%2Bseller_api1.gmail.com&PWD=PRTZZX6JDACB95SA&SIGNATURE=AJnjtLN0ozBP-BF2ZJrj5sfbmGAxAnf5tev1-MgK5Z8IASmtj-Fw.5pt&VERSION=72.0&TRANSACTIONID=4GP25924UB013401J&PROFILEREFERENCE=12345&PAYMENTREQUEST_0_CUSTOM=12345&PAYMENTREQUEST_0_INVNUM=12345&REFUNDTYPE=Full&PAYMENTREQUEST_0_AMT=9.00&AMT=9.00&PAYMENTREQUEST_0_CURRENCYCODE=BRL&CURRENCYCODE=BRL&METHOD=RefundTransaction + headers: + accept: + - ! '*/*' + user-agent: + - PayPal::Recurring/1.0.0 + content-type: + - application/x-www-form-urlencoded + connection: + - close + response: + status: + code: 200 + message: OK + headers: + date: + - Mon, 23 Apr 2012 10:53:04 GMT + server: + - Apache + content-length: + - '251' + connection: + - close + content-type: + - text/plain; charset=utf-8 + body: + encoding: US-ASCII + string: REFUNDTRANSACTIONID=5MM61417CA010574T&FEEREFUNDAMT=0%2e71&GROSSREFUNDAMT=9%2e00&NETREFUNDAMT=8%2e29&CURRENCYCODE=BRL&TOTALREFUNDEDAMOUNT=9%2e00&TIMESTAMP=2012%2d04%2d23T10%3a53%3a10Z&CORRELATIONID=b902163c2d526&ACK=Success&VERSION=72%2e0&BUILD=2808426 + http_version: '1.1' + recorded_at: Mon, 23 Apr 2012 10:53:10 GMT +recorded_with: VCR 2.1.0 diff --git a/spec/paypal/response/refund_spec.rb b/spec/paypal/response/refund_spec.rb new file mode 100644 index 0000000..a092e5a --- /dev/null +++ b/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